diff options
| author | Dhandapani <dhandapani@gluster.com> | 2011-07-25 21:58:39 +0530 |
|---|---|---|
| committer | Dhandapani <dhandapani@gluster.com> | 2011-07-25 21:58:39 +0530 |
| commit | 2c0409e7809aec2398526cfccbea88528952694d (patch) | |
| tree | 800e6be6f6c02b065215302a9ded07916031ea84 /src/com.gluster.storage.management.server | |
| parent | 483500a2f159e29a9304a659c327b6be56f44cd3 (diff) | |
| parent | 93cd7eb0184797e8e4a799c763cec3c6648c7382 (diff) | |
Merge branch 'master' of git@github.com:gluster/console
Diffstat (limited to 'src/com.gluster.storage.management.server')
| -rw-r--r-- | src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java index e3332648..2d5034ec 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java @@ -61,6 +61,7 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.exceptions.GlusterValidationException; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.Server.SERVER_STATUS; +import com.gluster.storage.management.core.model.ServerStats; import com.gluster.storage.management.core.model.TaskStatus; import com.gluster.storage.management.core.response.GlusterServerListResponse; import com.gluster.storage.management.core.response.ServerNameListResponse; @@ -502,27 +503,47 @@ public class GlusterServersResource extends AbstractServersResource { @GET @Produces(MediaType.APPLICATION_XML) @Path("{" + PATH_PARAM_SERVER_NAME + "}/" + RESOURCE_STATISTICS) - public Response getPerformanceDataXML(@PathParam(PATH_PARAM_SERVER_NAME) String serverName, + public Response getPerformanceDataXML(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_SERVER_NAME) String serverName, @QueryParam(QUERY_PARAM_TYPE) String type, @QueryParam(QUERY_PARAM_PERIOD) String period, @QueryParam(QUERY_PARAM_INTERFACE) String networkInterface) { - return getPerformanceData(serverName, type, period, networkInterface, MediaType.APPLICATION_XML); + return getPerformanceData(clusterName, serverName, type, period, networkInterface, MediaType.APPLICATION_XML); } @GET @Produces(MediaType.APPLICATION_JSON) @Path("{" + PATH_PARAM_SERVER_NAME + "}/" + RESOURCE_STATISTICS) - public Response getPerformanceDataJSON(@PathParam(PATH_PARAM_SERVER_NAME) String serverName, + public Response getPerformanceDataJSON(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_SERVER_NAME) String serverName, @QueryParam(QUERY_PARAM_TYPE) String type, @QueryParam(QUERY_PARAM_PERIOD) String period, @QueryParam(QUERY_PARAM_INTERFACE) String networkInterface) { - return getPerformanceData(serverName, type, period, networkInterface, MediaType.APPLICATION_JSON); + return getPerformanceData(clusterName, serverName, type, period, networkInterface, MediaType.APPLICATION_JSON); } private Response getAggregaredPerformanceData(String clusterName, String type, String period, String mediaType) { + if (clusterName == null || clusterName.isEmpty()) { + throw new GlusterValidationException("Cluster name must not be empty!"); + } + + ClusterInfo cluster = clusterService.getCluster(clusterName); + if (cluster == null) { + return notFoundResponse("Cluster [" + clusterName + "] not found!"); + } + + if (cluster.getServers().size() == 0) { + // cluster is empty. return empty stats. + return okResponse(new ServerStats(), mediaType); + } + List<String> serverNames = getServerNames(getGlusterServers(clusterName, false)); return okResponse(getStatsFactory(type).fetchAggregatedStats(serverNames, period), mediaType); } - private Response getPerformanceData(String serverName, String type, String period, String networkInterface, String mediaType) { + private Response getPerformanceData(String clusterName, String serverName, String type, String period, String networkInterface, String mediaType) { + if (clusterName == null || clusterName.isEmpty()) { + throw new GlusterValidationException("Cluster name must not be empty!"); + } + if (serverName == null || serverName.isEmpty()) { + throw new GlusterValidationException("Server name must not be empty!"); + } return okResponse(getStatsFactory(type).fetchStats(serverName, period, networkInterface), mediaType); } |
