summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-07-26 12:48:55 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-07-26 18:50:50 +0530
commit6038c29da2928448bfe30a6ac6f35f89c7be42ff (patch)
tree1b2861e2f95bf7dcff68a60f346721e22d2197b5 /src/com.gluster.storage.management.server
parent070771ad1da13a9a6c874a51cecabd6abe98e603 (diff)
Story #38 - CPU Usage graph
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/GlusterExceptionMapper.java39
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java18
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java39
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java18
4 files changed, 36 insertions, 78 deletions
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java
deleted file mode 100644
index 99089eb7..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
- * This file is part of Gluster Management Console.
- *
- * Gluster Management Console is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Gluster Management Console is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- *******************************************************************************/
-package com.gluster.storage.management.server.resources.v1_0;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-
-import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
-
-@Provider
-public class GlusterExceptionMapper implements ExceptionMapper<GlusterRuntimeException> {
-
- /* (non-Javadoc)
- * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
- */
- @Override
- public Response toResponse(GlusterRuntimeException exception) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage())
- .type(MediaType.TEXT_PLAIN).build();
- }
-}
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 1b2bb41e..9693ace9 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
@@ -522,6 +522,14 @@ public class GlusterServersResource extends AbstractServersResource {
if (clusterName == null || clusterName.isEmpty()) {
throw new GlusterValidationException("Cluster name must not be empty!");
}
+
+ if (type == null || type.isEmpty()) {
+ throw new GlusterValidationException("Statistics type name must not be empty!");
+ }
+
+ if (period == null || period.isEmpty()) {
+ throw new GlusterValidationException("Statistics period name must not be empty! Valid values are 1d/1w/1m/1y");
+ }
ClusterInfo cluster = clusterService.getCluster(clusterName);
if (cluster == null) {
@@ -541,9 +549,19 @@ public class GlusterServersResource extends AbstractServersResource {
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!");
}
+
+ if (type == null || type.isEmpty()) {
+ throw new GlusterValidationException("Statistics type name must not be empty!");
+ }
+
+ if (period == null || period.isEmpty()) {
+ throw new GlusterValidationException("Statistics period name must not be empty! Valid values are 1d/1w/1m/1y");
+ }
+
return okResponse(getStatsFactory(type).fetchStats(serverName, period, networkInterface), mediaType);
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java
deleted file mode 100644
index cab6cc62..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
- * This file is part of Gluster Management Console.
- *
- * Gluster Management Console is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Gluster Management Console is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- *******************************************************************************/
-package com.gluster.storage.management.server.resources.v1_0;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-
-import com.gluster.storage.management.core.exceptions.GlusterValidationException;
-
-@Provider
-public class ValidationExceptionMapper implements ExceptionMapper<GlusterValidationException> {
-
- /* (non-Javadoc)
- * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
- */
- @Override
- public Response toResponse(GlusterValidationException exception) {
- return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage())
- .type(MediaType.TEXT_PLAIN).build();
- }
-}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
index 96bb0c65..2a50d598 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
@@ -27,6 +27,7 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.model.NetworkInterface;
import com.gluster.storage.management.core.model.Server;
import com.gluster.storage.management.core.model.ServerStats;
+import com.gluster.storage.management.core.model.ServerStatsRow;
/**
*
@@ -102,4 +103,21 @@ public class NetworkStatsFactory extends AbstractStatsFactory {
averageAggregatedStats(aggregatedStats, dataCount);
}
+
+ @Override
+ public ServerStats fetchStats(String serverName, String period, String... args) {
+ ServerStats stats = super.fetchStats(serverName, period, args);
+
+ // the data returned by rrd contains "bytes" transferred in the given time step. Update the stats object to represent KiB/s
+ int step = stats.getMetadata().getStep();
+ for(ServerStatsRow row : stats.getRows()) {
+ List<Double> data = row.getUsageData();
+ for (int i = 0; i < data.size(); i++) {
+ Double val = data.get(i);
+ data.set(i, val / 1024 / step);
+ }
+ }
+
+ return stats;
+ }
}