Skip to content

Commit a984835

Browse files
author
Cristi
committed
added server group support
1 parent d1d06e6 commit a984835

File tree

4 files changed

+344
-3
lines changed

4 files changed

+344
-3
lines changed

src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public List<Metric> all() throws IOException {
4444
/**
4545
* all is used to get a list of all metrics.
4646
*
47+
* @param options
48+
* filter the Metrics. e.g. filter by metric name.
4749
* @return List<Metric>
4850
* @throws IOException
4951
*/
@@ -107,11 +109,27 @@ public List<MetricGroup> getAllMetricGroups() throws IOException {
107109
});
108110
}
109111

112+
/**
113+
* Get all metric groups.
114+
*
115+
* @param options
116+
* filter the MetricGroups. e.g. filter by metric name.
117+
*
118+
* @return List of all MetricGroups
119+
* @throws IOException
120+
*/
121+
public List<MetricGroup> getAllMetricGroups(Options options) throws IOException {
122+
String url = "/metricgroups/";
123+
url += (options.hasQuery() ? "?" : "&") + options.query();
124+
return api.callWithAuth("GET", url, null, new TypeReference<List<MetricGroup>>() {
125+
});
126+
}
127+
110128
/**
111129
* Get a specific metric group.
112130
*
113131
* @param id
114-
* the id of the metric group
132+
* the id of the metric group.
115133
* @return MetricGroup
116134
* @throws IOException
117135
*/
@@ -145,8 +163,9 @@ public MetricGroup insertMetricGroup(MetricGroupInsert metricGroup) throws IOExc
145163
* @throws IOException
146164
*/
147165
public Msg deleteMetricGroup(long id) throws IOException {
148-
return api.callWithAuth("DELETE", "/metricgroups/" + id + '/', null, new TypeReference<Msg>() {
149-
});
166+
return api.callWithAuth("DELETE", "/metricgroups/" + id + '/', null,
167+
new TypeReference<Msg>() {
168+
});
150169
}
151170

152171
/**
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.coscale.sdk.client.servers;
2+
3+
import java.util.List;
4+
5+
import javax.annotation.Nullable;
6+
7+
import com.coscale.sdk.client.metrics.State;
8+
import com.google.common.base.MoreObjects;
9+
import com.google.common.base.Objects;
10+
11+
public class ServerGroup {
12+
13+
@Nullable
14+
public Long id;
15+
16+
@Nullable
17+
public String source;
18+
19+
@Nullable
20+
public List<Server> servers;
21+
22+
@Nullable
23+
public String description;
24+
25+
@Nullable
26+
public String name;
27+
28+
public State state;
29+
30+
@Nullable
31+
public List<ServerGroup> servergroups;
32+
33+
@Nullable
34+
public String type;
35+
36+
@Nullable
37+
public Long version;
38+
39+
public ServerGroup(State state) {
40+
this.state = state;
41+
}
42+
43+
public ServerGroup(Long id, String source, List<Server> servers, String description,
44+
String name, State state, List<ServerGroup> servergroups, String type, Long version) {
45+
this.id = id;
46+
this.source = source;
47+
this.servers = servers;
48+
this.description = description;
49+
this.name = name;
50+
this.state = state;
51+
this.servergroups = servergroups;
52+
this.type = type;
53+
this.version = version;
54+
}
55+
56+
public ServerGroup() {
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return MoreObjects.toStringHelper(this).add("id", id).add("source", source)
62+
.add("servers", servers).add("description", description).add("name", name)
63+
.add("state", state).add("servergroups", servergroups).add("version", version)
64+
.toString();
65+
}
66+
67+
@Override
68+
public boolean equals(Object obj) {
69+
if (obj == null) {
70+
return false;
71+
}
72+
if (getClass() != obj.getClass()) {
73+
return false;
74+
}
75+
final ServerGroup other = (ServerGroup) obj;
76+
77+
return Objects.equal(this.id, other.id) && Objects.equal(this.source, other.source)
78+
&& Objects.equal(this.servers, other.servers)
79+
&& Objects.equal(this.description, other.description)
80+
&& Objects.equal(this.name, other.name) && Objects.equal(this.state, other.state)
81+
&& Objects.equal(this.servergroups, other.servergroups)
82+
&& Objects.equal(this.type, other.type)
83+
&& Objects.equal(this.version, other.version);
84+
}
85+
86+
@Override
87+
public int hashCode() {
88+
return Objects.hashCode(id, source, servers, description, name, state, servergroups, type,
89+
version);
90+
}
91+
92+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.coscale.sdk.client.servers;
2+
3+
import javax.annotation.Nullable;
4+
5+
import com.coscale.sdk.client.ApiClient;
6+
import com.google.common.base.MoreObjects;
7+
import com.google.common.base.Objects;
8+
9+
public class ServerGroupInsert {
10+
11+
public String name;
12+
13+
public String description;
14+
15+
public String type;
16+
17+
public String source;
18+
19+
@Nullable
20+
public Long parentId;
21+
22+
public ServerGroupInsert(String name, String description, String type) {
23+
this.name = name;
24+
this.description = description;
25+
this.type = type;
26+
this.source = ApiClient.getSource();
27+
}
28+
29+
public ServerGroupInsert(String name, String description, String type, Long parentId) {
30+
this.name = name;
31+
this.description = description;
32+
this.type = type;
33+
this.source = ApiClient.getSource();
34+
this.parentId = parentId;
35+
}
36+
37+
public ServerGroupInsert() {
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return MoreObjects.toStringHelper(this).add("name", name).add("description", description)
43+
.add("type", type).add("source", source).add("parentId", parentId).toString();
44+
}
45+
46+
@Override
47+
public boolean equals(Object obj) {
48+
if (obj == null) {
49+
return false;
50+
}
51+
if (getClass() != obj.getClass()) {
52+
return false;
53+
}
54+
final ServerGroupInsert other = (ServerGroupInsert) obj;
55+
56+
return Objects.equal(this.name, other.name)
57+
&& Objects.equal(this.description, other.description)
58+
&& Objects.equal(this.type, other.type) && Objects.equal(this.source, other.source)
59+
&& Objects.equal(this.parentId, other.parentId);
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hashCode(name, description, type, source, parentId);
65+
}
66+
67+
}

src/main/java/com/coscale/sdk/client/servers/ServersApi.java

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,167 @@ public Msg delete(long serverId) throws IOException {
113113
new TypeReference<Msg>() {
114114
});
115115
}
116+
117+
/** Server groups Calls */
118+
119+
/**
120+
* Get all server groups.
121+
*
122+
* @return List of all ServerGroups
123+
* @throws IOException
124+
*/
125+
public List<ServerGroup> getAllServerGroups() throws IOException {
126+
return api.callWithAuth("GET", "/servergroups/", null,
127+
new TypeReference<List<ServerGroup>>() {
128+
});
129+
}
130+
131+
/**
132+
* Get all server groups.
133+
*
134+
* @param options
135+
* filter the ServerGroups. e.g. filter by server name.
136+
*
137+
* @return List of all ServerGroups
138+
* @throws IOException
139+
*/
140+
public List<ServerGroup> getAllServerGroups(Options options) throws IOException {
141+
String url = "/servergroups/";
142+
url += (options.hasQuery() ? "?" : "&") + options.query();
143+
return api.callWithAuth("GET", url, null, new TypeReference<List<ServerGroup>>() {
144+
});
145+
}
146+
147+
/**
148+
* Get a specific server group.
149+
*
150+
* @param id
151+
* the id of the server group.
152+
* @return ServerGroup
153+
* @throws IOException
154+
*/
155+
public ServerGroup getServerGroup(long id) throws IOException {
156+
return api.callWithAuth("GET", "/servergroups/" + id + '/', null,
157+
new TypeReference<ServerGroup>() {
158+
});
159+
}
160+
161+
/**
162+
* Insert a new server group. Optionally set which ServerGroup will be its
163+
* parent (this is set in ServerGroupInsert object).
164+
*
165+
* @param serverGroup
166+
* the server group to insert.
167+
* @return ServerGroup
168+
* @throws IOException
169+
*/
170+
public ServerGroup insertServerGroup(ServerGroupInsert serverGroup) throws IOException {
171+
return api.callWithAuth("POST", "/servergroups/", serverGroup,
172+
new TypeReference<ServerGroup>() {
173+
});
174+
}
175+
176+
/**
177+
* Delete a specific server group.
178+
*
179+
* @param id
180+
* the id of the server group.
181+
* @return Msg
182+
* @throws IOException
183+
*/
184+
public Msg deleteServerGroup(long id) throws IOException {
185+
return api.callWithAuth("DELETE", "/servergroups/" + id + '/', null,
186+
new TypeReference<Msg>() {
187+
});
188+
}
189+
190+
/**
191+
* Add an existing server group to another server group.
192+
*
193+
* @param childId
194+
* @param parentId
195+
* @return List of groups contained by the parent group.
196+
* @throws IOException
197+
*/
198+
public List<ServerGroup> addGroupToGroup(long childId, long parentId) throws IOException {
199+
return api.callWithAuth("POST", "/servergroups/" + parentId + "/servergroups/" + childId
200+
+ '/', null, new TypeReference<List<ServerGroup>>() {
201+
});
202+
}
203+
204+
/**
205+
* Add an existing server to a server group.
206+
*
207+
* @param serverId
208+
* @param groupId
209+
* @return List of Server contained by the group.
210+
* @throws IOException
211+
*/
212+
public List<Server> addServerToGroup(long serverId, long groupId) throws IOException {
213+
return api.callWithAuth("POST", "/servergroups/" + groupId + "/servers/" + serverId + '/',
214+
null, new TypeReference<List<Server>>() {
215+
});
216+
}
217+
218+
/**
219+
* * Get all servers in the server group.
220+
*
221+
* @param groupId
222+
* the id of the server group.
223+
* @return List of Server.
224+
* @throws IOException
225+
*/
226+
public List<Server> getGroupServers(long groupId) throws IOException {
227+
return api.callWithAuth("GET", "/servergroups/" + groupId + "/servers/", null,
228+
new TypeReference<List<Server>>() {
229+
});
230+
}
231+
232+
/**
233+
* Delete a server from a server group.
234+
*
235+
* @param serverId
236+
* the id of the server.
237+
* @param groupId
238+
* the id of the group.
239+
* @return Msg.
240+
* @throws IOException
241+
*/
242+
public Msg deleteServerFromGroup(long serverId, long groupId) throws IOException {
243+
return api.callWithAuth("DELETE",
244+
"/servergroups/" + groupId + "/servers/" + serverId + '/', null,
245+
new TypeReference<Msg>() {
246+
});
247+
}
248+
249+
/**
250+
* Get all child server groups for a server group.
251+
*
252+
* @param groupId
253+
* the if of the group.
254+
* @return List of ServerGroup.
255+
* @throws IOException
256+
*/
257+
public List<ServerGroup> getGroupsFromGroup(long groupId) throws IOException {
258+
return api.callWithAuth("GET", "/servergroups/" + groupId + "/servergroups/", null,
259+
new TypeReference<List<ServerGroup>>() {
260+
});
261+
}
262+
263+
/**
264+
* Delete a server group from another server group.
265+
*
266+
* @param childId
267+
* the id of the group that will be removed.
268+
* @param parentId
269+
* the id of the group from which the child group will be
270+
* removed.
271+
* @return Msg.
272+
* @throws IOException
273+
*/
274+
public Msg deleteGroupFromGroup(long childId, long parentId) throws IOException {
275+
return api.callWithAuth("DELETE", "/servergroups/" + parentId + "/servergroups/" + childId
276+
+ '/', null, new TypeReference<Msg>() {
277+
});
278+
}
116279
}

0 commit comments

Comments
 (0)