summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-06-06 13:37:16 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-06-06 13:37:16 +0530
commit4d109b1521c1f6e09f007aeacbb319443c45dfc8 (patch)
tree079def03878482a1360a466ed54696bb456f241f /src/com.gluster.storage.management.server
parent94ebe963e0c448cd2d0ba7de241d3adc0a815606 (diff)
Design changes - introducing cluster-server mapping on gateway
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/GlusterServersResource.java68
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java31
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/ClusterService.java87
3 files changed, 119 insertions, 67 deletions
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
index 608783a1..7de9015d 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
@@ -18,16 +18,15 @@
*******************************************************************************/
package com.gluster.storage.management.server.resources;
+import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_SERVER_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_CLUSTER_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_SERVER_NAME;
-import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_SERVER_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS;
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_SERVERS;
import java.util.ArrayList;
import java.util.List;
-import javax.persistence.EntityTransaction;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
@@ -42,7 +41,6 @@ import org.springframework.stereotype.Component;
import com.gluster.storage.management.core.constants.CoreConstants;
import com.gluster.storage.management.core.exceptions.ConnectionException;
-import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.model.GlusterServer;
import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS;
import com.gluster.storage.management.core.model.Status;
@@ -50,8 +48,8 @@ import com.gluster.storage.management.core.response.GlusterServerListResponse;
import com.gluster.storage.management.core.response.GlusterServerResponse;
import com.gluster.storage.management.core.utils.LRUCache;
import com.gluster.storage.management.server.data.ClusterInfo;
-import com.gluster.storage.management.server.data.PersistenceDao;
import com.gluster.storage.management.server.data.ServerInfo;
+import com.gluster.storage.management.server.services.ClusterService;
import com.gluster.storage.management.server.utils.GlusterUtil;
import com.gluster.storage.management.server.utils.SshUtil;
import com.sun.jersey.api.core.InjectParam;
@@ -69,7 +67,7 @@ public class GlusterServersResource extends AbstractServersResource {
private DiscoveredServersResource discoveredServersResource;
@Autowired
- private PersistenceDao<ClusterInfo> clusterDao;
+ private ClusterService clusterService;
@Autowired
private SshUtil sshUtil;
@@ -103,8 +101,7 @@ public class GlusterServersResource extends AbstractServersResource {
// Doesn't use cache
public GlusterServer getNewOnlineServer(String clusterName, String exceptServerName) {
- // no known online server for this cluster. find one.
- ClusterInfo cluster = getCluster(clusterName);
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
if(cluster == null) {
return null;
}
@@ -129,7 +126,7 @@ public class GlusterServersResource extends AbstractServersResource {
@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName) {
List<GlusterServer> glusterServers = new ArrayList<GlusterServer>();
- ClusterInfo cluster = getCluster(clusterName);
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
if(cluster == null) {
return new GlusterServerListResponse(new Status(Status.STATUS_CODE_FAILURE, "Cluster [" + clusterName
+ "] doesn't exist!"), null);
@@ -226,7 +223,7 @@ public class GlusterServersResource extends AbstractServersResource {
@Produces(MediaType.TEXT_XML)
public GlusterServerResponse addServer(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@FormParam(FORM_PARAM_SERVER_NAME) String serverName) {
- ClusterInfo cluster = getCluster(clusterName);
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
if(cluster == null) {
return new GlusterServerResponse(new Status(Status.STATUS_CODE_FAILURE, "Cluster [" + clusterName
+ "] doesn't exist!"), null);
@@ -255,7 +252,7 @@ public class GlusterServersResource extends AbstractServersResource {
try {
// add the cluster-server mapping
- addServerToCluster(clusterName, serverName);
+ clusterService.mapServerToCluster(clusterName, serverName);
} catch (Exception e) {
return new GlusterServerResponse(new Status(Status.STATUS_CODE_PART_SUCCESS, e.getMessage()), null);
}
@@ -281,59 +278,12 @@ public class GlusterServersResource extends AbstractServersResource {
return serverResponse;
}
- private void addServerToCluster(String clusterName, String serverName) {
- EntityTransaction txn = clusterDao.startTransaction();
- ClusterInfo cluster = getCluster(clusterName);
- ServerInfo server = new ServerInfo(serverName);
- server.setCluster(cluster);
- try {
- clusterDao.save(server);
- cluster.addServer(server);
- clusterDao.update(cluster);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- throw new GlusterRuntimeException("Couldn't create cluster-server mapping [" + clusterName + "]["
- + serverName + "]! Error: " + e.getMessage(), e);
- }
- }
-
- private void removeServerFromCluster(String clusterName, String serverName) {
- EntityTransaction txn = clusterDao.startTransaction();
- ClusterInfo cluster = getCluster(clusterName);
- List<ServerInfo> servers = cluster.getServers();
- for(ServerInfo server : servers) {
- if(server.getName().equals(serverName)) {
- servers.remove(server);
- clusterDao.delete(server);
- break;
- }
- }
- try {
- clusterDao.update(cluster);
- txn.commit();
- } catch(Exception e) {
- txn.rollback();
- throw new GlusterRuntimeException("Couldn't unmap server [" + serverName + "] from cluster [" + clusterName
- + "]! Error: " + e.getMessage(), e);
- }
- }
-
- private ClusterInfo getCluster(String clusterName) {
- List<ClusterInfo> clusters = clusterDao.findBy("name = ?1", clusterName);
- if(clusters.size() == 0) {
- return null;
- }
-
- return clusters.get(0);
- }
-
@DELETE
@Produces(MediaType.TEXT_XML)
@Path("{" + PATH_PARAM_SERVER_NAME + "}")
public Status removeServer(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@PathParam(PATH_PARAM_SERVER_NAME) String serverName) {
- ClusterInfo cluster = getCluster(clusterName);
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
if(cluster == null) {
return new Status(Status.STATUS_CODE_FAILURE, "Cluster [" + clusterName + "] doesn't exist!");
}
@@ -379,7 +329,7 @@ public class GlusterServersResource extends AbstractServersResource {
try {
- removeServerFromCluster(clusterName, serverName);
+ clusterService.unmapServerFromCluster(clusterName, serverName);
} catch (Exception e) {
return new Status(Status.STATUS_CODE_PART_SUCCESS, e.getMessage());
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
index d16f7678..204d23a9 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
@@ -29,9 +29,8 @@ import static com.gluster.storage.management.core.constants.RESTConstants.FORM_P
import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_CLUSTER_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_VOLUME_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_BRICKS;
+import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_BRICK_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DELETE_OPTION;
-import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DISK_NAME;
-import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DOWNLOAD;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_FROM_TIMESTAMP;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_LINE_COUNT;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_LOG_SEVERITY;
@@ -69,6 +68,8 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
+import org.springframework.beans.factory.annotation.Autowired;
+
import com.gluster.storage.management.core.constants.CoreConstants;
import com.gluster.storage.management.core.constants.RESTConstants;
import com.gluster.storage.management.core.exceptions.ConnectionException;
@@ -87,6 +88,8 @@ import com.gluster.storage.management.core.utils.FileUtil;
import com.gluster.storage.management.core.utils.GlusterCoreUtil;
import com.gluster.storage.management.core.utils.ProcessUtil;
import com.gluster.storage.management.server.constants.VolumeOptionsDefaults;
+import com.gluster.storage.management.server.data.ClusterInfo;
+import com.gluster.storage.management.server.services.ClusterService;
import com.gluster.storage.management.server.utils.GlusterUtil;
import com.gluster.storage.management.server.utils.ServerUtil;
import com.sun.jersey.api.core.InjectParam;
@@ -102,11 +105,14 @@ public class VolumesResource {
@InjectParam
private GlusterServersResource glusterServersResource;
- @InjectParam
+ @Autowired
private ServerUtil serverUtil;
- @InjectParam
+ @Autowired
private GlusterUtil glusterUtil;
+
+ @Autowired
+ private ClusterService clusterService;
private FileUtil fileUtil = new FileUtil();
@@ -467,17 +473,26 @@ public class VolumesResource {
@Path("{" + PATH_PARAM_VOLUME_NAME + "}/" + RESOURCE_LOGS)
public LogMessageListResponse getLogs(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@PathParam(PATH_PARAM_VOLUME_NAME) String volumeName,
- @QueryParam(QUERY_PARAM_DISK_NAME) String brickName,
+ @QueryParam(QUERY_PARAM_BRICK_NAME) String brickName,
@QueryParam(QUERY_PARAM_LOG_SEVERITY) String severity,
@QueryParam(QUERY_PARAM_FROM_TIMESTAMP) String fromTimestamp,
@QueryParam(QUERY_PARAM_TO_TIMESTAMP) String toTimestamp,
- @QueryParam(QUERY_PARAM_LINE_COUNT) Integer lineCount,
- @QueryParam(QUERY_PARAM_DOWNLOAD) Boolean download) {
+ @QueryParam(QUERY_PARAM_LINE_COUNT) Integer lineCount) {
List<LogMessage> logMessages = null;
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
+ if(cluster == null) {
+ return new LogMessageListResponse(new Status(Status.STATUS_CODE_FAILURE, "Cluster [" + clusterName
+ + "] doesn't exist!"), null);
+ }
+
try {
- // TODO: Fetch logs from brick(s) of given cluster only
Volume volume = (Volume)getVolume(clusterName, volumeName).getData();
+ if(volume == null) {
+ return new LogMessageListResponse(new Status(Status.STATUS_CODE_FAILURE, "Volume [" + volumeName
+ + "] doesn't exist in cluster [" + clusterName + "]!"), null);
+ }
+
if (brickName == null || brickName.isEmpty() || brickName.equals(CoreConstants.ALL)) {
logMessages = getLogsForAllBricks(volume, lineCount);
} else {
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/ClusterService.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/ClusterService.java
new file mode 100644
index 00000000..d043278c
--- /dev/null
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/ClusterService.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.services;
+
+import java.util.List;
+
+import javax.persistence.EntityTransaction;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
+import com.gluster.storage.management.server.data.ClusterInfo;
+import com.gluster.storage.management.server.data.PersistenceDao;
+import com.gluster.storage.management.server.data.ServerInfo;
+
+/**
+ * Service class for functionality related to clusters
+ */
+@Component
+public class ClusterService {
+ @Autowired
+ private PersistenceDao<ClusterInfo> clusterDao;
+
+ public ClusterInfo getCluster(String clusterName) {
+ List<ClusterInfo> clusters = clusterDao.findBy("name = ?1", clusterName);
+ if(clusters.size() == 0) {
+ return null;
+ }
+
+ return clusters.get(0);
+ }
+
+ public void mapServerToCluster(String clusterName, String serverName) {
+ EntityTransaction txn = clusterDao.startTransaction();
+ ClusterInfo cluster = getCluster(clusterName);
+ ServerInfo server = new ServerInfo(serverName);
+ server.setCluster(cluster);
+ try {
+ clusterDao.save(server);
+ cluster.addServer(server);
+ clusterDao.update(cluster);
+ txn.commit();
+ } catch (Exception e) {
+ txn.rollback();
+ throw new GlusterRuntimeException("Couldn't create cluster-server mapping [" + clusterName + "]["
+ + serverName + "]! Error: " + e.getMessage(), e);
+ }
+ }
+
+ public void unmapServerFromCluster(String clusterName, String serverName) {
+ EntityTransaction txn = clusterDao.startTransaction();
+ ClusterInfo cluster = getCluster(clusterName);
+ List<ServerInfo> servers = cluster.getServers();
+ for(ServerInfo server : servers) {
+ if(server.getName().equals(serverName)) {
+ servers.remove(server);
+ clusterDao.delete(server);
+ break;
+ }
+ }
+ try {
+ clusterDao.update(cluster);
+ txn.commit();
+ } catch(Exception e) {
+ txn.rollback();
+ throw new GlusterRuntimeException("Couldn't unmap server [" + serverName + "] from cluster [" + clusterName
+ + "]! Error: " + e.getMessage(), e);
+ }
+ }
+}