Skip to content

Commit b6d229b

Browse files
authored
Add file resource interfaces (#1802)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent f8a1aef commit b6d229b

9 files changed

Lines changed: 432 additions & 1 deletion

File tree

sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,34 @@ public ListRefreshExternalCollectionJobsResp listRefreshExternalCollectionJobs(L
12401240
return rpcUtils.retry(() -> utilityService.listRefreshExternalCollectionJobs(this.getRpcStub(), request));
12411241
}
12421242

1243+
/**
1244+
* Add a file resource to Milvus.
1245+
*
1246+
* @param request add file resource request containing name and path
1247+
*/
1248+
public void addFileResource(AddFileResourceReq request) {
1249+
rpcUtils.retry(() -> utilityService.addFileResource(this.getRpcStub(), request));
1250+
}
1251+
1252+
/**
1253+
* Remove a file resource from Milvus.
1254+
*
1255+
* @param request remove file resource request containing name
1256+
*/
1257+
public void removeFileResource(RemoveFileResourceReq request) {
1258+
rpcUtils.retry(() -> utilityService.removeFileResource(this.getRpcStub(), request));
1259+
}
1260+
1261+
/**
1262+
* List all file resources in Milvus.
1263+
*
1264+
* @param request list file resources request
1265+
* @return ListFileResourcesResp containing the list of file resources
1266+
*/
1267+
public ListFileResourcesResp listFileResources(ListFileResourcesReq request) {
1268+
return rpcUtils.retry(() -> utilityService.listFileResources(this.getRpcStub(), request));
1269+
}
1270+
12431271
/**
12441272
* Optimize collection to adjust segment sizes for better query performance.
12451273
*

sdk-core/src/main/java/io/milvus/v2/service/utility/UtilityService.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,61 @@ private io.milvus.v2.service.utility.response.RefreshExternalCollectionJobInfo c
408408
.endTime(info.getEndTime())
409409
.build();
410410
}
411+
412+
public Void addFileResource(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
413+
AddFileResourceReq request) {
414+
if (StringUtils.isEmpty(request.getName())) {
415+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "File resource name cannot be null or empty");
416+
}
417+
if (StringUtils.isEmpty(request.getPath())) {
418+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "File resource path cannot be null or empty");
419+
}
420+
String title = String.format("AddFileResource name: '%s', path: '%s'", request.getName(), request.getPath());
421+
422+
AddFileResourceRequest grpcRequest = AddFileResourceRequest.newBuilder()
423+
.setName(request.getName())
424+
.setPath(request.getPath())
425+
.build();
426+
427+
Status status = blockingStub.addFileResource(grpcRequest);
428+
rpcUtils.handleResponse(title, status);
429+
return null;
430+
}
431+
432+
public Void removeFileResource(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
433+
RemoveFileResourceReq request) {
434+
if (StringUtils.isEmpty(request.getName())) {
435+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "File resource name cannot be null or empty");
436+
}
437+
String title = String.format("RemoveFileResource name: '%s'", request.getName());
438+
439+
RemoveFileResourceRequest grpcRequest = RemoveFileResourceRequest.newBuilder()
440+
.setName(request.getName())
441+
.build();
442+
443+
Status status = blockingStub.removeFileResource(grpcRequest);
444+
rpcUtils.handleResponse(title, status);
445+
return null;
446+
}
447+
448+
public ListFileResourcesResp listFileResources(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
449+
ListFileResourcesReq request) {
450+
String title = "ListFileResources";
451+
452+
ListFileResourcesRequest grpcRequest = ListFileResourcesRequest.newBuilder().build();
453+
454+
ListFileResourcesResponse response = blockingStub.listFileResources(grpcRequest);
455+
rpcUtils.handleResponse(title, response.getStatus());
456+
457+
List<io.milvus.v2.service.utility.response.FileResourceInfo> resources = new ArrayList<>();
458+
for (io.milvus.grpc.FileResourceInfo info : response.getResourcesList()) {
459+
resources.add(io.milvus.v2.service.utility.response.FileResourceInfo.builder()
460+
.name(info.getName())
461+
.path(info.getPath())
462+
.build());
463+
}
464+
return ListFileResourcesResp.builder()
465+
.resources(resources)
466+
.build();
467+
}
411468
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.utility.request;
21+
22+
public class AddFileResourceReq {
23+
private final String name;
24+
private final String path;
25+
26+
private AddFileResourceReq(AddFileResourceReqBuilder builder) {
27+
this.name = builder.name;
28+
this.path = builder.path;
29+
}
30+
31+
public static AddFileResourceReqBuilder builder() {
32+
return new AddFileResourceReqBuilder();
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public String getPath() {
40+
return path;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "AddFileResourceReq{" +
46+
"name='" + name + '\'' +
47+
", path='" + path + '\'' +
48+
'}';
49+
}
50+
51+
public static class AddFileResourceReqBuilder {
52+
private String name;
53+
private String path;
54+
55+
public AddFileResourceReqBuilder name(String name) {
56+
this.name = name;
57+
return this;
58+
}
59+
60+
public AddFileResourceReqBuilder path(String path) {
61+
this.path = path;
62+
return this;
63+
}
64+
65+
public AddFileResourceReq build() {
66+
return new AddFileResourceReq(this);
67+
}
68+
}
69+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.utility.request;
21+
22+
public class ListFileResourcesReq {
23+
24+
private ListFileResourcesReq(ListFileResourcesReqBuilder builder) {
25+
}
26+
27+
public static ListFileResourcesReqBuilder builder() {
28+
return new ListFileResourcesReqBuilder();
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "ListFileResourcesReq{}";
34+
}
35+
36+
public static class ListFileResourcesReqBuilder {
37+
38+
public ListFileResourcesReq build() {
39+
return new ListFileResourcesReq(this);
40+
}
41+
}
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.utility.request;
21+
22+
public class RemoveFileResourceReq {
23+
private final String name;
24+
25+
private RemoveFileResourceReq(RemoveFileResourceReqBuilder builder) {
26+
this.name = builder.name;
27+
}
28+
29+
public static RemoveFileResourceReqBuilder builder() {
30+
return new RemoveFileResourceReqBuilder();
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "RemoveFileResourceReq{" +
40+
"name='" + name + '\'' +
41+
'}';
42+
}
43+
44+
public static class RemoveFileResourceReqBuilder {
45+
private String name;
46+
47+
public RemoveFileResourceReqBuilder name(String name) {
48+
this.name = name;
49+
return this;
50+
}
51+
52+
public RemoveFileResourceReq build() {
53+
return new RemoveFileResourceReq(this);
54+
}
55+
}
56+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.utility.response;
21+
22+
public class FileResourceInfo {
23+
private final String name;
24+
private final String path;
25+
26+
private FileResourceInfo(FileResourceInfoBuilder builder) {
27+
this.name = builder.name;
28+
this.path = builder.path;
29+
}
30+
31+
public static FileResourceInfoBuilder builder() {
32+
return new FileResourceInfoBuilder();
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public String getPath() {
40+
return path;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "FileResourceInfo{" +
46+
"name='" + name + '\'' +
47+
", path='" + path + '\'' +
48+
'}';
49+
}
50+
51+
public static class FileResourceInfoBuilder {
52+
private String name;
53+
private String path;
54+
55+
public FileResourceInfoBuilder name(String name) {
56+
this.name = name;
57+
return this;
58+
}
59+
60+
public FileResourceInfoBuilder path(String path) {
61+
this.path = path;
62+
return this;
63+
}
64+
65+
public FileResourceInfo build() {
66+
return new FileResourceInfo(this);
67+
}
68+
}
69+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.utility.response;
21+
22+
import java.util.List;
23+
24+
public class ListFileResourcesResp {
25+
private final List<FileResourceInfo> resources;
26+
27+
private ListFileResourcesResp(ListFileResourcesRespBuilder builder) {
28+
this.resources = builder.resources;
29+
}
30+
31+
public static ListFileResourcesRespBuilder builder() {
32+
return new ListFileResourcesRespBuilder();
33+
}
34+
35+
public List<FileResourceInfo> getResources() {
36+
return resources;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "ListFileResourcesResp{" +
42+
"resources=" + resources +
43+
'}';
44+
}
45+
46+
public static class ListFileResourcesRespBuilder {
47+
private List<FileResourceInfo> resources;
48+
49+
public ListFileResourcesRespBuilder resources(List<FileResourceInfo> resources) {
50+
this.resources = resources;
51+
return this;
52+
}
53+
54+
public ListFileResourcesResp build() {
55+
return new ListFileResourcesResp(this);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)