Browse Source

1.add get loading process interface;2.add uri param in connect. (#397)

Signed-off-by: xun.huang@zilliz.com <xun.huang@zilliz.com>

Signed-off-by: xun.huang@zilliz.com <xun.huang@zilliz.com>
yelusion 2 years ago
parent
commit
19c578935c

+ 75 - 0
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -44,6 +44,7 @@ import io.milvus.param.collection.DropCollectionParam;
 import io.milvus.param.collection.FieldType;
 import io.milvus.param.collection.FlushParam;
 import io.milvus.param.collection.GetCollectionStatisticsParam;
+import io.milvus.param.collection.GetLoadingProgressParam;
 import io.milvus.param.collection.HasCollectionParam;
 import io.milvus.param.collection.LoadCollectionParam;
 import io.milvus.param.collection.ReleaseCollectionParam;
@@ -2358,6 +2359,80 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
         }
     }
 
+    @Override
+    public R<GetLoadingProgressResponse> getLoadingProgress(GetLoadingProgressParam requestParam) {
+        if (!clientIsReady()) {
+            return R.failed(new ClientNotConnectedException("Client rpc channel is not ready"));
+        }
+
+        logInfo(requestParam.toString());
+
+        try {
+            GetLoadingProgressRequest releasePartitionsRequest = GetLoadingProgressRequest.newBuilder()
+                    .setCollectionName(requestParam.getCollectionName())
+                    .addAllPartitionNames(requestParam.getPartitionNames())
+                    .build();
+
+            GetLoadingProgressResponse response = blockingStub().getLoadingProgress(releasePartitionsRequest);
+
+            if (response.getStatus().getErrorCode() == ErrorCode.Success) {
+                logDebug("GetLoadingProgressParam successfully! Collection name:{}, partition names:{}",
+                        requestParam.getCollectionName(), requestParam.getPartitionNames());
+                return R.success(response);
+            } else {
+                return failedStatus("ReleasePartitionsRequest", response.getStatus());
+            }
+        } catch (StatusRuntimeException e) {
+            logError("GetLoadingProgressParam RPC failed! Collection name:{}, partition names:{}\n{}",
+                    requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getStatus().toString());
+            return R.failed(e);
+        } catch (Exception e) {
+            logError("GetLoadingProgressParam failed! Collection name:{}, partition names:{}\n{}",
+                    requestParam.getCollectionName(), requestParam.getPartitionNames(), e.getMessage());
+            return R.failed(e);
+        }
+    }
+
+    public R<CheckHealthResponse> checkHealth() {
+        if (!clientIsReady()) {
+            return R.failed(new ClientNotConnectedException("Client rpc channel is not ready"));
+        }
+        try {
+            CheckHealthResponse response = blockingStub().checkHealth(CheckHealthRequest.newBuilder().build());
+            if (response.getStatus().getErrorCode() != ErrorCode.Success) {
+                return failedStatus("SelectGrant", response.getStatus());
+            }
+            logDebug("CheckHealth successfully!");
+            return R.success(response);
+        } catch (StatusRuntimeException e) {
+            logError("CheckHealth RPC failed!", e.getStatus().toString());
+            return R.failed(e);
+        } catch (Exception e) {
+            logError("CheckHealth failed! ", e.getMessage());
+            return R.failed(e);
+        }
+    }
+
+    public R<GetVersionResponse> getVersion() {
+        if (!clientIsReady()) {
+            return R.failed(new ClientNotConnectedException("Client rpc channel is not ready"));
+        }
+        try {
+            GetVersionResponse response = blockingStub().getVersion(GetVersionRequest.newBuilder().build());
+            if (response.getStatus().getErrorCode() != ErrorCode.Success) {
+                return failedStatus("SelectGrant", response.getStatus());
+            }
+            logDebug("GetVersion successfully!");
+            return R.success(response);
+        } catch (StatusRuntimeException e) {
+            logError("GetVersion RPC failed!", e.getStatus().toString());
+            return R.failed(e);
+        } catch (Exception e) {
+            logError("GetVersion failed! ", e.getMessage());
+            return R.failed(e);
+        }
+    }
+
     ///////////////////// Log Functions//////////////////////
     private void logDebug(String msg, Object... params) {
         logger.debug(msg, params);

+ 24 - 0
src/main/java/io/milvus/client/MilvusClient.java

@@ -34,6 +34,7 @@ import io.milvus.param.collection.DescribeCollectionParam;
 import io.milvus.param.collection.DropCollectionParam;
 import io.milvus.param.collection.FlushParam;
 import io.milvus.param.collection.GetCollectionStatisticsParam;
+import io.milvus.param.collection.GetLoadingProgressParam;
 import io.milvus.param.collection.HasCollectionParam;
 import io.milvus.param.collection.LoadCollectionParam;
 import io.milvus.param.collection.ReleaseCollectionParam;
@@ -590,4 +591,27 @@ public interface MilvusClient {
      * @return {status:result code, data:ListImportTasksResponse{status,info}}
      */
     R<ListImportTasksResponse> listBulkInsertTasks(ListBulkInsertTasksParam requestParam);
+
+    /**
+     * Check Server Health
+     *
+     * @return {status:result code, data:CheckHealthResponse{status,info}}
+     */
+    R<CheckHealthResponse> checkHealth();
+
+
+    /**
+     * Get Server Version
+     *
+     * @return {status:result code, data:GetVersionResponse{status,info}}
+     */
+    R<GetVersionResponse> getVersion();
+
+    /**
+     * Get Loading Collection Progress
+     *
+     * @param requestParam {@link GetLoadingProgressParam}
+     * @return {status:result code, data:GetLoadingProgressResponse{status}}
+     */
+    R<GetLoadingProgressResponse> getLoadingProgress(GetLoadingProgressParam requestParam);
 }

+ 14 - 0
src/main/java/io/milvus/client/MilvusMultiServiceClient.java

@@ -39,6 +39,7 @@ import io.milvus.param.collection.DescribeCollectionParam;
 import io.milvus.param.collection.DropCollectionParam;
 import io.milvus.param.collection.FlushParam;
 import io.milvus.param.collection.GetCollectionStatisticsParam;
+import io.milvus.param.collection.GetLoadingProgressParam;
 import io.milvus.param.collection.HasCollectionParam;
 import io.milvus.param.collection.LoadCollectionParam;
 import io.milvus.param.collection.ReleaseCollectionParam;
@@ -511,6 +512,19 @@ public class MilvusMultiServiceClient implements MilvusClient {
         return this.clusterFactory.getMaster().getClient().listBulkInsertTasks(requestParam);
     }
 
+    public R<CheckHealthResponse> checkHealth(){
+        return this.clusterFactory.getMaster().getClient().checkHealth();
+    }
+
+    public R<GetVersionResponse> getVersion() {
+        return this.clusterFactory.getMaster().getClient().getVersion();
+    }
+
+    @Override
+    public R<GetLoadingProgressResponse> getLoadingProgress(GetLoadingProgressParam requestParam) {
+        return this.clusterFactory.getMaster().getClient().getLoadingProgress(requestParam);
+    }
+
     private <T> R<T> handleResponse(List<R<T>> response) {
         if (CollectionUtils.isNotEmpty(response)) {
             R<T> rSuccess = null;

+ 4 - 0
src/main/java/io/milvus/common/constant/MilvusClientConstant.java

@@ -7,4 +7,8 @@ public class MilvusClientConstant {
 
         public final static String HOST_HTTP_PREFIX = "http://";
     }
+    public static class StringValue {
+        public final static String COLON = ":";
+        public final static String DOUBLE_SLASH = "//";
+    }
 }

+ 28 - 5
src/main/java/io/milvus/param/ConnectParam.java

@@ -21,6 +21,7 @@ package io.milvus.param;
 
 import io.milvus.exception.ParamException;
 import lombok.NonNull;
+import org.apache.commons.lang3.StringUtils;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Base64;
@@ -28,6 +29,7 @@ import java.util.concurrent.TimeUnit;
 
 import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTPS_PREFIX;
 import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTP_PREFIX;
+import static io.milvus.common.constant.MilvusClientConstant.StringValue.COLON;
 
 /**
  * Parameters for client connection.
@@ -35,6 +37,7 @@ import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_H
 public class ConnectParam {
     private final String host;
     private final int port;
+    private final String uri;
     private final long connectTimeoutMs;
     private final long keepAliveTimeMs;
     private final long keepAliveTimeoutMs;
@@ -46,6 +49,7 @@ public class ConnectParam {
     private ConnectParam(@NonNull Builder builder) {
         this.host = builder.host;
         this.port = builder.port;
+        this.uri = builder.uri;
         this.connectTimeoutMs = builder.connectTimeoutMs;
         this.keepAliveTimeMs = builder.keepAliveTimeMs;
         this.keepAliveTimeoutMs = builder.keepAliveTimeoutMs;
@@ -101,6 +105,7 @@ public class ConnectParam {
     public static class Builder {
         private String host = "localhost";
         private int port = 19530;
+        private String uri;
         private long connectTimeoutMs = 10000;
         private long keepAliveTimeMs = Long.MAX_VALUE; // Disabling keep alive
         private long keepAliveTimeoutMs = 20000;
@@ -134,6 +139,17 @@ public class ConnectParam {
             return this;
         }
 
+        /**
+         * Sets the uri
+         *
+         * @param uri
+         * @return <code>Builder</code>
+         */
+        public Builder withUri(String uri) {
+            this.uri = uri;
+            return this;
+        }
+
         /**
          * Sets the connection timeout value of client channel. The timeout value must be greater than zero.
          *
@@ -242,11 +258,18 @@ public class ConnectParam {
          */
         public ConnectParam build() throws ParamException {
             ParamUtils.CheckNullEmptyString(host, "Host name");
-            if(host.startsWith(HOST_HTTPS_PREFIX)){
-                this.host = host.replace(HOST_HTTPS_PREFIX, "");
-                this.secure = true;
-            }else if(host.startsWith(HOST_HTTP_PREFIX)){
-                this.host = host.replace(HOST_HTTP_PREFIX, "");
+            if (StringUtils.isNotEmpty(uri)) {
+                if (uri.startsWith(HOST_HTTPS_PREFIX)) {
+                    this.uri = uri.replace(HOST_HTTPS_PREFIX, "");
+                    this.secure = true;
+                } else if (uri.startsWith(HOST_HTTP_PREFIX)) {
+                    this.uri = uri.replace(HOST_HTTP_PREFIX, "");
+                }
+                String[] uriArray = uri.split(COLON);
+                this.host = uriArray[0];
+                if(uriArray.length == 2){
+                    this.port = Integer.valueOf(uriArray[1]);
+                }
             }
 
             if (port < 0 || port > 0xFFFF) {

+ 112 - 0
src/main/java/io/milvus/param/collection/GetLoadingProgressParam.java

@@ -0,0 +1,112 @@
+/*
+ * 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 io.milvus.param.collection;
+
+import com.google.common.collect.Lists;
+import io.milvus.exception.ParamException;
+import io.milvus.param.Constant;
+import io.milvus.param.ParamUtils;
+import io.milvus.param.dml.QueryParam;
+import io.milvus.param.partition.ReleasePartitionsParam;
+import lombok.Getter;
+import lombok.NonNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Parameters for <code>loadCollection</code> interface.
+ */
+@Getter
+public class GetLoadingProgressParam {
+    private final String collectionName;
+    private final List<String> partitionNames;
+
+    public GetLoadingProgressParam(@NonNull Builder builder) {
+        this.collectionName = builder.collectionName;
+        this.partitionNames = builder.partitionNames;
+    }
+
+    public static Builder newBuilder() {
+        return new Builder();
+    }
+
+    /**
+     * Builder for {@link GetLoadingProgressParam} class.
+     */
+    public static final class Builder {
+        private String collectionName;
+
+        private final List<String> partitionNames = Lists.newArrayList();
+
+        private Builder() {
+        }
+
+        /**
+         * Sets the collection name. Collection name cannot be empty or null.
+         *
+         * @param collectionName collection name
+         * @return <code>Builder</code>
+         */
+        public Builder withCollectionName(@NonNull String collectionName) {
+            this.collectionName = collectionName;
+            return this;
+        }
+
+        /**
+         * Sets partition names list to specify query scope (Optional).
+         *
+         * @param partitionNames partition names list
+         * @return <code>Builder</code>
+         */
+        public GetLoadingProgressParam.Builder withPartitionNames(@NonNull List<String> partitionNames) {
+            partitionNames.forEach(this::addPartitionName);
+            return this;
+        }
+
+        /**
+         * Adds a partition by name. Partition name cannot be empty or null.
+         *
+         * @param partitionName partition name
+         * @return <code>Builder</code>
+         */
+        public GetLoadingProgressParam.Builder addPartitionName(@NonNull String partitionName) {
+            if (!this.partitionNames.contains(partitionName)) {
+                this.partitionNames.add(partitionName);
+            }
+            return this;
+        }
+
+    }
+
+    /**
+     * Constructs a <code>String</code> by {@link GetLoadingProgressParam} instance.
+     *
+     * @return <code>String</code>
+     */
+    @Override
+    public String toString() {
+        return "GetLoadingProgressParam{" +
+                "collectionName='" + collectionName + '\'' +
+                ", partitionNames='" + partitionNames.toString() + '\'' +
+                '}';
+    }
+}

+ 1 - 1
src/main/milvus-proto

@@ -1 +1 @@
-Subproject commit 7a703d4485b551f20efa5b6d22a211e8967624d1
+Subproject commit 44f59db22b27cc55e4168c8e53b6e781c010a713