diff options
Diffstat (limited to 'src/com.gluster.storage.management.core')
7 files changed, 128 insertions, 41 deletions
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 a082d49b..a2d222a8 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 @@ -47,6 +47,16 @@ public class RESTConstants { public static final String TASK_STATUS = "status"; public static final String TASK_DELETE = "delete"; + public static final String FORM_PARAM_VOLUME_NAME = "name"; + public static final String FORM_PARAM_VOLUME_TYPE = "volumeType"; + public static final String FORM_PARAM_TRANSPORT_TYPE = "transportType"; + public static final String FORM_PARAM_REPLICA_COUNT = "replicaCount"; + public static final String FORM_PARAM_STRIPE_COUNT = "stripeCount"; + public static final String FORM_PARAM_BRICKS = "bricks"; + public static final String FORM_PARAM_ACCESS_PROTOCOLS = "accessProtocols"; + public static final String FORM_PARAM_VOLUME_OPTIONS = "options"; + + public static final String FORM_PARAM_CLUSTER_NAME = "clusterName"; public static final String FORM_PARAM_SERVER_NAME = "serverName"; public static final String FORM_PARAM_DISKS = "disks"; @@ -56,9 +66,9 @@ public class RESTConstants { public static final String FORM_PARAM_OPTION_VALUE = "value"; public static final String FORM_PARAM_SOURCE = "source"; public static final String FORM_PARAM_TARGET = "target"; - public static final String FORM_PARAM_BRICKS = "bricks"; public static final String FORM_PARAM_AUTO_COMMIT = "autoCommit"; + public static final String PATH_PARAM_FORMAT = "format"; public static final String PATH_PARAM_VOLUME_NAME = "volumeName"; public static final String PATH_PARAM_CLUSTER_NAME = "clusterName"; public static final String PATH_PARAM_SERVER_NAME = "serverName"; @@ -75,4 +85,7 @@ public class RESTConstants { public static final String QUERY_PARAM_TO_TIMESTAMP = "toTimestamp"; public static final String QUERY_PARAM_DOWNLOAD = "download"; public static final String QUERY_PARAM_SERVER_NAME = "serverName"; + + public static final String FORMAT_XML = "xml"; + public static final String FORMAT_JSON = "json"; } 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 399192f4..1d5b2fec 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 @@ -88,6 +88,14 @@ public class Volume extends Entity { public static String getVolumeTypeStr(VOLUME_TYPE volumeType) { return VOLUME_TYPE_STR[volumeType.ordinal()]; } + + public static VOLUME_TYPE getVolumeTypeByStr(String volumeTypeStr) { + return VOLUME_TYPE.valueOf(volumeTypeStr); + } + + public static TRANSPORT_TYPE getTransportTypeByStr(String transportTypeStr) { + return TRANSPORT_TYPE.valueOf(transportTypeStr); + } public String getTransportTypeStr() { return TRANSPORT_TYPE_STR[getTransportType().ordinal()]; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/LogMessageListResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/LogMessageListResponse.java index be374e8b..c1f879bb 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/LogMessageListResponse.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/LogMessageListResponse.java @@ -7,25 +7,27 @@ import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import com.gluster.storage.management.core.model.VolumeLogMessage; import com.gluster.storage.management.core.model.Status; +import com.gluster.storage.management.core.model.VolumeLogMessage; -@XmlRootElement(name = "response") +@XmlRootElement(name = "logMessages") public class LogMessageListResponse extends AbstractResponse { private List<VolumeLogMessage> logMessages = new ArrayList<VolumeLogMessage>(); public LogMessageListResponse() { } + public LogMessageListResponse(List<VolumeLogMessage> logMessages) { + setLogMessages(logMessages); + } + public LogMessageListResponse(Status status, List<VolumeLogMessage> logMessages) { setStatus(status); setLogMessages(logMessages); } - @XmlElementWrapper(name = "logMessages") @XmlElement(name = "logMessage", type = VolumeLogMessage.class) public List<VolumeLogMessage> getLogMessages() { return logMessages; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskIdResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskIdResponse.java new file mode 100644 index 00000000..f2610104 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskIdResponse.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.core.response; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + */ +@XmlRootElement(name="task") +public class TaskIdResponse { + private String id; + + public TaskIdResponse() { + } + + public TaskIdResponse(String id) { + setId(id); + } + + public void setId(String id) { + this.id = id; + } + + @XmlElement(name="id") + public String getId() { + return id; + } +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeListResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeListResponse.java index 97085603..6518f0d5 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeListResponse.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/VolumeListResponse.java @@ -4,27 +4,22 @@ import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.Volume; -@XmlRootElement(name = "response") -public class VolumeListResponse extends AbstractResponse { +@XmlRootElement(name = "volumes") +public class VolumeListResponse { private List<Volume> volumes = new ArrayList<Volume>(); public VolumeListResponse() { } - public VolumeListResponse(Status status, List<Volume> volumes) { - setStatus(status); + public VolumeListResponse(List<Volume> volumes) { setVolumes(volumes); } - @XmlElementWrapper(name = "volumes") @XmlElement(name = "volume", type = Volume.class) public List<Volume> getVolumes() { return this.volumes; @@ -33,10 +28,4 @@ public class VolumeListResponse extends AbstractResponse { public void setVolumes(List<Volume> volumes) { this.volumes = volumes; } - - @Override - @XmlTransient - public Object getData() { - return this.volumes; - } } 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 629ccbee..affe1e00 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 @@ -22,47 +22,28 @@ import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.VolumeOptionInfo; -@XmlRootElement(name = "response") -public class VolumeOptionInfoListResponse extends AbstractResponse { +@XmlRootElement(name = "options") +public class VolumeOptionInfoListResponse { private List<VolumeOptionInfo> options = new ArrayList<VolumeOptionInfo>(); public VolumeOptionInfoListResponse() { } public VolumeOptionInfoListResponse(Status status, List<VolumeOptionInfo> options) { - setStatus(status); setOptions(options); } - @XmlElementWrapper(name = "volumeOptionDefaults") - @XmlElement(name = "volumeOption", type=VolumeOptionInfo.class) + @XmlElement(name = "option", type=VolumeOptionInfo.class) public List<VolumeOptionInfo> getOptions() { return options; } - /** - * @param options - * the options to set - */ public void setOptions(List<VolumeOptionInfo> options) { this.options = options; } - - /* - * (non-Javadoc) - * - * @see com.gluster.storage.management.core.model.Response#getData() - */ - @Override - @XmlTransient - public List<VolumeOptionInfo> getData() { - return getOptions(); - } } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java index c238cad7..14bad4fd 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java @@ -21,7 +21,9 @@ package com.gluster.storage.management.core.utils; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.Disk; @@ -44,4 +46,50 @@ public class GlusterCoreUtil { } return qualifiedBricks; } + + /** + * Extracts a list from a string by splitting it on given delimiter + * @param input the input string + * @return A {@link List} of extracted tokens + */ + public List<String> extractList(String input, String delim) { + String[] arr = input.split(delim); + List<String> output = new ArrayList<String>(); + for(String str : arr) { + String brick = str.trim(); + if(!brick.isEmpty()) { + output.add(brick); + } + } + return null; + } + + /** + * Extracts a map from a string by splitting it on the given primary and secondary delimiter. e.g. The input string + * <i>k1=v1,k2=v2,k3=v3</i> will yield the following map:<br> + * k1 -> v1<br> + * k2 -> v2<br> + * k3 -> v3<br> + * where <b>,</b> is the primary delimiter and <b>=</b> is the secondary delimiter. + * + * @param input + * @param majorDelim + * @param minorDelim + * @return Map of key value pairs + */ + public Map<String, String> extractMap(String input, String majorDelim, String minorDelim) { + String[] arr = input.split(majorDelim); + Map<String, String> output = new LinkedHashMap<String, String>(); + for(String str : arr) { + String[] elements = str.split(minorDelim); + if(elements.length == 2) { + String key = elements[0].trim(); + String value = elements[1].trim(); + if(!key.isEmpty() && !value.isEmpty()) { + output.put(key, value); + } + } + } + return output; + } } |
