diff options
| author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-28 02:33:06 -0700 |
|---|---|---|
| committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-28 02:33:06 -0700 |
| commit | cc69aaa3d4bce99ccd795296dd6bed8311c24fc8 (patch) | |
| tree | 7a2b3988e9c82d9c457f71824214ed8ebdcf5c05 | |
| parent | 0aa85e9e8b67492fbf26e761f54ca282539116e8 (diff) | |
| parent | eb58d91bb775a897c39ac7303993b361b48f35a9 (diff) | |
Merge pull request #83 from Dhandapani/master
Story #1: Rebalance Volume
6 files changed, 376 insertions, 46 deletions
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 c04389d1..4ec3ff13 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 @@ -229,6 +229,27 @@ public class VolumesClient extends AbstractClient { putRequest(volumeName + "/" + RESTConstants.RESOURCE_BRICKS, form); } + + public void rebalanceStart(String volumeName, Boolean fixLayout, Boolean migrateData, Boolean forcedDataMigrate) { + Form form = new Form(); + form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_REBALANCE_START); + form.add(RESTConstants.FORM_PARAM_FIX_LAYOUT, fixLayout); + form.add(RESTConstants.FORM_PARAM_MIGRATE_DATA, migrateData); + form.add(RESTConstants.FORM_PARAM_FORCED_DATA_MIGRATE, forcedDataMigrate); + 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); + putRequest(volumeName, form); + } public static void main(String[] args) { UsersClient usersClient = new UsersClient(); 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 c37869dc..527ae2a1 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 @@ -48,6 +48,9 @@ public class RESTConstants { public static final String TASK_COMMIT = "commit"; public static final String TASK_STATUS = "status"; public static final String TASK_DELETE = "delete"; + public static final String TASK_REBALANCE_START = "rebalanceStart"; + public static final String TASK_REBALANCE_STATUS = "rebalanceStatus"; + public static final String TASK_REBALANCE_STOP = "rebalanceStop"; public static final String FORM_PARAM_VOLUME_NAME = "name"; public static final String FORM_PARAM_VOLUME_TYPE = "volumeType"; @@ -68,6 +71,9 @@ public class RESTConstants { public static final String FORM_PARAM_SOURCE = "source"; public static final String FORM_PARAM_TARGET = "target"; public static final String FORM_PARAM_AUTO_COMMIT = "autoCommit"; + public static final String FORM_PARAM_FIX_LAYOUT = "fix-layout"; + public static final String FORM_PARAM_MIGRATE_DATA = "migrate-data"; + public static final String FORM_PARAM_FORCED_DATA_MIGRATE = "forced-data-migrate"; public static final String PATH_PARAM_FORMAT = "format"; public static final String PATH_PARAM_VOLUME_NAME = "volumeName"; diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java index 5339beb0..33ca0e5b 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RebalanceVolumeAction.java @@ -19,11 +19,44 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; + +import com.gluster.storage.management.client.VolumesClient; +import com.gluster.storage.management.core.model.Volume; public class RebalanceVolumeAction extends AbstractActionDelegate { + private Volume volume; + + @Override + protected void performAction(final IAction action) { + + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + final String actionDesc = action.getDescription(); + try { + new VolumesClient().rebalanceStart(volume.getName(), false, false, false); + showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] rebalance started successfully!"); + } catch (Exception e) { + showErrorDialog(actionDesc, + "Volume rebalance could not be started on [" + volume.getName() + "]! Error: [" + e.getMessage() + "]"); + } + + } + }); + } + @Override - protected void performAction(IAction action) { - System.out.println("Running [" + this.getClass().getSimpleName() + "]"); + public void selectionChanged(IAction action, ISelection selection) { + super.selectionChanged(action, selection); + + action.setEnabled(false); + if (selectedEntity instanceof Volume) { + volume = (Volume) selectedEntity; + action.setEnabled(true); + } } @Override 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 7b506e67..0bb61245 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 @@ -54,6 +54,9 @@ import static com.gluster.storage.management.core.constants.RESTConstants.RESOUR import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_VOLUMES; import static com.gluster.storage.management.core.constants.RESTConstants.TASK_START; import static com.gluster.storage.management.core.constants.RESTConstants.TASK_STOP; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_FIX_LAYOUT; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_MIGRATE_DATA; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_FORCED_DATA_MIGRATE; import java.io.File; import java.io.IOException; @@ -139,11 +142,11 @@ public class VolumesResource extends AbstractResource { public Response getVolumes(String clusterName, String mediaType) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } return okResponse(getVolumes(clusterName), mediaType); @@ -176,24 +179,24 @@ public class VolumesResource extends AbstractResource { @FormParam(FORM_PARAM_BRICKS) String bricks, @FormParam(FORM_PARAM_ACCESS_PROTOCOLS) String accessProtocols, @FormParam(FORM_PARAM_VOLUME_OPTIONS) String options) { if(clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } String missingParam = checkMissingParamsForCreateVolume(volumeName, volumeType, transportType, replicaCount, stripeCount, bricks, accessProtocols, options); if(missingParam != null) { - return badRequestResponse("Parameter [" + missingParam + "] is missing in request!"); + return notFoundResponse("Parameter [" + missingParam + "] is missing in request!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } if (volumeType.equals(VOLUME_TYPE.DISTRIBUTED_MIRROR) && replicaCount <= 0) { - return badRequestResponse("Replica count must be a positive integer"); + return notFoundResponse("Replica count must be a positive integer"); } if (volumeType.equals(VOLUME_TYPE.DISTRIBUTED_STRIPE) && stripeCount <= 0) { - return badRequestResponse("Stripe count must be a positive integer"); + return notFoundResponse("Stripe count must be a positive integer"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); @@ -267,11 +270,11 @@ public class VolumesResource extends AbstractResource { Volume volume = null; if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } try { @@ -306,23 +309,34 @@ public class VolumesResource extends AbstractResource { @PUT @Path("{" + PATH_PARAM_VOLUME_NAME + "}") public Response performOperation(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, - @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_OPERATION) String operation) { + @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_OPERATION) String operation, + @FormParam(FORM_PARAM_FIX_LAYOUT) Boolean isFixLayout, + @FormParam(FORM_PARAM_MIGRATE_DATA) Boolean isMigrateData, + @FormParam(FORM_PARAM_FORCED_DATA_MIGRATE) Boolean isForcedDataMigrate) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); if (onlineServer == null) { return errorResponse("No online servers found in cluster [" + clusterName + "]"); } + + if (operation.equals(RESTConstants.TASK_REBALANCE_START)) { + return rebalanceStart(clusterName, volumeName, isFixLayout, isMigrateData, isForcedDataMigrate); + } else if (operation.equals(RESTConstants.TASK_REBALANCE_STATUS)) { + return rebalanceStatus(clusterName, volumeName); + } else if (operation.equals(RESTConstants.TASK_REBALANCE_STOP)) { + return rebalanceStop(clusterName, volumeName); + } try { performOperation(volumeName, operation, onlineServer); @@ -359,15 +373,15 @@ public class VolumesResource extends AbstractResource { @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @QueryParam(QUERY_PARAM_DELETE_OPTION) Boolean deleteFlag) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty"); + return notFoundResponse("Cluster name must not be empty"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty"); + return notFoundResponse("Volume name must not be empty"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } if (deleteFlag == null) { @@ -408,19 +422,19 @@ public class VolumesResource extends AbstractResource { List<String> brickList = Arrays.asList(bricks.split(",")); // Convert from comma separated string (query // parameter) if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (bricks == null || bricks.isEmpty()) { - return badRequestResponse("Parameter [" + QUERY_PARAM_BRICKS + "] is missing in request!"); + return notFoundResponse("Parameter [" + QUERY_PARAM_BRICKS + "] is missing in request!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } if(deleteFlag == null) { @@ -511,23 +525,23 @@ public class VolumesResource extends AbstractResource { @FormParam(RESTConstants.FORM_PARAM_OPTION_KEY) String key, @FormParam(RESTConstants.FORM_PARAM_OPTION_VALUE) String value) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if(volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if(key == null || key.isEmpty()) { - return badRequestResponse("Parameter [" + FORM_PARAM_OPTION_KEY + "] is missing in request!"); + return notFoundResponse("Parameter [" + FORM_PARAM_OPTION_KEY + "] is missing in request!"); } if(value == null || value.isEmpty()) { - return badRequestResponse("Parameter [" + FORM_PARAM_OPTION_VALUE + "] is missing in request!"); + return notFoundResponse("Parameter [" + FORM_PARAM_OPTION_VALUE + "] is missing in request!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); @@ -561,15 +575,15 @@ public class VolumesResource extends AbstractResource { public Response resetOptions(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if(volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); @@ -647,15 +661,15 @@ public class VolumesResource extends AbstractResource { public Response downloadLogs(@PathParam(PATH_PARAM_CLUSTER_NAME) final String clusterName, @PathParam(PATH_PARAM_VOLUME_NAME) final String volumeName) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } try { @@ -739,15 +753,15 @@ public class VolumesResource extends AbstractResource { public Response getLogs(String clusterName, String volumeName, String brickName, String severity, String fromTimestamp, String toTimestamp, Integer lineCount, String mediaType) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } List<VolumeLogMessage> logMessages = null; @@ -840,19 +854,19 @@ public class VolumesResource extends AbstractResource { public Response addBricks(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_BRICKS) String bricks) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (bricks == null || bricks.isEmpty()) { - return badRequestResponse("Parameter [" + FORM_PARAM_BRICKS + "] is missing in request!"); + return notFoundResponse("Parameter [" + FORM_PARAM_BRICKS + "] is missing in request!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); @@ -889,23 +903,23 @@ public class VolumesResource extends AbstractResource { @FormParam(FORM_PARAM_TARGET) String toBrick, @FormParam(FORM_PARAM_AUTO_COMMIT) Boolean autoCommit) { if (clusterName == null || clusterName.isEmpty()) { - return badRequestResponse("Cluster name must not be empty!"); + return notFoundResponse("Cluster name must not be empty!"); } if (volumeName == null || volumeName.isEmpty()) { - return badRequestResponse("Volume name must not be empty!"); + return notFoundResponse("Volume name must not be empty!"); } if (fromBrick == null || fromBrick.isEmpty()) { - return badRequestResponse("Parameter [" + FORM_PARAM_SOURCE + "] is missing in request!"); + return notFoundResponse("Parameter [" + FORM_PARAM_SOURCE + "] is missing in request!"); } if (toBrick == null || toBrick.isEmpty()) { - return badRequestResponse("Parameter [" + FORM_PARAM_TARGET + "] is missing in request!"); + return notFoundResponse("Parameter [" + FORM_PARAM_TARGET + "] is missing in request!"); } if (clusterService.getCluster(clusterName) == null) { - return badRequestResponse("Cluster [" + clusterName + "] not found!"); + return notFoundResponse("Cluster [" + clusterName + "] not found!"); } GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); @@ -935,6 +949,92 @@ public class VolumesResource extends AbstractResource { return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS, clusterName, RESOURCE_TASKS, taskId); } + + private Response rebalanceStart(String clusterName, String volumeName, Boolean isFixLayout, Boolean isMigrateData, + Boolean isForcedDataMigrate) { + + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if (onlineServer == null) { + return notFoundResponse("No online servers found in cluster [" + clusterName + "]"); + } + + String layout = ""; + String taskId = null; + if (isForcedDataMigrate) { + layout = "forced-data-migrate = true"; + } else if (isMigrateData) { + layout = "migrate-data = true"; + } else if (isFixLayout) { + layout = "fix-layout = true"; + } + + try { + taskId = glusterUtil.rebalanceStart(volumeName, layout, onlineServer.getName()); + } catch (ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + + try { + taskId = glusterUtil.rebalanceStart(volumeName, layout, onlineServer.getName()); + } catch(Exception e1) { + return errorResponse(e1.getMessage()); + } + } catch(Exception e1) { + return errorResponse(e1.getMessage()); + } + + return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS, clusterName, RESOURCE_TASKS, taskId); + } + + private Response rebalanceStatus(String clusterName, String volumeName) { + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if (onlineServer == null) { + return notFoundResponse("No online servers found in cluster [" + clusterName + "]"); + } + + String taskId = null; + try { + taskId = glusterUtil.rebalanceStatus(volumeName, onlineServer.getName()); + } catch (ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + + try { + taskId = glusterUtil.rebalanceStatus(volumeName, onlineServer.getName()); + } catch (Exception e1) { + return errorResponse(e1.getMessage()); + } + } catch(Exception e1) { + return errorResponse(e1.getMessage()); + } + + return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS, clusterName, RESOURCE_TASKS, taskId); + } + + private Response rebalanceStop(String clusterName, String volumeName) { + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if (onlineServer == null) { + return notFoundResponse("No online servers found in cluster [" + clusterName + "]"); + } + + String taskId = null; + try { + taskId = glusterUtil.rebalanceStop(volumeName, onlineServer.getName()); + } catch (ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + + try { + taskId = glusterUtil.rebalanceStop(volumeName, onlineServer.getName()); + } catch (Exception e1) { + return errorResponse(e1.getMessage()); + } + } catch(Exception e1) { + return errorResponse(e1.getMessage()); + } + + return acceptedResponse(RESTConstants.RESOURCE_PATH_CLUSTERS, clusterName, RESOURCE_TASKS, taskId); + } public static void main(String[] args) throws ClassNotFoundException { VolumesResource vr = new VolumesResource(); 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 new file mode 100644 index 00000000..720c050e --- /dev/null +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/RebalanceVolumeTask.java @@ -0,0 +1,127 @@ +/** + * RebalanceVolumeTask.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.server.tasks; + +import com.gluster.storage.management.core.model.Status; +import com.gluster.storage.management.core.model.Task; +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.utils.SshUtil; + +public class RebalanceVolumeTask extends Task { + + private String layout; + private SshUtil sshUtil = new SshUtil(); + + public RebalanceVolumeTask(TaskInfo taskInfo) { + super(taskInfo); + } + + public RebalanceVolumeTask(String volumeName) { + super(TASK_TYPE.VOLUME_REBALANCE, volumeName, "Volume rebalance running on " + volumeName, false, true, false); + } + + @Override + public String getId() { + return taskInfo.getType() + "-" + taskInfo.getReference(); + } + + @Override + public void start() { + String command = "gluster volume rebalance " + getTaskInfo().getReference() + " " + getLayout() + " start"; + 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_RUNNING); + } 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 resume() { + getTaskInfo().setStatus( + new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, "Pause/Resume is not supported in Volume Rebalance"))); + } + + @Override + public void stop() { + 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"))); + } + + @Override + public TaskStatus checkStatus() { + String command = "gluster volume rebalance " + getTaskInfo().getReference() + " status"; + ProcessResult processResult = sshUtil.executeRemote(serverName, command); + TaskStatus taskStatus = new TaskStatus(); + if (processResult.isSuccess()) { + if (processResult.getOutput().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; + } + + public String getLayout() { + return layout; + } + + @Override + public void commit() { + // TODO Auto-generated method stub + } +} 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 0a0892f0..767b15c3 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 @@ -36,7 +36,7 @@ import com.gluster.storage.management.core.model.Brick.BRICK_STATUS; 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.TASK_TYPE; +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; @@ -46,6 +46,7 @@ import com.gluster.storage.management.core.utils.ProcessResult; import com.gluster.storage.management.core.utils.StringUtil; import com.gluster.storage.management.server.resources.TasksResource; import com.gluster.storage.management.server.tasks.MigrateDiskTask; +import com.gluster.storage.management.server.tasks.RebalanceVolumeTask; import com.sun.jersey.api.core.InjectParam; @Component @@ -553,6 +554,48 @@ public class GlusterUtil { return migrateDiskTask.getId(); } + public String rebalanceStart(String volumeName, String layout, String knownServer) { + + RebalanceVolumeTask rebalanceTask = new RebalanceVolumeTask(volumeName); + rebalanceTask.setOnlineServer(knownServer); + rebalanceTask.setLayout(layout); + rebalanceTask.start(); + int status = rebalanceTask.getTaskInfo().getStatus().getCode(); + + if(status != Status.STATUS_CODE_FAILURE) { + TasksResource taskResource = new TasksResource(); + taskResource.addTask(rebalanceTask); + } else { + throw new GlusterRuntimeException( rebalanceTask.getTaskInfo().getStatus().getMessage()); + } + return rebalanceTask.getId(); + } + + public String rebalanceStatus(String volumeName, String knownServer) { + RebalanceVolumeTask rebalanceTask = new RebalanceVolumeTask(volumeName); + rebalanceTask.setOnlineServer(knownServer); + + rebalanceTask.checkStatus(); + int status = rebalanceTask.getTaskInfo().getStatus().getCode(); + + if (status == Status.STATUS_CODE_FAILURE) { + throw new GlusterRuntimeException(rebalanceTask.getTaskInfo().getStatus().getMessage()); + } + return rebalanceTask.getId(); + } + + public String rebalanceStop(String volumeName, String knownServer) { + RebalanceVolumeTask rebalanceTask = new RebalanceVolumeTask(volumeName); + rebalanceTask.setOnlineServer(knownServer); + + rebalanceTask.stop(); + int status = rebalanceTask.getTaskInfo().getStatus().getCode(); + + if (status == Status.STATUS_CODE_FAILURE) { + throw new GlusterRuntimeException(rebalanceTask.getTaskInfo().getStatus().getMessage()); + } + return rebalanceTask.getId(); + } public Status removeBricks(String volumeName, List<String> bricks, String knownServer) { StringBuilder command = new StringBuilder("gluster --mode=script volume remove-brick " + volumeName); |
