diff --git a/examples/main/java/io/milvus/v1/BulkWriterExample.java b/examples/main/java/io/milvus/v1/BulkWriterExample.java index 7c42afe38..157918825 100644 --- a/examples/main/java/io/milvus/v1/BulkWriterExample.java +++ b/examples/main/java/io/milvus/v1/BulkWriterExample.java @@ -27,7 +27,7 @@ import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import io.milvus.bulkwriter.BulkWriter; -import io.milvus.bulkwriter.CloudImportV2; +import io.milvus.bulkwriter.CloudImport; import io.milvus.bulkwriter.LocalBulkWriter; import io.milvus.bulkwriter.LocalBulkWriterParam; import io.milvus.bulkwriter.RemoteBulkWriter; @@ -40,12 +40,9 @@ import io.milvus.bulkwriter.connect.AzureConnectParam; import io.milvus.bulkwriter.connect.S3ConnectParam; import io.milvus.bulkwriter.connect.StorageConnectParam; -import io.milvus.bulkwriter.request.v2.BulkImportV2Request; -import io.milvus.bulkwriter.request.v2.GetImportProgressV2Request; -import io.milvus.bulkwriter.request.v2.ListImportJobsV2Request; -import io.milvus.bulkwriter.response.v2.BulkImportV2Response; -import io.milvus.bulkwriter.response.v2.GetImportProgressV2Response; -import io.milvus.bulkwriter.response.v2.ListImportJobsV2Response; +import io.milvus.bulkwriter.request.BulkImportRequest; +import io.milvus.bulkwriter.request.GetImportProgressRequest; +import io.milvus.bulkwriter.request.ListImportJobsRequest; import io.milvus.client.MilvusClient; import io.milvus.client.MilvusServiceClient; import io.milvus.common.utils.ExceptionUtils; @@ -81,7 +78,6 @@ import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -561,7 +557,7 @@ private void callBulkInsert(CollectionSchemaParam collectionSchema, List> batchFiles, String collectionName, String partitionName) throws InterruptedException, MalformedURLException { + private void callCloudImport(List> batchFiles, String collectionName, String partitionName) throws InterruptedException { System.out.println("\n===================== call cloudImport ===================="); String objectUrl = StorageConsts.cloudStorage == CloudStorage.AZURE @@ -570,28 +566,34 @@ private void callCloudImport(List> batchFiles, String collectionNam String accessKey = StorageConsts.cloudStorage == CloudStorage.AZURE ? StorageConsts.AZURE_ACCOUNT_NAME : StorageConsts.STORAGE_ACCESS_KEY; String secretKey = StorageConsts.cloudStorage == CloudStorage.AZURE ? StorageConsts.AZURE_ACCOUNT_KEY : StorageConsts.STORAGE_SECRET_KEY; - BulkImportV2Request bulkImportRequest = BulkImportV2Request.builder() + BulkImportRequest bulkImportRequest = BulkImportRequest.builder() .objectUrl(objectUrl).accessKey(accessKey).secretKey(secretKey) .clusterId(CloudImportConsts.CLUSTER_ID).collectionName(collectionName).partitionName(partitionName) .build(); - BulkImportV2Response bulkImportResponse = CloudImportV2.createImportJobs(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, bulkImportRequest); - String jobId = bulkImportResponse.getJobId(); + String bulkImportResult = CloudImport.bulkImport(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, bulkImportRequest); + JsonObject bulkImportObject = convertDataMap(bulkImportResult); + + String jobId = bulkImportObject.getAsJsonObject("data").get("jobId").getAsString(); System.out.println("Create a cloudImport job, job id: " + jobId); while (true) { System.out.println("Wait 5 second to check bulkInsert job state..."); TimeUnit.SECONDS.sleep(5); - GetImportProgressV2Request request = GetImportProgressV2Request.builder().clusterId(CloudImportConsts.CLUSTER_ID).jobId(jobId).build(); - GetImportProgressV2Response getImportProgressResponse = CloudImportV2.getImportJobProgress(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, request); - if ("Completed".equals(getImportProgressResponse.getState())) { + GetImportProgressRequest request = GetImportProgressRequest.builder().clusterId(CloudImportConsts.CLUSTER_ID).jobId(jobId).build(); + String getImportProgressResult = CloudImport.getImportProgress(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, request); + JsonObject getImportProgressObject = convertDataMap(getImportProgressResult); + String importProgressState = getImportProgressObject.getAsJsonObject("data").get("state").getAsString(); + String reason = getImportProgressObject.getAsJsonObject("data").get("reason").getAsString(); + String progress = getImportProgressObject.getAsJsonObject("data").get("progress").getAsString(); + if ("Completed".equals(importProgressState)) { System.out.printf("The job %s completed%n", jobId); break; - } else if (StringUtils.isNotEmpty(getImportProgressResponse.getReason())) { - System.out.printf("The job %s failed or canceled, reason: %s%n", jobId, getImportProgressResponse.getReason()); + } else if (StringUtils.isNotEmpty(reason)) { + System.out.printf("The job %s failed or canceled, reason: %s%n", jobId, reason); break; } else { - System.out.printf("The job %s is running, progress:%s%n", jobId, getImportProgressResponse.getProgress()); + System.out.printf("The job %s is running, progress:%s%n", jobId, progress); } } @@ -768,25 +770,27 @@ private Long getCollectionStatistics() { return wrapper.getRowCount(); } - private static void exampleCloudImport() throws MalformedURLException { + private static void exampleCloudImport() { System.out.println("\n===================== import files to cloud vectordb ===================="); - BulkImportV2Request request = BulkImportV2Request.builder() + BulkImportRequest request = BulkImportRequest.builder() .objectUrl(CloudImportConsts.OBJECT_URL).accessKey(CloudImportConsts.OBJECT_ACCESS_KEY).secretKey(CloudImportConsts.OBJECT_SECRET_KEY) .clusterId(CloudImportConsts.CLUSTER_ID).collectionName(CloudImportConsts.COLLECTION_NAME).partitionName(CloudImportConsts.PARTITION_NAME) .build(); - BulkImportV2Response bulkImportResponse = CloudImportV2.createImportJobs(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, request); - System.out.println(GSON_INSTANCE.toJson(bulkImportResponse)); + String bulkImportResult = CloudImport.bulkImport(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, request); + System.out.println(bulkImportResult); System.out.println("\n===================== get import job progress ===================="); - String jobId = bulkImportResponse.getJobId(); - GetImportProgressV2Request getImportProgressRequest = GetImportProgressV2Request.builder().clusterId(CloudImportConsts.CLUSTER_ID).jobId(jobId).build(); - GetImportProgressV2Response getImportProgressResponse = CloudImportV2.getImportJobProgress(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, getImportProgressRequest); - System.out.println(GSON_INSTANCE.toJson(getImportProgressResponse)); + + JsonObject bulkImportObject = convertDataMap(bulkImportResult); + String jobId = bulkImportObject.getAsJsonObject("data").get("jobId").getAsString(); + GetImportProgressRequest getImportProgressRequest = GetImportProgressRequest.builder().clusterId(CloudImportConsts.CLUSTER_ID).jobId(jobId).build(); + String getImportProgressResult = CloudImport.getImportProgress(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, getImportProgressRequest); + System.out.println(getImportProgressResult); System.out.println("\n===================== list import jobs ===================="); - ListImportJobsV2Request listImportJobsRequest = ListImportJobsV2Request.builder().clusterId(CloudImportConsts.CLUSTER_ID).currentPage(1).pageSize(10).build(); - ListImportJobsV2Response listImportJobsResponse = CloudImportV2.listImportJobs(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, listImportJobsRequest); - System.out.println(GSON_INSTANCE.toJson(listImportJobsResponse)); + ListImportJobsRequest listImportJobsRequest = ListImportJobsRequest.builder().clusterId(CloudImportConsts.CLUSTER_ID).currentPage(1).pageSize(10).build(); + String listImportJobsResult = CloudImport.listImportJobs(CloudImportConsts.CLOUD_ENDPOINT, CloudImportConsts.API_KEY, listImportJobsRequest); + System.out.println(listImportJobsResult); } private CollectionSchemaParam buildSimpleSchema() { @@ -968,4 +972,8 @@ private void checkMilvusClientIfExist() { throw new RuntimeException(msg); } } + + private static JsonObject convertDataMap(String result) { + return GSON_INSTANCE.fromJson(result, JsonObject.class); + } } diff --git a/src/main/java/io/milvus/bulkwriter/BaseCloudImport.java b/src/main/java/io/milvus/bulkwriter/BaseCloudImport.java index bef490987..183f338b3 100644 --- a/src/main/java/io/milvus/bulkwriter/BaseCloudImport.java +++ b/src/main/java/io/milvus/bulkwriter/BaseCloudImport.java @@ -19,7 +19,6 @@ package io.milvus.bulkwriter; -import com.google.gson.Gson; import io.milvus.bulkwriter.response.RestfulResponse; import io.milvus.common.utils.ExceptionUtils; import kong.unirest.Unirest; @@ -28,8 +27,6 @@ import java.util.Map; public class BaseCloudImport { - private static final Gson GSON_INSTANCE = new Gson(); - protected static String postRequest(String url, String apiKey, Map params, int timeout) { try { kong.unirest.HttpResponse response = Unirest.post(url) @@ -37,7 +34,7 @@ protected static String postRequest(String url, String apiKey, Map params = new HashMap<>(); - params.put("objectUrl", objectUrl); - params.put("accessKey", accessKey); - params.put("secretKey", secretKey); - params.put("clusterId", clusterId); - params.put("collectionName", collectionName); - + Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); + RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); handleResponse(requestURL, response); - return response.getData(); + return body; } - public static GetImportProgressResponse getImportProgress(String url, String apiKey, String jobId, String clusterId) throws MalformedURLException { - url = convertToV2ControlBaseURL(url); - String requestURL = url + "/v2/vectordb/jobs/import/getProgress"; - - Map params = new HashMap<>(); - params.put("clusterId", clusterId); - params.put("jobId", jobId); + public static String getImportProgress(String url, String apiKey, GetImportProgressRequest request) { + String requestURL = url + "/v2/vectordb/jobs/import/describe"; + Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); + RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); handleResponse(requestURL, response); - return response.getData().toGetImportProgressResponse(); + return body; } - public static ListImportJobsResponse listImportJobs(String url, String apiKey, String clusterId, int pageSize, int currentPage) throws MalformedURLException { - url = convertToV2ControlBaseURL(url); + public static String listImportJobs(String url, String apiKey, ListImportJobsRequest request) { String requestURL = url + "/v2/vectordb/jobs/import/list"; - Map params = new HashMap<>(); - params.put("clusterId", clusterId); - params.put("pageSize", pageSize); - params.put("currentPage", currentPage); - + Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); + RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); handleResponse(requestURL, response); - return response.getData().toListImportJobsResponse(); + return body; } } diff --git a/src/main/java/io/milvus/bulkwriter/CloudImportV2.java b/src/main/java/io/milvus/bulkwriter/CloudImportV2.java deleted file mode 100644 index 84b7a6106..000000000 --- a/src/main/java/io/milvus/bulkwriter/CloudImportV2.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.bulkwriter; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import io.milvus.bulkwriter.request.v2.BulkImportV2Request; -import io.milvus.bulkwriter.request.v2.GetImportProgressV2Request; -import io.milvus.bulkwriter.request.v2.ListImportJobsV2Request; -import io.milvus.bulkwriter.response.RestfulResponse; -import io.milvus.bulkwriter.response.v2.BulkImportV2Response; -import io.milvus.bulkwriter.response.v2.GetImportProgressV2Response; -import io.milvus.bulkwriter.response.v2.ListImportJobsV2Response; - -import java.net.MalformedURLException; -import java.util.Map; - -public class CloudImportV2 extends BaseCloudImport { - private static final Gson GSON_INSTANCE = new Gson(); - - public static BulkImportV2Response createImportJobs(String url, String apiKey, BulkImportV2Request request) throws MalformedURLException { - String requestURL = url + "/v2/vectordb/jobs/import/create"; - - Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); - String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); - handleResponse(requestURL, response); - return response.getData(); - } - - public static GetImportProgressV2Response getImportJobProgress(String url, String apiKey, GetImportProgressV2Request request) throws MalformedURLException { - String requestURL = url + "/v2/vectordb/jobs/import/getProgress"; - - Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); - String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); - handleResponse(requestURL, response); - return response.getData(); - } - - public static ListImportJobsV2Response listImportJobs(String url, String apiKey, ListImportJobsV2Request request) throws MalformedURLException { - String requestURL = url + "/v2/vectordb/jobs/import/list"; - - Map params = GSON_INSTANCE.fromJson(GSON_INSTANCE.toJson(request), new TypeToken>() {}.getType()); - - - String body = postRequest(requestURL, apiKey, params, 60 * 1000); - RestfulResponse response = GSON_INSTANCE.fromJson(body, new TypeToken>(){}.getType()); - handleResponse(requestURL, response); - return response.getData(); - } -} diff --git a/src/main/java/io/milvus/bulkwriter/request/v2/BulkImportV2Request.java b/src/main/java/io/milvus/bulkwriter/request/BulkImportRequest.java similarity index 92% rename from src/main/java/io/milvus/bulkwriter/request/v2/BulkImportV2Request.java rename to src/main/java/io/milvus/bulkwriter/request/BulkImportRequest.java index 4be58c3b5..99500f36e 100644 --- a/src/main/java/io/milvus/bulkwriter/request/v2/BulkImportV2Request.java +++ b/src/main/java/io/milvus/bulkwriter/request/BulkImportRequest.java @@ -17,7 +17,7 @@ * under the License. */ -package io.milvus.bulkwriter.request.v2; +package io.milvus.bulkwriter.request; import lombok.AllArgsConstructor; import lombok.Builder; @@ -30,7 +30,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class BulkImportV2Request implements Serializable { +public class BulkImportRequest implements Serializable { private static final long serialVersionUID = 8192049841043084620L; private String objectUrl; private String accessKey; diff --git a/src/main/java/io/milvus/bulkwriter/request/v2/GetImportProgressV2Request.java b/src/main/java/io/milvus/bulkwriter/request/GetImportProgressRequest.java similarity index 91% rename from src/main/java/io/milvus/bulkwriter/request/v2/GetImportProgressV2Request.java rename to src/main/java/io/milvus/bulkwriter/request/GetImportProgressRequest.java index e6b31bc54..c232b0f9b 100644 --- a/src/main/java/io/milvus/bulkwriter/request/v2/GetImportProgressV2Request.java +++ b/src/main/java/io/milvus/bulkwriter/request/GetImportProgressRequest.java @@ -17,7 +17,7 @@ * under the License. */ -package io.milvus.bulkwriter.request.v2; +package io.milvus.bulkwriter.request; import lombok.AllArgsConstructor; import lombok.Builder; @@ -30,7 +30,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class GetImportProgressV2Request implements Serializable { +public class GetImportProgressRequest implements Serializable { private static final long serialVersionUID = -787626534606813089L; private String clusterId; private String jobId; diff --git a/src/main/java/io/milvus/bulkwriter/request/v2/ListImportJobsV2Request.java b/src/main/java/io/milvus/bulkwriter/request/ListImportJobsRequest.java similarity index 91% rename from src/main/java/io/milvus/bulkwriter/request/v2/ListImportJobsV2Request.java rename to src/main/java/io/milvus/bulkwriter/request/ListImportJobsRequest.java index f911023c2..980952158 100644 --- a/src/main/java/io/milvus/bulkwriter/request/v2/ListImportJobsV2Request.java +++ b/src/main/java/io/milvus/bulkwriter/request/ListImportJobsRequest.java @@ -17,7 +17,7 @@ * under the License. */ -package io.milvus.bulkwriter.request.v2; +package io.milvus.bulkwriter.request; import lombok.AllArgsConstructor; import lombok.Builder; @@ -30,7 +30,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class ListImportJobsV2Request implements Serializable { +public class ListImportJobsRequest implements Serializable { private static final long serialVersionUID = -1890380396466908530L; private String clusterId; diff --git a/src/main/java/io/milvus/bulkwriter/response/GetImportProgressResponse.java b/src/main/java/io/milvus/bulkwriter/response/GetImportProgressResponse.java index 8d646505e..7444bcfb9 100644 --- a/src/main/java/io/milvus/bulkwriter/response/GetImportProgressResponse.java +++ b/src/main/java/io/milvus/bulkwriter/response/GetImportProgressResponse.java @@ -32,21 +32,26 @@ @AllArgsConstructor @NoArgsConstructor public class GetImportProgressResponse implements Serializable { - private static final long serialVersionUID = -7162743560382861611L; + + private static final long serialVersionUID = -2302203037749197132L; + + private String jobId; + + private String collectionName; private String fileName; private Integer fileSize; - private Double readyPercentage; + private String state; - private String completeTime; + private Integer progress; - private String errorMessage; + private String completeTime; - private String collectionName; + private String reason; - private String jobId; + private Integer totalRows; private List details; @@ -54,11 +59,12 @@ public class GetImportProgressResponse implements Serializable { @Builder @AllArgsConstructor @NoArgsConstructor - public static class Detail { + private static class Detail { private String fileName; private Integer fileSize; - private Double readyPercentage; + private String state; + private Integer progress; private String completeTime; - private String errorMessage; + private String reason; } } diff --git a/src/main/java/io/milvus/bulkwriter/response/ListImportJobsResponse.java b/src/main/java/io/milvus/bulkwriter/response/ListImportJobsResponse.java index 0ada63341..f2e9a6558 100644 --- a/src/main/java/io/milvus/bulkwriter/response/ListImportJobsResponse.java +++ b/src/main/java/io/milvus/bulkwriter/response/ListImportJobsResponse.java @@ -32,7 +32,8 @@ @AllArgsConstructor @NoArgsConstructor public class ListImportJobsResponse implements Serializable { - private static final long serialVersionUID = -7162743560382861611L; + + private static final long serialVersionUID = -8400893490624599225L; private Integer count; @@ -40,10 +41,5 @@ public class ListImportJobsResponse implements Serializable { private Integer pageSize; - private List tasks; - - @Deprecated - // Invalid field, please use tasks. private List records; - } diff --git a/src/main/java/io/milvus/bulkwriter/response/v2/BulkImportV2Response.java b/src/main/java/io/milvus/bulkwriter/response/v2/BulkImportV2Response.java deleted file mode 100644 index 542d9e77c..000000000 --- a/src/main/java/io/milvus/bulkwriter/response/v2/BulkImportV2Response.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.bulkwriter.response.v2; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class BulkImportV2Response implements Serializable { - - private static final long serialVersionUID = 4782067096929198967L; - private String jobId; -} diff --git a/src/main/java/io/milvus/bulkwriter/response/v2/GetImportProgressV2Response.java b/src/main/java/io/milvus/bulkwriter/response/v2/GetImportProgressV2Response.java deleted file mode 100644 index dcab2f2c3..000000000 --- a/src/main/java/io/milvus/bulkwriter/response/v2/GetImportProgressV2Response.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.bulkwriter.response.v2; - -import io.milvus.bulkwriter.response.GetImportProgressResponse; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.List; -import java.util.stream.Collectors; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class GetImportProgressV2Response implements Serializable { - - private static final long serialVersionUID = -2302203037749197132L; - - private String jobId; - - private String collectionName; - - private String fileName; - - private Integer fileSize; - - private String state; - - private Integer progress; - - private String completeTime; - - private String reason; - - private Integer totalRows; - - private List details; - - @Data - @Builder - @AllArgsConstructor - @NoArgsConstructor - private static class DetailV2 { - private String fileName; - private Integer fileSize; - private String state; - private Integer progress; - private String completeTime; - private String reason; - - - public GetImportProgressResponse.Detail toDetail() { - GetImportProgressResponse.Detail detail = new GetImportProgressResponse.Detail(); - detail.setFileName(fileName); - detail.setFileSize(fileSize); - detail.setReadyPercentage(progress == null ? null : Double.valueOf(progress)); - detail.setErrorMessage(reason); - detail.setCompleteTime(completeTime); - return detail; - } - } - - public GetImportProgressResponse toGetImportProgressResponse() { - GetImportProgressResponse response = new GetImportProgressResponse(); - response.setJobId(jobId); - response.setCollectionName(collectionName); - response.setFileName(fileName); - response.setFileSize(fileSize); - response.setReadyPercentage(progress == null ? null : Double.valueOf(progress)); - response.setCompleteTime(completeTime); - response.setErrorMessage(reason); - - List details = this.details.stream().map(DetailV2::toDetail).collect(Collectors.toList()); - response.setDetails(details); - return response; - } - -} diff --git a/src/main/java/io/milvus/bulkwriter/response/v2/ListImportJobsV2Response.java b/src/main/java/io/milvus/bulkwriter/response/v2/ListImportJobsV2Response.java deleted file mode 100644 index f09d3cacf..000000000 --- a/src/main/java/io/milvus/bulkwriter/response/v2/ListImportJobsV2Response.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.bulkwriter.response.v2; - -import com.google.common.collect.ImmutableMap; -import io.milvus.bulkwriter.response.ListImportJobsResponse; -import io.milvus.bulkwriter.response.Record; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class ListImportJobsV2Response implements Serializable { - - private static final long serialVersionUID = -8400893490624599225L; - - private Integer count; - - private Integer currentPage; - - private Integer pageSize; - - private List records; - - public ListImportJobsResponse toListImportJobsResponse() { - Map newOldStateMap = ImmutableMap.of( - "Pending","ImportPending", - "Importing","ImportRunning", - "Completed","ImportCompleted", - "Failed","ImportFailed", - "Cancel","ImportCancel" - ); - - List tasks = new ArrayList<>(); - for (Record record : records) { - Record task = Record.builder() - .jobId(record.getJobId()) - .collectionName(record.getCollectionName()) - .state(newOldStateMap.get(record.getState())) - .build(); - tasks.add(task); - } - - ListImportJobsResponse listImportJobsResponse = new ListImportJobsResponse(); - listImportJobsResponse.setCount(count); - listImportJobsResponse.setCurrentPage(currentPage); - listImportJobsResponse.setPageSize(pageSize); - listImportJobsResponse.setTasks(tasks); - return listImportJobsResponse; - } -}