summaryrefslogtreecommitdiffstats
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
parent94ebe963e0c448cd2d0ba7de241d3adc0a815606 (diff)
Design changes - introducing cluster-server mapping on gateway
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java14
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java2
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/VolumeLogsPage.java26
-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
6 files changed, 140 insertions, 88 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java
index 4ab21a01..43435675 100644
--- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java
@@ -120,8 +120,8 @@ public class VolumesClient extends AbstractClient {
*
* @param volumeName
* Name of volume whose logs are to be fetched
- * @param diskName
- * Name of the disk whose logs are to be fetched. Pass ALL to fetch log messages from all disks of the
+ * @param brickName
+ * Name of the brick whose logs are to be fetched. Pass ALL to fetch log messages from all bricks of the
* volume.
* @param severity
* Log severity {@link GlusterConstants#VOLUME_LOG_LEVELS_ARR}. Pass ALL to fetch log messages of all
@@ -134,9 +134,9 @@ public class VolumesClient extends AbstractClient {
* Number of most recent log messages to be fetched (from each disk)
* @return Log Message List response received from the Gluster Management Server.
*/
- public LogMessageListResponse getLogs(String volumeName, String diskName, String severity, Date fromTimestamp,
+ public LogMessageListResponse getLogs(String volumeName, String brickName, String severity, Date fromTimestamp,
Date toTimestamp, int messageCount) {
- MultivaluedMap<String, String> queryParams = prepareGetLogQueryParams(diskName, severity, fromTimestamp,
+ MultivaluedMap<String, String> queryParams = prepareGetLogQueryParams(brickName, severity, fromTimestamp,
toTimestamp, messageCount);
return (LogMessageListResponse) fetchSubResource(volumeName + "/" + RESTConstants.RESOURCE_LOGS,
@@ -169,12 +169,12 @@ public class VolumesClient extends AbstractClient {
return queryParams;
}
- private MultivaluedMap<String, String> prepareGetLogQueryParams(String diskName, String severity,
+ private MultivaluedMap<String, String> prepareGetLogQueryParams(String brickName, String severity,
Date fromTimestamp, Date toTimestamp, int messageCount) {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(RESTConstants.QUERY_PARAM_LINE_COUNT, "" + messageCount);
- if (!diskName.equals(CoreConstants.ALL)) {
- queryParams.add(RESTConstants.QUERY_PARAM_DISK_NAME, diskName);
+ if (!brickName.equals(CoreConstants.ALL)) {
+ queryParams.add(RESTConstants.QUERY_PARAM_BRICK_NAME, brickName);
}
if (!severity.equals(CoreConstants.ALL)) {
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
index 33323021..428eb53f 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
@@ -57,7 +57,7 @@ public class RESTConstants {
public static final String PATH_PARAM_CLUSTER_NAME = "clusterName";
public static final String PATH_PARAM_SERVER_NAME = "serverName";
- public static final String QUERY_PARAM_DISK_NAME = "diskName";
+ public static final String QUERY_PARAM_BRICK_NAME = "brickName";
public static final String QUERY_PARAM_DISKS = "disks";
public static final String QUERY_PARAM_BRICKS = "bricks";
public static final String QUERY_PARAM_LINE_COUNT = "lineCount";
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/VolumeLogsPage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/VolumeLogsPage.java
index 811b4c5c..f2170162 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/VolumeLogsPage.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/VolumeLogsPage.java
@@ -73,7 +73,7 @@ public class VolumeLogsPage extends Composite {
private static final String[] LOG_TABLE_COLUMN_NAMES = new String[] { "Date", "Time", "Disk", "Severity", "Message" };
private TableViewer tableViewer;
- private Combo disksCombo;
+ private Combo bricksCombo;
private Combo severityCombo;
private DateTime fromDate;
private DateTime fromTime;
@@ -110,8 +110,8 @@ public class VolumeLogsPage extends Composite {
createLineCountLabel(composite);
createLineCountText(composite);
- createDiskLabel(composite);
- createDisksCombo(composite);
+ createBricksLabel(composite);
+ createBricksCombo(composite);
createSeverityLabel(composite);
createSeverityCombo(composite);
@@ -185,7 +185,7 @@ public class VolumeLogsPage extends Composite {
return;
}
- LogMessageListResponse response = client.getLogs(volume.getName(), disksCombo.getText(),
+ LogMessageListResponse response = client.getLogs(volume.getName(), bricksCombo.getText(),
severityCombo.getText(), fromTimestamp, toTimestamp, Integer.parseInt(lineCountText.getText()));
Status status = response.getStatus();
if (status.isSuccess()) {
@@ -321,17 +321,17 @@ public class VolumeLogsPage extends Composite {
lblSeverity.setBounds(480, 15, 70, 20);
}
- private void createDisksCombo(Composite composite) {
- disksCombo = new Combo(composite, SWT.READ_ONLY);
- disksCombo.setBounds(365, 15, 100, 20);
- disksCombo.setItems( volume.getBrickDirectories().toArray(new String[0]));
- disksCombo.add(CoreConstants.ALL, 0);
- toolkit.adapt(disksCombo);
- toolkit.paintBordersFor(disksCombo);
- disksCombo.select(0);
+ private void createBricksCombo(Composite composite) {
+ bricksCombo = new Combo(composite, SWT.READ_ONLY);
+ bricksCombo.setBounds(365, 15, 100, 20);
+ bricksCombo.setItems( volume.getBrickDirectories().toArray(new String[0]));
+ bricksCombo.add(CoreConstants.ALL, 0);
+ toolkit.adapt(bricksCombo);
+ toolkit.paintBordersFor(bricksCombo);
+ bricksCombo.select(0);
}
- private void createDiskLabel(Composite composite) {
+ private void createBricksLabel(Composite composite) {
Label lblMessagesAndFilter = toolkit.createLabel(composite, "messages, and filter on bricks", SWT.NONE);
lblMessagesAndFilter.setBounds(160, 15, 200, 20);
}
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);
+ }
+ }
+}