summaryrefslogtreecommitdiffstats
path: root/com.gluster.storage.management.server/src
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-03-22 17:53:14 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-03-22 17:53:14 +0530
commitc0767db8bf79afd62cdb750558ab7db1a227838f (patch)
tree86e64122f70f8a03a3a9dbe677ac1be89948490a /com.gluster.storage.management.server/src
parent97964bbc552cf0c3a86d0dff8ba00d930f60fd5d (diff)
story#21 Start Volume
Diffstat (limited to 'com.gluster.storage.management.server/src')
-rw-r--r--com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java59
1 files changed, 44 insertions, 15 deletions
diff --git a/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java b/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
index abd4411d..c370fd53 100644
--- a/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
+++ b/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java
@@ -20,12 +20,21 @@
*/
package com.gluster.storage.management.server.resources;
+import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_OPERATION;
+import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_START;
+import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_STOP;
+import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_VOLUME_NAME;
+import static com.gluster.storage.management.core.constants.RESTConstants.PATH_RESOURCE_VOLUMES;
+
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@@ -35,52 +44,57 @@ import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.Volume;
import com.gluster.storage.management.core.model.Volume.TRANSPORT_TYPE;
import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE;
+import com.gluster.storage.management.core.utils.GlusterUtil;
import com.gluster.storage.management.core.utils.ProcessResult;
import com.gluster.storage.management.core.utils.ProcessUtil;
+import com.sun.jersey.spi.resource.Singleton;
-@Path("/cluster/volumes")
+@Singleton
+@Path(PATH_RESOURCE_VOLUMES)
public class VolumesResource {
+ private final GlusterUtil glusterUtil = new GlusterUtil();
@POST
@Consumes(MediaType.TEXT_XML)
@Produces(MediaType.TEXT_XML)
public GenericResponse<String> createVolume(Volume volume) {
-
- int count=1; // replica or stripe count
+
+ int count = 1; // replica or stripe count
String volumeType = null;
- VOLUME_TYPE volType = volume.getVolumeType();
- if(volType == VOLUME_TYPE.DISTRIBUTED_MIRROR) {
+ VOLUME_TYPE volType = volume.getVolumeType();
+ if (volType == VOLUME_TYPE.DISTRIBUTED_MIRROR) {
volumeType = "replica";
count = 2;
- } else if(volType == VOLUME_TYPE.DISTRIBUTED_STRIPE) {
+ } else if (volType == VOLUME_TYPE.DISTRIBUTED_STRIPE) {
volumeType = "stripe";
count = 4;
}
-
+
String transportTypeStr = null;
TRANSPORT_TYPE transportType = volume.getTransportType();
- transportTypeStr = (transportType == TRANSPORT_TYPE.ETHERNET) ? "tcp" : "rdma";
-
+ transportTypeStr = (transportType == TRANSPORT_TYPE.ETHERNET) ? "tcp" : "rdma";
+
List<String> command = new ArrayList<String>();
command.add("gluster");
command.add("volume");
command.add("create");
command.add(volume.getName());
- if(volumeType != null) {
+ if (volumeType != null) {
command.add(volumeType);
command.add("" + count);
}
command.add("transport");
command.add(transportTypeStr);
-
- for(Disk disk : volume.getDisks()) {
+
+ for (Disk disk : volume.getDisks()) {
command.add(getBrickNotation(volume, disk));
}
-
+
ProcessResult result = new ProcessUtil().executeCommand(command);
-
+
if (!result.isSuccess()) {
- return new GenericResponse<String>(Status.STATUS_FAILURE, "Volume creation failed: [" + result.getOutput() + "]");
+ return new GenericResponse<String>(Status.STATUS_FAILURE, "Volume creation failed: [" + result.getOutput()
+ + "]");
}
return new GenericResponse<String>(Status.STATUS_SUCCESS, "Volume created successfully!");
}
@@ -94,4 +108,19 @@ public class VolumesResource {
String dirName = "/export/" + vol.getName() + "/" + disk.getName();
return disk.getServerName() + ":" + dirName;
}
+
+ @PUT
+ @Path("{" + PATH_PARAM_VOLUME_NAME + "}")
+ @Produces(MediaType.TEXT_XML)
+ public Status performOperation(@FormParam(FORM_PARAM_OPERATION) String operation,
+ @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName) {
+
+ if (operation.equals(FORM_PARAM_VALUE_START)) {
+ return new Status(glusterUtil.startVolume(volumeName));
+ }
+ if (operation.equals(FORM_PARAM_VALUE_STOP)) {
+ return new Status(glusterUtil.stopVolume(volumeName));
+ }
+ return new Status(Status.STATUS_CODE_FAILURE, "Invalid operation code [" + operation + "]");
+ }
}