diff --git a/src/main/java/com/coscale/sdk/client/commons/Msg.java b/src/main/java/com/coscale/sdk/client/commons/Msg.java index 349e488..0a24ced 100755 --- a/src/main/java/com/coscale/sdk/client/commons/Msg.java +++ b/src/main/java/com/coscale/sdk/client/commons/Msg.java @@ -2,7 +2,6 @@ import javax.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; @@ -10,7 +9,6 @@ * Msg is used to parse request responses that return a Status Message. * */ -@JsonIgnoreProperties({ "measurements" }) public class Msg { @Nullable diff --git a/src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java b/src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java index d409609..8bf6b88 100755 --- a/src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java +++ b/src/main/java/com/coscale/sdk/client/metrics/MetricsApi.java @@ -44,6 +44,8 @@ public List 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 * @throws IOException */ @@ -107,11 +109,27 @@ public List 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 getAllMetricGroups(Options options) throws IOException { + String url = "/metricgroups/"; + url += (options.hasQuery() ? "?" : "&") + options.query(); + return api.callWithAuth("GET", url, null, new TypeReference>() { + }); + } + /** * Get a specific metric group. * * @param id - * the id of the metric group + * the id of the metric group. * @return MetricGroup * @throws IOException */ @@ -145,8 +163,9 @@ 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() { - }); + return api.callWithAuth("DELETE", "/metricgroups/" + id + '/', null, + new TypeReference() { + }); } /** @@ -154,12 +173,12 @@ public Msg deleteMetricGroup(long id) throws IOException { * * @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 addGroupToGroup(long childId, long parentId) throws IOException { return api.callWithAuth("POST", "/metricgroups/" + parentId + "/metricgroups/" + childId - + '/', null, new TypeReference() { + + '/', null, new TypeReference>() { }); } @@ -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 addMetricToGroup(long metricId, long groupId) throws IOException { return api.callWithAuth("POST", "/metricgroups/" + groupId + "/metrics/" + metricId + '/', - null, new TypeReference() { + null, new TypeReference>() { }); } diff --git a/src/main/java/com/coscale/sdk/client/servers/ServerGroup.java b/src/main/java/com/coscale/sdk/client/servers/ServerGroup.java new file mode 100644 index 0000000..aeb6df3 --- /dev/null +++ b/src/main/java/com/coscale/sdk/client/servers/ServerGroup.java @@ -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 servers; + + @Nullable + public String description; + + @Nullable + public String name; + + public State state; + + @Nullable + public List servergroups; + + @Nullable + public String type; + + @Nullable + public Long version; + + public ServerGroup(State state) { + this.state = state; + } + + public ServerGroup(Long id, String source, List servers, String description, + String name, State state, List 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); + } + +} \ No newline at end of file diff --git a/src/main/java/com/coscale/sdk/client/servers/ServerGroupInsert.java b/src/main/java/com/coscale/sdk/client/servers/ServerGroupInsert.java new file mode 100644 index 0000000..1a00829 --- /dev/null +++ b/src/main/java/com/coscale/sdk/client/servers/ServerGroupInsert.java @@ -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); + } + +} \ No newline at end of file diff --git a/src/main/java/com/coscale/sdk/client/servers/ServersApi.java b/src/main/java/com/coscale/sdk/client/servers/ServersApi.java index 8cf8bb0..5f6d520 100755 --- a/src/main/java/com/coscale/sdk/client/servers/ServersApi.java +++ b/src/main/java/com/coscale/sdk/client/servers/ServersApi.java @@ -113,4 +113,167 @@ public Msg delete(long serverId) throws IOException { new TypeReference() { }); } + + /** Server groups Calls */ + + /** + * Get all server groups. + * + * @return List of all ServerGroups + * @throws IOException + */ + public List getAllServerGroups() throws IOException { + return api.callWithAuth("GET", "/servergroups/", null, + new TypeReference>() { + }); + } + + /** + * Get all server groups. + * + * @param options + * filter the ServerGroups. e.g. filter by server name. + * + * @return List of all ServerGroups + * @throws IOException + */ + public List getAllServerGroups(Options options) throws IOException { + String url = "/servergroups/"; + url += (options.hasQuery() ? "?" : "&") + options.query(); + return api.callWithAuth("GET", url, null, new TypeReference>() { + }); + } + + /** + * Get a specific server group. + * + * @param id + * the id of the server group. + * @return ServerGroup + * @throws IOException + */ + public ServerGroup getServerGroup(long id) throws IOException { + return api.callWithAuth("GET", "/servergroups/" + id + '/', null, + new TypeReference() { + }); + } + + /** + * Insert a new server group. Optionally set which ServerGroup will be its + * parent (this is set in ServerGroupInsert object). + * + * @param serverGroup + * the server group to insert. + * @return ServerGroup + * @throws IOException + */ + public ServerGroup insertServerGroup(ServerGroupInsert serverGroup) throws IOException { + return api.callWithAuth("POST", "/servergroups/", serverGroup, + new TypeReference() { + }); + } + + /** + * Delete a specific server group. + * + * @param id + * the id of the server group. + * @return Msg + * @throws IOException + */ + public Msg deleteServerGroup(long id) throws IOException { + return api.callWithAuth("DELETE", "/servergroups/" + id + '/', null, + new TypeReference() { + }); + } + + /** + * Add an existing server group to another server group. + * + * @param childId + * @param parentId + * @return List of groups contained by the parent group. + * @throws IOException + */ + public List addGroupToGroup(long childId, long parentId) throws IOException { + return api.callWithAuth("POST", "/servergroups/" + parentId + "/servergroups/" + childId + + '/', null, new TypeReference>() { + }); + } + + /** + * Add an existing server to a server group. + * + * @param serverId + * @param groupId + * @return List of Server contained by the group. + * @throws IOException + */ + public List addServerToGroup(long serverId, long groupId) throws IOException { + return api.callWithAuth("POST", "/servergroups/" + groupId + "/servers/" + serverId + '/', + null, new TypeReference>() { + }); + } + + /** + * * Get all servers in the server group. + * + * @param groupId + * the id of the server group. + * @return List of Server. + * @throws IOException + */ + public List getGroupServers(long groupId) throws IOException { + return api.callWithAuth("GET", "/servergroups/" + groupId + "/servers/", null, + new TypeReference>() { + }); + } + + /** + * Delete a server from a server group. + * + * @param serverId + * the id of the server. + * @param groupId + * the id of the group. + * @return Msg. + * @throws IOException + */ + public Msg deleteServerFromGroup(long serverId, long groupId) throws IOException { + return api.callWithAuth("DELETE", + "/servergroups/" + groupId + "/servers/" + serverId + '/', null, + new TypeReference() { + }); + } + + /** + * Get all child server groups for a server group. + * + * @param groupId + * the if of the group. + * @return List of ServerGroup. + * @throws IOException + */ + public List getGroupsFromGroup(long groupId) throws IOException { + return api.callWithAuth("GET", "/servergroups/" + groupId + "/servergroups/", null, + new TypeReference>() { + }); + } + + /** + * Delete a server group from another server group. + * + * @param childId + * the id of the group that will be removed. + * @param parentId + * the id of the group from which the child group will be + * removed. + * @return Msg. + * @throws IOException + */ + public Msg deleteGroupFromGroup(long childId, long parentId) throws IOException { + return api.callWithAuth("DELETE", "/servergroups/" + parentId + "/servergroups/" + childId + + '/', null, new TypeReference() { + }); + } } diff --git a/src/main/java/com/coscale/sdk/client/utils/MapperSupport.java b/src/main/java/com/coscale/sdk/client/utils/MapperSupport.java index 75dedf0..f404262 100755 --- a/src/main/java/com/coscale/sdk/client/utils/MapperSupport.java +++ b/src/main/java/com/coscale/sdk/client/utils/MapperSupport.java @@ -1,6 +1,7 @@ package com.coscale.sdk.client.utils; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; public class MapperSupport { @@ -19,6 +20,9 @@ private static class Keeper { private static ObjectMapper configure(ObjectMapper mapper) { mapper.setSerializationInclusion(Include.NON_NULL); + + // Ignore Unknown fiels. + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper; } }