summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-04-05 19:47:23 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-04-05 19:47:23 +0530
commit8607a637093bda070f78289c34c529a990967ff4 (patch)
tree5581bdc1eb91fbf24185e2245a312dd4d8c21420 /src
parentc3c30b10360ac6c994ad72d9b857231b033a29f9 (diff)
Story #15 - Volume Options View - REST resource changes
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java4
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java51
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java15
3 files changed, 39 insertions, 31 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
index 2322fa84..2386bcee 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
@@ -29,7 +29,6 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
-import com.gluster.storage.management.core.model.Disk.DISK_STATUS;
import com.gluster.storage.management.core.utils.StringUtil;
@XmlRootElement
@@ -49,6 +48,7 @@ public class Volume extends Entity {
public enum NAS_PROTOCOL {
GLUSTERFS, NFS
};
+ private static final String OPTION_AUTH_ALLOW = "auth.allow:";
private static final String[] VOLUME_TYPE_STR = new String[] { "Plain Distribute", "Distributed Mirror",
"Distributed Stripe" };
@@ -174,7 +174,7 @@ public class Volume extends Entity {
}
public String getAccessControlList() {
- return accessControlList;
+ return options.get(OPTION_AUTH_ALLOW);
}
public void setAccessControlList(String accessControlList) {
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java
index 0e2b0b8d..a5e6728f 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import com.gluster.storage.management.core.constants.CoreConstants;
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.model.Disk;
import com.gluster.storage.management.core.model.GlusterServer;
import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS;
@@ -48,7 +49,6 @@ public class GlusterUtil {
private static final String VOLUME_TRANSPORT_TYPE_PFX = "Transport-type:";
private static final String VOLUME_BRICKS_GROUP_PFX = "Bricks"; // Colon not used
private static final String VOLUME_OPTIONS_RECONFIG_PFX = "Options Reconfigured";
- private static final String VOLUME_OPTIONS_AUTH_ALLOW = "auth.allow:";
private static final ProcessUtil processUtil = new ProcessUtil();
@@ -230,45 +230,54 @@ public class GlusterUtil {
return disk.getServerName() + ":" + dirName;
}
- public ProcessResult getVolumeInfo() {
- return new ProcessUtil().executeCommand("gluster", "volume", "info");
+ private String getVolumeInfo() {
+ ProcessResult result = new ProcessUtil().executeCommand("gluster", "volume", "info");
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException("Command [gluster volume info] failed with error: ["
+ + result.getExitValue() + "][" + result.getOutput() + "]");
+ }
+ return result.getOutput();
}
- public List<Volume> getAllVolumes(String volumeInfoText) {
+ public List<Volume> getAllVolumes() {
+ String volumeInfoText = getVolumeInfo();
+
List<Volume> volumes = new ArrayList<Volume>();
boolean isBricksGroupFound = false;
boolean isOptionReconfigFound = false;
- List<String> bricks = new ArrayList<String>();
Volume volume = null;
for (String line : volumeInfoText.split(CoreConstants.NEWLINE)) {
- if (extractToken(line, VOLUME_NAME_PFX) != null) {
+ String volumeName = extractToken(line, VOLUME_NAME_PFX);
+ if (volumeName != null) {
if (volume != null) {
- volume.setDisks(bricks);
- bricks.clear();
+ // add the previously read volume to volume list
volumes.add(volume);
}
+
+ // prepare next volume to be read
volume = new Volume();
- volume.setName(extractToken(line, VOLUME_NAME_PFX));
+ volume.setName(volumeName);
isBricksGroupFound = isOptionReconfigFound = false;
continue;
}
- if (extractToken(line, VOLUME_TYPE_PFX) != null) {
- String volumeType = extractToken(line, VOLUME_TYPE_PFX);
+ String volumeType = extractToken(line, VOLUME_TYPE_PFX);
+ if (volumeType != null) {
volume.setVolumeType((volumeType == "Distribute") ? VOLUME_TYPE.PLAIN_DISTRIBUTE
: VOLUME_TYPE.DISTRIBUTED_MIRROR); // TODO: for Stripe
continue;
}
- if (extractToken(line, VOLUME_STATUS_PFX) != null) {
- volume.setStatus(extractToken(line, VOLUME_STATUS_PFX).equals("Started") ? VOLUME_STATUS.ONLINE : VOLUME_STATUS.OFFLINE);
+ String volumeStatus = extractToken(line, VOLUME_STATUS_PFX);
+ if (volumeStatus != null) {
+ volume.setStatus(volumeStatus.equals("Started") ? VOLUME_STATUS.ONLINE : VOLUME_STATUS.OFFLINE);
continue;
}
- if (extractToken(line, VOLUME_TRANSPORT_TYPE_PFX) != null) {
- volume.setTransportType((extractToken(line,
- VOLUME_TRANSPORT_TYPE_PFX) == "tcp") ? TRANSPORT_TYPE.ETHERNET
+ String transportType = extractToken(line, VOLUME_TRANSPORT_TYPE_PFX);
+ if (transportType != null) {
+ volume.setTransportType(transportType.equals("tcp") ? TRANSPORT_TYPE.ETHERNET
: TRANSPORT_TYPE.INFINIBAND);
continue;
}
@@ -280,7 +289,7 @@ public class GlusterUtil {
if (isBricksGroupFound) {
if (line.matches("Brick[0-9]+:.*")) {
- bricks.add( line.split(":")[2].trim().split("/")[2].trim() ); // line: "Brick1: server1:/export/md0/volume-name"
+ volume.addDisk(line.split(":")[2].trim().split("/")[2].trim()); // line: "Brick1: server1:/export/md0/volume-name"
continue;
} else {
isBricksGroupFound = false;
@@ -293,14 +302,16 @@ public class GlusterUtil {
}
if (isOptionReconfigFound) {
- if (extractToken(line, VOLUME_OPTIONS_AUTH_ALLOW) != null) {
- volume.setAccessControlList( extractToken(line, VOLUME_OPTIONS_AUTH_ALLOW) );
+ if(line.matches("^[^:]*:[^:]*$")) {
+ String[] parts = line.split(":");
+ volume.setOption(parts[0].trim(), parts[1].trim());
+ } else {
isOptionReconfigFound = false;
}
}
}
+
if (volume != null) {// Adding the last volume parsed
- volume.setDisks(bricks);
volumes.add(volume);
}
return volumes;
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 67814126..aae740e4 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
@@ -27,8 +27,6 @@ import static com.gluster.storage.management.core.constants.RESTConstants.PATH_P
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_VOLUMES;
import static com.gluster.storage.management.core.constants.RESTConstants.SUBRESOURCE_DEFAULT_OPTIONS;
-
-import java.util.ArrayList;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
@@ -39,7 +37,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-
import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.Volume;
import com.gluster.storage.management.core.response.GenericResponse;
@@ -54,6 +51,7 @@ import com.sun.jersey.spi.resource.Singleton;
@Singleton
@Path(RESOURCE_PATH_VOLUMES)
public class VolumesResource {
+
private final GlusterUtil glusterUtil = new GlusterUtil();
@InjectParam
@@ -62,12 +60,11 @@ public class VolumesResource {
@GET
@Produces(MediaType.TEXT_XML)
public VolumeListResponse getAllVolumes() {
- ProcessResult response = glusterUtil.getVolumeInfo();
- if (response.isSuccess()) {
- return new VolumeListResponse( Status.STATUS_SUCCESS, glusterUtil.getAllVolumes(response.getOutput()) );
- } else {
- //TODO: log the error
- return new VolumeListResponse(Status.STATUS_FAILURE, new ArrayList<Volume>());
+ try {
+ return new VolumeListResponse(Status.STATUS_SUCCESS, glusterUtil.getAllVolumes());
+ } catch(Exception e) {
+ // TODO: log the error
+ return new VolumeListResponse(new Status(Status.STATUS_CODE_FAILURE, e.getMessage()), null);
}
}