Skip to content

Commit df61d90

Browse files
committed
Add file resource interfaces
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent f8a1aef commit df61d90

9 files changed

Lines changed: 437 additions & 0 deletions

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+
return 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+
return 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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,53 @@ 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+
String title = String.format("AddFileResource name: '%s', path: '%s'", request.getName(), request.getPath());
415+
416+
AddFileResourceRequest grpcRequest = AddFileResourceRequest.newBuilder()
417+
.setName(request.getName())
418+
.setPath(request.getPath())
419+
.build();
420+
421+
Status status = blockingStub.addFileResource(grpcRequest);
422+
rpcUtils.handleResponse(title, status);
423+
return null;
424+
}
425+
426+
public Void removeFileResource(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
427+
RemoveFileResourceReq request) {
428+
String title = String.format("RemoveFileResource name: '%s'", request.getName());
429+
430+
RemoveFileResourceRequest grpcRequest = RemoveFileResourceRequest.newBuilder()
431+
.setName(request.getName())
432+
.build();
433+
434+
Status status = blockingStub.removeFileResource(grpcRequest);
435+
rpcUtils.handleResponse(title, status);
436+
return null;
437+
}
438+
439+
public ListFileResourcesResp listFileResources(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
440+
ListFileResourcesReq request) {
441+
String title = "ListFileResources";
442+
443+
ListFileResourcesRequest grpcRequest = ListFileResourcesRequest.newBuilder().build();
444+
445+
ListFileResourcesResponse response = blockingStub.listFileResources(grpcRequest);
446+
rpcUtils.handleResponse(title, response.getStatus());
447+
448+
List<io.milvus.v2.service.utility.response.FileResourceInfo> resources = new ArrayList<>();
449+
for (io.milvus.grpc.FileResourceInfo info : response.getResourcesList()) {
450+
resources.add(io.milvus.v2.service.utility.response.FileResourceInfo.builder()
451+
.id(info.getId())
452+
.name(info.getName())
453+
.path(info.getPath())
454+
.build());
455+
}
456+
return ListFileResourcesResp.builder()
457+
.resources(resources)
458+
.build();
459+
}
411460
}
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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 long id;
24+
private final String name;
25+
private final String path;
26+
27+
private FileResourceInfo(FileResourceInfoBuilder builder) {
28+
this.id = builder.id;
29+
this.name = builder.name;
30+
this.path = builder.path;
31+
}
32+
33+
public static FileResourceInfoBuilder builder() {
34+
return new FileResourceInfoBuilder();
35+
}
36+
37+
public long getId() {
38+
return id;
39+
}
40+
41+
public String getName() {
42+
return name;
43+
}
44+
45+
public String getPath() {
46+
return path;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "FileResourceInfo{" +
52+
"id=" + id +
53+
", name='" + name + '\'' +
54+
", path='" + path + '\'' +
55+
'}';
56+
}
57+
58+
public static class FileResourceInfoBuilder {
59+
private long id;
60+
private String name;
61+
private String path;
62+
63+
public FileResourceInfoBuilder id(long id) {
64+
this.id = id;
65+
return this;
66+
}
67+
68+
public FileResourceInfoBuilder name(String name) {
69+
this.name = name;
70+
return this;
71+
}
72+
73+
public FileResourceInfoBuilder path(String path) {
74+
this.path = path;
75+
return this;
76+
}
77+
78+
public FileResourceInfo build() {
79+
return new FileResourceInfo(this);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)