summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.client
diff options
context:
space:
mode:
Diffstat (limited to 'src/com.gluster.storage.management.client')
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java24
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java16
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/RunningTaskClient.java26
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java96
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java33
5 files changed, 124 insertions, 71 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
index e8df26cb..5a1a28a7 100644
--- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
@@ -42,7 +42,8 @@ public abstract class AbstractClient {
* This constructor will work only after the data model manager has been initialized.
*/
public AbstractClient() {
- this(GlusterDataModelManager.getInstance().getSecurityToken(), GlusterDataModelManager.getInstance().getClusterName());
+ this(GlusterDataModelManager.getInstance().getSecurityToken(), GlusterDataModelManager.getInstance()
+ .getClusterName());
}
/**
@@ -55,8 +56,8 @@ public abstract class AbstractClient {
public AbstractClient(String securityToken, String clusterName) {
this.clusterName = clusterName;
setSecurityToken(securityToken);
-
- SSLContext context = initializeSSLContext();
+
+ SSLContext context = initializeSSLContext();
DefaultClientConfig config = createClientConfig(context);
// this must be after setting clusterName as sub-classes may refer to cluster name in the getResourcePath method
@@ -84,16 +85,16 @@ public abstract class AbstractClient {
SSLContext context = null;
try {
context = SSLContext.getInstance(PROTOCOL_TLS);
-
+
KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE_JKS);
keyStore.load(loadResource(TRUSTED_KEYSTORE), TRUSTED_KEYSTORE_ACCESS.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(ALGORITHM_SUNX509);
keyManagerFactory.init(keyStore, TRUSTED_KEYSTORE_ACCESS.toCharArray());
-
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM_SUNX509);
- trustManagerFactory.init(keyStore);
-
+
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM_SUNX509);
+ trustManagerFactory.init(keyStore);
+
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
} catch (Exception e) {
throw new GlusterRuntimeException(
@@ -101,7 +102,7 @@ public abstract class AbstractClient {
}
return context;
}
-
+
private InputStream loadResource(String resourcePath) {
return this.getClass().getClassLoader().getResourceAsStream(resourcePath);
}
@@ -286,6 +287,11 @@ public abstract class AbstractClient {
.header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.TEXT_XML).put(responseClass);
}
+ protected Object putRequest(String subResourceName, Class responseClass, MultivaluedMap<String, String> queryParams) {
+ return resource.path(subResourceName).queryParams(queryParams).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
+ .header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.TEXT_XML).put(responseClass);
+ }
+
/**
* Submits given object to the resource and returns the object received as response
*
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java
index e5d58ca4..15ee1adc 100644
--- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java
@@ -33,13 +33,13 @@ import com.gluster.storage.management.core.model.Event.EVENT_TYPE;
import com.gluster.storage.management.core.model.GlusterDataModel;
import com.gluster.storage.management.core.model.GlusterServer;
import com.gluster.storage.management.core.model.Server;
+import com.gluster.storage.management.core.model.TaskInfo;
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_STATUS;
import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE;
import com.gluster.storage.management.core.model.VolumeOptionInfo;
import com.gluster.storage.management.core.response.GlusterServerListResponse;
-import com.gluster.storage.management.core.response.RunningTaskListResponse;
import com.gluster.storage.management.core.response.ServerListResponse;
import com.gluster.storage.management.core.response.VolumeListResponse;
import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse;
@@ -94,7 +94,7 @@ public class GlusterDataModelManager {
initializeAutoDiscoveredServers(cluster);
// initializeDisks();
- initializeRunningTasks(cluster);
+ initializeTasks(cluster);
initializeAlerts(cluster);
initializeVolumeOptionsDefaults();
@@ -136,12 +136,14 @@ public class GlusterDataModelManager {
this.volumeOptionsDefaults = response.getOptions();
}
- public void initializeRunningTasks(Cluster cluster) {
- RunningTaskListResponse runningTaskResponse = new RunningTaskClient(cluster.getName()).getRunningTasks();
- if (!runningTaskResponse.getStatus().isSuccess()) {
- throw new GlusterRuntimeException(runningTaskResponse.getStatus().getMessage());
+ public void initializeTasks(Cluster cluster) {
+ try {
+ List<TaskInfo> taskInfoList = new TasksClient(cluster.getName()). getAllTasks();
+ cluster.setTaskInfoList(taskInfoList);
+ } catch(GlusterRuntimeException e) {
+ //TODO show the error dialog
+ //showErrorDialog( "Tasks", "Fetching tasks failed! Error: [" + e.getMessage() + "]");
}
- cluster.setRunningTasks(runningTaskResponse.getRunningTasks());
}
public void initializeAlerts(Cluster cluster) {
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/RunningTaskClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/RunningTaskClient.java
deleted file mode 100644
index cfeddcc2..00000000
--- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/RunningTaskClient.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.gluster.storage.management.client;
-
-import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS;
-import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_RUNNING_TASKS;
-
-import com.gluster.storage.management.core.response.RunningTaskListResponse;
-
-public class RunningTaskClient extends AbstractClient {
-
- public RunningTaskClient(String clusterName) {
- super(clusterName);
- }
-
- public RunningTaskClient(String securityToken, String clusterName) {
- super(securityToken, clusterName);
- }
-
- @Override
- public String getResourcePath() {
- return RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESOURCE_RUNNING_TASKS;
- }
-
- public RunningTaskListResponse getRunningTasks() {
- return (RunningTaskListResponse) fetchResource(RunningTaskListResponse.class);
- }
-}
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java
new file mode 100644
index 00000000..c1cfd9bd
--- /dev/null
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java
@@ -0,0 +1,96 @@
+/**
+ * tasksClient.java
+ *
+ * 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.client;
+
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import com.gluster.storage.management.core.constants.RESTConstants;
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
+import com.gluster.storage.management.core.model.Status;
+import com.gluster.storage.management.core.model.TaskInfo;
+import com.gluster.storage.management.core.response.TaskListResponse;
+import com.gluster.storage.management.core.response.TaskResponse;
+import com.sun.jersey.api.representation.Form;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+public class TasksClient extends AbstractClient {
+
+ public TasksClient(String clusterName) {
+ super(clusterName);
+ }
+
+ public TasksClient(String securityToken,String clusterName) {
+ super(securityToken, clusterName);
+ }
+
+ @Override
+ public String getResourcePath() {
+ return RESTConstants.RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESTConstants.RESOURCE_TASKS + "/";
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<TaskInfo> getAllTasks() { // TaskListResponse get only the list of taskInfo not list of Tasks
+ TaskListResponse response = (TaskListResponse) fetchResource(TaskListResponse.class);
+ if (response.getStatus().isSuccess()) {
+ return (List<TaskInfo>) response.getData();
+ } else {
+ throw new GlusterRuntimeException("Exception on fetching tasks [" + response.getStatus().getMessage() + "]");
+ }
+ }
+
+ // see startMigration @ VolumesClient
+ public TaskResponse pauseMigration(String taskId) {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(RESTConstants.QUERY_PARAM_TASK_OPERATION, RESTConstants.TASK_PAUSE);
+
+ return (TaskResponse) putRequest( taskId, TaskResponse.class, queryParams);
+ }
+
+ public TaskResponse resumeMigration(String taskId) {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(RESTConstants.QUERY_PARAM_TASK_OPERATION, RESTConstants.TASK_RESUME);
+
+ return (TaskResponse) putRequest( taskId, TaskResponse.class, queryParams);
+ }
+
+ public TaskResponse stopMigration(String taskId) {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(RESTConstants.QUERY_PARAM_TASK_OPERATION, RESTConstants.TASK_STOP);
+
+ return (TaskResponse) putRequest( taskId, TaskResponse.class, queryParams);
+ }
+
+ public TaskResponse statusMigration(String taskId) {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(RESTConstants.QUERY_PARAM_TASK_OPERATION, RESTConstants.TASK_STATUS);
+
+ return (TaskResponse) putRequest( taskId, Status.class, queryParams);
+ }
+
+ public TaskInfo deleteMigration(String taskId) {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(RESTConstants.QUERY_PARAM_TASK_OPERATION, RESTConstants.TASK_DELETE);
+
+ return (TaskInfo) putRequest( taskId, Status.class, queryParams);
+ }
+}
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 3b1a4dc0..124e37ea 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
@@ -71,11 +71,11 @@ public class VolumesClient extends AbstractClient {
}
public Status startVolume(String volumeName) {
- return performOperation(volumeName, RESTConstants.FORM_PARAM_VALUE_START);
+ return performOperation(volumeName, RESTConstants.TASK_START);
}
public Status stopVolume(String volumeName) {
- return performOperation(volumeName, RESTConstants.FORM_PARAM_VALUE_STOP);
+ return performOperation(volumeName, RESTConstants.TASK_STOP);
}
public Status setVolumeOption(String volume, String key, String value) {
@@ -196,37 +196,12 @@ public class VolumesClient extends AbstractClient {
Form form = new Form();
form.add(RESTConstants.FORM_PARAM_SOURCE, brickFrom);
form.add(RESTConstants.FORM_PARAM_TARGET, brickTo);
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_VALUE_START);
+ form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_START);
return (Status) putRequest( volumeName + "/" + RESTConstants.RESOURCE_BRICKS, Status.class, form);
}
- public Status stopMigration(String volumeName, String brickFrom, String brickkTo) {
- Form form = new Form();
- form.add(RESTConstants.FORM_PARAM_SOURCE, brickFrom);
- form.add(RESTConstants.FORM_PARAM_TARGET, brickkTo);
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_VALUE_STOP);
-
- return (Status) putRequest( volumeName + "/" + RESTConstants.RESOURCE_BRICKS, Status.class, form);
- }
-
- public Status pauseMigration(String volumeName, String brickFrom, String brickTo) {
- Form form = new Form();
- form.add(RESTConstants.FORM_PARAM_SOURCE, brickFrom);
- form.add(RESTConstants.FORM_PARAM_TARGET, brickTo);
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_VALUE_PAUSE);
-
- return (Status) putRequest( volumeName + "/" + RESTConstants.RESOURCE_BRICKS, Status.class, form);
- }
-
- public Status statusMigration(String volumeName, String brickFrom, String brickTo) {
- Form form = new Form();
- form.add(RESTConstants.FORM_PARAM_SOURCE, brickFrom);
- form.add(RESTConstants.FORM_PARAM_TARGET, brickTo);
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_VALUE_STATUS);
-
- return (Status) putRequest( volumeName + "/" + RESTConstants.RESOURCE_BRICKS, Status.class, form);
- }
+
public static void main(String[] args) {
UsersClient usersClient = new UsersClient();