summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeOptionInfoListResponse.java4
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/constants/VolumeOptionsDefaults.java73
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java4
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java2
4 files changed, 75 insertions, 8 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeOptionInfoListResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeOptionInfoListResponse.java
index affe1e00..6dc1b400 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeOptionInfoListResponse.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeOptionInfoListResponse.java
@@ -27,7 +27,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.VolumeOptionInfo;
-@XmlRootElement(name = "options")
+@XmlRootElement(name = "volumeOptionsDefaults")
public class VolumeOptionInfoListResponse {
private List<VolumeOptionInfo> options = new ArrayList<VolumeOptionInfo>();
@@ -38,7 +38,7 @@ public class VolumeOptionInfoListResponse {
setOptions(options);
}
- @XmlElement(name = "option", type=VolumeOptionInfo.class)
+ @XmlElement(name = "volumeOption", type=VolumeOptionInfo.class)
public List<VolumeOptionInfo> getOptions() {
return options;
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/constants/VolumeOptionsDefaults.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/constants/VolumeOptionsDefaults.java
index 1f577c89..bfc5106d 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/constants/VolumeOptionsDefaults.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/constants/VolumeOptionsDefaults.java
@@ -23,25 +23,42 @@ package com.gluster.storage.management.gateway.constants;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
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.VolumeOptionInfo;
+import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse;
+import com.gluster.storage.management.gateway.services.ClusterService;
+import com.gluster.storage.management.gateway.utils.ServerUtil;
+import com.sun.jersey.api.core.InjectParam;
@Component
public class VolumeOptionsDefaults {
- public List<VolumeOptionInfo> options;
+ @Autowired
+ private ServerUtil serverUtil;
+
+ @InjectParam
+ private ClusterService clusterService;
+ public List<VolumeOptionInfo> options;
+
+
public VolumeOptionsDefaults() {
}
/**
* @return list of volume option information objects
*/
- public List<VolumeOptionInfo> getDefaults() {
+ public List<VolumeOptionInfo> getDefaults(String clusterName) {
+ // return getVolumeOptionsInfo(clusterName);
return getVolumeOptionsInfo();
}
-
+
+
/**
* Fetches the list of all volume options with their information from GlusterFS and returns the same
*
@@ -115,4 +132,54 @@ public class VolumeOptionsDefaults {
return volumeOptionsInfo;
}
+
+
+ public List<VolumeOptionInfo> getVolumeOptionsInfo(String clusterName) {
+ String command = "gluster volume set help-xml";
+ VolumeOptionInfoListResponse options = new VolumeOptionInfoListResponse();
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
+
+ try {
+ options = runDefaultVolumeOptions(onlineServer.getName(), command);
+ return options.getOptions();
+ } catch (ConnectionException e) {
+ onlineServer = clusterService.getNewOnlineServer(clusterName);
+ options = runDefaultVolumeOptions(onlineServer.getName(), command);
+ return options.getOptions();
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Fetching volume options default failed! [" + e.getMessage() + "]");
+ }
+ }
+
+ private VolumeOptionInfoListResponse runDefaultVolumeOptions(String serverName, String command) {
+ return (VolumeOptionInfoListResponse) serverUtil.executeOnServer(true, serverName, command,
+ VolumeOptionInfoListResponse.class);
+ }
+
+
+ public static void main(String[] args) {
+// String command = "gluster volume set help-xml";
+// String output = "";
+// ServerUtil serverUtil = new ServerUtil();
+// try {
+// Process p = Runtime.getRuntime().exec(command);
+// p.waitFor();
+// BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+// String line = reader.readLine();
+// while (line != null) {
+// output += line;
+// line = reader.readLine();
+// }
+// } catch (Exception e) {
+// System.out.println("Error in executing command ...." + e.getMessage());
+// }
+// Object response = serverUtil.unmarshal(VolumeOptionInfoListResponse.class, output, false);
+// if (response instanceof Status) {
+// System.out.println("Error: " + response.toString());
+// return;
+// }
+// for (VolumeOptionInfo option : ((VolumeOptionInfoListResponse) response).getOptions()) {
+// System.out.println(option.getName() + " : " + option.getDefaultValue() );
+// }
+ }
} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
index 31dff630..923293fd 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
@@ -808,7 +808,7 @@ public class VolumesResource extends AbstractResource {
public VolumeOptionInfoListResponse getDefaultOptionsXML(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName) {
// TODO: Fetch all volume options with their default values from GlusterFS
// whenever such a CLI command is made available in GlusterFS
- return new VolumeOptionInfoListResponse(Status.STATUS_SUCCESS, volumeOptionsDefaults.getDefaults());
+ return new VolumeOptionInfoListResponse(Status.STATUS_SUCCESS, volumeOptionsDefaults.getDefaults(clusterName));
}
@GET
@@ -817,7 +817,7 @@ public class VolumesResource extends AbstractResource {
public VolumeOptionInfoListResponse getDefaultOptionsJSON(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName) {
// TODO: Fetch all volume options with their default values from GlusterFS
// whenever such a CLI command is made available in GlusterFS
- return new VolumeOptionInfoListResponse(Status.STATUS_SUCCESS, volumeOptionsDefaults.getDefaults());
+ return new VolumeOptionInfoListResponse(Status.STATUS_SUCCESS, volumeOptionsDefaults.getDefaults(clusterName));
}
private List<VolumeLogMessage> getBrickLogs(Volume volume, Brick brick, Integer lineCount)
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
index 6cd8303c..84514893 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
@@ -238,7 +238,7 @@ public class ServerUtil {
* @return Object of given expected class, or a status object in case first unmarshalling fails.
*/
@SuppressWarnings("rawtypes")
- private Object unmarshal(Class expectedClass, String input, boolean tryGenericResponseOnFailure) {
+ public Object unmarshal(Class expectedClass, String input, boolean tryGenericResponseOnFailure) {
try {
// create JAXB context and instantiate marshaller
JAXBContext context = JAXBContext.newInstance(expectedClass);