This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/skywalking-banyandb-java-client.git
The following commit(s) were added to refs/heads/main by this push:
new 73553cb Adopt the status field which is changed to the string type
(#77)
73553cb is described below
commit 73553cbd754b45d29b29553786fd653ddda8ac24
Author: Gao Hongtao <[email protected]>
AuthorDate: Sat Jan 11 20:50:13 2025 +0800
Adopt the status field which is changed to the string type (#77)
---
CHANGES.md | 3 ++
.../banyandb/v1/client/BanyanDBClient.java | 28 +++++++++++--
.../v1/client/MeasureBulkWriteProcessor.java | 8 +++-
.../v1/client/StreamBulkWriteProcessor.java | 8 +++-
.../banyandb/v1/client/util/StatusUtil.java | 42 +++++++++++++++++++
src/main/proto/banyandb/v1/banyandb-common.proto | 26 ++++++++++++
src/main/proto/banyandb/v1/banyandb-measure.proto | 2 +-
src/main/proto/banyandb/v1/banyandb-model.proto | 1 +
src/main/proto/banyandb/v1/banyandb-stream.proto | 2 +-
.../banyandb/v1/client/BanyanDBClientTestCI.java | 2 +-
.../banyandb/v1/client/ITBanyanDBCommonTests.java | 49 ++++++++++++++++++++++
11 files changed, 162 insertions(+), 9 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index eb27d36..8543da4 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,11 +3,14 @@ Changes by Version
Release Notes.
0.8.0
+------------------
### Features
* Bump up the API to support the index mode of Measure.
* Bump up the API to support the new property.
+* Bump up the API to adopt the status field which is changed to the string
type due to the compatibility issue.
+* Bump up the API to support getting the API version.
0.7.0
------------------
diff --git
a/src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java
b/src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java
index bf52a73..912a14f 100644
--- a/src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java
+++ b/src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java
@@ -34,12 +34,14 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Group;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Metadata;
+import org.apache.skywalking.banyandb.common.v1.ServiceGrpc;
import
org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.TopNAggregation;
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Measure;
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Stream;
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.IndexRule;
import
org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.IndexRuleBinding;
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Subject;
+import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty;
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.Property;
import
org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest.Strategy;
@@ -75,6 +77,8 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
+
+import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
import org.apache.skywalking.banyandb.v1.client.util.TimeUtils;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -227,7 +231,10 @@ public class BanyanDBClient implements Closeable {
@Override
public void onNext(BanyandbStream.WriteResponse
writeResponse) {
- switch (writeResponse.getStatus()) {
+ BanyandbModel.Status status =
StatusUtil.convertStringToStatus(writeResponse.getStatus());
+ switch (status) {
+ case STATUS_SUCCEED:
+ break;
case STATUS_INVALID_TIMESTAMP:
responseException = new
InvalidArgumentException(
"Invalid timestamp: " +
streamWrite.getTimestamp(), null, Status.Code.INVALID_ARGUMENT, false);
@@ -250,11 +257,10 @@ public class BanyanDBClient implements Closeable {
responseException = new
InvalidArgumentException(
"Expired revision: " +
metadata.getModRevision(), null, Status.Code.INVALID_ARGUMENT, true);
break;
- case STATUS_INTERNAL_ERROR:
+ default:
responseException = new
InternalException(
- "Internal error occurs in
server", null, Status.Code.INTERNAL, true);
+ String.format("Internal error
(%s) occurs in server", writeResponse.getStatus()), null, Status.Code.INTERNAL,
true);
break;
- default:
}
}
@@ -1064,6 +1070,20 @@ public class BanyanDBClient implements Closeable {
return this.metadataCache.updateMeasureFromSever(group, name);
}
+ /**
+ * Get the API version of the server
+ *
+ * @return the API version of the server
+ * @throws BanyanDBException if the server is not reachable
+ */
+ public BanyandbCommon.APIVersion getAPIVersion() throws BanyanDBException {
+ ServiceGrpc.ServiceBlockingStub stub =
ServiceGrpc.newBlockingStub(this.channel);
+ return HandleExceptionsWith.callAndTranslateApiException(() -> {
+ BanyandbCommon.GetAPIVersionResponse resp =
stub.getAPIVersion(BanyandbCommon.GetAPIVersionRequest.getDefaultInstance());
+ return resp.getVersion();
+ });
+ }
+
@Override
public void close() throws IOException {
connectionEstablishLock.lock();
diff --git
a/src/main/java/org/apache/skywalking/banyandb/v1/client/MeasureBulkWriteProcessor.java
b/src/main/java/org/apache/skywalking/banyandb/v1/client/MeasureBulkWriteProcessor.java
index 10d663f..fbc71a7 100644
---
a/src/main/java/org/apache/skywalking/banyandb/v1/client/MeasureBulkWriteProcessor.java
+++
b/src/main/java/org/apache/skywalking/banyandb/v1/client/MeasureBulkWriteProcessor.java
@@ -24,7 +24,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
import org.apache.skywalking.banyandb.measure.v1.BanyandbMeasure;
import org.apache.skywalking.banyandb.measure.v1.MeasureServiceGrpc;
+import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
import
org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
+import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
import javax.annotation.concurrent.ThreadSafe;
@@ -69,7 +71,10 @@ public class MeasureBulkWriteProcessor extends
AbstractBulkWriteProcessor<Banyan
@Override
public void onNext(BanyandbMeasure.WriteResponse writeResponse) {
- switch (writeResponse.getStatus()) {
+ BanyandbModel.Status status =
StatusUtil.convertStringToStatus(writeResponse.getStatus());
+ switch (status) {
+ case STATUS_SUCCEED:
+ break;
case STATUS_EXPIRED_SCHEMA:
BanyandbCommon.Metadata metadata =
writeResponse.getMetadata();
String schemaKey = metadata.getGroup() + "." +
metadata.getName();
@@ -84,6 +89,7 @@ public class MeasureBulkWriteProcessor extends
AbstractBulkWriteProcessor<Banyan
}
break;
default:
+ log.warn("Write measure failed with status: {}",
status);
}
}
diff --git
a/src/main/java/org/apache/skywalking/banyandb/v1/client/StreamBulkWriteProcessor.java
b/src/main/java/org/apache/skywalking/banyandb/v1/client/StreamBulkWriteProcessor.java
index 15323f7..ce2ab61 100644
---
a/src/main/java/org/apache/skywalking/banyandb/v1/client/StreamBulkWriteProcessor.java
+++
b/src/main/java/org/apache/skywalking/banyandb/v1/client/StreamBulkWriteProcessor.java
@@ -23,9 +23,11 @@ import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
+import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
import org.apache.skywalking.banyandb.stream.v1.StreamServiceGrpc;
import org.apache.skywalking.banyandb.stream.v1.BanyandbStream;
import
org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
+import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
import javax.annotation.concurrent.ThreadSafe;
@@ -70,7 +72,10 @@ public class StreamBulkWriteProcessor extends
AbstractBulkWriteProcessor<Banyand
@Override
public void onNext(BanyandbStream.WriteResponse
writeResponse) {
- switch (writeResponse.getStatus()) {
+ BanyandbModel.Status status =
StatusUtil.convertStringToStatus(writeResponse.getStatus());
+ switch (status) {
+ case STATUS_SUCCEED:
+ break;
case STATUS_EXPIRED_SCHEMA:
BanyandbCommon.Metadata metadata =
writeResponse.getMetadata();
String schemaKey = metadata.getGroup() + "." +
metadata.getName();
@@ -85,6 +90,7 @@ public class StreamBulkWriteProcessor extends
AbstractBulkWriteProcessor<Banyand
}
break;
default:
+ log.warn("Write stream failed with status:
{}", status);
}
}
diff --git
a/src/main/java/org/apache/skywalking/banyandb/v1/client/util/StatusUtil.java
b/src/main/java/org/apache/skywalking/banyandb/v1/client/util/StatusUtil.java
new file mode 100644
index 0000000..21aff7c
--- /dev/null
+++
b/src/main/java/org/apache/skywalking/banyandb/v1/client/util/StatusUtil.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.banyandb.v1.client.util;
+
+import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
+
+/**
+ * Status is a utility class for converting between strings and Status enums.
+ */
+public class StatusUtil {
+
+ /**
+ * Convert a Status enum to a string.
+ *
+ * @param statusString the string to convert
+ * @return the Status enum
+ */
+ public static BanyandbModel.Status convertStringToStatus(String
statusString) {
+ try {
+ return BanyandbModel.Status.valueOf(statusString);
+ } catch (IllegalArgumentException e) {
+ // Return a specific enum value for unknown strings
+ return BanyandbModel.Status.STATUS_UNSPECIFIED;
+ }
+ }
+}
diff --git a/src/main/proto/banyandb/v1/banyandb-common.proto
b/src/main/proto/banyandb/v1/banyandb-common.proto
index 67e64ba..75aa950 100644
--- a/src/main/proto/banyandb/v1/banyandb-common.proto
+++ b/src/main/proto/banyandb/v1/banyandb-common.proto
@@ -115,3 +115,29 @@ message Tag {
// value is the value of the tag.
string value = 2;
}
+
+
+// APIVersion is the version of the API
+message APIVersion {
+ // version is the version of the API
+ string version = 1;
+ // revision is the commit hash of the API
+ string revision = 2;
+}
+
+// GetAPIVersionRequest is the request for GetAPIVersion
+message GetAPIVersionRequest {
+ // empty
+}
+
+// GetAPIVersionResponse is the response for GetAPIVersion
+message GetAPIVersionResponse {
+ // version is the version of the API
+ APIVersion version = 1;
+}
+
+// Service is the service for the API
+service Service {
+ // GetAPIVersion returns the version of the API
+ rpc GetAPIVersion(GetAPIVersionRequest) returns (GetAPIVersionResponse);
+}
\ No newline at end of file
diff --git a/src/main/proto/banyandb/v1/banyandb-measure.proto
b/src/main/proto/banyandb/v1/banyandb-measure.proto
index 8294081..69d533c 100644
--- a/src/main/proto/banyandb/v1/banyandb-measure.proto
+++ b/src/main/proto/banyandb/v1/banyandb-measure.proto
@@ -169,7 +169,7 @@ message WriteResponse {
// the message_id from request.
uint64 message_id = 1 [(validate.rules).uint64.gt = 0];
// status indicates the request processing result
- model.v1.Status status = 2 [(validate.rules).enum.defined_only = true];
+ string status = 2;
// the metadata from request when request fails
common.v1.Metadata metadata = 3;
}
diff --git a/src/main/proto/banyandb/v1/banyandb-model.proto
b/src/main/proto/banyandb/v1/banyandb-model.proto
index 4aa8fbf..149fcbe 100644
--- a/src/main/proto/banyandb/v1/banyandb-model.proto
+++ b/src/main/proto/banyandb/v1/banyandb-model.proto
@@ -216,4 +216,5 @@ enum Status {
STATUS_NOT_FOUND = 3;
STATUS_EXPIRED_SCHEMA = 4;
STATUS_INTERNAL_ERROR = 5;
+ STATUS_DISK_FULL = 6;
}
diff --git a/src/main/proto/banyandb/v1/banyandb-stream.proto
b/src/main/proto/banyandb/v1/banyandb-stream.proto
index 0f29944..611cae3 100644
--- a/src/main/proto/banyandb/v1/banyandb-stream.proto
+++ b/src/main/proto/banyandb/v1/banyandb-stream.proto
@@ -102,7 +102,7 @@ message WriteResponse {
// the message_id from request.
uint64 message_id = 1 [(validate.rules).uint64.gt = 0];
// status indicates the request processing result
- model.v1.Status status = 2 [(validate.rules).enum.defined_only = true];
+ string status = 2;
// the metadata from request when request fails
common.v1.Metadata metadata = 3;
}
diff --git
a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
index 5ccaacc..a73a404 100644
---
a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
+++
b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
@@ -31,7 +31,7 @@ import java.io.IOException;
public class BanyanDBClientTestCI {
private static final String REGISTRY = "ghcr.io";
private static final String IMAGE_NAME = "apache/skywalking-banyandb";
- private static final String TAG =
"1d4ddc3d42103dc3364ad729403c4154690be195";
+ private static final String TAG =
"362d68ed79c532e6d61dd6674cce38090caa0da7";
private static final String IMAGE = REGISTRY + "/" + IMAGE_NAME + ":" +
TAG;
diff --git
a/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBCommonTests.java
b/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBCommonTests.java
new file mode 100644
index 0000000..d82c0bd
--- /dev/null
+++
b/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBCommonTests.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.banyandb.v1.client;
+
+import com.google.common.base.Strings;
+import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
+import
org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class ITBanyanDBCommonTests extends BanyanDBClientTestCI {
+ @Before
+ public void setUp() throws IOException, BanyanDBException,
InterruptedException {
+ super.setUpConnection();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ this.closeClient();
+ }
+
+ @Test
+ public void test_GetAPIVersion() throws BanyanDBException {
+ BanyandbCommon.APIVersion version = this.client.getAPIVersion();
+ Assert.assertEquals("0.8", version.getVersion());
+ Assert.assertFalse(Strings.isNullOrEmpty(version.getRevision()));
+ }
+
+}