summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSelvasundaram <selvam@gluster.com>2011-07-04 19:06:51 +0530
committerSelvasundaram <selvam@gluster.com>2011-07-04 19:06:51 +0530
commitf9ddc60ee998d24ff1f2b5f158a2b0e14f965b0d (patch)
tree6efef62ed2b7fd7791cb6016cfbf2ddfaa58479f /src
parent552e7c7f05bfd553c9d539926f4aca0f08c5c246 (diff)
parent2710aaba814aeac87cc7d83a45c066ab7b7a164e (diff)
Merge branch 'master' of github.com:gluster/console
Conflicts: src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java76
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java6
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java13
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java1
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RefreshDataAction.java5
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java9
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java2
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java54
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java78
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java3
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java51
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java33
12 files changed, 201 insertions, 130 deletions
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 a1c7823a..a9c966c3 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
@@ -105,45 +105,50 @@ public class GlusterDataModelManager {
return model;
}
- public void updateModel(GlusterDataModel model) {
+ public void refreshModel() {
+ updateModel(fetchData(clusterName));
+ }
+
+ private void updateModel(GlusterDataModel model) {
updateVolumes(model);
+ updateServers(model);
+ // TODO: Update other entities like discovered servers
}
- private void updateVolumes(GlusterDataModel model) {
- List<Volume> currentVolumes = this.model.getCluster().getVolumes();
- List<Volume> latestVolumes = model.getCluster().getVolumes();
+ private void updateServers(GlusterDataModel newModel) {
+ List<GlusterServer> oldServers = model.getCluster().getServers();
+ List<GlusterServer> newServers = newModel.getCluster().getServers();
- List<Volume> addedVolumes = getAddedVolumes(currentVolumes, latestVolumes);
- for(ClusterListener listener : listeners) {
- for(Volume addedVolume : addedVolumes) {
- listener.volumeAdded(addedVolume);
- }
+ List<GlusterServer> addedServers = GlusterCoreUtil.getAddedEntities(oldServers, newServers, true);
+ for (GlusterServer addedServer : addedServers) {
+ addGlusterServer(addedServer);
}
-
- List<Volume> removedVolumes = getRemovedVolumes(currentVolumes, latestVolumes);
- for(ClusterListener listener : listeners) {
- for(Volume removedVolume : addedVolumes) {
- listener.volumeRemoved(removedVolume);
- }
+
+ List<GlusterServer> removedServers = GlusterCoreUtil.getAddedEntities(newServers, oldServers, true);
+ for (GlusterServer removedServer : removedServers) {
+ removeGlusterServer(removedServer);
}
- }
-
- private List<Volume> getRemovedVolumes(List<Volume> currentVolumes, List<Volume> latestVolumes) {
- // TODO Auto-generated method stub
- return null;
+
+ // TODO: Refresh "modified" servers
}
- private List<Volume> getAddedVolumes(List<Volume> currentVolumes, List<Volume> newVolumes) {
- List<Volume> addedVolumes = new ArrayList<Volume>();
- for(Volume newVolume : addedVolumes) {
- if(!GlusterCoreUtil.containsEntity(currentVolumes, newVolume, false)) {
- // current volume list doesn't contain this volume. mark it.
- addedVolumes.add(newVolume);
- }
+ private void updateVolumes(GlusterDataModel newModel) {
+ List<Volume> oldVolumes = model.getCluster().getVolumes();
+ List<Volume> newVolumes = newModel.getCluster().getVolumes();
+
+ List<Volume> addedVolumes = GlusterCoreUtil.getAddedEntities(oldVolumes, newVolumes, false);
+ for (Volume addedVolume : addedVolumes) {
+ addVolume(addedVolume);
}
- return addedVolumes;
+
+ List<Volume> removedVolumes = GlusterCoreUtil.getAddedEntities(newVolumes, oldVolumes, false);
+ for (Volume removedVolume : removedVolumes) {
+ deleteVolume(removedVolume);
+ }
+
+ // TODO: Refresh "modified" volumes
}
-
+
private void initializeGlusterServers(Cluster cluster) {
cluster.setServers(new GlusterServersClient().getServers());
}
@@ -323,6 +328,8 @@ public class GlusterDataModelManager {
for (ClusterListener listener : listeners) {
listener.serverAdded(server);
}
+
+ removeDiscoveredServer(server.getName());
}
public void addDiscoveredServer(Server server) {
@@ -333,6 +340,17 @@ public class GlusterDataModelManager {
listener.discoveredServerAdded(server);;
}
}
+
+ public void removeDiscoveredServer(String serverName) {
+ Cluster cluster = model.getCluster();
+ // TODO: Move auto-discovered servers outside the cluster
+ for(Server server : cluster.getAutoDiscoveredServers()) {
+ if(server.getName().toUpperCase().equals(serverName.toUpperCase())) {
+ removeDiscoveredServer(server);
+ break;
+ }
+ }
+ }
public void removeDiscoveredServer(Server server) {
Cluster cluster = model.getCluster();
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 b5d2711a..2866a8e1 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
@@ -241,12 +241,6 @@ public class VolumesClient extends AbstractClient {
putRequest(volumeName, form);
}
- public void rebalanceStatus(String volumeName) {
- Form form = new Form();
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_REBALANCE_STATUS);
- putRequest(volumeName, form);
- }
-
public void rebalanceStop(String volumeName) {
Form form = new Form();
form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_REBALANCE_STOP);
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 20b652f4..76a7fbfc 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
@@ -53,12 +53,13 @@ public class GlusterCoreUtil {
*
* @param oldEntities
* @param newEntities
+ * @param caseInsensitive If true, the entity name comparison will be done in case insensitive manner
* @return List of entities that are present only in the second argument <code>newEntities</code>
*/
- public static List<Entity> getAddedEntities(List<? extends Entity> oldEntities, List<Entity> newEntities) {
- List<Entity> addedEntities = new ArrayList<Entity>();
- for(Entity newEntity : newEntities) {
- if(!containsEntity(oldEntities, newEntity, false)) {
+ public static <T extends Entity> List<T> getAddedEntities(List<T> oldEntities, List<T> newEntities, boolean caseInsensitive) {
+ List<T> addedEntities = new ArrayList<T>();
+ for(T newEntity : newEntities) {
+ if(!containsEntity(oldEntities, newEntity, caseInsensitive)) {
// old entity list doesn't contain this entity. mark it as new.
addedEntities.add(newEntity);
}
@@ -66,13 +67,13 @@ public class GlusterCoreUtil {
return addedEntities;
}
- public static boolean containsEntity(List<? extends Entity> entityList, Entity searchEntity, boolean caseInsensitive) {
+ public static <T extends Entity> boolean containsEntity(List<T> entityList, Entity searchEntity, boolean caseInsensitive) {
String searchEntityName = searchEntity.getName();
if(caseInsensitive) {
searchEntityName = searchEntityName.toUpperCase();
}
- for(Entity entity : entityList) {
+ for(T entity : entityList) {
String nextEntityName = entity.getName();
if(caseInsensitive) {
nextEntityName = nextEntityName.toUpperCase();
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java
index 0e6cd6b2..81661942 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java
@@ -53,7 +53,6 @@ public class AddServerAction extends AbstractActionDelegate {
try {
glusterServersClient.addServer(server);
- modelManager.removeDiscoveredServer(server);
modelManager.addGlusterServer(glusterServersClient.getGlusterServer(server.getName()));
successServers.add(server);
} catch (Exception e) {
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RefreshDataAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RefreshDataAction.java
index 4a569c50..fe358caa 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RefreshDataAction.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RefreshDataAction.java
@@ -20,6 +20,8 @@ package com.gluster.storage.management.gui.actions;
import org.eclipse.jface.action.IAction;
+import com.gluster.storage.management.client.GlusterDataModelManager;
+
/**
*
*/
@@ -39,7 +41,6 @@ public class RefreshDataAction extends AbstractActionDelegate {
*/
@Override
protected void performAction(IAction action) {
- // TODO Auto-generated method stub
-
+ GlusterDataModelManager.getInstance().refreshModel();
}
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
index a9ef7fbb..1f4b15de 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
@@ -414,13 +414,14 @@ public class GlusterServersResource extends AbstractServersResource {
return badRequestResponse("Disk name must not be empty!");
}
- InitializeDiskTask initializeTask = new InitializeDiskTask(clusterService, clusterName, diskName, serverName);
+ InitializeDiskTask initializeTask = new InitializeDiskTask(clusterService, clusterName, serverName, diskName);
try {
initializeTask.start();
taskResource.addTask(initializeTask);
- return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESOURCE_TASKS
- + "/" + initializeTask.getId());
- } catch (ConnectionException e) {
+
+ return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESOURCE_TASKS + "/"
+ + initializeTask.getId());
+ } catch (Exception e) {
return errorResponse(e.getMessage());
}
}
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 d568d519..4318945c 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
@@ -978,7 +978,7 @@ public class VolumesResource extends AbstractResource {
return rebalanceStart(clusterName, volumeName, layout);
}
- public String rebalanceStart(String clusterName, String volumeName, String layout) {
+ private String rebalanceStart(String clusterName, String volumeName, String layout) {
RebalanceVolumeTask rebalanceTask = new RebalanceVolumeTask(clusterService, clusterName, volumeName);
rebalanceTask.setLayout(layout);
rebalanceTask.start();
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java
index 5f3f8e30..4592b759 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java
@@ -20,21 +20,26 @@
*/
package com.gluster.storage.management.server.tasks;
+import com.gluster.storage.management.core.exceptions.ConnectionException;
+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.model.TaskInfo.TASK_TYPE;
import com.gluster.storage.management.core.model.TaskStatus;
+import com.gluster.storage.management.core.utils.ProcessResult;
import com.gluster.storage.management.server.services.ClusterService;
+import com.gluster.storage.management.server.utils.GlusterUtil;
import com.gluster.storage.management.server.utils.SshUtil;
+import com.sun.jersey.core.util.Base64;
public class InitializeDiskTask extends Task {
private static final String INITIALIZE_DISK_SCRIPT = "initialize_disk.py";
- private static final String INITIALIZE_DISK_STATUS_SCRIPT = "initialize_disk_status.py";
private String serverName;
private String diskName;
private SshUtil sshUtil = new SshUtil();
+ private GlusterUtil glusterUtil;
public InitializeDiskTask(ClusterService clusterService, String clusterName, String serverName, String diskName) {
super(clusterService, clusterName, TASK_TYPE.DISK_FORMAT, diskName, "Initialize disk " + serverName + ":"
@@ -50,22 +55,29 @@ public class InitializeDiskTask extends Task {
@Override
public String getId() {
- return taskInfo.getType() + "-" + serverName + ":" + diskName;
+ return new String(
+ Base64.encode(getClusterName() + "-" + taskInfo.getType() + "-" + serverName + ":" + diskName));
}
@Override
public void resume() {
- getTaskInfo().setStatus( new TaskStatus( new Status(Status.STATUS_CODE_FAILURE, "Can not resume disk initialization")));
+ getTaskInfo().setStatus(
+ new TaskStatus(new Status(Status.STATUS_CODE_FAILURE,
+ "Stop/Pause/Resume is not supported in Disk Initialization")));
}
@Override
public void stop() {
- getTaskInfo().setStatus( new TaskStatus( new Status(Status.STATUS_CODE_FAILURE, "Can not stop disk initialization")));
+ getTaskInfo().setStatus(
+ new TaskStatus(new Status(Status.STATUS_CODE_FAILURE,
+ "Stop/Pause/Resume is not supported in Disk Initialization")));
}
@Override
public void pause() {
- getTaskInfo().setStatus( new TaskStatus( new Status(Status.STATUS_CODE_FAILURE, "Can not suspend disk initialization")));
+ getTaskInfo().setStatus(
+ new TaskStatus(new Status(Status.STATUS_CODE_FAILURE,
+ "Stop/Pause/Resume is not supported in Disk Initialization")));
}
@Override
@@ -85,17 +97,37 @@ public class InitializeDiskTask extends Task {
@Override
public void start() {
- getTaskInfo().setStatus(
- new TaskStatus(new Status(sshUtil.executeRemote(getServerName(), INITIALIZE_DISK_SCRIPT + " "
- + getDiskName()))));
+ try {
+ startInitializeDisk(serverName);
+ } catch(ConnectionException e) {
+ // online server might have gone offline. update the failure status
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, e.getMessage())));
+ }
+ }
+
+ private void startInitializeDisk(String serverName) {
+ ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_SCRIPT + " " + getDiskName());
+ if (processResult.isSuccess()) {
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput())));
+ return;
+ }
+
+ // if we reach here, it means Initialize disk start failed.
+ throw new GlusterRuntimeException(processResult.toString());
+
}
@Override
public TaskStatus checkStatus() {
- return new TaskStatus(new Status(sshUtil.executeRemote(getServerName(), INITIALIZE_DISK_STATUS_SCRIPT + " "
- + getDiskName())));
+
+ try {
+ return glusterUtil.checkInitializeDiskStatus(serverName, getDiskName());
+ } catch(ConnectionException e) {
+ // online server might have gone offline. update the failure status
+ return new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, e.getMessage()));
+ }
}
-
+
public void setDiskName(String diskName) {
this.diskName = diskName;
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java
index 7f9fb6bf..f94613e0 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java
@@ -28,33 +28,40 @@ import com.gluster.storage.management.core.model.TaskInfo.TASK_TYPE;
import com.gluster.storage.management.core.model.TaskStatus;
import com.gluster.storage.management.core.utils.ProcessResult;
import com.gluster.storage.management.server.services.ClusterService;
+import com.gluster.storage.management.server.utils.GlusterUtil;
import com.gluster.storage.management.server.utils.SshUtil;
+import com.sun.jersey.core.util.Base64;
public class RebalanceVolumeTask extends Task {
private String layout;
+ private String serverName;
private SshUtil sshUtil = new SshUtil();
+ private GlusterUtil glusterUtil = new GlusterUtil();
public RebalanceVolumeTask(ClusterService clusterService, String clusterName, TaskInfo taskInfo) {
super(clusterService, clusterName, taskInfo);
}
public RebalanceVolumeTask(ClusterService clusterService, String clusterName, String volumeName) {
- super(clusterService, clusterName, TASK_TYPE.VOLUME_REBALANCE, volumeName, "Volume rebalance running on " + volumeName, false, true, false);
+ super(clusterService, clusterName, TASK_TYPE.VOLUME_REBALANCE, volumeName, "Volume " + volumeName
+ + " Rebalance", false, true, false);
}
@Override
public String getId() {
- return taskInfo.getType() + "-" + taskInfo.getReference();
+ return new String(Base64.encode(getClusterName() + "-" + taskInfo.getType() + "-" + taskInfo.getReference()));
}
@Override
public void start() {
try {
- startRebalance(getOnlineServer().getName());
+ serverName = getOnlineServer().getName();
+ startRebalance(serverName);
} catch(ConnectionException e) {
// online server might have gone offline. try with a new one
- startRebalance(getNewOnlineServer().getName());
+ serverName = getNewOnlineServer().getName();
+ startRebalance(serverName);
}
}
@@ -62,11 +69,10 @@ public class RebalanceVolumeTask extends Task {
String command = "gluster volume rebalance " + getTaskInfo().getReference() + " " + getLayout() + " start";
ProcessResult processResult = sshUtil.executeRemote(serverName, command);
if (processResult.isSuccess()) {
- if (processResult.getOutput().trim().matches(".*has been successful$")) {
- getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput())));
- }
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput())));
+ return;
}
-
+
// if we reach here, it means rebalance start failed.
throw new GlusterRuntimeException(processResult.toString());
}
@@ -74,70 +80,38 @@ public class RebalanceVolumeTask extends Task {
@Override
public void resume() {
getTaskInfo().setStatus(
- new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, "Pause/Resume is not supported in Volume Rebalance")));
+ new TaskStatus(new Status(Status.STATUS_CODE_FAILURE,
+ "Pause/Resume is not supported in Volume Rebalance")));
}
@Override
public void stop() {
try {
- stopRebalance(getOnlineServer().getName());
- } catch(ConnectionException e) {
- // online server might have gone offline. try with a new one
- stopRebalance(getNewOnlineServer().getName());
+ glusterUtil.stopRebalance(serverName, getTaskInfo().getReference());
+ } catch (ConnectionException e) {
+ // online server might have gone offline. update the failure status
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, e.getMessage())));
}
}
- private void stopRebalance(String serverName) {
- String command = "gluster volume rebalance " + getTaskInfo().getReference() + " stop";
- ProcessResult processResult = sshUtil.executeRemote(serverName, command);
- TaskStatus taskStatus = new TaskStatus();
- if (processResult.isSuccess()) {
- if (processResult.getOutput().trim().matches(".*has been successful$")) {
- taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
- } else {
- taskStatus.setCode(Status.STATUS_CODE_FAILURE);
- }
- } else {
- taskStatus.setCode(Status.STATUS_CODE_FAILURE);
- }
- taskStatus.setMessage(processResult.getOutput()); // Common
- getTaskInfo().setStatus(taskStatus);
- }
-
@Override
public void pause() {
getTaskInfo().setStatus(
- new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, "Pause/Resume is not supported in Volume Rebalance")));
+ new TaskStatus(new Status(Status.STATUS_CODE_FAILURE,
+ "Pause/Resume is not supported in Volume Rebalance")));
}
@Override
public TaskStatus checkStatus() {
try {
- return checkRebalanceStatus(getOnlineServer().getName());
+ return glusterUtil.checkRebalanceStatus(serverName, getTaskInfo().getReference());
} catch(ConnectionException e) {
- // online server might have gone offline. try with a new one.
- return checkRebalanceStatus(getNewOnlineServer().getName());
+ // online server might have gone offline. update the failure status
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, e.getMessage())));
+ return getTaskInfo().getStatus();
}
}
- // TODO: This method should move to glusterUtil
- private TaskStatus checkRebalanceStatus(String serverName) {
- String command = "gluster volume rebalance " + getTaskInfo().getReference() + " status";
- ProcessResult processResult = sshUtil.executeRemote(serverName, command);
- TaskStatus taskStatus = new TaskStatus();
- if (processResult.isSuccess()) {
- if (processResult.getOutput().trim().matches(".*rebalance completed$")) {
- taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
- } else {
- taskStatus.setCode(Status.STATUS_CODE_RUNNING);
- }
- } else {
- taskStatus.setCode(Status.STATUS_CODE_FAILURE);
- }
- taskStatus.setMessage(processResult.getOutput()); // Common
- return taskStatus;
- }
-
public void setLayout(String layout) {
this.layout = layout;
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java
index 4fa6e08c..119f6297 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/Task.java
@@ -33,7 +33,8 @@ public abstract class Task {
protected String clusterName;
private ClusterService clusterService;
- public Task(ClusterService clusterService, String clusterName, TASK_TYPE type, String reference, String desc, boolean canPause, boolean canStop, boolean canCommit) {
+ public Task(ClusterService clusterService, String clusterName, TASK_TYPE type, String reference, String desc,
+ boolean canPause, boolean canStop, boolean canCommit) {
TaskInfo taskInfo = new TaskInfo();
taskInfo.setType(type);
taskInfo.setReference(reference);
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
index 788e3eab..1dc5eb1a 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
@@ -37,6 +37,7 @@ import com.gluster.storage.management.core.model.GlusterServer;
import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS;
import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.TaskInfo;
+import com.gluster.storage.management.core.model.TaskStatus;
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;
@@ -71,6 +72,8 @@ public class GlusterUtil {
private static final String VOLUME_TYPE_REPLICATE = "Replicate";
private static final GlusterCoreUtil glusterCoreUtil = new GlusterCoreUtil();
+
+ private static final String INITIALIZE_DISK_STATUS_SCRIPT = "initialize_disk_status.py";
@Autowired
private SshUtil sshUtil;
@@ -550,6 +553,54 @@ public class GlusterUtil {
throw new GlusterRuntimeException("Couldn't remove server [" + serverName + "]! Error: " + result);
}
}
+
+ public TaskStatus checkRebalanceStatus(String serverName, String volumeName) {
+ String command = "gluster volume rebalance " + volumeName + " status";
+ ProcessResult processResult = sshUtil.executeRemote(serverName, command);
+ TaskStatus taskStatus = new TaskStatus();
+ if (processResult.isSuccess()) {
+ if (processResult.getOutput().trim().matches("^rebalance completed.*")) {
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ } else if(processResult.getOutput().trim().matches(".*in progress:.*")) {
+ taskStatus.setCode(Status.STATUS_CODE_RUNNING);
+ } else {
+ taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ }
+ } else {
+ taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ }
+ taskStatus.setMessage(processResult.getOutput()); // Common
+ return taskStatus;
+ }
+
+ public void stopRebalance(String serverName, String volumeName) {
+ String command = "gluster volume rebalance " + volumeName + " stop";
+ ProcessResult processResult = sshUtil.executeRemote(serverName, command);
+ TaskStatus taskStatus = new TaskStatus();
+ if (processResult.isSuccess()) {
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ taskStatus.setMessage(processResult.getOutput());
+ }
+ }
+
+ public TaskStatus checkInitializeDiskStatus(String serverName, String diskName) {
+ ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_STATUS_SCRIPT + " " + diskName);
+ TaskStatus taskStatus = new TaskStatus();
+ if (processResult.isSuccess()) {
+ // TODO: Message needs to change according to the script return
+ if (processResult.getOutput().trim().matches(".*Initailize completed$")) {
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ } else {
+ // TODO: Percentage completed needs to be set, according to the script output
+ taskStatus.setCode(Status.STATUS_CODE_RUNNING);
+ // taskStatus.setPercentCompleted(processResult.getOutput());
+ }
+ } else {
+ taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ }
+ taskStatus.setMessage(processResult.getOutput());
+ return taskStatus;
+ }
public static void main(String args[]) {
// List<String> names = new GlusterUtil().getGlusterServerNames();
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
index d56cd47c..4f0b04cf 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
@@ -226,6 +226,10 @@ public class SshUtil {
return conn;
}
+ private boolean wasTerminated(int condition) {
+ return ((condition | ChannelCondition.EXIT_SIGNAL) == condition);
+ }
+
private boolean hasErrors(int condition, Session session) {
return (hasErrorStream(condition) || (exitedGracefully(condition) && exitedWithError(session)));
}
@@ -239,7 +243,7 @@ public class SshUtil {
}
private boolean exitedGracefully(int condition) {
- return (condition == ChannelCondition.EXIT_STATUS);
+ return (condition | ChannelCondition.EXIT_STATUS) == condition;
}
private boolean hasErrorStream(int condition) {
@@ -292,24 +296,19 @@ public class SshUtil {
private ProcessResult prepareProcessResult(Session session, int condition, String output) {
ProcessResult result = null;
- switch(condition) {
- case ChannelCondition.TIMEOUT:
- result = new ProcessResult(ProcessResult.FAILURE, "Command timed out!");
- break;
- case ChannelCondition.EXIT_SIGNAL:
- // terminated
+
+ if (wasTerminated(condition)) {
result = new ProcessResult(ProcessResult.FAILURE, output);
- break;
- default:
- if (hasErrors(condition, session)) {
- Integer exitStatus = session.getExitStatus();
- int statusCode = (exitStatus == null ? ProcessResult.FAILURE : exitStatus);
- result = new ProcessResult(statusCode, output);
- } else {
- result = new ProcessResult(ProcessResult.SUCCESS, output);
- }
- break;
+ } else if (timedOut(condition)) {
+ result = new ProcessResult(ProcessResult.FAILURE, "Command timed out!");
+ } else if (hasErrors(condition, session)) {
+ Integer exitStatus = session.getExitStatus();
+ int statusCode = (exitStatus == null ? ProcessResult.FAILURE : exitStatus);
+ result = new ProcessResult(statusCode, output);
+ } else {
+ result = new ProcessResult(ProcessResult.SUCCESS, output);
}
+
return result;
}