-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathWeaviateAliasClient.java
More file actions
124 lines (112 loc) · 5.01 KB
/
Copy pathWeaviateAliasClient.java
File metadata and controls
124 lines (112 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package io.weaviate.client6.v1.api.alias;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import io.weaviate.client6.v1.api.WeaviateApiException;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.rest.RestTransport;
public class WeaviateAliasClient {
private final RestTransport restTransport;
public WeaviateAliasClient(RestTransport restTransport) {
this.restTransport = restTransport;
}
/**
* Create a new collection alias.
*
* @param collection Original collection name.
* @param alias Collection alias.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void create(String collection, String alias) throws IOException {
create(new Alias(collection, alias));
}
/**
* Create a new collection alias.
*
* @param alias Alias object.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void create(Alias alias) throws IOException {
this.restTransport.performRequest(new CreateAliasRequest(alias), CreateAliasRequest._ENDPOINT);
}
/**
* List all collection aliases defined in the cluster.
*
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public List<Alias> list() throws IOException {
return list(ListAliasRequest.of());
}
/**
* List all collection aliases defined in the cluster.
*
* @param fn Lambda expression for optional parameters.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
* @return A list of aliases.
*/
public List<Alias> list(Function<ListAliasRequest.Builder, ObjectBuilder<ListAliasRequest>> fn) throws IOException {
return list(ListAliasRequest.of(fn));
}
private List<Alias> list(ListAliasRequest request) throws IOException {
return this.restTransport.performRequest(request, ListAliasRequest._ENDPOINT);
}
/**
* Get alias by name.
*
* @param alias Collection alias.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
* @return Alias if one exists and empty {@code Optional} otherwise.
*/
public Optional<Alias> get(String alias) throws IOException {
return this.restTransport.performRequest(new GetAliasRequest(alias), GetAliasRequest._ENDPOINT);
}
/**
* Change which collection this alias references.
*
* @param alias Collection alias.
* @param newTargetCollection Collection name.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void update(String alias, String newTargetCollection) throws IOException {
this.restTransport.performRequest(new UpdateAliasRequest(alias, newTargetCollection),
UpdateAliasRequest._ENDPOINT);
}
/**
* Delete an alias. The previously aliased collection is not affected.
*
* @param alias Collection alias.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void delete(String alias) throws IOException {
this.restTransport.performRequest(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
}
}