summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.gui
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-04-14 19:16:42 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-04-14 19:16:42 +0530
commit6044ba8846610911dedbce10eecaef4a7d144abd (patch)
tree1441fef647a4414c63ed4cfc0c862d5ecb2baa88 /src/com.gluster.storage.management.gui
parente0efe1a6d06870034ca3eef5f50913a0ef6e957a (diff)
Remote directory creation and directory cleanup script enhanced - incorporated review comments
Diffstat (limited to 'src/com.gluster.storage.management.gui')
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumePage1.java390
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumeWizard.java37
2 files changed, 254 insertions, 173 deletions
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumePage1.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumePage1.java
index 84241624..7dd8e27d 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumePage1.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumePage1.java
@@ -62,7 +62,6 @@ public class CreateVolumePage1 extends WizardPage {
private Button btnNfs;
private Button btnStartVolume;
private Link linkCustomize;
- private ValidationListener valListener = new ValidationListener();
/**
* Create the wizard.
@@ -85,127 +84,102 @@ public class CreateVolumePage1 extends WizardPage {
return disks;
}
- private class ValidationListener implements ModifyListener {
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- @Override
- public void modifyText(ModifyEvent e) {
- String volumeName = txtName.getText().trim();
- String accessControl = txtAccessControl.getText().trim();
- String volumeNameToken = "^[a-zA-Z][a-zA-Z0-9\\-]*";
-
-
- setErrorMessage(null);
- setPageComplete(true);
-
- if(volumeName.length() == 0) {
- setPageComplete(false);
- setErrorMessage("Please enter Volume Name");
- }
-
- if (!volumeName.matches(volumeNameToken)) {
- setPageComplete(false);
- setErrorMessage("Please enter valid Volume Name");
- }
-
- if(accessControl.length() == 0) {
- setPageComplete(false);
- setErrorMessage("Please enter Access Control");
- }
-
- if(volume.getDisks().size() < 1) {
- setPageComplete(false);
- setErrorMessage("No disk found");
- }
-
- // acl validation
- String[] aclList = accessControl.split(",");
- for (String ip : aclList) {
- if (!isValidIP(ip)) {
- setPageComplete(false);
- setErrorMessage("Please enter valid access control list");
- }
- }
-
- }
-
- private Boolean isValidIP(String ip) {
- // String pattern = "^.[0-9]{1,3}/..[0-9]{1,3}/..[0-9]{1,3}/..[0-9]{1,3}";
- String pattern = "^.[0-9]{1,3}/.";
- if (ip == "*") {
- return true;
- }
- String[] ipQuads = ip.split(".");
- for (String quad : ipQuads) {
- if (!quad.matches(pattern)) {
- return false;
- }
- }
- return true;
-
- }
- }
-
/**
* Create contents of the wizard.
* @param parent
*/
public void createControl(Composite parent) {
-
setPageComplete(false);
- Composite container = new Composite(parent, SWT.NULL);
-
- setControl(container);
- GridLayout gl_container = new GridLayout(2, false);
- gl_container.verticalSpacing = 10;
- gl_container.marginHeight = 10;
- gl_container.marginLeft = 20;
- gl_container.horizontalSpacing = 10;
- container.setLayout(gl_container);
+ Composite container = createContainer(parent);
- new Label(container, SWT.NONE);
- new Label(container, SWT.NONE);
+ createEmptyRow(container);
- Label lblName = new Label(container, SWT.NONE);
- lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblName.setText("Name: ");
+ createNameLabel(container);
+ createNameText(container);
- txtName = new Text(container, SWT.BORDER);
- GridData txtNameData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
- txtNameData.widthHint = 300;
- txtName.setLayoutData(txtNameData);
- txtName.addModifyListener(valListener);
+ createTypeLabel(container);
+ createTypeCombo(container);
- Label lblType = new Label(container, SWT.NONE);
- lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblType.setText("Type: ");
+ createTransportTypeLabel(container);
+ createTransportTypeValueLabel(container);
- typeComboViewer = new ComboViewer(container, SWT.READ_ONLY);
- Combo typeCombo = typeComboViewer.getCombo();
- GridData typeComboData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
- typeCombo.setLayoutData(typeComboData);
- typeComboViewer.setContentProvider(new ArrayContentProvider());
- typeComboViewer.setInput(Volume.VOLUME_TYPE.values());
- typeCombo.select(VOLUME_TYPE.PLAIN_DISTRIBUTE.ordinal()); // default type = Plain Distribute
- typeComboViewer.setLabelProvider(new LabelProvider() {
- @Override
- public String getText(Object element) {
- VOLUME_TYPE volumeType = (VOLUME_TYPE)element;
- return Volume.getVolumeTypeStr(volumeType);
- }
- });
+ createDisksLabel(container);
+ createDisksCustomizeLink(container);
- Label lblTransportType = new Label(container, SWT.NONE);
- lblTransportType.setText("Transport Type: ");
+ createNasProtocolLabel(container);
+ createNasProtocolCheckboxes(container);
- Label lblEthernet = new Label(container, SWT.NONE);
- lblEthernet.setText("Ethernet");
+ createAccessControlLabel(container);
+ createAccessControlText(container);
+
+ createEmptyLabel(container);
+ createAccessControlInfoLabel(container);
- Label lblDisks = new Label(container, SWT.RIGHT);
- lblDisks.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblDisks.setText("Disks: ");
+ createStartVolumeLabel(container);
+ createStartVolumeCheckbox(container);
+ }
+
+ private void createStartVolumeCheckbox(Composite container) {
+ btnStartVolume = new Button(container, SWT.CHECK);
+ btnStartVolume.setSelection(true);
+ }
+
+ private void createStartVolumeLabel(Composite container) {
+ Label lblStartVolume = new Label(container, SWT.NONE);
+ lblStartVolume.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblStartVolume.setText("Start Volume: ");
+ }
+
+ private void createAccessControlInfoLabel(Composite container) {
+ Label lblAccessControlInfo = new Label(container, SWT.TOP);
+ lblAccessControlInfo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ lblAccessControlInfo.setText("(Comma separated list of IP addresses/hostnames)");
+ }
+
+ private void createEmptyLabel(Composite container) {
+ new Label(container, SWT.NONE);
+ }
+
+ private void createAccessControlText(Composite container) {
+ txtAccessControl = new Text(container, SWT.BORDER);
+ txtAccessControl.setText("*");
+ GridData accessControlData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
+ accessControlData.widthHint = 300;
+ txtAccessControl.setLayoutData(accessControlData);
+ txtAccessControl.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validateForm();
+ }
+ });
+ }
+
+ private void createAccessControlLabel(Composite container) {
+ Label lblAccessControl = new Label(container, SWT.NONE);
+ lblAccessControl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblAccessControl.setText("Access Control: ");
+ }
+
+ private void createNasProtocolCheckboxes(Composite container) {
+ Button btnGluster = new Button(container, SWT.CHECK);
+ btnGluster.setEnabled(false);
+ btnGluster.setSelection(true);
+ btnGluster.setText("Gluster");
+ createEmptyLabel(container);
+ btnNfs = new Button(container, SWT.CHECK);
+ btnNfs.setEnabled(false);
+ btnNfs.setSelection(true);
+ btnNfs.setText("NFS");
+ }
+
+ private void createNasProtocolLabel(Composite container) {
+ Label lblNasProtocol = new Label(container, SWT.RIGHT);
+ lblNasProtocol.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblNasProtocol.setText("NAS Protocol: ");
+ }
+
+ private void createDisksCustomizeLink(Composite container) {
linkCustomize = new Link(container, SWT.UNDERLINE_LINK);
linkCustomize.setText("All Disk(s) (<a>customize</a>)");
linkCustomize.addListener (SWT.Selection, new Listener () {
@@ -226,44 +200,82 @@ public class CreateVolumePage1 extends WizardPage {
});
}
});
-
- Label lblNasProtocol = new Label(container, SWT.RIGHT);
- lblNasProtocol.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblNasProtocol.setText("NAS Protocol: ");
-
- Button btnGluster = new Button(container, SWT.CHECK);
- btnGluster.setEnabled(false);
- btnGluster.setSelection(true);
- btnGluster.setText("Gluster");
- new Label(container, SWT.NONE);
-
- btnNfs = new Button(container, SWT.CHECK);
- btnNfs.setEnabled(false);
- btnNfs.setSelection(true);
- btnNfs.setText("NFS");
-
- Label lblAccessControl = new Label(container, SWT.NONE);
- lblAccessControl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblAccessControl.setText("Access Control: ");
-
- txtAccessControl = new Text(container, SWT.BORDER);
- txtAccessControl.setText("*");
- GridData accessControlData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
- accessControlData.widthHint = 300;
- txtAccessControl.setLayoutData(accessControlData);
- txtAccessControl.addModifyListener(valListener);
+ }
- new Label(container, SWT.NONE);
- Label lblAccessControlInfo = new Label(container, SWT.TOP);
- lblAccessControlInfo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
- lblAccessControlInfo.setText("(Comma separated list of IP addresses/Hostname)");
-
- Label lblStartVolume = new Label(container, SWT.NONE);
- lblStartVolume.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- lblStartVolume.setText("Start Volume: ");
-
- btnStartVolume = new Button(container, SWT.CHECK);
- btnStartVolume.setSelection(true);
+ private void createDisksLabel(Composite container) {
+ Label lblDisks = new Label(container, SWT.RIGHT);
+ lblDisks.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblDisks.setText("Disks: ");
+ }
+
+ private void createTransportTypeValueLabel(Composite container) {
+ Label lblEthernet = new Label(container, SWT.NONE);
+ lblEthernet.setText("Ethernet");
+ }
+
+ private void createTransportTypeLabel(Composite container) {
+ Label lblTransportType = new Label(container, SWT.NONE);
+ lblTransportType.setText("Transport Type: ");
+ }
+
+ private void createTypeCombo(Composite container) {
+ typeComboViewer = new ComboViewer(container, SWT.READ_ONLY);
+ Combo typeCombo = typeComboViewer.getCombo();
+ GridData typeComboData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
+ typeCombo.setLayoutData(typeComboData);
+ typeComboViewer.setContentProvider(new ArrayContentProvider());
+ typeComboViewer.setInput(Volume.VOLUME_TYPE.values());
+ typeCombo.select(VOLUME_TYPE.PLAIN_DISTRIBUTE.ordinal()); // default type = Plain Distribute
+ typeComboViewer.setLabelProvider(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ VOLUME_TYPE volumeType = (VOLUME_TYPE)element;
+ return Volume.getVolumeTypeStr(volumeType);
+ }
+ });
+ }
+
+ private void createTypeLabel(Composite container) {
+ Label lblType = new Label(container, SWT.NONE);
+ lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblType.setText("Type: ");
+ }
+
+ private void createNameText(Composite container) {
+ txtName = new Text(container, SWT.BORDER);
+ GridData txtNameData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
+ txtNameData.widthHint = 300;
+ txtName.setLayoutData(txtNameData);
+ txtName.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validateForm();
+ }
+ });
+ }
+
+ private void createNameLabel(Composite container) {
+ Label lblName = new Label(container, SWT.NONE);
+ lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblName.setText("Name: ");
+ }
+
+ private void createEmptyRow(Composite container) {
+ createEmptyLabel(container);
+ createEmptyLabel(container);
+ }
+
+ private Composite createContainer(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ setControl(container);
+
+ GridLayout gl_container = new GridLayout(2, false);
+ gl_container.verticalSpacing = 10;
+ gl_container.marginHeight = 10;
+ gl_container.marginLeft = 20;
+ gl_container.horizontalSpacing = 10;
+ container.setLayout(gl_container);
+ return container;
}
public Volume getVolume() {
@@ -277,20 +289,16 @@ public class CreateVolumePage1 extends WizardPage {
nasProtocols.add(NAS_PROTOCOL.GLUSTERFS);
nasProtocols.add(NAS_PROTOCOL.NFS);
-// if(btnNfs.getSelection()) {
-// nasProtocols.add(NAS_PROTOCOL.NFS);
-// }
-
volume.setAccessControlList(txtAccessControl.getText());
return volume;
}
- public Boolean getStartVolumeRequest() {
+ public Boolean startVolumeAfterCreation() {
return btnStartVolume.getSelection();
}
- public Boolean isVolumeExist(String volumeName) {
+ public Boolean volumeExists(String volumeName) {
List<Volume> volumes = GlusterDataModelManager.getInstance().getModel().getCluster().getVolumes();
for (Volume volume : volumes) {
if (volume.getName().equals(volumeName)) {
@@ -301,20 +309,80 @@ public class CreateVolumePage1 extends WizardPage {
return true;
}
- public Boolean isValidCreateVolumeForm() {
- IStructuredSelection selection = (IStructuredSelection)typeComboViewer.getSelection();
- if (selection.getFirstElement().equals(VOLUME_TYPE.DISTRIBUTED_MIRROR) && ((int)volume.getDisks().size()) % 2 != 0 ) {
- setErrorMessage("Mirror type volume requires disk in multiples of two");
- return false;
- } else if(selection.getFirstElement().equals(VOLUME_TYPE.DISTRIBUTED_STRIPE) && ((int)volume.getDisks().size()) % 4 != 0) {
- setErrorMessage("Stripe type volume requires disk in multiples of four");
- return false;
+ private Boolean isValidIP(String ip) {
+ // String pattern = "^.[0-9]{1,3}/..[0-9]{1,3}/..[0-9]{1,3}/..[0-9]{1,3}";
+ String pattern = "^.[0-9]{1,3}/.";
+ if (ip == "*") {
+ return true;
}
+ String[] ipQuads = ip.split(".");
+ for (String quad : ipQuads) {
+ if (!quad.matches(pattern)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void validateForm() {
+ clearErrors();
+ validateVolumeName();
+ validateAccessControl();
+ validateDisks();
+ }
+
+ private void validateDisks() {
+ int diskCount = volume.getDisks().size();
- if(!isVolumeExist(txtName.getText())) {
- return false;
+ if(diskCount < 1) {
+ setError("At least one disk must be selected!");
}
- return true;
+ String volumeType = (String)((IStructuredSelection)typeComboViewer.getSelection()).getFirstElement();
+ if (volumeType.equals(VOLUME_TYPE.DISTRIBUTED_MIRROR) && (diskCount % 2 != 0)) {
+ setError("Mirror type volume requires disks in multiples of two");
+ } else if(volumeType.equals(VOLUME_TYPE.DISTRIBUTED_STRIPE) && (diskCount % 4 != 0)) {
+ setError("Stripe type volume requires disks in multiples of four");
+ }
+ }
+
+ private void validateAccessControl() {
+ String accessControl = txtAccessControl.getText().trim();
+ if(accessControl.length() == 0) {
+ setError("Please enter Access Control");
+ }
+ // acl validation
+ String[] aclList = accessControl.split(",");
+ for (String ip : aclList) {
+ if (!isValidIP(ip)) {
+ setError("Please enter valid access control list");
+ }
+ }
+ }
+
+ private void validateVolumeName() {
+ String volumeName = txtName.getText().trim();
+ String volumeNameToken = "^[a-zA-Z][a-zA-Z0-9\\-]*";
+ if(volumeName.length() == 0) {
+ setError("Please enter Volume Name");
+ }
+
+ if (!volumeName.matches(volumeNameToken)) {
+ setError("Please enter valid Volume Name");
+ }
+
+ if(!volumeExists(volumeName)) {
+ setError("Volume [" + volumeName + "] already exists!");
+ }
+ }
+
+ private void clearErrors() {
+ setErrorMessage(null);
+ setPageComplete(true);
+ }
+
+ private void setError(String errorMsg) {
+ setPageComplete(false);
+ setErrorMessage(errorMsg);
}
}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumeWizard.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumeWizard.java
index 36755bec..66c26a89 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumeWizard.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/CreateVolumeWizard.java
@@ -38,33 +38,46 @@ public class CreateVolumeWizard extends Wizard {
public void addPages() {
addPage(new CreateVolumePage1());
}
-
+
@Override
public boolean performFinish() {
+ String dialogTitle = "Create Volume";
CreateVolumePage1 page = (CreateVolumePage1) getPage(CreateVolumePage1.PAGE_NAME);
- if (!page.isValidCreateVolumeForm()) {
- return false;
- }
-
+
Volume newVolume = page.getVolume();
GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();
VolumesClient volumesClient = new VolumesClient(modelManager.getSecurityToken());
Status status = volumesClient.createVolume(newVolume);
-
+
if (status.isSuccess()) {
+ String message = "Volume created successfully!";
+ boolean warning = false;
newVolume.setStatus(VOLUME_STATUS.OFFLINE);
- if (page.getStartVolumeRequest()) {
+ if (page.startVolumeAfterCreation()) {
Status volumeStartStatus = volumesClient.startVolume(newVolume.getName());
if (volumeStartStatus.isSuccess()) {
newVolume.setStatus(VOLUME_STATUS.ONLINE);
+ message = "Volume created and started successfully!";
+ } else {
+ message = "Volume created successfuly, but couldn't be started. Error: " + volumeStartStatus;
+ warning = true;
}
}
- //update the model
- modelManager.addVolume(newVolume);
- MessageDialog.openInformation(getShell(), "Create Volume", "Volume created successfully and configuration added!");
+
+ // update the model
+ modelManager.addVolume(newVolume);
+ if (warning) {
+ MessageDialog.openWarning(getShell(), dialogTitle, message);
+ } else {
+ MessageDialog.openInformation(getShell(), dialogTitle, message);
+ }
} else {
- MessageDialog.openError(getShell(), "Create Volume", "Volume creation failed! [" + status.getCode() + "]["
- + status.getMessage() + "]");
+ if (status.isPartSuccess()) {
+ MessageDialog.openWarning(getShell(), dialogTitle, "Volume created, but following error(s) occured: "
+ + status);
+ } else {
+ MessageDialog.openError(getShell(), dialogTitle, "Volume creation failed! " + status);
+ }
}
return true;