Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/java/com/coscale/sdk/client/commons/Msg.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

/**
* Msg is used to parse request responses that return a Status Message.
*
*/
@JsonIgnoreProperties({ "measurements" })
public class Msg {

@Nullable
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public List<Metric> all() throws IOException {
/**
* all is used to get a list of all metrics.
*
* @param options
* filter the Metrics. e.g. filter by metric name.
* @return List<Metric>
* @throws IOException
*/
Expand Down Expand Up @@ -107,11 +109,27 @@ public List<MetricGroup> getAllMetricGroups() throws IOException {
});
}

/**
* Get all metric groups.
*
* @param options
* filter the MetricGroups. e.g. filter by metric name.
*
* @return List of all MetricGroups
* @throws IOException
*/
public List<MetricGroup> getAllMetricGroups(Options options) throws IOException {
String url = "/metricgroups/";
url += (options.hasQuery() ? "?" : "&") + options.query();
return api.callWithAuth("GET", url, null, new TypeReference<List<MetricGroup>>() {
});
}

/**
* Get a specific metric group.
*
* @param id
* the id of the metric group
* the id of the metric group.
* @return MetricGroup
* @throws IOException
*/
Expand Down Expand Up @@ -145,21 +163,22 @@ public MetricGroup insertMetricGroup(MetricGroupInsert metricGroup) throws IOExc
* @throws IOException
*/
public Msg deleteMetricGroup(long id) throws IOException {
return api.callWithAuth("DELETE", "/metricgroups/" + id + '/', null, new TypeReference<Msg>() {
});
return api.callWithAuth("DELETE", "/metricgroups/" + id + '/', null,
new TypeReference<Msg>() {
});
}

/**
* Add an existing metric group to another metric group.
*
* @param childId
* @param parentId
* @return MetricGroup: the added metric group.
* @return List of groups contained by the parent group.
* @throws IOException
*/
public MetricGroup addGroupToGroup(long childId, long parentId) throws IOException {
public List<MetricGroup> addGroupToGroup(long childId, long parentId) throws IOException {
return api.callWithAuth("POST", "/metricgroups/" + parentId + "/metricgroups/" + childId
+ '/', null, new TypeReference<MetricGroup>() {
+ '/', null, new TypeReference<List<MetricGroup>>() {
});
}

Expand All @@ -168,12 +187,12 @@ public MetricGroup addGroupToGroup(long childId, long parentId) throws IOExcepti
*
* @param metricId
* @param groupId
* @return Metric: the inserted metric.
* @return List of Metrics contained by the group.
* @throws IOException
*/
public Metric addMetricToGroup(long metricId, long groupId) throws IOException {
public List<Metric> addMetricToGroup(long metricId, long groupId) throws IOException {
return api.callWithAuth("POST", "/metricgroups/" + groupId + "/metrics/" + metricId + '/',
null, new TypeReference<Metric>() {
null, new TypeReference<List<Metric>>() {
});
}

Expand Down
92 changes: 92 additions & 0 deletions src/main/java/com/coscale/sdk/client/servers/ServerGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.coscale.sdk.client.servers;

import java.util.List;

import javax.annotation.Nullable;

import com.coscale.sdk.client.metrics.State;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

public class ServerGroup {

@Nullable
public Long id;

@Nullable
public String source;

@Nullable
public List<Server> servers;

@Nullable
public String description;

@Nullable
public String name;

public State state;

@Nullable
public List<ServerGroup> servergroups;

@Nullable
public String type;

@Nullable
public Long version;

public ServerGroup(State state) {
this.state = state;
}

public ServerGroup(Long id, String source, List<Server> servers, String description,
String name, State state, List<ServerGroup> servergroups, String type, Long version) {
this.id = id;
this.source = source;
this.servers = servers;
this.description = description;
this.name = name;
this.state = state;
this.servergroups = servergroups;
this.type = type;
this.version = version;
}

public ServerGroup() {
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("id", id).add("source", source)
.add("servers", servers).add("description", description).add("name", name)
.add("state", state).add("servergroups", servergroups).add("version", version)
.toString();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ServerGroup other = (ServerGroup) obj;

return Objects.equal(this.id, other.id) && Objects.equal(this.source, other.source)
&& Objects.equal(this.servers, other.servers)
&& Objects.equal(this.description, other.description)
&& Objects.equal(this.name, other.name) && Objects.equal(this.state, other.state)
&& Objects.equal(this.servergroups, other.servergroups)
&& Objects.equal(this.type, other.type)
&& Objects.equal(this.version, other.version);
}

@Override
public int hashCode() {
return Objects.hashCode(id, source, servers, description, name, state, servergroups, type,
version);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.coscale.sdk.client.servers;

import javax.annotation.Nullable;

import com.coscale.sdk.client.ApiClient;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

public class ServerGroupInsert {

public String name;

public String description;

public String type;

public String source;

@Nullable
public Long parentId;

public ServerGroupInsert(String name, String description, String type) {
this.name = name;
this.description = description;
this.type = type;
this.source = ApiClient.getSource();
}

public ServerGroupInsert(String name, String description, String type, Long parentId) {
this.name = name;
this.description = description;
this.type = type;
this.source = ApiClient.getSource();
this.parentId = parentId;
}

public ServerGroupInsert() {
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("name", name).add("description", description)
.add("type", type).add("source", source).add("parentId", parentId).toString();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ServerGroupInsert other = (ServerGroupInsert) obj;

return Objects.equal(this.name, other.name)
&& Objects.equal(this.description, other.description)
&& Objects.equal(this.type, other.type) && Objects.equal(this.source, other.source)
&& Objects.equal(this.parentId, other.parentId);
}

@Override
public int hashCode() {
return Objects.hashCode(name, description, type, source, parentId);
}

}
Loading