summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSelvasundaram <selvam@gluster.com>2011-07-29 21:39:26 +0530
committerSelvasundaram <selvam@gluster.com>2011-07-29 21:42:20 +0530
commit0e927535772808136b5ed8cbfe708fc0b1e839eb (patch)
tree83c200c819482c444b62147003d192fe6a94e408
parent47246e06150b1024dc7f4af9312337d6b1b8542a (diff)
Start, Stop and Delete volume operation on multiple selection feature
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java103
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java99
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java104
3 files changed, 235 insertions, 71 deletions
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java
index eb038738..fa686c72 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DeleteVolumeAction.java
@@ -18,7 +18,10 @@
*******************************************************************************/
package com.gluster.storage.management.gui.actions;
-import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
@@ -26,24 +29,31 @@ import org.eclipse.jface.viewers.ISelection;
import com.gluster.storage.management.client.VolumesClient;
import com.gluster.storage.management.core.model.Volume;
import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS;
+import com.gluster.storage.management.core.utils.StringUtil;
import com.gluster.storage.management.gui.GlusterDataModelManager;
import com.gluster.storage.management.gui.IImageKeys;
import com.gluster.storage.management.gui.utils.GUIHelper;
public class DeleteVolumeAction extends AbstractActionDelegate {
- private Volume volume;
private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();
- private static final Logger logger = Logger.getLogger(DeleteVolumeAction.class);
+ private List<Volume> volumes = new ArrayList<Volume>();
+ private List<String> selectedVolumeNames = new ArrayList<String>();
+ private List<String> onlineVolumeNames = new ArrayList<String>();
@Override
protected void performAction(final IAction action) {
final String actionDesc = action.getDescription();
+ VolumesClient vc = new VolumesClient();
+ collectVolumeNames();
String warningMessage;
- if (volume.getStatus() == VOLUME_STATUS.OFFLINE) {
- warningMessage = "Are you sure to delete the Volume[" + volume.getName() + "] ?";
+ if (onlineVolumeNames.size() > 0) { // There are some online volumes, get confirmation to stop and delete all
+ // the volumes
+ warningMessage = "Following volume(s) [" + StringUtil.collectionToString(onlineVolumeNames, ", ")
+ + "] are online, \nAre you sure to continue?";
} else {
- warningMessage = "Volume [" + volume.getName() + "] is online, \nAre you sure to continue?";
+ warningMessage = "Are you sure to delete the following volume(s) ["
+ + StringUtil.collectionToString(selectedVolumeNames, ", ") + "] ?";
}
Integer deleteOption = new MessageDialog(getShell(), "Delete Volume", GUIHelper.getInstance().getImage(
@@ -53,36 +63,56 @@ public class DeleteVolumeAction extends AbstractActionDelegate {
return;
}
- VolumesClient client = new VolumesClient();
+ boolean confirmDelete = (deleteOption == 1) ? true : false;
+ List<String> deletedVolumes = new ArrayList<String>();
+ List<String> failedVolumes = new ArrayList<String>();
+ String errorMessage = "";
- if (volume.getStatus() == VOLUME_STATUS.ONLINE) { // To stop the volume service, if running
+ for (Volume volume : volumes) {
try {
- client.stopVolume(volume.getName());
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) { // stop if online volume
+ vc.stopVolume(volume.getName());
+ }
+ vc.deleteVolume(volume, confirmDelete);
+ modelManager.deleteVolume(volume);
+ deletedVolumes.add(volume.getName());
} catch (Exception e) {
- showErrorDialog(actionDesc,
- "Volume [" + volume.getName() + "] could not be stopped! Error: [" + e.getMessage() + "]");
- return;
+ // there is a possibility that the error was in post-delete operation, which means
+ // volume was deleted, but some other error happened. check if this is the case.
+ if (vc.volumeExists(volume.getName())) {
+ errorMessage += "\nVolume [" + volume.getName() + "] could not be deleted! Error: ["
+ + e.getMessage() + "]";
+ failedVolumes.add(volume.getName());
+ } else {
+ errorMessage += "\nVolume deleted, but following error(s) occured: [" + e.getMessage() + "]";
+ modelManager.deleteVolume(volume);
+ deletedVolumes.add(volume.getName());
+ }
}
}
- boolean confirmDelete = false;
- if (deleteOption == 1) {
- confirmDelete = true;
+ // Display the success or failure info
+ if (deletedVolumes.size() == 0) { // No volume(s) deleted successfully
+ showErrorDialog(actionDesc, "Following colume(s) [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] could not be delete! " + "\nError: [" + errorMessage + "]");
+ } else {
+ String info = "Following volumes [" + StringUtil.collectionToString(deletedVolumes, ", ")
+ + "] are deleted successfully!";
+ if (errorMessage != "") {
+ info += "\n\nFollowing volumes [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] are failed to delete! [" + errorMessage + "]";
+ }
+ showInfoDialog(actionDesc, info);
}
+ }
- try {
- client.deleteVolume(volume, confirmDelete);
- showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] deleted successfully!");
- modelManager.deleteVolume(volume);
- } catch (Exception e) {
- // there is a possibility that the error was in post-delete operation, which means
- // volume was deleted, but some other error happened. check if this is the case.
- if (client.volumeExists(volume.getName())) {
- showErrorDialog(actionDesc,
- "Volume [" + volume.getName() + "] could not be deleted! Error: [" + e.getMessage() + "]");
- } else {
- showWarningDialog(actionDesc, "Volume deleted, but following error(s) occured: " + e.getMessage());
- modelManager.deleteVolume(volume);
+ private void collectVolumeNames() {
+ selectedVolumeNames.clear();
+ onlineVolumeNames.clear();
+ for (Volume volume : volumes) {
+ selectedVolumeNames.add(volume.getName());
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ onlineVolumeNames.add(volume.getName());
}
}
}
@@ -94,12 +124,17 @@ public class DeleteVolumeAction extends AbstractActionDelegate {
@Override
public void selectionChanged(IAction action, ISelection selection) {
- super.selectionChanged(action, selection);
- if (selectedEntity instanceof Volume) {
- volume = (Volume) selectedEntity;
- action.setEnabled(true);
- }else {
- action.setEnabled(false);
+ Set<Volume> selectedVolumes = GUIHelper.getInstance().getSelectedEntities(getWindow(), Volume.class);
+ volumes.clear();
+ if (selectedVolumes == null || selectedVolumes.isEmpty()) {
+ super.selectionChanged(action, selection);
+ if (selectedEntity instanceof Volume) {
+ volumes.add((Volume) selectedEntity);
+ }
+ } else {
+ volumes.addAll(selectedVolumes); //TODO reverse the collection to maintain the selected order
}
+
+ action.setEnabled( (volumes.size() > 0) );
}
}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java
index a6151824..b52952af 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StartVolumeAction.java
@@ -18,39 +18,89 @@
*******************************************************************************/
package com.gluster.storage.management.gui.actions;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import com.gluster.storage.management.client.VolumesClient;
import com.gluster.storage.management.core.model.Volume;
import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS;
+import com.gluster.storage.management.core.utils.StringUtil;
import com.gluster.storage.management.gui.GlusterDataModelManager;
+import com.gluster.storage.management.gui.utils.GUIHelper;
public class StartVolumeAction extends AbstractActionDelegate {
- private Volume volume;
+ //private Volume volume;
private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();
+ private List<Volume> volumes = new ArrayList<Volume>();
+ private List<String> selectedVolumeNames = new ArrayList<String>();
+ private List<String> offlineVolumeNames = new ArrayList<String>();
@Override
protected void performAction(IAction action) {
- if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ final String actionDesc = action.getDescription();
+ VolumesClient vc = new VolumesClient();
+
+ collectVolumeNames();
+
+ if (offlineVolumeNames.size() == 0) {
+ String errorMessage;
+ if (selectedVolumeNames.size() == 1) {
+ errorMessage = "Volume [" + StringUtil.collectionToString(selectedVolumeNames, ", ") + "] is already online!";
+ } else {
+ errorMessage = "Volumes [" + StringUtil.collectionToString(selectedVolumeNames, ", ") + "] are already online!";
+ }
+ showWarningDialog(actionDesc, errorMessage);
return; // Volume already online. Don't do anything.
}
+
+ List<String> startedVolumes = new ArrayList<String>();
+ List<String> failedVolumes = new ArrayList<String>();
+ String errorMessage = "";
+
+ for (Volume volume : volumes) {
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ continue; // skip if online volume
+ }
+ try {
+ vc.startVolume(volume.getName());
+ modelManager.updateVolumeStatus(volume, VOLUME_STATUS.ONLINE);
+ startedVolumes.add(volume.getName());
+ }catch (Exception e) {
+ failedVolumes.add(volume.getName());
+ errorMessage += e.getMessage();
+ }
+ }
- VolumesClient client = new VolumesClient();
- final String actionDesc = action.getDescription();
- try {
- client.startVolume(volume.getName());
- showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] started successfully!");
- modelManager.updateVolumeStatus(volume, VOLUME_STATUS.ONLINE);
-
- Volume updatedVolume = client.getVolume(volume.getName());
- modelManager.volumeChanged(volume, updatedVolume);
- } catch (Exception e) {
- showErrorDialog(actionDesc,
- "Volume [" + volume.getName() + "] could not be started! Error: [" + e.getMessage() + "]");
+ // Display the success or failure info
+ if (startedVolumes.size() == 0) { // No volume(s) started successfully
+ showErrorDialog(actionDesc, "Following volume(s) [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] could not be start! " + "\nError: [" + errorMessage + "]");
+ } else {
+ String info = "Following volume(s) [" + StringUtil.collectionToString(startedVolumes, ", ")
+ + "] are started successfully!";
+ if (errorMessage != "") {
+ info += "\n\nFollowing volume(s) [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] are failed to start! [" + errorMessage + "]";
+ }
+ showInfoDialog(actionDesc, info);
}
}
+ private void collectVolumeNames() {
+ selectedVolumeNames.clear();
+ offlineVolumeNames.clear();
+ for (Volume volume : volumes) {
+ selectedVolumeNames.add(volume.getName());
+ if (volume.getStatus() == VOLUME_STATUS.OFFLINE) {
+ offlineVolumeNames.add(volume.getName());
+ }
+ }
+ }
+
@Override
public void dispose() {
@@ -58,11 +108,24 @@ public class StartVolumeAction extends AbstractActionDelegate {
@Override
public void selectionChanged(IAction action, ISelection selection) {
- super.selectionChanged(action, selection);
+ Set<Volume> selectedVolumes = GUIHelper.getInstance().getSelectedEntities(getWindow(), Volume.class);
+ volumes.clear();
+ if (selectedVolumes == null || selectedVolumes.isEmpty()) {
+ super.selectionChanged(action, selection);
+ if (selectedEntity instanceof Volume) {
+ volumes.add((Volume) selectedEntity);
+ }
+ } else {
+ volumes.addAll(selectedVolumes); //TODO reverse the collection to maintain the selected order
+ }
- if (selectedEntity instanceof Volume) {
- volume = (Volume) selectedEntity;
- action.setEnabled(volume.getStatus() == VOLUME_STATUS.OFFLINE);
+ action.setEnabled(false);
+ // To enable the action
+ for (Volume volume : volumes) {
+ if (volume.getStatus() == VOLUME_STATUS.OFFLINE) {
+ action.setEnabled(true);
+ break;// If find an online volume, enable the action
+ }
}
}
}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java
index 23365bf8..f2d23490 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopVolumeAction.java
@@ -18,6 +18,10 @@
*******************************************************************************/
package com.gluster.storage.management.gui.actions;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
@@ -25,37 +29,87 @@ import org.eclipse.jface.viewers.ISelection;
import com.gluster.storage.management.client.VolumesClient;
import com.gluster.storage.management.core.model.Volume;
import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS;
+import com.gluster.storage.management.core.utils.StringUtil;
import com.gluster.storage.management.gui.GlusterDataModelManager;
import com.gluster.storage.management.gui.IImageKeys;
import com.gluster.storage.management.gui.utils.GUIHelper;
public class StopVolumeAction extends AbstractActionDelegate {
- private Volume volume;
private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();
+ private List<Volume> volumes = new ArrayList<Volume>();
+ private List<String> selectedVolumeNames = new ArrayList<String>();
+ private List<String> onlineVolumeNames = new ArrayList<String>();
@Override
protected void performAction(final IAction action) {
final String actionDesc = action.getDescription();
- if (volume.getStatus() == VOLUME_STATUS.OFFLINE) {
- showWarningDialog(actionDesc, "Volume [" + volume.getName() + "] is already offline!");
+ VolumesClient vc = new VolumesClient();
+
+ collectVolumeNames();
+
+ if (onlineVolumeNames.size() == 0) {
+ String errorMessage;
+ if (selectedVolumeNames.size() == 1) {
+ errorMessage = "Volume [" + StringUtil.collectionToString(selectedVolumeNames, ", ")
+ + "] is already offline!";
+ } else {
+ errorMessage = "Volumes [" + StringUtil.collectionToString(selectedVolumeNames, ", ")
+ + "] are already offline!";
+ }
+ showWarningDialog(actionDesc, errorMessage);
return; // Volume already offline. Don't do anything.
}
- Integer deleteOption = new MessageDialog(getShell(), "Stop Volume", GUIHelper.getInstance().getImage(
- IImageKeys.VOLUME_16x16), "Are you sure you want to stop the volume [" + volume.getName() + "] ?",
- MessageDialog.QUESTION, new String[] { "No", "Yes" }, -1).open();
+ Integer userAction = new MessageDialog(getShell(), "Stop Volume", GUIHelper.getInstance().getImage(
+ IImageKeys.VOLUME_16x16), "Are you sure you want to stop the following volume(s)?\n" + "["
+ + StringUtil.collectionToString(onlineVolumeNames, ", ") + "]", MessageDialog.QUESTION, new String[] {
+ "No", "Yes" }, -1).open();
- if (deleteOption <= 0) {
+ if (userAction <= 0) { // user select cancel or pressed escape key
return;
}
- try {
- new VolumesClient().stopVolume(volume.getName());
- showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] stopped successfully!");
- modelManager.updateVolumeStatus(volume, VOLUME_STATUS.OFFLINE);
- } catch (Exception e) {
- showErrorDialog(actionDesc,
- "Volume [" + volume.getName() + "] could not be stopped! Error: [" + e.getMessage() + "]");
+ List<String> stoppedVolumes = new ArrayList<String>();
+ List<String> failedVolumes = new ArrayList<String>();
+ String errorMessage = "";
+
+ for (Volume volume : volumes) {
+ if (volume.getStatus() == VOLUME_STATUS.OFFLINE) {
+ continue; // skip if offline volume
+ }
+ try {
+ vc.stopVolume(volume.getName());
+ modelManager.updateVolumeStatus(volume, VOLUME_STATUS.OFFLINE);
+ stoppedVolumes.add(volume.getName());
+ } catch (Exception e) {
+ failedVolumes.add(volume.getName());
+ errorMessage += e.getMessage();
+ }
+ }
+
+ // Display the success or failure info
+ if (stoppedVolumes.size() == 0) { // No volume(s) stopped successfully
+ showErrorDialog(actionDesc, "Following volume(s) [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] could not be stopped! " + "\nError: [" + errorMessage + "]");
+ } else {
+ String info = "Following volume(s) [" + StringUtil.collectionToString(stoppedVolumes, ", ")
+ + "] are stopped successfully!";
+ if (errorMessage != "") {
+ info += "\n\nFollowing volume(s) [" + StringUtil.collectionToString(failedVolumes, ", ")
+ + "] are failed to stop! [" + errorMessage + "]";
+ }
+ showInfoDialog(actionDesc, info);
+ }
+ }
+
+ private void collectVolumeNames() {
+ selectedVolumeNames.clear();
+ onlineVolumeNames.clear();
+ for (Volume volume : volumes) {
+ selectedVolumeNames.add(volume.getName());
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ onlineVolumeNames.add(volume.getName());
+ }
}
}
@@ -72,13 +126,25 @@ public class StopVolumeAction extends AbstractActionDelegate {
*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
- super.selectionChanged(action, selection);
- if (selectedEntity instanceof Volume) {
- volume = (Volume) selectedEntity;
- action.setEnabled(volume.getStatus() == VOLUME_STATUS.ONLINE);
+ Set<Volume> selectedVolumes = GUIHelper.getInstance().getSelectedEntities(getWindow(), Volume.class);
+ volumes.clear();
+ if (selectedVolumes == null || selectedVolumes.isEmpty()) {
+ super.selectionChanged(action, selection);
+ if (selectedEntity instanceof Volume) {
+ volumes.add((Volume) selectedEntity);
+ }
} else {
- action.setEnabled(false);
+ volumes.addAll(selectedVolumes); //TODO reverse the collection to maintain the selected order
+ }
+
+ action.setEnabled(false);
+ // To enable the action
+ for (Volume volume : volumes) {
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ action.setEnabled(true);
+ break;// If find an online volume, enable the action
+ }
}
}
}