summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSelvasundaram <selvam@gluster.com>2011-08-05 12:39:40 +0530
committerSelvasundaram <selvam@gluster.com>2011-08-07 16:01:31 +0530
commitc0a83f26fa8ab983fa3528f4b55f02f87ed4b7e0 (patch)
tree7f85c62e734ffe7114503c7d579a1a8f129dc6b5
parent21f17bedf2419045d373d318b791af09a9a64196 (diff)
Volume cifs service integration
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java3
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java189
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java4
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java10
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java5
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java263
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java1
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java5
10 files changed, 277 insertions, 211 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 3b506f2a..e3bba8e9 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
@@ -22,7 +22,6 @@ package com.gluster.storage.management.client;
import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_ACCESS_PROTOCOLS;
import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_BRICKS;
-import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_CIFS_ENABLE;
import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_CIFS_USERS;
import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_REPLICA_COUNT;
import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_STRIPE_COUNT;
@@ -105,7 +104,7 @@ public class VolumesClient extends AbstractClient {
public void setCifsConfig(String volumeName, Boolean isCifsEnabled, String cifsUsers) {
Form form = new Form();
- form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_CIFS_CONFIG);
+ form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_CIFS_CONFIG);
form.add(RESTConstants.FORM_PARAM_CIFS_ENABLE, isCifsEnabled);
form.add(RESTConstants.FORM_PARAM_CIFS_USERS, cifsUsers);
putRequest(volumeName, form);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java
index 588dfdd6..1fa63269 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java
@@ -72,6 +72,10 @@ public class StartVolumeAction extends AbstractActionDelegate {
startedVolumes.add(volume.getName());
}catch (Exception e) {
failedVolumes.add(volume.getName());
+ // If any post volume start activity failed, update the volume status
+ if (vc.getVolume(volume.getName()).getStatus() == VOLUME_STATUS.ONLINE) {
+ modelManager.updateVolumeStatus(volume, VOLUME_STATUS.ONLINE);
+ }
errorMessage += e.getMessage();
}
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java
index bcfadcc5..bf86f2ec 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java
@@ -84,6 +84,10 @@ public class StopVolumeAction extends AbstractActionDelegate {
stoppedVolumes.add(volume.getName());
} catch (Exception e) {
failedVolumes.add(volume.getName());
+ // If any post volume stop activity failed, update the volume status
+ if (vc.getVolume(volume.getName()).getStatus() == VOLUME_STATUS.OFFLINE) {
+ modelManager.updateVolumeStatus(volume, VOLUME_STATUS.OFFLINE);
+ }
errorMessage += e.getMessage();
}
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java
index 92b4b22e..73cd14a6 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java
@@ -65,7 +65,7 @@ public class VolumeSummaryView extends ViewPart {
private CLabel lblStatusValue;
private DefaultClusterListener volumeChangedListener;
private Hyperlink changeLink;
- private Hyperlink CifsChangeLink;
+ private Hyperlink cifsChangeLink;
private Text accessControlText;
private Text cifsUsersText;
private ControlDecoration errDecoration;
@@ -270,29 +270,17 @@ public class VolumeSummaryView extends ViewPart {
}
private void createCifsField(Composite section) {
- GridData data = new GridData();
- data.heightHint = 0;
-
cifsLabel = toolkit.createLabel(section, "CIFS: ", SWT.NONE);
- cifsLabel.setLayoutData(data);
- cifsLabel.setVisible(false);
-
cifsUsersText = toolkit.createText(section, volume.getAccessControlList(), SWT.BORDER);
populateCifsUsersText();
addKeyListenerForCifsUser();
- cifsUsersText.setLayoutData(createDefaultLayoutData());
- cifsUsersText.setEnabled(true);
- cifsUsersText.setLayoutData(data);
- cifsUsersText.setVisible(false);
cifsUpdateLinkComposite = toolkit.createComposite(section, SWT.NONE);
- cifsUpdateLinkComposite.setVisible(false);
- cifsUpdateLinkComposite.setLayoutData(data);
cifsUpdateLinkComposite.setLayout(new FillLayout());
+ cifsUpdateLinkComposite.setVisible(volume.isCifsEnable());
createChangeLinkForCifs(cifsUpdateLinkComposite);
-
- // error decoration used while validating the cifs users text
+ renderCifsUsers(cifsCheckbox.getSelection());
errCifsDecoration = guiHelper.createErrorDecoration(cifsUsersText);
errCifsDecoration.hide();
}
@@ -381,18 +369,16 @@ public class VolumeSummaryView extends ViewPart {
}
private void createChangeLinkForCifs(Composite section) {
- CifsChangeLink = toolkit.createHyperlink(section, "Update", SWT.NONE);
- CifsChangeLink.addHyperlinkListener(new HyperlinkAdapter() {
+ cifsChangeLink = toolkit.createHyperlink(section, "change", SWT.NONE);
+ cifsChangeLink.addHyperlinkListener(new HyperlinkAdapter() {
private void finishEdit() {
saveCifsConfiguration();
}
private void startEdit() {
- cifsUsersText.setEnabled(true);
- cifsUsersText.setFocus();
+ enableCifsUsersControls(true);
cifsUsersText.selectAll();
- CifsChangeLink.setText("update");
}
@Override
@@ -408,47 +394,47 @@ public class VolumeSummaryView extends ViewPart {
});
}
+
private void saveCifsConfiguration() {
- final String cifsUsers = cifsUsersText.getText();
-
guiHelper.setStatusMessage("Setting Cifs Configuration...");
parent.update();
-
- List<String> userList = volume.getCifsUsers();
- String configuredUsers = "";
- if (userList != null) {
- configuredUsers = StringUtil.collectionToString(userList, ",");
- }
- if (cifsUsersText.equals(configuredUsers)) {
- cifsUsersText.setEnabled(false);
- CifsChangeLink.setText("change");
- // There is no change in the users list
- } else if(isvalidCifsUser()) {
+ final String cifsUsers = cifsUsersText.getText().trim();
+ List<String> userList = volume.getCifsUsers();
+ String configuredUsers = (userList != null) ? StringUtil.collectionToString(userList, ",") : "";
+
+ // To check if no changes in the users list
+ if (! isvalidCifsUser()) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Cifs Configuration",
+ "Please enter cifs user name ");
+ enableCifsUsersControls(true);
+ validateCifsUsers();
+ } else if (cifsUsers.equals(configuredUsers)) { // Nothing to do.
+ enableCifsUsersControls(false);
+ } else {
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
@Override
public void run() {
try {
new VolumesClient().setCifsConfig(volume.getName(), cifsCheckbox.getSelection(), cifsUsers);
- cifsUsersText.setEnabled(false);
- CifsChangeLink.setText("change");
-
+ enableCifsUsersControls(false);
GlusterDataModelManager.getInstance().setCifsConfig(volume, cifsCheckbox.getSelection(),
Arrays.asList(cifsUsers.split(",")));
} catch (Exception e) {
- MessageDialog.openError(Display.getDefault().getActiveShell(), "Cifs Configuration", e.getMessage());
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Cifs Configuration",
+ e.getMessage());
+ cifsCheckbox.setSelection(volume.isCifsEnable());
populateCifsUsersText();
}
}
});
- } else {
- MessageDialog.openError(Display.getDefault().getActiveShell(), "Cifs Configuration", "Please enter cifs user name ");
- cifsUsersText.setFocus();
- }
+ }
guiHelper.clearStatusMessage();
parent.update();
}
+
+
private void saveNFSOption() {
guiHelper.setStatusMessage("Setting NFS option...");
parent.update();
@@ -508,24 +494,25 @@ public class VolumeSummaryView extends ViewPart {
case SWT.ESC:
// Reset to default
populateCifsUsersText();
+ enableCifsUsersControls(false);
+ form.reflow(true);
break;
case 13:
// User has pressed enter. Save the new value
saveCifsConfiguration();
break;
}
- validateCifsUsers();
+ // validateCifsUsers();
}
});
}
private void populateCifsUsersText() {
List<String> userList = volume.getCifsUsers();
- if (userList == null) {
- cifsUsersText.setText("");
+ if (volume.isCifsEnable() && userList != null) {
+ cifsUsersText.setText(StringUtil.collectionToString(userList, ","));
} else {
- String users = StringUtil.collectionToString(userList, ",");
- cifsUsersText.setText(users);
+ cifsUsersText.setText("");
}
}
@@ -548,54 +535,92 @@ public class VolumeSummaryView extends ViewPart {
// CIFS checkbox
cifsCheckbox = createCheckbox(nasProtocolsComposite, "CIFS", volume.isCifsEnable(), true);
- cifsCheckboxListner(cifsCheckbox);
-
+ createCifsCheckboxListner(cifsCheckbox);
+
toolkit.createLabel(section, "", SWT.NONE); // dummy
}
- private void cifsCheckboxListner(final Button cifsCheckbox) {
+ private void createCifsCheckboxListner(final Button cifsCheckbox) {
cifsCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (cifsCheckbox.getSelection()) {
- GridData data = new GridData();
- data.heightHint = 20;
- data.widthHint = 100;
-
- cifsLabel.setVisible(true);
- cifsLabel.setLayoutData(data);
-
- GridData data1 = new GridData();
- data1.heightHint = 20;
- data1.widthHint = 300;
- cifsUsersText.setVisible(true);
- cifsUsersText.setLayoutData(data1);
-
- GridData data2 = new GridData();
- data2.heightHint = 25;
- data2.widthHint = 75;
- cifsUpdateLinkComposite.setVisible(true);
- cifsUpdateLinkComposite.setLayoutData(data2);
- form.reflow(true);
+ // need to enable cifs
+ // TODO: Open the text box (empty and enabled),
+ // the hyperlink next to the textbox should have label "update"
+ // when user clicks on that hyperlink,
+ // saveCifsConfiguration should be called
+ // Also, if user presses the "ESC" key,
+ // return to the previous state of checkbox and hide the textbox + hyperlink
+ showCifsUsersControls(true);
+ enableCifsUsersControls(true);
+ // saveCifsConfiguration();
} else {
- GridData data = new GridData();
- data.heightHint = 0;
-
- cifsUsersText.setVisible(false);
- cifsUsersText.setLayoutData(data);
-
- cifsLabel.setVisible(false);
- cifsLabel.setLayoutData(data);
-
- cifsUpdateLinkComposite.setVisible(false);
- cifsUpdateLinkComposite.setLayoutData(data);
-
- form.reflow(true);
+ // need to disable cifs
+ // TODO: hide the textbox and the link AFTER disabling cifs
+ showCifsUsersControls(false);
+ enableCifsUsersControls(false);
}
+ populateCifsUsersText();
+ form.reflow(true);
}
});
}
+
+ private void renderCifsUsers(Boolean cifsSelection) {
+ if (cifsSelection) {
+ enableCifsUsersControls(false);
+ showCifsUsersControls(true);
+ } else {
+ showCifsUsersControls(false);
+ }
+ }
+
+ private void showCifsUsersControls(Boolean visible) {
+ if ( visible) {
+ GridData data = new GridData();
+ data.heightHint = 20;
+ data.widthHint = 100;
+ cifsLabel.setLayoutData(data);
+
+ GridData data1 = new GridData();
+ data1.heightHint = 20;
+ data1.widthHint = 300;
+
+ cifsUsersText.setLayoutData(data1);
+
+ GridData data2 = new GridData();
+ data2.heightHint = 25;
+ data2.widthHint = 75;
+ cifsUpdateLinkComposite.setLayoutData(data2);
+ } else {
+ GridData data = new GridData();
+ data.heightHint = 0;
+ cifsLabel.setLayoutData(data);
+ cifsUsersText.setLayoutData(data);
+ cifsUpdateLinkComposite.setLayoutData(data);
+ }
+
+ cifsLabel.setVisible(visible);
+ cifsUsersText.setVisible(visible);
+ cifsUpdateLinkComposite.setVisible(visible);
+ form.reflow(true);
+ }
+
+ private void enableCifsUsersControls(Boolean enable) {
+ cifsUsersText.setEnabled(enable);
+ cifsChangeLink.setText((enable) ? "update" : "change");
+ if (enable) {
+ cifsUsersText.setFocus();
+ validateCifsUsers();
+ } else {
+ if (errCifsDecoration != null) {
+ errCifsDecoration.hide();
+ }
+ }
+ }
+
private Button createCheckbox(Composite parent, String label, boolean checked, boolean enabled) {
final Button checkBox = toolkit.createButton(parent, label, SWT.CHECK);
checkBox.setSelection(checked);
@@ -609,7 +634,6 @@ public class VolumeSummaryView extends ViewPart {
nfsCheckBox.setSelection(isNFSExported);
}
-
private void updateBrickChanges(Volume volume) {
numberOfBricks.setText("" + volume.getNumOfBricks());
totalDiskSpace.setText("" + NumberUtil.formatNumber((getTotalDiskSpace() / 1024)));
@@ -745,6 +769,7 @@ public class VolumeSummaryView extends ViewPart {
return true;
}
}
+ validateCifsUsers();
return true;
}
}
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 0a9fd383..737f4d7b 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
@@ -54,7 +54,6 @@ public class RESTConstants {
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 TASK_CIFS_CONFIG = "cifsConfig";
public static final String FORM_PARAM_VOLUME_NAME = "name";
public static final String FORM_PARAM_VOLUME_TYPE = "volumeType";
@@ -67,7 +66,8 @@ public class RESTConstants {
public static final String FORM_PARAM_FSTYPE = "fsType";
public static final String FORM_PARAM_CIFS_ENABLE = "enableCifs";
public static final String FORM_PARAM_CIFS_USERS = "cifsUsers";
-
+ public static final String FORM_PARAM_CIFS_CONFIG = "cifsConfig";
+
public static final String FORM_PARAM_CLUSTER_NAME = "clusterName";
public static final String FORM_PARAM_SERVER_NAME = "serverName";
public static final String FORM_PARAM_DISKS = "disks";
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
index 2c3bd2ba..c3b73c27 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java
@@ -256,7 +256,9 @@ public class Volume extends Entity {
}
public void enableCifs() {
- nasProtocols.add(NAS_PROTOCOL.CIFS);
+ if (!nasProtocols.contains(NAS_PROTOCOL.CIFS)) {
+ nasProtocols.add(NAS_PROTOCOL.CIFS);
+ }
}
public void disableCifs() {
@@ -264,11 +266,7 @@ public class Volume extends Entity {
}
public boolean isCifsEnable() {
- if (nasProtocols.contains(NAS_PROTOCOL.CIFS)) {
- return true;
- } else {
- return false;
- }
+ return nasProtocols.contains(NAS_PROTOCOL.CIFS);
}
public void setCifsUsers(List<String> cifsUsers) {
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java
index 507c6d95..becd46a7 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java
@@ -24,6 +24,7 @@ import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
@@ -64,7 +65,6 @@ public class ProcessUtil {
StringBuilder output = new StringBuilder();
try {
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
-
if (runInForeground) {
process.waitFor(); // Wait for process to finish
@@ -85,7 +85,8 @@ public class ProcessUtil {
return new ProcessResult(process.exitValue(), output.toString());
} catch (Throwable e) {
- throw new GlusterRuntimeException("Exception while executing command [" + command + "]", e);
+ throw new GlusterRuntimeException("Exception while executing command [" + command + "] : ["
+ + e.getMessage() + "]", e);
}
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
index 1c109ed3..c1d449ab 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java
@@ -62,7 +62,6 @@ import static com.gluster.storage.management.core.constants.RESTConstants.TASK_S
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -120,13 +119,16 @@ public class VolumesResource extends AbstractResource {
private static final String VOLUME_DIRECTORY_CLEANUP_SCRIPT = "clear_volume_directory.py";
private static final String VOLUME_CIFS_GRUN_SCRIPT = "grun.py";
- private static final String VOLUME_CREATE_CIFS_SCRIPT = "create_volume_cifs.py";
- private static final String VOLUME_START_CIFS_SCRIPT = "start_volume_cifs.py";
- private static final String VOLUME_STOP_CIFS_SCRIPT = "stop_volume_cifs.py";
- private static final String VOLUME_DELETE_CIFS_SCRIPT = "delete_volume_cifs.py";
- private static final String VOLUME_MODIFY_CIFS_SCRIPT = "modify_volume_cifs.py";
- private static final String ALL_SERVERS_FILE_NAME = "servers";
+ private static final String VOLUME_CREATE_CIFS_SCRIPT = "create_volume_cifs_all.py";
+ private static final String VOLUME_GET_CIFS_USERS_SCRIPT = "get_volume_user_cifs.py";
+ private static final String VOLUME_DELETE_CIFS_SCRIPT = "delete_volume_cifs_all.py";
+ private static final String VOLUME_MODIFY_CIFS_SCRIPT = "update_volume_cifs_all.py";
+ private static final String VOLUME_START_CIFS_PEER_SCRIPT = "start_volume_cifs.py";
+ private static final String VOLUME_STOP_CIFS_PEER_SCRIPT = "stop_volume_cifs.py";
+
+ private static final String ALL_SERVERS_FILE_NAME = "servers";
+
private static final String VOLUME_BRICK_LOG_SCRIPT = "get_volume_brick_log.py";
private static final Logger logger = Logger.getLogger(VolumesResource.class);
@@ -184,26 +186,27 @@ public class VolumesResource extends AbstractResource {
}
try {
- return new VolumeListResponse(glusterUtil.getAllVolumes(onlineServer.getName()));
+ return new VolumeListResponse(getVolumesCifsUsers(clusterName, glusterUtil.getAllVolumes(onlineServer.getName())));
} catch (ConnectionException e) {
// online server has gone offline! try with a different one.
onlineServer = clusterService.getNewOnlineServer(clusterName);
if (onlineServer == null) {
return new VolumeListResponse(new ArrayList<Volume>());
}
-
- return new VolumeListResponse(glusterUtil.getAllVolumes(onlineServer.getName()));
+ return new VolumeListResponse(getVolumesCifsUsers(clusterName, glusterUtil.getAllVolumes(onlineServer.getName())));
}
}
@POST
@Produces(MediaType.APPLICATION_XML)
- public Response createVolume(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @FormParam(FORM_PARAM_VOLUME_NAME) String volumeName,
- @FormParam(FORM_PARAM_VOLUME_TYPE) String volumeType, @FormParam(FORM_PARAM_TRANSPORT_TYPE) String transportType,
- @FormParam(FORM_PARAM_REPLICA_COUNT) Integer replicaCount, @FormParam(FORM_PARAM_STRIPE_COUNT) Integer stripeCount,
- @FormParam(FORM_PARAM_BRICKS) String bricks, @FormParam(FORM_PARAM_ACCESS_PROTOCOLS) String accessProtocols,
+ public Response createVolume(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
+ @FormParam(FORM_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_VOLUME_TYPE) String volumeType,
+ @FormParam(FORM_PARAM_TRANSPORT_TYPE) String transportType,
+ @FormParam(FORM_PARAM_REPLICA_COUNT) Integer replicaCount,
+ @FormParam(FORM_PARAM_STRIPE_COUNT) Integer stripeCount, @FormParam(FORM_PARAM_BRICKS) String bricks,
+ @FormParam(FORM_PARAM_ACCESS_PROTOCOLS) String accessProtocols,
@FormParam(FORM_PARAM_VOLUME_OPTIONS) String options, @FormParam(FORM_PARAM_CIFS_USERS) String cifsUsers) {
- if(clusterName == null || clusterName.isEmpty()) {
+ if (clusterName == null || clusterName.isEmpty()) {
return badRequestResponse("Cluster name must not be empty!");
}
@@ -226,22 +229,23 @@ public class VolumesResource extends AbstractResource {
}
try {
- performCreateVolume(clusterName, volumeName, volumeType, transportType, replicaCount, stripeCount, bricks, accessProtocols,
- options, cifsUsers);
+ performCreateVolume(clusterName, volumeName, volumeType, transportType, replicaCount, stripeCount, bricks,
+ accessProtocols, options, cifsUsers);
return createdResponse(volumeName);
} catch (Exception e) {
return errorResponse(e.getMessage());
}
}
- public void performCreateVolume(String clusterName, String volumeName, String volumeType, String transportType, Integer replicaCount,
- Integer stripeCount, String bricks, String accessProtocols, String options, String cifsUsers) {
+ public void performCreateVolume(String clusterName, String volumeName, String volumeType, String transportType,
+ Integer replicaCount, Integer stripeCount, String bricks, String accessProtocols, String options,
+ String cifsUsers) {
GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
if (onlineServer == null) {
throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
}
- try {
+ try {
glusterUtil.createVolume(onlineServer.getName(), volumeName, volumeType, transportType, replicaCount,
stripeCount, bricks, accessProtocols, options);
} catch (ConnectionException e) {
@@ -254,12 +258,12 @@ public class VolumesResource extends AbstractResource {
glusterUtil.createVolume(onlineServer.getName(), volumeName, volumeType, transportType, replicaCount,
stripeCount, bricks, accessProtocols, options);
}
-
+
List<String> nasProtocols = Arrays.asList(accessProtocols.split(","));
- // only if cifs enabled
+ // if cifs enabled
if (nasProtocols.contains(NAS_PROTOCOL.CIFS.toString())) {
try {
- createCIFSUsers(clusterName, volumeName, Arrays.asList(cifsUsers.split(",")));
+ createCIFSUsers(clusterName, volumeName, cifsUsers);
} catch (Exception e) {
throw new GlusterRuntimeException(CoreConstants.NEWLINE + e.getMessage());
}
@@ -337,14 +341,17 @@ public class VolumesResource extends AbstractResource {
try {
volume = glusterUtil.getVolume(volumeName, onlineServer.getName());
+ // Collect the CIFS users if CIFS Re-exported
+ getVolumeCifsUsers(clusterName, volume);
} catch (ConnectionException e) {
// online server has gone offline! try with a different one.
onlineServer = clusterService.getNewOnlineServer(clusterName);
if (onlineServer == null) {
throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
}
-
volume = glusterUtil.getVolume(volumeName, onlineServer.getName());
+ // Collect the CIFS users if CIFS Re-exported
+ getVolumeCifsUsers(clusterName, volume);
}
return volume;
}
@@ -376,11 +383,15 @@ public class VolumesResource extends AbstractResource {
+ "/" + taskId);
} else if (operation.equals(RESTConstants.TASK_REBALANCE_STOP)) {
rebalanceStop(clusterName, volumeName);
- } else if (operation.equals(RESTConstants.TASK_CIFS_CONFIG)) {
+ } else if (operation.equals(RESTConstants.FORM_PARAM_CIFS_CONFIG)) {
if (enableCifs) {
- modifyCIFSUsers(clusterName, volumeName, Arrays.asList(cifsUsers.split(",")));
+ modifyCIFSUsers(clusterName, volumeName, cifsUsers);
} else {
- stopCifsReexport(clusterName, volumeName);
+ deleteCifsUsers(clusterName, volumeName);
+ //TODO: workaround - If samba service are not stopped by "deleteCifsUsers" script,
+ // gateway needs to stop the services
+ // modifyCIFSUsers(clusterName, volumeName, "");
+ // stopCifsReExport(clusterName, volumeName);
}
} else {
performVolumeOperation(clusterName, volumeName, operation);
@@ -420,20 +431,16 @@ public class VolumesResource extends AbstractResource {
result = glusterUtil.startVolume(volumeName, onlineServer.getName());
// call the start_volume_cifs.py script only if the volume is cifs enabled
- if (volume.getNASProtocols().contains(NAS_PROTOCOL.CIFS)) {
- if (result.isSuccess()) {
- startCifsReexport(onlineServer.getName(), volumeName);
- }
+ if (volume.isCifsEnable() && result.isSuccess()) {
+ startCifsReExport(clusterName, volumeName);
}
return result;
} else if (operation.equals(TASK_STOP)) {
result = glusterUtil.stopVolume(volumeName, onlineServer.getName());
// call the stop_volume_cifs.py script only if the volume is cifs enabled
- if (volume.getNASProtocols().contains(NAS_PROTOCOL.CIFS)) {
- if (result.isSuccess()) {
- stopCifsReexport(onlineServer.getName(), volumeName);
- }
+ if (volume.isCifsEnable() && result.isSuccess()) {
+ stopCifsReExport(clusterName, volumeName);
}
return result;
} else {
@@ -441,110 +448,131 @@ public class VolumesResource extends AbstractResource {
}
}
- private void startCifsReexport(String clusterName, String volumeName) {
- File file;
+ private void startCifsReExport(String clusterName, String volumeName) {
try {
- file = createOnlineServerList(clusterName);
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error in CIFS configuration after stop volume [" + volumeName + "]: " + e.getMessage());
- }
-
- ProcessResult result = processUtil.executeCommand(VOLUME_CIFS_GRUN_SCRIPT + " " + file.getAbsolutePath() + " " +
- VOLUME_START_CIFS_SCRIPT + " " + volumeName);
- file.delete();
- if (!result.isSuccess()) {
- throw new GlusterRuntimeException("Error in cifs configuration after start volume [" + volumeName + "]: "
- + result);
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil.executeGlusterScript(true, VOLUME_CIFS_GRUN_SCRIPT,
+ file.getAbsolutePath(), VOLUME_START_CIFS_PEER_SCRIPT, volumeName);
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in starting CIFS services for volume [" + volumeName + "]: "
+ + e.getMessage());
}
}
- private void stopCifsReexport(String clusterName, String volumeName) {
- File file;
+ private void stopCifsReExport(String clusterName, String volumeName) {
try {
- file = createOnlineServerList(clusterName);
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error in CIFS configuration after stop volume [" + volumeName + "]: " + e.getMessage());
- }
-
- ProcessResult result = processUtil.executeCommand(VOLUME_CIFS_GRUN_SCRIPT + " " + file.getAbsolutePath() + " " +
- VOLUME_STOP_CIFS_SCRIPT + " " + volumeName);
- file.delete();
- if (!result.isSuccess()) {
- throw new GlusterRuntimeException("Error in cifs configuration after stop volume [" + volumeName + "]: "
- + result);
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil.executeGlusterScript(true, VOLUME_CIFS_GRUN_SCRIPT,
+ file.getAbsolutePath(), VOLUME_STOP_CIFS_PEER_SCRIPT, volumeName);
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in stoping CIFS services for volume [" + volumeName + "]: "
+ + e.getMessage());
}
}
private void deleteCifsUsers(String clusterName, String volumeName) {
- File file;
try {
- file = createOnlineServerList(clusterName);
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error in deleting CIFS configuration [" + volumeName + "]: " + e.getMessage());
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil.executeGlusterScript(true, VOLUME_DELETE_CIFS_SCRIPT,
+ file.getAbsolutePath(), volumeName);
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in deleting CIFS configuration [" + volumeName + "]: "
+ + e.getMessage());
}
+ }
- ProcessResult result = processUtil.executeCommand(VOLUME_CIFS_GRUN_SCRIPT + " " + file.getAbsolutePath() + " " +
- VOLUME_DELETE_CIFS_SCRIPT + " " + volumeName);
- file.delete();
- if (!result.isSuccess()) {
- throw new GlusterRuntimeException("Error in cifs configuration after delete volume [" + volumeName + "]: "
- + result);
+ private void createCIFSUsers(String clusterName, String volumeName, String cifsUsers) {
+ try {
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil.executeGlusterScript(true, VOLUME_CREATE_CIFS_SCRIPT,
+ file.getAbsolutePath(), volumeName, cifsUsers.replace(",", " "));
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in creating CIFS configuration [" + volumeName + "]: "
+ + e.getMessage());
}
}
- private void createCIFSUsers(String clusterName, String volumeName, List<String> cifsUsers) {
- File file;
+ private void modifyCIFSUsers(String clusterName, String volumeName, String cifsUsers) {
try {
- file = createOnlineServerList(clusterName);
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error in CIFS configuration [" + volumeName + "]: " + e.getMessage());
- }
- String users = "";
- for (String user : cifsUsers) {
- users += " " + user;
- }
- ProcessResult result = processUtil.executeCommand(VOLUME_CIFS_GRUN_SCRIPT + " " + file.getAbsolutePath() + " " +
- VOLUME_CREATE_CIFS_SCRIPT + " " + volumeName + users);
- file.delete();
- if (!result.isSuccess()) {
- throw new GlusterRuntimeException("Error in CIFS configuration [" + volumeName + "]: " + result);
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil.executeGlusterScript(true, VOLUME_MODIFY_CIFS_SCRIPT,
+ file.getAbsolutePath(), volumeName, cifsUsers.replace(",", " "));
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in updating CIFS configuration [" + volumeName + "]: "
+ + e.getMessage());
}
}
-
- private void modifyCIFSUsers(String clusterName, String volumeName, List<String> cifsUsers) {
- File file;
+
+ private void getVolumeCifsUsers(String clusterName, Volume volume) {
+ List<String> users = new ArrayList<String>();
try {
- file = createOnlineServerList(clusterName);
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error in CIFS configuration [" + volumeName + "]: " + e.getMessage());
- }
- String users = "";
- for (String user : cifsUsers) {
- users += " " + user;
+ File file = createOnlineServerList(clusterName);
+ ProcessResult result = serverUtil
+ .executeGlusterScript(true, VOLUME_GET_CIFS_USERS_SCRIPT, volume.getName());
+ file.delete();
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ String output = result.getOutput().trim();
+ if (output.isEmpty()) {
+ volume.disableCifs();
+ } else {
+ users = Arrays.asList(output.split(CoreConstants.NEWLINE));
+ volume.enableCifs();
+ volume.setCifsUsers(users);
+ }
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in fetching CIFS users [" + volume.getName() + "]: "
+ + e.getMessage());
}
- ProcessResult result = processUtil.executeCommand(VOLUME_CIFS_GRUN_SCRIPT + " " + file.getAbsolutePath() + " " +
- VOLUME_MODIFY_CIFS_SCRIPT + " " + volumeName + users);
- file.delete();
- if (!result.isSuccess()) {
- throw new GlusterRuntimeException("Error in CIFS configuration [" + volumeName + "]: " + result);
+ return;
+ }
+
+ private List<Volume> getVolumesCifsUsers(String clusterName, List<Volume> volumes) {
+ for (Volume volume: volumes) {
+ getVolumeCifsUsers(clusterName, volume);
}
+ return volumes;
}
- public File createOnlineServerList(String clusterName) throws IOException {
+ public File createOnlineServerList(String clusterName) {
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
-
- GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
String clusterServersListFile = FileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR
- + ALL_SERVERS_FILE_NAME + "_" + timestamp;
- List<GlusterServer> glusterServers = glusterUtil.getGlusterServers(onlineServer);
- File serversFile = new File(clusterServersListFile);
- FileOutputStream fos = new FileOutputStream(serversFile);
- for (GlusterServer server : glusterServers) {
- fos.write((server.getName() + CoreConstants.NEWLINE).getBytes());
- }
- fos.close();
- return serversFile;
+ + ALL_SERVERS_FILE_NAME + "_" + timestamp;
+ try {
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
+ List<GlusterServer> glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ File serversFile = new File(clusterServersListFile);
+ FileOutputStream fos = new FileOutputStream(serversFile);
+ for (GlusterServer server : glusterServers) {
+ fos.write((server.getName() + CoreConstants.NEWLINE).getBytes());
+ }
+ fos.close();
+ return serversFile;
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in preparing server list: [" + e.getMessage() + "]");
+ }
}
@DELETE
@@ -572,7 +600,7 @@ public class VolumesResource extends AbstractResource {
try {
volume = getVolume(clusterName, volumeName);
} catch (Exception e) {
- // TODO: Log the exception
+ logger.error(e);
return errorResponse(e.getMessage());
}
@@ -586,20 +614,21 @@ public class VolumesResource extends AbstractResource {
try {
postDelete(volumeName, bricks, deleteFlag);
} catch(Exception e) {
+ logger.error(e);
return errorResponse("Volume [" + volumeName
+ "] deleted from cluster, however following errors happened: " + CoreConstants.NEWLINE
+ e.getMessage());
}
// call the delete_volume_cifs.py script only if the volume is cifs enabled
- if (volume.getNASProtocols().contains(NAS_PROTOCOL.CIFS)) {
+ if (volume.isCifsEnable()) {
try {
deleteCifsUsers(clusterName, volumeName);
} catch (Exception e) {
+ logger.error(e);
return errorResponse(CoreConstants.NEWLINE + e.getMessage());
}
}
-
return noContentResponse();
}
@@ -885,7 +914,7 @@ public class VolumesResource extends AbstractResource {
}
String gzipPath = FileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR + volume.getName() + "-logs.tar.gz";
- new ProcessUtil().executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName());
+ processUtil.executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName());
// delete the temp directory
FileUtil.recursiveDelete(tempDir);
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java
index 598dae13..883141d3 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java
@@ -264,6 +264,7 @@ public class GlusterUtil {
String command = prepareVolumeCreateCommand(volumeName, StringUtil.extractList(bricks, ","), count,
volTypeArg, transportTypeArg);
+
ProcessResult result = sshUtil.executeRemote(knownServer, command);
if (!result.isSuccess()) {
throw new GlusterRuntimeException("Error in creating volume [" + volumeName + "]: " + result);
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
index 1c46064b..9364ea68 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
@@ -23,6 +23,7 @@ package com.gluster.storage.management.gateway.utils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletContext;
@@ -65,6 +66,10 @@ public class ServerUtil {
this.sshUtil = sshUtil;
}
+ public ProcessResult executeGlusterScript(boolean runInForeground, String scriptName, String...arguments) {
+ return executeGlusterScript(runInForeground, scriptName, Arrays.asList(arguments));
+ }
+
public ProcessResult executeGlusterScript(boolean runInForeground, String scriptName, List<String> arguments) {
List<String> command = new ArrayList<String>();