Skip to content

Commit f7cb84b

Browse files
authored
Bump up the API to support the new property (#76)
1 parent 546fa54 commit f7cb84b

File tree

11 files changed

+182
-305
lines changed

11 files changed

+182
-305
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Release Notes.
77
### Features
88

99
* Bump up the API to support the index mode of Measure.
10+
* Bump up the API to support the new property.
1011

1112
0.7.0
1213
------------------

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -496,35 +496,27 @@ Property property = Property.create("default", "sw", "ui_template")
496496
this.client.apply(property); //created:false tagsNum:1
497497
```
498498

499-
The property supports setting TTL.
500-
501-
```java
502-
Property property = Property.create("default", "sw", "temp_date")
503-
.addTag(TagAndValue.newStringTag("state", "failed"))
504-
.ttl("30m")
505-
.build();
506-
this.client.apply(property); //created:false tagsNum:1 lease_id:1
507-
```
508-
The property's TTL can be extended by calling `Client.keepAliveProperty`,
509-
510-
```java
511-
this.client.keepAliveProperty(1); //lease_id:1
512-
```
513-
514-
The property's live time is reset to 30 minutes.
515-
516499
### Query
517500

518501
Property can be queried via `Client.findProperty`,
519502

520503
```java
521-
Property gotProperty = this.client.findProperty("default", "sw", "ui_template");
504+
BanyandbProperty.QueryResponse resp = client.query(BanyandbProperty.QueryRequest.newBuilder()
505+
.addGroups("default")
506+
.setContainer("sw")
507+
.addIds("ui_template")
508+
.build());
522509
```
523510

524511
The query operation could filter tags,
525512

526513
```java
527-
Property gotProperty = this.client.findProperty("default", "sw", "ui_template", "state");
514+
BanyandbProperty.QueryResponse resp = client.query(BanyandbProperty.QueryRequest.newBuilder()
515+
.addGroups("default")
516+
.setContainer("sw")
517+
.addIds("ui_template")
518+
.addTagProjection("state")
519+
.build());
528520
```
529521

530522
### Delete

src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import org.apache.skywalking.banyandb.v1.client.metadata.IndexRuleMetadataRegistry;
6161
import org.apache.skywalking.banyandb.v1.client.metadata.MeasureMetadataRegistry;
6262
import org.apache.skywalking.banyandb.v1.client.metadata.MetadataCache;
63-
import org.apache.skywalking.banyandb.v1.client.metadata.PropertyStore;
6463
import org.apache.skywalking.banyandb.v1.client.metadata.ResourceExist;
6564
import org.apache.skywalking.banyandb.v1.client.metadata.StreamMetadataRegistry;
6665
import org.apache.skywalking.banyandb.v1.client.metadata.TopNAggregationMetadataRegistry;
@@ -830,50 +829,14 @@ public ApplyResponse apply(Property property, Strategy strategy) throws
830829
}
831830

832831
/**
833-
* Find property
832+
* Query properties
834833
*
835-
* @param group group of the metadata
836-
* @param name name of the metadata
837-
* @param id identity of the property
838-
* @param tags tags to be returned
839-
* @return property if it can be found
840-
*/
841-
public Property findProperty(String group, String name, String id, String... tags) throws BanyanDBException {
842-
PropertyStore store = new PropertyStore(checkNotNull(this.channel));
843-
try {
844-
return store.get(group, name, id, tags);
845-
} catch (BanyanDBException ex) {
846-
if (ex.getStatus().equals(Status.Code.NOT_FOUND)) {
847-
return null;
848-
}
849-
throw ex;
850-
}
851-
}
852-
853-
/**
854-
* List Properties
855-
*
856-
* @param group group of the metadata
857-
* @param name name of the metadata
858-
* @return all properties belonging to the group and the name
859-
*/
860-
public List<Property> findProperties(String group, String name) throws BanyanDBException {
861-
return findProperties(group, name, null, null);
862-
863-
}
864-
865-
/**
866-
* List Properties
867-
*
868-
* @param group group of the metadata
869-
* @param name name of the metadata
870-
* @param ids identities of the properties
871-
* @param tags tags to be returned
872-
* @return all properties belonging to the group and the name
834+
* @param request query request
835+
* @return query response
873836
*/
874-
public List<Property> findProperties(String group, String name, List<String> ids, List<String> tags) throws BanyanDBException {
837+
public BanyandbProperty.QueryResponse query(BanyandbProperty.QueryRequest request) throws BanyanDBException {
875838
PropertyStore store = new PropertyStore(checkNotNull(this.channel));
876-
return store.list(group, name, ids, tags);
839+
return store.query(request);
877840
}
878841

879842
/**
@@ -882,23 +845,12 @@ public List<Property> findProperties(String group, String name, List<String> ids
882845
* @param group group of the metadata
883846
* @param name name of the metadata
884847
* @param id identity of the property
885-
* @param tags tags to be deleted. If null, the property is deleted
886848
* @return if this property has been deleted
887849
*/
888-
public DeleteResponse deleteProperty(String group, String name, String id, String... tags) throws
850+
public DeleteResponse deleteProperty(String group, String name, String id) throws
889851
BanyanDBException {
890852
PropertyStore store = new PropertyStore(checkNotNull(this.channel));
891-
return store.delete(group, name, id, tags);
892-
}
893-
894-
/**
895-
* Keep alive the property
896-
*
897-
* @param leaseId lease id of the property
898-
*/
899-
public void keepAliveProperty(long leaseId) throws BanyanDBException {
900-
PropertyStore store = new PropertyStore(checkNotNull(this.channel));
901-
store.keepAlive(leaseId);
853+
return store.delete(group, name, id);
902854
}
903855

904856
/**
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.banyandb.v1.client;
20+
21+
import io.grpc.Channel;
22+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty;
23+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest;
24+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest.Strategy;
25+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyResponse;
26+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.DeleteResponse;
27+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.Property;
28+
import org.apache.skywalking.banyandb.property.v1.PropertyServiceGrpc;
29+
import org.apache.skywalking.banyandb.v1.client.grpc.HandleExceptionsWith;
30+
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
31+
32+
public class PropertyStore {
33+
private final PropertyServiceGrpc.PropertyServiceBlockingStub stub;
34+
35+
public PropertyStore(Channel channel) {
36+
this.stub = PropertyServiceGrpc.newBlockingStub(channel);
37+
}
38+
39+
public ApplyResponse apply(Property payload) throws BanyanDBException {
40+
return apply(payload, Strategy.STRATEGY_MERGE);
41+
}
42+
43+
public ApplyResponse apply(Property payload, Strategy strategy) throws BanyanDBException {
44+
BanyandbProperty.ApplyRequest.Strategy s = BanyandbProperty.ApplyRequest.Strategy.STRATEGY_MERGE;
45+
ApplyRequest r = BanyandbProperty.ApplyRequest.newBuilder()
46+
.setProperty(payload)
47+
.setStrategy(strategy)
48+
.build();
49+
return HandleExceptionsWith.callAndTranslateApiException(() ->
50+
this.stub.apply(r));
51+
}
52+
53+
public DeleteResponse delete(String group, String name, String id) throws BanyanDBException {
54+
return HandleExceptionsWith.callAndTranslateApiException(() ->
55+
this.stub.delete(BanyandbProperty.DeleteRequest.newBuilder()
56+
.setGroup(group)
57+
.setContainer(name)
58+
.setId(id)
59+
.build()));
60+
}
61+
62+
public BanyandbProperty.QueryResponse query(BanyandbProperty.QueryRequest req) throws BanyanDBException {
63+
return HandleExceptionsWith.callAndTranslateApiException(() ->
64+
this.stub.query(req));
65+
}
66+
}

src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/PropertyStore.java

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/main/proto/banyandb/v1/banyandb-common.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum Catalog {
2828
CATALOG_UNSPECIFIED = 0;
2929
CATALOG_STREAM = 1;
3030
CATALOG_MEASURE = 2;
31+
CATALOG_PROPERTY = 3;
3132
}
3233

3334
// Metadata is for multi-tenant, multi-model use
@@ -61,9 +62,9 @@ message ResourceOpts {
6162
// shard_num is the number of shards
6263
uint32 shard_num = 1 [(validate.rules).uint32.gt = 0];
6364
// segment_interval indicates the length of a segment
64-
IntervalRule segment_interval = 2 [(validate.rules).message.required = true];
65+
IntervalRule segment_interval = 2;
6566
// ttl indicates time to live, how long the data will be cached
66-
IntervalRule ttl = 3 [(validate.rules).message.required = true];
67+
IntervalRule ttl = 3;
6768
}
6869

6970
// Group is an internal object for Group management

0 commit comments

Comments
 (0)