34
34
import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon ;
35
35
import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon .Group ;
36
36
import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon .Metadata ;
37
+ import org .apache .skywalking .banyandb .common .v1 .ServiceGrpc ;
37
38
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .TopNAggregation ;
38
39
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Measure ;
39
40
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Stream ;
40
41
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .IndexRule ;
41
42
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .IndexRuleBinding ;
42
43
import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Subject ;
44
+ import org .apache .skywalking .banyandb .model .v1 .BanyandbModel ;
43
45
import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty ;
44
46
import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty .Property ;
45
47
import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty .ApplyRequest .Strategy ;
75
77
import java .util .concurrent .TimeUnit ;
76
78
import java .util .concurrent .locks .ReentrantLock ;
77
79
import java .util .stream .Collectors ;
80
+
81
+ import org .apache .skywalking .banyandb .v1 .client .util .StatusUtil ;
78
82
import org .apache .skywalking .banyandb .v1 .client .util .TimeUtils ;
79
83
80
84
import static com .google .common .base .Preconditions .checkNotNull ;
@@ -227,7 +231,10 @@ public CompletableFuture<Void> write(StreamWrite streamWrite) {
227
231
228
232
@ Override
229
233
public void onNext (BanyandbStream .WriteResponse writeResponse ) {
230
- switch (writeResponse .getStatus ()) {
234
+ BanyandbModel .Status status = StatusUtil .convertStringToStatus (writeResponse .getStatus ());
235
+ switch (status ) {
236
+ case STATUS_SUCCEED :
237
+ break ;
231
238
case STATUS_INVALID_TIMESTAMP :
232
239
responseException = new InvalidArgumentException (
233
240
"Invalid timestamp: " + streamWrite .getTimestamp (), null , Status .Code .INVALID_ARGUMENT , false );
@@ -250,11 +257,10 @@ public void onNext(BanyandbStream.WriteResponse writeResponse) {
250
257
responseException = new InvalidArgumentException (
251
258
"Expired revision: " + metadata .getModRevision (), null , Status .Code .INVALID_ARGUMENT , true );
252
259
break ;
253
- case STATUS_INTERNAL_ERROR :
260
+ default :
254
261
responseException = new InternalException (
255
- "Internal error occurs in server" , null , Status .Code .INTERNAL , true );
262
+ String . format ( "Internal error (%s) occurs in server" , writeResponse . getStatus ()) , null , Status .Code .INTERNAL , true );
256
263
break ;
257
- default :
258
264
}
259
265
}
260
266
@@ -1064,6 +1070,20 @@ public MetadataCache.EntityMetadata updateMeasureMetadataCacheFromSever(String g
1064
1070
return this .metadataCache .updateMeasureFromSever (group , name );
1065
1071
}
1066
1072
1073
+ /**
1074
+ * Get the API version of the server
1075
+ *
1076
+ * @return the API version of the server
1077
+ * @throws BanyanDBException if the server is not reachable
1078
+ */
1079
+ public BanyandbCommon .APIVersion getAPIVersion () throws BanyanDBException {
1080
+ ServiceGrpc .ServiceBlockingStub stub = ServiceGrpc .newBlockingStub (this .channel );
1081
+ return HandleExceptionsWith .callAndTranslateApiException (() -> {
1082
+ BanyandbCommon .GetAPIVersionResponse resp = stub .getAPIVersion (BanyandbCommon .GetAPIVersionRequest .getDefaultInstance ());
1083
+ return resp .getVersion ();
1084
+ });
1085
+ }
1086
+
1067
1087
@ Override
1068
1088
public void close () throws IOException {
1069
1089
connectionEstablishLock .lock ();
0 commit comments