Skip to content

Commit a963684

Browse files
Merge pull request #2 from CoScale/fixMG
fixed MetriGroup api problems
2 parents 93ad4da + de6a457 commit a963684

File tree

6 files changed

+354
-11
lines changed

6 files changed

+354
-11
lines changed

src/main/java/com/coscale/sdk/client/commons/Msg.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import javax.annotation.Nullable;
44

5-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
65
import com.google.common.base.MoreObjects;
76
import com.google.common.base.Objects;
87

98
/**
109
* Msg is used to parse request responses that return a Status Message.
1110
*
1211
*/
13-
@JsonIgnoreProperties({ "measurements" })
1412
public class Msg {
1513

1614
@Nullable

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

Lines changed: 28 additions & 9 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,21 +163,22 @@ 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
/**
153172
* Add an existing metric group to another metric group.
154173
*
155174
* @param childId
156175
* @param parentId
157-
* @return MetricGroup: the added metric group.
176+
* @return List of groups contained by the parent group.
158177
* @throws IOException
159178
*/
160-
public MetricGroup addGroupToGroup(long childId, long parentId) throws IOException {
179+
public List<MetricGroup> addGroupToGroup(long childId, long parentId) throws IOException {
161180
return api.callWithAuth("POST", "/metricgroups/" + parentId + "/metricgroups/" + childId
162-
+ '/', null, new TypeReference<MetricGroup>() {
181+
+ '/', null, new TypeReference<List<MetricGroup>>() {
163182
});
164183
}
165184

@@ -168,12 +187,12 @@ public MetricGroup addGroupToGroup(long childId, long parentId) throws IOExcepti
168187
*
169188
* @param metricId
170189
* @param groupId
171-
* @return Metric: the inserted metric.
190+
* @return List of Metrics contained by the group.
172191
* @throws IOException
173192
*/
174-
public Metric addMetricToGroup(long metricId, long groupId) throws IOException {
193+
public List<Metric> addMetricToGroup(long metricId, long groupId) throws IOException {
175194
return api.callWithAuth("POST", "/metricgroups/" + groupId + "/metrics/" + metricId + '/',
176-
null, new TypeReference<Metric>() {
195+
null, new TypeReference<List<Metric>>() {
177196
});
178197
}
179198

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+
}

0 commit comments

Comments
 (0)