diff options
| author | Dhandapani <dhandapani@gluster.com> | 2011-04-29 16:36:54 +0530 |
|---|---|---|
| committer | Dhandapani <dhandapani@gluster.com> | 2011-05-04 15:38:20 +0530 |
| commit | 5152d0873bfdc9d2a3ba37da4ceab26bea5864b8 (patch) | |
| tree | a3a761b310e509e398ce5cd67de0c0d6a5c3e9b1 | |
| parent | 37f9decd283c3351dd23a5f7c9d4369a3b1dfcd7 (diff) | |
Story #13: Remove Disk(s) Client and Resource Changes
5 files changed, 81 insertions, 5 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 f8005044..97b3e1a0 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 @@ -215,6 +215,15 @@ public abstract class AbstractClient { .delete(responseClass);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected Object deleteSubResource(String subResourceName, Class responseClass, String volumeName, String disks,
+ String deleteOption) {
+ return resource.path(subResourceName).queryParam(RESTConstants.QUERY_PARAM_VOLUME_NAME, volumeName)
+ .queryParam(RESTConstants.QUERY_PARAM_DISKS, disks)
+ .queryParam(RESTConstants.QUERY_PARAM_DELETE_OPTION, deleteOption).header("Authorization", authHeader)
+ .delete(responseClass);
+ }
+
public abstract String getResourceName();
/**
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 4af70c5a..767b4eb7 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 @@ -23,6 +23,7 @@ package com.gluster.storage.management.client; import java.util.ArrayList; import java.util.Date; import java.util.List; + import javax.ws.rs.core.MultivaluedMap; import com.gluster.storage.management.core.constants.CoreConstants; @@ -142,6 +143,11 @@ public class VolumesClient extends AbstractClient { public void downloadLogs(String volumeName) { downloadSubResource((volumeName) + "/" + RESTConstants.SUBRESOURCE_LOGS + "/" + RESTConstants.SUBRESOURCE_DOWNLOAD); } + + public Status removeBricks(String volumeName, List<Disk> diskList, String deleteOption) { + String disks = StringUtil.ListToString( GlusterCoreUtil.getQualifiedDiskNames(diskList), ","); + return (Status) deleteSubResource(volumeName + "/" + RESTConstants.SUBRESOURCE_DISKS, Status.class, volumeName, disks, deleteOption); + } private MultivaluedMap<String, String> prepareGetLogQueryParams(String diskName, String severity, Date fromTimestamp, Date toTimestamp, int messageCount) { diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveDiskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveDiskAction.java index 19cf84f7..1524f334 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveDiskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/RemoveDiskAction.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchPart; @@ -12,8 +13,9 @@ import org.eclipse.ui.IWorkbenchPart; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.VolumesClient; import com.gluster.storage.management.core.model.Disk; -import com.gluster.storage.management.core.model.Entity; +import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.Volume; +import com.gluster.storage.management.gui.IImageKeys; import com.gluster.storage.management.gui.utils.GUIHelper; import com.gluster.storage.management.gui.views.VolumeDisksView; @@ -21,11 +23,34 @@ public class RemoveDiskAction extends AbstractActionDelegate { private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance(); private GUIHelper guiHelper = GUIHelper.getInstance(); private List<Disk> disks; + private Volume volume; @Override protected void performAction(IAction action) { + final String actionDesc = action.getDescription(); + Integer deleteOption = new MessageDialog(getShell(), "Remove Disk(s)", GUIHelper.getInstance().getImage( + IImageKeys.VOLUME), "Are you sure you want to remove disks from volume [" + volume.getName() + + "] ?", MessageDialog.QUESTION, new String[] { "Cancel", "Remove disks, delete volume data from them", + "Remove disks, back-up volume data from them" }, 2).open(); + if (deleteOption == 0) { + return; + } + + String confirmDelete = ""; + if (deleteOption == 1) { + confirmDelete = "-d"; + } + VolumesClient client = new VolumesClient(modelManager.getSecurityToken()); - // final Status status = client.removeDisk(); + Status status = client.removeBricks(volume.getName(), disks, confirmDelete); + + if (status.isSuccess()) { + showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] disk(s) removed successfully!"); + modelManager.deleteVolume(volume); + } else { + showErrorDialog(actionDesc, "Volume [" + volume.getName() + "] disk(s) could not be removed! Error: [" + + status + "]"); + } } @Override @@ -37,8 +62,8 @@ public class RemoveDiskAction extends AbstractActionDelegate { super.selectionChanged(action, selection); action.setEnabled(false); - Volume selectedVolume = (Volume)guiHelper.getSelectedEntity(window, Volume.class); - if (selectedVolume != null) { + volume = (Volume)guiHelper.getSelectedEntity(window, Volume.class); + if (volume != null) { // a volume is selected on navigation tree. Let's check if the currently open view is volume disks view IWorkbenchPart view = guiHelper.getActiveView(); if(view instanceof VolumeDisksView) { @@ -51,6 +76,7 @@ public class RemoveDiskAction extends AbstractActionDelegate { private List<Disk> getSelectedDisks(ISelection selection) { List<Disk> selectedDisks = new ArrayList<Disk>(); + if (selection instanceof IStructuredSelection) { Iterator<Object> iter = ((IStructuredSelection) selection).iterator(); while (iter.hasNext()) { 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 e635510a..4fc70202 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 @@ -189,6 +189,30 @@ public class VolumesResource { return status; } + @DELETE + @Path("{" + QUERY_PARAM_VOLUME_NAME + "}/" + SUBRESOURCE_DISKS) + @Produces(MediaType.TEXT_XML) + public Status removeBricks(@PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, + @QueryParam(QUERY_PARAM_DISKS) String disks, @QueryParam(QUERY_PARAM_DELETE_OPTION) String deleteOption) { + List<String> bricks = Arrays.asList(disks.split(",")); // Convert from comma separated string (query parameter) + List<String> volumeBrick = new ArrayList<String>(); + for (String brickInfo : bricks) { + String diskInfo[] = brickInfo.split(":"); + volumeBrick.add(getBrickForDisk(getVolume(volumeName), diskInfo[1])); + } + + Status status = glusterUtil.removeBricks(volumeName, volumeBrick); + + if (status.isSuccess()) { + Status cleanupStatus = cleanupDirectories(bricks, volumeName, bricks.size(), deleteOption); + if (!cleanupStatus.isSuccess()) { + // append cleanup error to prepare brick error + status.setMessage(status.getMessage() + CoreConstants.NEWLINE + cleanupStatus.getMessage()); + } + } + return status; + } + private Status postDelete(String volumeName, List<String> disks, String deleteFlag) { String serverName, diskName, diskInfo[]; Status result; 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 3ca11069..fa49a529 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 @@ -184,7 +184,7 @@ public class GlusterUtil { List<String> command = prepareVolumeCreateCommand(volume, bricks, count, volumeType, transportTypeStr); ProcessResult result = processUtil.executeCommand(command); if (!result.isSuccess()) { - // TODO: Perform cleanup on all nodes before returning + // Perform cleanup on all nodes before returning return new Status(result); } @@ -474,6 +474,17 @@ public class GlusterUtil { return new Status(processUtil.executeCommand("gluster", "volume", "replace-brick", volumeName, diskFrom, diskTo, operation)); } + public Status removeBricks(String volumeName, List<String> bricks) { + List<String> command = new ArrayList<String>(); + command.add("gluster"); + command.add("volume"); + command.add("remove-brick"); + command.add(volumeName); + command.addAll(bricks); + return new Status(processUtil.executeCommand(command)); + } + + public static void main(String args[]) { // List<String> names = new GlusterUtil().getGlusterServerNames(); // System.out.println(names); |
