3434import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon ;
3535import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon .Group ;
3636import org .apache .skywalking .banyandb .common .v1 .BanyandbCommon .Metadata ;
37+ import org .apache .skywalking .banyandb .common .v1 .ServiceGrpc ;
3738import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .TopNAggregation ;
3839import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Measure ;
3940import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Stream ;
4041import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .IndexRule ;
4142import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .IndexRuleBinding ;
4243import org .apache .skywalking .banyandb .database .v1 .BanyandbDatabase .Subject ;
44+ import org .apache .skywalking .banyandb .model .v1 .BanyandbModel ;
4345import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty ;
4446import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty .Property ;
4547import org .apache .skywalking .banyandb .property .v1 .BanyandbProperty .ApplyRequest .Strategy ;
7577import java .util .concurrent .TimeUnit ;
7678import java .util .concurrent .locks .ReentrantLock ;
7779import java .util .stream .Collectors ;
80+
81+ import org .apache .skywalking .banyandb .v1 .client .util .StatusUtil ;
7882import org .apache .skywalking .banyandb .v1 .client .util .TimeUtils ;
7983
8084import static com .google .common .base .Preconditions .checkNotNull ;
@@ -227,7 +231,10 @@ public CompletableFuture<Void> write(StreamWrite streamWrite) {
227231
228232 @ Override
229233 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 ;
231238 case STATUS_INVALID_TIMESTAMP :
232239 responseException = new InvalidArgumentException (
233240 "Invalid timestamp: " + streamWrite .getTimestamp (), null , Status .Code .INVALID_ARGUMENT , false );
@@ -250,11 +257,10 @@ public void onNext(BanyandbStream.WriteResponse writeResponse) {
250257 responseException = new InvalidArgumentException (
251258 "Expired revision: " + metadata .getModRevision (), null , Status .Code .INVALID_ARGUMENT , true );
252259 break ;
253- case STATUS_INTERNAL_ERROR :
260+ default :
254261 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 );
256263 break ;
257- default :
258264 }
259265 }
260266
@@ -1064,6 +1070,20 @@ public MetadataCache.EntityMetadata updateMeasureMetadataCacheFromSever(String g
10641070 return this .metadataCache .updateMeasureFromSever (group , name );
10651071 }
10661072
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+
10671087 @ Override
10681088 public void close () throws IOException {
10691089 connectionEstablishLock .lock ();
0 commit comments