summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-10-10 16:10:17 +0530
committerTim <timothyasir@gluster.com>2011-10-10 16:10:17 +0530
commitb651f8219c014dbae7efecdb99fc815c9108e3fd (patch)
treeeb38b2b9a1c4f314a3ba3844dfa1903922610389
parentf3794d604a5dfcdd3152aa9cd4ee3322f097cc24 (diff)
parent2babe9c17733e9c05d24b10c549469f56748df5f (diff)
Merge remote-tracking branch 'upstream/master'
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java8
-rw-r--r--src/com.gluster.storage.management.console/plugin.xml18
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ApplicationWorkbenchAdvisor.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/GlusterDataModelManager.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ServerDiskTableLabelProvider.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/DeleteVolumeAction.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/MigrateBrickAction.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RebalanceVolumeAction.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveBrickAction.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java13
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java7
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StartVolumeAction.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/StopVolumeAction.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java64
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/BricksSelectionPage.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickPage1.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickWizard.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/SelectDisksDialog.java6
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/preferences/GlusterPreferencePage.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DiscoveredServerView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DisksView.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerDisksView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerLogsView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerSummaryView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersSummaryView.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/NavigationView.java1
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeBricksView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeLogsView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeOptionsView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeSummaryView.java10
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeView.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumesSummaryView.java4
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/AbstractDisksPage.java2
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/DiskTreeContentProvider.java6
-rw-r--r--src/com.gluster.storage.management.core/META-INF/MANIFEST.MF1
-rw-r--r--src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java234
-rw-r--r--src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java481
-rw-r--r--src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java73
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java2
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java4
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Version.java65
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java17
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/VolumesResource.java7
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/AbstractGlusterInterface.java38
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/ClusterService.java8
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/Gluster323InterfaceService.java (renamed from src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java)327
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterface.java358
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterfaceService.java256
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java108
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java28
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java38
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java81
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java6
55 files changed, 1960 insertions, 373 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 4c75c375..f85afd4d 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
@@ -258,6 +258,14 @@ public class VolumesClient extends AbstractClient {
putRequest(volumeName, form);
}
+ public void volumeLogRotate(String volumeName, List<String> brickList) {
+ Form form = new Form();
+ String bricks = StringUtil.collectionToString(brickList, ",");
+ form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_LOG_ROTATE);
+ form.add(FORM_PARAM_BRICKS, bricks);
+ putRequest(volumeName, form);
+ }
+
public static void main(String[] args) {
UsersClient usersClient = new UsersClient();
try {
diff --git a/src/com.gluster.storage.management.console/plugin.xml b/src/com.gluster.storage.management.console/plugin.xml
index e7c2c2d4..6983b9dd 100644
--- a/src/com.gluster.storage.management.console/plugin.xml
+++ b/src/com.gluster.storage.management.console/plugin.xml
@@ -302,6 +302,11 @@
id="com.gluster.storage.management.console.commands.Preferences"
name="Settings">
</command>
+ <command
+ description="Volume Log Rotate"
+ id="com.gluster.storage.management.console.commands.LogRotate"
+ name="LogRotate">
+ </command>
</extension>
<extension
point="org.eclipse.ui.bindings">
@@ -521,6 +526,19 @@
label="Volume Actions"
visible="false">
<action
+ class="com.gluster.storage.management.console.actions.VolumeLogRotateAction"
+ definitionId="com.gluster.storage.management.console.commands.LogRotate"
+ icon="icons/tango/32x32/download-log.png"
+ id="com.gluster.storage.management.console.actions.LogRotateAction"
+ label="L&amp;og Rotate"
+ menubarPath="com.gluster.storage.management.console.menu.volume/volume"
+ pulldown="false"
+ state="true"
+ style="push"
+ toolbarPath="Normal"
+ tooltip="Rotate the volume logs">
+ </action>
+ <action
allowLabelUpdate="false"
class="com.gluster.storage.management.console.actions.MigrateBrickAction"
definitionId="com.gluster.storage.management.console.commands.MigrateDisk"
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ApplicationWorkbenchAdvisor.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ApplicationWorkbenchAdvisor.java
index fcbe3fcf..8d6c81da 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ApplicationWorkbenchAdvisor.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ApplicationWorkbenchAdvisor.java
@@ -65,7 +65,7 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
@Override
public void propertyChange(PropertyChangeEvent event) {
if(event.getProperty().equals(PreferenceConstants.P_DATA_SYNC_INTERVAL)) {
- JOB_INTERVAL = (Integer)event.getNewValue() * 1000l;
+ JOB_INTERVAL = (Integer)event.getNewValue() * 1000L;
}
}
};
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/GlusterDataModelManager.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/GlusterDataModelManager.java
index 83986745..e43bcbae 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/GlusterDataModelManager.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/GlusterDataModelManager.java
@@ -331,7 +331,7 @@ public class GlusterDataModelManager {
device.setStatus(status);
device.setType(DEVICE_TYPE.DATA);
for (ClusterListener listener : listeners) {
- listener.serverChanged((GlusterServer) server, new Event(EVENT_TYPE.DEVICES_CHANGED, device));
+ listener.serverChanged(server, new Event(EVENT_TYPE.DEVICES_CHANGED, device));
}
}
}
@@ -676,7 +676,7 @@ public class GlusterDataModelManager {
cluster.addDiscoveredServer(server);
for (ClusterListener listener : listeners) {
- listener.discoveredServerAdded(server);;
+ listener.discoveredServerAdded(server);
}
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ServerDiskTableLabelProvider.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ServerDiskTableLabelProvider.java
index 2f49d2b3..d733701c 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ServerDiskTableLabelProvider.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/ServerDiskTableLabelProvider.java
@@ -20,7 +20,7 @@ package com.gluster.storage.management.console;
import org.eclipse.swt.graphics.Image;
-import com.gluster.storage.management.console.DeviceTableLabelProvider.DEVICE_COLUMN_INDICES;
+import static com.gluster.storage.management.console.DeviceTableLabelProvider.DEVICE_COLUMN_INDICES;
import com.gluster.storage.management.console.utils.GUIHelper;
import com.gluster.storage.management.console.views.pages.ServerDisksPage.SERVER_DISK_TABLE_COLUMN_INDICES;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/DeleteVolumeAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/DeleteVolumeAction.java
index 2befda7d..3de3f945 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/DeleteVolumeAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/DeleteVolumeAction.java
@@ -114,7 +114,7 @@ public class DeleteVolumeAction extends AbstractMonitoredActionDelegate {
+ "Error: [" + errorMessage + "]");
} else {
String info = "Volumes " + deletedVolumeNames + " deleted successfully!";
- if (errorMessage != "") {
+ if (!errorMessage.equals("")) {
info += CoreConstants.NEWLINE + CoreConstants.NEWLINE + "Volumes " + failedVolumes
+ " could not be deleted! [" + errorMessage + "]";
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/MigrateBrickAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/MigrateBrickAction.java
index 4816871e..db416c07 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/MigrateBrickAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/MigrateBrickAction.java
@@ -54,7 +54,7 @@ public class MigrateBrickAction extends AbstractActionDelegate {
action.setEnabled(false);
if (selectedEntity instanceof Brick) {
bricks = GUIHelper.getInstance().getSelectedEntities(getWindow(), Brick.class);
- brick = (Brick) bricks.iterator().next();
+ brick = bricks.iterator().next();
action.setEnabled(brick != null);
}
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RebalanceVolumeAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RebalanceVolumeAction.java
index 5ae93ede..016ffb8b 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RebalanceVolumeAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RebalanceVolumeAction.java
@@ -51,7 +51,7 @@ public class RebalanceVolumeAction extends AbstractActionDelegate {
// Add the task to model
TasksClient taskClient = new TasksClient();
TaskInfo taskInfo = taskClient.getTaskInfo(uri);
- if (taskInfo != null && taskInfo instanceof TaskInfo) {
+ if (taskInfo != null) {
GlusterDataModelManager.getInstance().addTask(taskInfo);
}
showInfoDialog(actionDesc, "Volume [" + volume.getName() + "] rebalance started successfully!");
@@ -68,7 +68,7 @@ public class RebalanceVolumeAction extends AbstractActionDelegate {
Volume selectedVolume = guiHelper.getSelectedEntity(getWindow(), Volume.class);
if (selectedVolume != null) {
- volume = (Volume) selectedVolume;
+ volume = selectedVolume;
action.setEnabled(true);
} else {
action.setEnabled(false);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveBrickAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveBrickAction.java
index 01d70b21..4b747294 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveBrickAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveBrickAction.java
@@ -69,7 +69,7 @@ public class RemoveBrickAction extends AbstractActionDelegate {
super.selectionChanged(action, selection);
action.setEnabled(false);
- volume = (Volume) guiHelper.getSelectedEntity(window, Volume.class);
+ 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();
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
index 8f52657c..7f33828a 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
@@ -32,10 +32,12 @@ import org.eclipse.jface.viewers.ISelection;
import com.gluster.storage.management.client.GlusterServersClient;
import com.gluster.storage.management.console.GlusterDataModelManager;
import com.gluster.storage.management.console.utils.GUIHelper;
+import com.gluster.storage.management.console.utils.GlusterLogger;
import com.gluster.storage.management.core.constants.CoreConstants;
import com.gluster.storage.management.core.model.GlusterServer;
public class RemoveServerAction extends AbstractMonitoredActionDelegate {
+ private static final GlusterLogger logger = GlusterLogger.getInstance();
private GlusterDataModelManager modelManager = GlusterDataModelManager.getInstance();
private GUIHelper guiHelper = GUIHelper.getInstance();
@@ -64,12 +66,12 @@ public class RemoveServerAction extends AbstractMonitoredActionDelegate {
GlusterServersClient client = new GlusterServersClient();
try {
client.removeServer(server.getName());
- GlusterServer glusterServer = (GlusterServer) server;
+ GlusterServer glusterServer = server;
modelManager.removeGlusterServer(glusterServer);
successServers.add(server);
} catch (Exception e) {
if (!serverExists(server.getName())) {
- modelManager.removeGlusterServer((GlusterServer) server);
+ modelManager.removeGlusterServer(server);
}
errMsg += "[" + server.getName() + "] : " + e.getMessage() + CoreConstants.NEWLINE;
}
@@ -83,12 +85,9 @@ public class RemoveServerAction extends AbstractMonitoredActionDelegate {
try {
GlusterServersClient client = new GlusterServersClient();
GlusterServer server = client.getGlusterServer(serverName);
- if (server != null && server.getName().length() > 0) {
- return true;
- } else {
- return false;
- }
+ return (server != null && server.getName().length() > 0);
} catch (Exception e) {
+ logger.error("Error while getting server info", e);
return false;
}
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java
index 183b1668..99a7c887 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ResetVolumeOptionsAction.java
@@ -53,11 +53,6 @@ public class ResetVolumeOptionsAction extends AbstractActionDelegate {
@Override
public void selectionChanged(IAction action, ISelection selection) {
volume = GUIHelper.getInstance().getSelectedEntity(getWindow(), Volume.class);
-
- if (volume instanceof Volume) {
- action.setEnabled(volume.getOptions().size() > 0);
- } else {
- action.setEnabled(false);
- }
+ action.setEnabled(volume.getOptions().size() > 0);
}
}
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 03cdc4e8..0df91ab8 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
@@ -111,7 +111,7 @@ public class StartVolumeAction extends AbstractMonitoredActionDelegate {
+ CoreConstants.NEWLINE + "Error: [" + errorMessage + "]");
} else {
String info = "Volumes " + startedVolumes + " started successfully!";
- if (errorMessage != "") {
+ if (!errorMessage.equals("")) {
info += CoreConstants.NEWLINE + CoreConstants.NEWLINE + "Volumes " + failedVolumes
+ " failed to start! [" + errorMessage + "]";
}
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 aa2a0c7c..31f8d164 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
@@ -123,7 +123,7 @@ public class StopVolumeAction extends AbstractMonitoredActionDelegate {
+ "Error: [" + errorMessage + "]");
} else {
String info = "Volumes " + stoppedVolumes + " stopped successfully!";
- if (errorMessage != "") {
+ if (!errorMessage.equals("")) {
info += CoreConstants.NEWLINE + CoreConstants.NEWLINE + "Volumes " + failedVolumes
+ " failed to stop! [" + errorMessage + "]";
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java
new file mode 100644
index 00000000..4c538be4
--- /dev/null
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java
@@ -0,0 +1,64 @@
+package com.gluster.storage.management.console.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 org.eclipse.ui.IWorkbenchPart;
+
+import com.gluster.storage.management.client.VolumesClient;
+import com.gluster.storage.management.console.utils.GUIHelper;
+import com.gluster.storage.management.console.views.VolumeBricksView;
+import com.gluster.storage.management.core.model.Brick;
+import com.gluster.storage.management.core.model.Volume;
+import com.gluster.storage.management.core.utils.GlusterCoreUtil;
+
+
+public class VolumeLogRotateAction extends AbstractActionDelegate {
+
+ private Volume volume;
+ private GUIHelper guiHelper = GUIHelper.getInstance();
+ private Set<Brick> bricks;
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ protected void performAction(IAction action) {
+ final String actionDesc = action.getDescription();
+ List<String> selectedBricks = new ArrayList<String>();
+ boolean confirmed = showConfirmDialog(actionDesc,
+ "Are you sure you want to Rotate logs for volume [" + volume.getName() + "] ? ");
+ if (!confirmed) {
+ return;
+ }
+
+ if (bricks != null) {
+ selectedBricks = GlusterCoreUtil.getQualifiedBrickList(bricks);
+ }
+ try {
+ new VolumesClient().volumeLogRotate(volume.getName(), selectedBricks);
+ showInfoDialog(actionDesc, "Volume logs for [" + volume.getName() + "] rotated successfully!");
+ } catch (Exception e) {
+ showErrorDialog(actionDesc, "Volume [" + volume.getName() + "] log rotation failed! Error: [" + e.getMessage() + "]");
+ }
+ }
+
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ super.selectionChanged(action, selection);
+ 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 bricks view
+ IWorkbenchPart view = guiHelper.getActiveView();
+ if (view instanceof VolumeBricksView) {
+ // volume bricks view is open. check if any brick is selected
+ bricks = GUIHelper.getInstance().getSelectedEntities(getWindow(), Brick.class);
+ }
+ }
+ }
+
+}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/BricksSelectionPage.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/BricksSelectionPage.java
index 06da5f55..1e4de2ef 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/BricksSelectionPage.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/BricksSelectionPage.java
@@ -308,7 +308,7 @@ public class BricksSelectionPage extends Composite {
}
public List<Device> getChosenDevices() {
- Object[] devicesArr = (Object[]) chosenBricksContentProvider.getElements(dualTableViewer);
+ Object[] devicesArr = chosenBricksContentProvider.getElements(dualTableViewer);
if (devicesArr != null) {
List<Device> devices = new ArrayList<Device>();
for (Object device : devicesArr) {
@@ -320,7 +320,7 @@ public class BricksSelectionPage extends Composite {
}
public Set<Brick> getChosenBricks(String volumeName) {
- Object[] bricksArr = (Object[]) chosenBricksContentProvider.getElements(dualTableViewer);
+ Object[] bricksArr = chosenBricksContentProvider.getElements(dualTableViewer);
if (bricksArr != null) {
Set<Brick> bricks = new HashSet<Brick>();
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java
index 4bbcb36b..4622dc84 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/LoginDialog.java
@@ -51,7 +51,7 @@ import com.gluster.storage.management.client.UsersClient;
import com.gluster.storage.management.console.Activator;
import com.gluster.storage.management.console.GlusterDataModelManager;
import com.gluster.storage.management.console.IImageKeys;
-import com.gluster.storage.management.console.dialogs.ClusterSelectionDialog.CLUSTER_MODE;
+import static com.gluster.storage.management.console.dialogs.ClusterSelectionDialog.CLUSTER_MODE;
import com.gluster.storage.management.console.preferences.PreferenceConstants;
import com.gluster.storage.management.console.utils.GUIHelper;
import com.gluster.storage.management.console.validators.StringRequiredValidator;
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickPage1.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickPage1.java
index 0dc06f6d..dfa0b352 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickPage1.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickPage1.java
@@ -152,10 +152,10 @@ public class MigrateBrickPage1 extends WizardPage {
}
private void setPageDescription(String source, String target) {
- if (source == null || source == "") {
+ if (source == null || source.equals("")) {
source = "From Brick";
}
- if (target == null || target == "") {
+ if (target == null || target.equals("")) {
target = "To Brick";
}
setDescription("Migrate volume data from \"" + source + "\" to \"" + target + "\"");
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickWizard.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickWizard.java
index 21c66b35..589b065f 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickWizard.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/MigrateBrickWizard.java
@@ -78,7 +78,7 @@ public class MigrateBrickWizard extends Wizard {
// To get the object
TasksClient taskClient = new TasksClient();
TaskInfo taskInfo = taskClient.getTaskInfo(uri);
- if (taskInfo != null && taskInfo instanceof TaskInfo) {
+ if (taskInfo != null) {
// cluster.addTaskInfo(taskInfo);
String volumeName = taskInfo.getReference().split("#")[0];
modelManager.addTask(taskInfo);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/SelectDisksDialog.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/SelectDisksDialog.java
index 5a5f6046..42c5e782 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/SelectDisksDialog.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/SelectDisksDialog.java
@@ -93,11 +93,7 @@ public class SelectDisksDialog extends Dialog {
return new Point(1024, 600);
}
- @Override
- protected void cancelPressed() {
- super.cancelPressed();
- }
-
+
@Override
protected void okPressed() {
if (this.getSelectedDevices().size() == 0) {
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/preferences/GlusterPreferencePage.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/preferences/GlusterPreferencePage.java
index 577cf733..2fc8de0e 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/preferences/GlusterPreferencePage.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/preferences/GlusterPreferencePage.java
@@ -70,7 +70,7 @@ public class GlusterPreferencePage
String[][] clusterNamesArr = new String[clusterNames.size()][2];
for(int i = 0; i < clusterNames.size(); i++) {
- String clusterName = clusterNames.get(i);;
+ String clusterName = clusterNames.get(i);
clusterNamesArr[i][0] = clusterName;
clusterNamesArr[i][1] = clusterName;
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DiscoveredServerView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DiscoveredServerView.java
index 96a2ca2a..abc9ec2f 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DiscoveredServerView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DiscoveredServerView.java
@@ -50,7 +50,7 @@ public class DiscoveredServerView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (server == null) {
- server = (Server) guiHelper.getSelectedEntity(getSite(), Server.class);
+ server = guiHelper.getSelectedEntity(getSite(), Server.class);
}
createSections(parent);
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DisksView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DisksView.java
index b0cf33b2..7ba1a88a 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DisksView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/DisksView.java
@@ -23,7 +23,7 @@ public class DisksView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (servers == null) {
- servers = (EntityGroup<GlusterServer>)guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
+ servers = guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
}
page = new DisksPage(parent, SWT.NONE, getSite(), getAllDisks(servers));
@@ -32,7 +32,7 @@ public class DisksView extends ViewPart {
private List<Disk> getAllDisks(EntityGroup<GlusterServer> servers) {
List<Disk> disks = new ArrayList<Disk>();
- for(GlusterServer server : (List<GlusterServer>)servers.getEntities()) {
+ for(GlusterServer server : servers.getEntities()) {
disks.addAll(server.getDisks());
}
return disks;
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerDisksView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerDisksView.java
index 951b5a91..d3cd98e8 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerDisksView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerDisksView.java
@@ -46,7 +46,7 @@ public class GlusterServerDisksView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (server == null) {
- server = (GlusterServer) guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
+ server = guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
}
page = new ServerDisksPage(parent, SWT.NONE, getSite(), server.getDisks());
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerLogsView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerLogsView.java
index 660da5a3..33c85be2 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerLogsView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerLogsView.java
@@ -40,7 +40,7 @@ public class GlusterServerLogsView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (server == null) {
- server = (GlusterServer) guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
+ server = guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
}
page = new ServerLogsPage(parent, SWT.NONE, server);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerSummaryView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerSummaryView.java
index 03c38df7..08344f84 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerSummaryView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServerSummaryView.java
@@ -111,7 +111,7 @@ public class GlusterServerSummaryView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (server == null) {
- server = (GlusterServer) guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
+ server = guiHelper.getSelectedEntity(getSite(), GlusterServer.class);
}
setPartName("Summary");
createSections(parent);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersSummaryView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersSummaryView.java
index b3879e4f..ad2f6331 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersSummaryView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersSummaryView.java
@@ -70,7 +70,7 @@ public class GlusterServersSummaryView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (servers == null) {
- servers = (EntityGroup<GlusterServer>)guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
+ servers = guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
}
setPartName("Summary");
createSections(parent);
@@ -170,7 +170,7 @@ public class GlusterServersSummaryView extends ViewPart {
private int getServerCountByStatus(EntityGroup<GlusterServer> servers, SERVER_STATUS status) {
int count = 0;
- for (GlusterServer server : (List<GlusterServer>)servers.getEntities()) {
+ for (GlusterServer server : servers.getEntities()) {
if (server.getStatus() == status) {
count++;
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersView.java
index 566befc3..66017990 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/GlusterServersView.java
@@ -50,7 +50,7 @@ public class GlusterServersView extends ViewPart implements IDoubleClickListener
@Override
public void createPartControl(Composite parent) {
if (servers == null) {
- servers = (EntityGroup<GlusterServer>) guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
+ servers = guiHelper.getSelectedEntity(getSite(), EntityGroup.class);
}
page = new GlusterServersPage(getSite(), parent, SWT.NONE, servers);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/NavigationView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/NavigationView.java
index bb942586..21fc4c7a 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/NavigationView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/NavigationView.java
@@ -89,6 +89,7 @@ public class NavigationView extends ViewPart implements ISelectionListener {
@Override
public void volumeChanged(Volume volume, Event event) {
super.volumeChanged(volume, event);
+ treeViewer.update(volume, null);
if (volume == entity) {
// this makes sure that the toolbar buttons get updated according to new status
selectEntity(volume);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeBricksView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeBricksView.java
index 0c494945..33cd1f38 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeBricksView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeBricksView.java
@@ -17,7 +17,7 @@ public class VolumeBricksView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (volume == null) {
- volume = (Volume) guiHelper.getSelectedEntity(getSite(), Volume.class);
+ volume = guiHelper.getSelectedEntity(getSite(), Volume.class);
}
createPage(parent);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeLogsView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeLogsView.java
index e6a5370f..7f35d332 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeLogsView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeLogsView.java
@@ -17,7 +17,7 @@ public class VolumeLogsView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (volume == null) {
- volume = (Volume) guiHelper.getSelectedEntity(getSite(), Volume.class);
+ volume = guiHelper.getSelectedEntity(getSite(), Volume.class);
}
createPage(parent);
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeOptionsView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeOptionsView.java
index 7be16f48..7129df5d 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeOptionsView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeOptionsView.java
@@ -17,7 +17,7 @@ public class VolumeOptionsView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (volume == null) {
- volume = (Volume) guiHelper.getSelectedEntity(getSite(), Volume.class);
+ volume = guiHelper.getSelectedEntity(getSite(), Volume.class);
}
createPage(parent);
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 e271623d..78c7caf2 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
@@ -93,7 +93,7 @@ public class VolumeSummaryView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (volume == null) {
- volume = (Volume) guiHelper.getSelectedEntity(getSite(), Volume.class);
+ volume = guiHelper.getSelectedEntity(getSite(), Volume.class);
}
this.parent = parent;
@@ -436,7 +436,7 @@ public class VolumeSummaryView extends ViewPart {
}
// If no cifs users and removing cifs config, nothing to do
- if (!(!cifsCheckbox.getSelection() && volume.getCifsUsers().toString() == "[]" && (cifsUsers
+ if (!(!cifsCheckbox.getSelection() && volume.getCifsUsers().toString().equals("[]") && (cifsUsers
.isEmpty() || cifsUsers.equals(""))) && userAction == 1) {
try {
vc.setCifsConfig(volume.getName(), cifsCheckbox.getSelection(), cifsUsers);
@@ -850,11 +850,7 @@ public class VolumeSummaryView extends ViewPart {
private boolean isvalidCifsUser() {
if (cifsCheckbox.getSelection()) {
String cifsUserList = cifsUsersText.getText().trim();
- if (cifsUserList.length() == 0) {
- return false;
- } else {
- return true;
- }
+ return (cifsUserList.length() != 0);
}
validateCifsUsers();
return true;
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeView.java
index 0c9ef92b..ced9335b 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumeView.java
@@ -50,7 +50,7 @@ public class VolumeView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
if (server == null) {
- server = (Server) guiHelper.getSelectedEntity(getSite(), Server.class);
+ server = guiHelper.getSelectedEntity(getSite(), Server.class);
}
createSections(parent, server, toolkit);
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumesSummaryView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumesSummaryView.java
index 79ebd84c..b5604643 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumesSummaryView.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/VolumesSummaryView.java
@@ -20,8 +20,6 @@
*/
package com.gluster.storage.management.console.views;
-import java.util.List;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.GridData;
@@ -243,7 +241,7 @@ public class VolumesSummaryView extends ViewPart {
private int getVolumeCountByStatus(EntityGroup<Volume> volumes, VOLUME_STATUS status) {
int count = 0;
- for (Volume volume : (List<Volume>) volumes.getEntities()) {
+ for (Volume volume : volumes.getEntities()) {
if (volume.getStatus() == status) {
count++;
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/AbstractDisksPage.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/AbstractDisksPage.java
index 43853752..417e67ea 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/AbstractDisksPage.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/AbstractDisksPage.java
@@ -270,7 +270,7 @@ public abstract class AbstractDisksPage extends AbstractTableTreeViewerPage<Disk
TasksClient taskClient = new TasksClient();
TaskInfo taskInfo = taskClient.getTaskInfo(uri);
- if (taskInfo != null && taskInfo instanceof TaskInfo) {
+ if (taskInfo != null) {
modelManager.addTask(taskInfo);
}
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/DiskTreeContentProvider.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/DiskTreeContentProvider.java
index 4081d614..79b54aa1 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/DiskTreeContentProvider.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/pages/DiskTreeContentProvider.java
@@ -111,11 +111,7 @@ public class DiskTreeContentProvider implements ITreeContentProvider {
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
public boolean hasChildren(Object element) {
- if(element instanceof Disk && ((Disk)element).getPartitions().size() > 0) {
- return true;
- } else {
- return false;
- }
+ return (element instanceof Disk && ((Disk)element).getPartitions().size() > 0);
}
diff --git a/src/com.gluster.storage.management.core/META-INF/MANIFEST.MF b/src/com.gluster.storage.management.core/META-INF/MANIFEST.MF
index b4431f53..9ddbca69 100644
--- a/src/com.gluster.storage.management.core/META-INF/MANIFEST.MF
+++ b/src/com.gluster.storage.management.core/META-INF/MANIFEST.MF
@@ -12,3 +12,4 @@ Export-Package: com.gluster.storage.management.core.constants,
com.gluster.storage.management.core.utils
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.6.0"
Bundle-ClassPath: .
+Import-Package: com.gluster.storage.management.core.exceptions
diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java
new file mode 100644
index 00000000..8b2fa2a1
--- /dev/null
+++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java
@@ -0,0 +1,234 @@
+package com.gluster.storage.management.core.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gluster.storage.management.core.constants.CoreConstants;
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
+
+/**
+ * The class <code>DateUtilTest</code> contains tests for the class <code>{@link DateUtil}</code>.
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ * @author root
+ * @version $Revision: 1.0 $
+ */
+public class DateUtilTest {
+ /**
+ * Run the String dateToString(Date) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testDateToString_1()
+ throws Exception {
+ Date date = new Date(1317275258795L);
+ String result = DateUtil.dateToString(date);
+
+ assertEquals("09/29/2011 11:17:38", result);
+ }
+
+ /**
+ * Run the String dateToString(Date,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testDateToString_2()
+ throws Exception {
+ Date date = new Date(1317275258795L);
+ String dateFormat = "";
+
+ String result = DateUtil.dateToString(date, dateFormat);
+ assertEquals("", result);
+ }
+
+ /**
+ * Run the String dateToString(Date,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testDateToString_3()
+ throws Exception {
+ Date date = new Date(1317275258795L);
+ String dateFormat = CoreConstants.PURE_DATE_FORMAT;
+
+ String result = DateUtil.dateToString(date, dateFormat);
+ assertEquals("09/29/2011", result);
+ }
+
+ /**
+ * Run the String formatDate(Date) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testFormatDate_1()
+ throws Exception {
+ String result = DateUtil.formatDate(new Date(1317275258795L));
+
+ assertEquals("09/29/2011", result);
+ }
+
+ /**
+ * Run the String formatDate(Date) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testFormatDate_2()
+ throws Exception {
+ String result = DateUtil.formatDate(new Date(0L));
+ assertEquals("01/01/1970", result);
+ }
+
+ /**
+ * Run the String formatDate(Date) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testFormatDate_3()
+ throws Exception {
+
+ String result = DateUtil.formatDate(new Date(-156784523000L));
+ assertEquals("01/12/1965", result);
+
+ }
+
+ /**
+ * Run the String formatTime(Date) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testFormatTime_1()
+ throws Exception {
+ Date inputDate = new Date(1317275258795L);
+
+ String result = DateUtil.formatTime(inputDate);
+
+ // add additional test code here
+ assertEquals("11:17:38.795", result);
+ }
+
+ /**
+ * Run the Date stringToDate(String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test(expected=GlusterRuntimeException.class)
+ public void testStringToDate_1()
+ throws Exception {
+ DateUtil.stringToDate("");
+ }
+
+ /**
+ * Run the Date stringToDate(String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test(expected=GlusterRuntimeException.class)
+ public void testStringToDate_2()
+ throws Exception {
+ String testDate = "09/29/2011";
+ DateUtil.stringToDate(testDate);
+ }
+
+ /**
+ * Run the Date stringToDate(String,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test
+ public void testStringToDate_3()
+ throws Exception {
+ String dateFormat = "MM/dd/yyyy";
+ String input = "09/29/2011"; // MM/dd/yyyy HH:mm:ss
+ Date expectedDate = new Date(1317234600000L);
+
+ Date result = DateUtil.stringToDate(input, dateFormat);
+ assertEquals(expectedDate, result);
+ }
+
+ /**
+ * Run the Date stringToDate(String,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Test(expected = GlusterRuntimeException.class)
+ public void testStringToDate_4()
+ throws Exception {
+ String inputDate = "";
+ String dateFormat = "";
+
+ DateUtil.stringToDate(inputDate, dateFormat);
+ }
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws Exception
+ * if the initialization fails for some reason
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @Before
+ public void setUp()
+ throws Exception {
+ // add additional set up code here
+ }
+
+ /**
+ * Perform post-test clean-up.
+ *
+ * @throws Exception
+ * if the clean-up fails for some reason
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ @After
+ public void tearDown()
+ throws Exception {
+ // Add additional tear down code here
+ }
+
+ /**
+ * Launch the test.
+ *
+ * @param args the command line arguments
+ *
+ * @generatedBy CodePro at 9/27/11 12:31 PM
+ */
+ public static void main(String[] args) {
+ new org.junit.runner.JUnitCore().run(DateUtilTest.class);
+ }
+} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java
new file mode 100644
index 00000000..9302619e
--- /dev/null
+++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java
@@ -0,0 +1,481 @@
+package com.gluster.storage.management.core.utils;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
+
+
+/**
+ * The class <code>FileUtilTest</code> contains tests for the class <code>{@link FileUtil}</code>.
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ * @author root
+ * @version $Revision: 1.0 $
+ */
+public class FileUtilTest {
+
+
+ private static final String TEST_FILE_PATH = FileUtil.getTempDirName() + "/test.txt";
+ private static final String TEST_FILE_CONTENT = "Welcome to Gluster Storage Management console.";
+
+
+ /**
+ * To write the text into given file.
+ *
+ * @generatedBy
+ */
+ private boolean writeToFile(String fileName, String text) {
+ try {
+ Writer output = null;
+ File file = new File(fileName);
+ output = new BufferedWriter(new FileWriter(file));
+ output.write(text);
+ output.close();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private boolean createNestedDir(String path) {
+ File file = new File(path);
+ return file.mkdirs();
+ }
+
+ private boolean createEmptyFile(String fileName) {
+ File file = new File(fileName);
+ if (file.exists()) {
+ return true;
+ }
+
+ try {
+ return file.createNewFile();
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Run the File createTempDir() method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testCreateTempDir_1()
+ throws Exception {
+
+ File result = FileUtil.createTempDir();
+
+ assertNotNull(result);
+ assertTrue(File.class.equals(result.getClass()));
+ }
+
+ /**
+ * Run the File createTempDir() method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testCreateTempDir_2()
+ throws Exception {
+
+ File result1 = FileUtil.createTempDir();
+ File result2 = FileUtil.createTempDir();
+
+ assertNotSame(result1, result2);
+ }
+
+
+ /**
+ * Run the void createTextFile(String,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test(expected=GlusterRuntimeException.class)
+ public void testCreateTextFile_1()
+ throws Exception {
+ String fileName = "";
+ String contents = "";
+ FileUtil.createTextFile(fileName, contents);
+ }
+
+ /**
+ * Run the String getTempDirName() method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testGetTempDirName_1()
+ throws Exception {
+ String result = FileUtil.getTempDirName();
+
+ // while running on linux
+ assertEquals("/tmp", result);
+ }
+
+ /**
+ * Run the byte[] readFileAsByteArray(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+
+ @Test(expected=GlusterRuntimeException.class)
+ public void testReadFileAsByteArray_1()
+ throws Exception {
+ File file = new File("");
+
+ byte[] result = FileUtil.readFileAsByteArray(file);
+ }
+
+ /**
+ * Run the byte[] readFileAsByteArray(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testReadFileAsByteArray_2()
+ throws Exception {
+ File file = new File(TEST_FILE_PATH);
+
+ byte[] result = FileUtil.readFileAsByteArray(file);
+ assertNotNull(result);
+ assertTrue(result instanceof byte[]);
+ assertTrue(TEST_FILE_CONTENT.equals(new String(result)));
+ }
+
+
+ /**
+ * Run the String readFileAsString(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+
+ @Test(expected=GlusterRuntimeException.class)
+ public void testReadFileAsString_1()
+ throws Exception {
+ File file = new File("");
+
+ FileUtil.readFileAsString(file);
+ }
+
+
+ /**
+ * Run the String readFileAsString(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testReadFileAsString_2()
+ throws Exception {
+ File file = new File(TEST_FILE_PATH);
+ String result = FileUtil.readFileAsString(file);
+
+ assertNotNull(result);
+ assertTrue(result instanceof String);
+ assertTrue(result.equals(TEST_FILE_CONTENT));
+ }
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testRecursiveDelete_1()
+ throws Exception {
+
+ //Delete empty directories recursively
+ File fileOrDir = new File(FileUtil.getTempDirName() + "/rd");
+
+ FileUtil.recursiveDelete(fileOrDir);
+ assertTrue(!fileOrDir.exists());
+ }
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+
+ @Test(expected=GlusterRuntimeException.class)
+ public void testRecursiveDelete_2()
+ throws Exception {
+ //Delete directories recursively (with some files)
+ File fileOrDir = new File(FileUtil.getTempDirName() + "/rdx");
+
+ FileUtil.recursiveDelete(fileOrDir);
+ assertTrue(!fileOrDir.exists());
+ }
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testRecursiveDelete_3()
+ throws Exception {
+ File fileOrDir = new File(FileUtil.getTempDirName() + "/rd");
+ FileUtil.recursiveDelete(fileOrDir);
+ assertTrue(!fileOrDir.exists());
+ }
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testRecursiveDelete_4()
+ throws Exception {
+ File file = new File(FileUtil.getTempDirName() + "/rd/b/bc/mydoc.txt");
+ assertTrue(!file.exists());
+
+ file = new File(FileUtil.getTempDirName() + "/rd//b/bc");
+ assertTrue(!file.exists());
+ }
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test(expected=GlusterRuntimeException.class)
+ public void testRecursiveDelete_5()
+ throws Exception {
+ File fileOrDir = new File(FileUtil.getTempDirName() + "/rd/*"); //Wild cards
+ FileUtil.recursiveDelete(fileOrDir);
+ }
+
+
+ /**
+ * Run the void recursiveDelete(File) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test(expected=GlusterRuntimeException.class)
+ public void testRecursiveDelete_6()
+ throws Exception {
+ File fileOrDir = new File(FileUtil.getTempDirName() + "/abcxyz");
+ FileUtil.recursiveDelete(fileOrDir);
+ }
+
+ /**
+ * Run the void renameFile(String,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+
+ @Test(expected=GlusterRuntimeException.class)
+ public void testRenameFile_1()
+ throws Exception {
+ String fromPath = FileUtil.getTempDirName() + "/test.txt";
+ new File(fromPath).createNewFile();
+ String toPath = "~/abc.txt"; // Relative path
+
+ FileUtil.renameFile(fromPath, toPath);
+ assertTrue(!new File(fromPath).exists());
+ assertTrue(new File(toPath).exists());
+ }
+
+ /**
+ * Run the void renameFile(String,String) method test.
+ *
+ * @throws Exception
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Test
+ public void testRenameFile_2()
+ throws Exception {
+ String fromPath = FileUtil.getTempDirName() + "/test.txt";
+ new File(fromPath).createNewFile();
+
+ String toPath = FileUtil.getTempDirName() + "/abc.txt"; // Absolute path example
+ FileUtil.renameFile(fromPath, toPath);
+ assertTrue(!new File(fromPath).exists());
+ assertTrue(new File(toPath).exists());
+ }
+
+ @Test
+ public void testRenameFile_3()
+ throws Exception {
+ String fromPath = FileUtil.getTempDirName() + "/test.txt";
+ new File(fromPath).createNewFile();
+
+ String toPath = FileUtil.getTempDirName() + "/renamefile.txt";
+ FileUtil.renameFile(fromPath, toPath);
+ assertTrue(!new File(fromPath).exists());
+ assertTrue(new File(toPath).exists());
+ }
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws Exception
+ * if the initialization fails for some reason
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @Before
+ public void setUp()
+ throws Exception {
+
+ // testReadFileAsByteArray_2()
+ if (!writeToFile(TEST_FILE_PATH, TEST_FILE_CONTENT)) {
+ fail("Setup: Text file creation error!");
+ }
+
+ // testRecursiveDelete_1()
+ if (!createNestedDir(FileUtil.getTempDirName() + "/rd/b/c/d")) {
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/mydoc.txt");
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/songs.mp3");
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/mysetup.cfg");
+
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/bc/mydoc.txt");
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/songs.mp3");
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/bc/mysetup.cfg");
+
+ createEmptyFile(FileUtil.getTempDirName() + "/rd//b/mydoc.txt");
+ createEmptyFile(FileUtil.getTempDirName() + "/rd/b/bc/songs.mp3");
+
+ }
+
+ if (! createEmptyFile(FileUtil.getTempDirName() + "/renamefile.txt") ) {
+ fail("Failed to create file [/renamefile.txt]");
+ }
+ }
+
+ /**
+ * Perform post-test clean-up.
+ *
+ * @throws Exception
+ * if the clean-up fails for some reason
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ @After
+ public void tearDown()
+ throws Exception {
+ File file = new File(TEST_FILE_PATH);
+ file.delete();
+ file = new File(FileUtil.getTempDirName() + "/rd/b/c/d");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd/b/c");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd/b/mydoc.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/rd/b/songs.mp3");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/rd/b/mysetup.cfg");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd/b/bc/mydoc.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/rd/b/bc/mysetup.cfg");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/rd/b/bc/songs.mp3");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd/b/bc");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd/b");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/rd");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ file = new File(FileUtil.getTempDirName() + "/abc.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File("~/abc.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/test.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ file = new File(FileUtil.getTempDirName() + "/renamefile.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+
+ /**
+ * Launch the test.
+ *
+ * @param args the command line arguments
+ *
+ * @generatedBy CodePro at 9/29/11 2:39 PM
+ */
+ public static void main(String[] args) {
+ new org.junit.runner.JUnitCore().run(FileUtilTest.class);
+ }
+} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java
deleted file mode 100644
index f562a53c..00000000
--- a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * TestFileUtil.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.core.utils;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestFileUtil {
- private String testFileName;
- private String fileContent;
- private FileUtil fileUtil;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- testFileName = "testFileUtil.txt";
- fileContent = "Testing FileUtil class.";
- fileUtil = new FileUtil();
-
- BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(testFileName));
- OutputStreamWriter writer = new OutputStreamWriter(outStream);
- writer.write(fileContent);
- writer.close();
- outStream.close();
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- File testFile = new File(testFileName);
- testFile.delete();
- }
-
- /**
- * Test method for {@link com.gluster.storage.management.core.utils.FileUtil#readFileAsString(java.io.File)}.
- */
- @Test
- public final void testReadFileAsString() {
- String readContent = fileUtil.readFileAsString(new File(testFileName));
- assertTrue("File contents expected [" + fileContent + "], actual [" + readContent + "]",
- readContent.equals(fileContent));
- }
-}
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 3e42b1c0..22d7e3dc 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
@@ -52,6 +52,7 @@ 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_LOG_ROTATE = "logRotate";
public static final String TASK_REBALANCE_START = "rebalanceStart";
public static final String TASK_REBALANCE_STATUS = "rebalanceStatus";
public static final String TASK_REBALANCE_STOP = "rebalanceStop";
@@ -68,6 +69,7 @@ public class RESTConstants {
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_LOG_ROTATE = "logRotate";
public static final String FORM_PARAM_CLUSTER_NAME = "clusterName";
public static final String FORM_PARAM_SERVER_NAME = "serverName";
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java
index c1205c0e..579cc9da 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java
@@ -34,6 +34,10 @@ public class TaskStatus extends Status {
super(status.getCode(), status.getMessage());
}
+ public boolean isCommitPending() {
+ return getCode() == STATUS_CODE_COMMIT_PENDING;
+ }
+
public boolean isPercentageSupported() {
return isPercentageSupported;
}
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Version.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Version.java
new file mode 100644
index 00000000..887506a9
--- /dev/null
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Version.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.core.model;
+
+/**
+ *
+ */
+public class Version implements Comparable<Version> {
+ public int major = 0;
+ public int minor = 0;
+ public int maintenance = 0;
+
+ public Version(String version) {
+ String[] versionParts = version.split(".", -1);
+ major = Integer.valueOf(versionParts[0]);
+ if(versionParts.length > 1) {
+ minor = Integer.valueOf(versionParts[1]);
+ }
+ if(versionParts.length > 2) {
+ maintenance = Integer.valueOf(versionParts[2]);
+ }
+ }
+
+ @Override
+ public int compareTo(Version newVer) {
+ if(this.major < newVer.major) {
+ return -1;
+ } else if(this.major > newVer.major) {
+ return 1;
+ }
+
+ // major version is same
+ if(this.minor < newVer.minor) {
+ return -1;
+ } else if(this.minor > newVer.minor) {
+ return 1;
+ }
+
+ // major.minor is same
+ if(this.maintenance < newVer.maintenance) {
+ return -1;
+ } else if(this.maintenance > newVer.maintenance) {
+ return 1;
+ }
+
+ // major.minor.maintenance is same
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java
index 7d9ec340..26c244dd 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java
@@ -100,4 +100,21 @@ public class StringUtil {
}
return output;
}
+
+ /**
+ * Extract value of given token from given line. It is assumed that the token, if present, will be of the following
+ * form: <code>token: value</code>
+ *
+ * @param line
+ * Line to be analyzed
+ * @param token
+ * Token whose value is to be extracted
+ * @return Value of the token, if present in the line
+ */
+ public static String extractToken(String line, String token) {
+ if (line.contains(token)) {
+ return line.split(token)[1].trim();
+ }
+ return null;
+ }
}
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 b892df32..4303aa63 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
@@ -59,6 +59,7 @@ import static com.gluster.storage.management.core.constants.RESTConstants.RESOUR
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_VOLUMES;
import java.io.File;
+import java.util.Arrays;
import java.util.List;
import javax.ws.rs.DELETE;
@@ -193,7 +194,8 @@ public class VolumesResource extends AbstractResource {
@FormParam(FORM_PARAM_FIX_LAYOUT) Boolean isFixLayout,
@FormParam(FORM_PARAM_MIGRATE_DATA) Boolean isMigrateData,
@FormParam(FORM_PARAM_FORCED_DATA_MIGRATE) Boolean isForcedDataMigrate,
- @FormParam(FORM_PARAM_CIFS_ENABLE) Boolean enableCifs, @FormParam(FORM_PARAM_CIFS_USERS) String cifsUsers) {
+ @FormParam(FORM_PARAM_CIFS_ENABLE) Boolean enableCifs, @FormParam(FORM_PARAM_CIFS_USERS) String cifsUsers,
+ @FormParam(FORM_PARAM_BRICKS) String bricks) {
if (clusterName == null || clusterName.isEmpty()) {
throw new GlusterValidationException("Cluster name must not be empty!");
}
@@ -228,6 +230,9 @@ public class VolumesResource extends AbstractResource {
}
volumeService.deleteCifsUsers(clusterName, volumeName);
}
+ } else if (operation.equals(RESTConstants.TASK_LOG_ROTATE)) {
+ List<String> brickList = Arrays.asList(bricks.split(","));
+ volumeService.logRotate(clusterName, volumeName, brickList);
} else {
volumeService.performVolumeOperation(clusterName, volumeName, operation);
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/AbstractGlusterInterface.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/AbstractGlusterInterface.java
new file mode 100644
index 00000000..93db0267
--- /dev/null
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/AbstractGlusterInterface.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.gateway.services;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.gluster.storage.management.gateway.utils.ServerUtil;
+
+/**
+ * Abstract Gluster Interface - provides functionality common across all versions of GlusterFS e.g. version check.
+ */
+public abstract class AbstractGlusterInterface implements GlusterInterface {
+
+ @Autowired
+ protected ServerUtil serverUtil;
+
+ @Override
+ public String getVersion(String serverName) {
+ return serverUtil.executeOnServer(serverName, "gluster --version").split("\n")[0].replaceAll("glusterfs ", "")
+ .replaceAll(" built.*", "");
+ }
+}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/ClusterService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/ClusterService.java
index 852d7365..4bc68c5e 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/ClusterService.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/ClusterService.java
@@ -35,7 +35,6 @@ import com.gluster.storage.management.core.utils.LRUCache;
import com.gluster.storage.management.gateway.data.ClusterInfo;
import com.gluster.storage.management.gateway.data.PersistenceDao;
import com.gluster.storage.management.gateway.data.ServerInfo;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
import com.gluster.storage.management.gateway.utils.ServerUtil;
import com.gluster.storage.management.gateway.utils.SshUtil;
@@ -51,7 +50,7 @@ public class ClusterService {
private PersistenceDao<ServerInfo> serverDao;
@Autowired
- private GlusterUtil glusterUtil;
+ private GlusterServerService glusterServerService;
@Autowired
private SshUtil sshUtil;
@@ -59,9 +58,6 @@ public class ClusterService {
@Autowired
private ServerUtil serverUtil;
- @Autowired
- private GlusterServerService glusterServerService;
-
private LRUCache<String, GlusterServer> onlineServerCache = new LRUCache<String, GlusterServer>(3);
private static final Logger logger = Logger.getLogger(ClusterService.class);
@@ -162,7 +158,7 @@ public class ClusterService {
GlusterServer server = new GlusterServer(knownServer);
try {
- List<GlusterServer> glusterServers = glusterUtil.getGlusterServers(server);
+ List<GlusterServer> glusterServers = glusterServerService.getGlusterServers(server.getName());
List<ServerInfo> servers = new ArrayList<ServerInfo>();
for(GlusterServer glusterServer : glusterServers) {
String serverName = glusterServer.getName();
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/services/Gluster323InterfaceService.java
index 3bcd5826..fba64352 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/services/Gluster323InterfaceService.java
@@ -1,6 +1,4 @@
-/**
- * GlusterUtil.java
- *
+/*******************************************************************************
* Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
* This file is part of Gluster Management Console.
*
@@ -8,17 +6,17 @@
* 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.gateway.utils;
+ *******************************************************************************/
+package com.gluster.storage.management.gateway.services;
import java.util.ArrayList;
import java.util.List;
@@ -26,7 +24,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.gluster.storage.management.core.constants.CoreConstants;
@@ -34,10 +32,6 @@ import com.gluster.storage.management.core.constants.GlusterConstants;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.model.Brick;
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.InitDiskStatusResponse;
-import com.gluster.storage.management.core.model.InitDiskStatusResponse.FORMAT_STATUS;
-import com.gluster.storage.management.core.model.Server.SERVER_STATUS;
import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.TaskStatus;
import com.gluster.storage.management.core.model.Volume;
@@ -47,12 +41,12 @@ import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE;
import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse;
import com.gluster.storage.management.core.utils.StringUtil;
+/**
+ * Gluster Interface for GlusterFS version 3.2.3
+ */
@Component
-public class GlusterUtil {
- private static final String HOSTNAME_PFX = "Hostname:";
- private static final String UUID_PFX = "Uuid:";
- private static final String STATE_PFX = "State:";
- private static final String GLUSTER_SERVER_STATUS_ONLINE = "Peer in Cluster (Connected)";
+@Lazy(value=true)
+public class Gluster323InterfaceService extends AbstractGlusterInterface {
private static final String VOLUME_NAME_PFX = "Volume Name:";
private static final String VOLUME_TYPE_PFX = "Type:";
@@ -68,126 +62,51 @@ public class GlusterUtil {
private static final String VOLUME_TYPE_STRIPE = "Stripe";
private static final String VOLUME_TYPE_DISTRIBUTED_STRIPE = "Distributed-Stripe";
- private static final String GLUSTERD_INFO_FILE = "/etc/glusterd/glusterd.info";
-
- private static final String INITIALIZE_DISK_STATUS_SCRIPT = "get_format_device_status.py";
private static final String BRICK_STATUS_SCRIPT = "get_brick_status.py";
+ private static final Logger logger = Logger.getLogger(Gluster323InterfaceService.class);
- private static final Logger logger = Logger.getLogger(GlusterUtil.class);
-
- @Autowired
- private ServerUtil serverUtil;
-
- /**
- * Extract value of given token from given line. It is assumed that the token, if present, will be of the following
- * form: <code>token: value</code>
- *
- * @param line
- * Line to be analyzed
- * @param token
- * Token whose value is to be extracted
- * @return Value of the token, if present in the line
- */
- private final String extractToken(String line, String token) {
- if (line.contains(token)) {
- return line.split(token)[1].trim();
- }
- return null;
- }
-
- public GlusterServer getGlusterServer(GlusterServer onlineServer, String serverName) {
- List<GlusterServer> servers = getGlusterServers(onlineServer);
- for (GlusterServer server : servers) {
- if (server.getName().equalsIgnoreCase(serverName)) {
- return server;
- }
- }
- return null;
- }
-
- private String getUuid(String serverName) {
- return serverUtil.executeOnServer(serverName, "cat " + GLUSTERD_INFO_FILE, String.class).split("=")[1];
- }
-
- public List<GlusterServer> getGlusterServers(GlusterServer knownServer) {
- String output = getPeerStatus(knownServer.getName());
-
- knownServer.setUuid(getUuid(knownServer.getName()));
-
- List<GlusterServer> glusterServers = new ArrayList<GlusterServer>();
- glusterServers.add(knownServer);
-
- GlusterServer server = null;
- boolean foundHost = false;
- boolean foundUuid = false;
- for (String line : output.split(CoreConstants.NEWLINE)) {
- if (foundHost && foundUuid) {
- // Host and UUID is found, we should look for state
- String state = extractToken(line, STATE_PFX);
- if (state != null) {
- server.setStatus(state.contains(GLUSTER_SERVER_STATUS_ONLINE) ? SERVER_STATUS.ONLINE
- : SERVER_STATUS.OFFLINE);
- // Completed populating current server. Add it to the list
- // and reset all related variables.
- glusterServers.add(server);
-
- foundHost = false;
- foundUuid = false;
- server = null;
- }
- } else if (foundHost) {
- // Host is found, look for UUID
- String uuid = extractToken(line, UUID_PFX);
- if (uuid != null) {
- server.setUuid(uuid);
- foundUuid = true;
- }
- } else {
- // Look for the next host
- if (server == null) {
- server = new GlusterServer();
- }
- String hostName = extractToken(line, HOSTNAME_PFX);
- if (hostName != null) {
- server.setName(hostName);
- foundHost = true;
- }
- }
-
- }
- return glusterServers;
- }
-
- /**
- * @param knownServer
- * A known server on which the gluster command will be executed to fetch peer status
- * @return Outout of the "gluster peer status" command
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#addServer(java.lang.String, java.lang.String)
*/
- private String getPeerStatus(String knownServer) {
- return serverUtil.executeOnServer(knownServer, "gluster peer status", String.class);
- }
-
+ @Override
public void addServer(String existingServer, String newServer) {
serverUtil.executeOnServer(existingServer, "gluster peer probe " + newServer);
// reverse peer probe to ensure that host names appear in peer status on both sides
serverUtil.executeOnServer(newServer, "gluster peer probe " + existingServer);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#startVolume(java.lang.String, java.lang.String)
+ */
+ @Override
public void startVolume(String volumeName, String knownServer) {
serverUtil.executeOnServer(knownServer, "gluster volume start " + volumeName);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#stopVolume(java.lang.String, java.lang.String)
+ */
+ @Override
public void stopVolume(String volumeName, String knownServer) {
serverUtil.executeOnServer(knownServer, "gluster --mode=script volume stop " + volumeName);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#resetOptions(java.lang.String, java.lang.String)
+ */
+ @Override
public void resetOptions(String volumeName, String knownServer) {
serverUtil.executeOnServer(knownServer, "gluster volume reset " + volumeName);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#createVolume(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
public void createVolume(String knownServer, String volumeName, String volumeTypeStr, String transportTypeStr,
Integer count, String bricks, String accessProtocols, String options) {
+ // TODO: Disable NFS if required depending on value of accessProtocols
VOLUME_TYPE volType = Volume.getVolumeTypeByStr(volumeTypeStr);
String volTypeArg = null;
if (volType == VOLUME_TYPE.REPLICATE || volType == VOLUME_TYPE.DISTRIBUTED_REPLICATE) {
@@ -227,6 +146,10 @@ public class GlusterUtil {
return command.toString();
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#createOptions(java.lang.String, java.util.Map, java.lang.String)
+ */
+ @Override
public void createOptions(String volumeName, Map<String, String> options, String knownServer) {
String errors = "";
if (options != null) {
@@ -248,11 +171,19 @@ public class GlusterUtil {
}
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#setOption(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
public void setOption(String volumeName, String key, String value, String knownServer) {
serverUtil.executeOnServer(knownServer, "gluster volume set " + volumeName + " " + key + " " + "\""
+ value + "\"");
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#deleteVolume(java.lang.String, java.lang.String)
+ */
+ @Override
public void deleteVolume(String volumeName, String knownServer) {
serverUtil.executeOnServer(knownServer, "gluster --mode=script volume delete " + volumeName);
}
@@ -266,7 +197,7 @@ public class GlusterUtil {
}
private boolean readVolumeType(Volume volume, String line) {
- String volumeType = extractToken(line, VOLUME_TYPE_PFX);
+ String volumeType = StringUtil.extractToken(line, VOLUME_TYPE_PFX);
if (volumeType != null) {
if (volumeType.equals(VOLUME_TYPE_DISTRIBUTE)) {
volume.setVolumeType(VOLUME_TYPE.DISTRIBUTE);
@@ -293,7 +224,7 @@ public class GlusterUtil {
}
private void readReplicaOrStripeCount(Volume volume, String line) {
- if (extractToken(line, "x") != null) {
+ if (StringUtil.extractToken(line, "x") != null) {
// expected formated of line is "Number of Bricks: 3 x 2 = 6"
int count = Integer.parseInt(line.split("x")[1].split("=")[0].trim());
if (volume.getVolumeType() == VOLUME_TYPE.STRIPE
@@ -309,7 +240,7 @@ public class GlusterUtil {
}
private boolean readVolumeStatus(Volume volume, String line) {
- String volumeStatus = extractToken(line, VOLUME_STATUS_PFX);
+ String volumeStatus = StringUtil.extractToken(line, VOLUME_STATUS_PFX);
if (volumeStatus != null) {
volume.setStatus(volumeStatus.equals("Started") ? VOLUME_STATUS.ONLINE : VOLUME_STATUS.OFFLINE);
return true;
@@ -318,7 +249,7 @@ public class GlusterUtil {
}
private boolean readTransportType(Volume volume, String line) {
- String transportType = extractToken(line, VOLUME_TRANSPORT_TYPE_PFX);
+ String transportType = StringUtil.extractToken(line, VOLUME_TRANSPORT_TYPE_PFX);
if (transportType != null) {
volume.setTransportType(transportType.equals("tcp") ? TRANSPORT_TYPE.ETHERNET : TRANSPORT_TYPE.INFINIBAND);
return true;
@@ -365,11 +296,11 @@ public class GlusterUtil {
}
private boolean readBrickGroup(String line) {
- return extractToken(line, VOLUME_BRICKS_GROUP_PFX) != null;
+ return StringUtil.extractToken(line, VOLUME_BRICKS_GROUP_PFX) != null;
}
private boolean readOptionReconfigGroup(String line) {
- return extractToken(line, VOLUME_OPTIONS_RECONFIG_PFX) != null;
+ return StringUtil.extractToken(line, VOLUME_OPTIONS_RECONFIG_PFX) != null;
}
private boolean readOption(Volume volume, String line) {
@@ -390,10 +321,18 @@ public class GlusterUtil {
return false;
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getVolume(java.lang.String, java.lang.String)
+ */
+ @Override
public Volume getVolume(String volumeName, String knownServer) {
return parseVolumeInfo(getVolumeInfo(volumeName, knownServer)).get(0);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getAllVolumes(java.lang.String)
+ */
+ @Override
public List<Volume> getAllVolumes(String knownServer) {
return parseVolumeInfo(getVolumeInfo(knownServer));
}
@@ -405,7 +344,7 @@ public class GlusterUtil {
Volume volume = null;
for (String line : volumeInfoText.split(CoreConstants.NEWLINE)) {
- String volumeName = extractToken(line, VOLUME_NAME_PFX);
+ String volumeName = StringUtil.extractToken(line, VOLUME_NAME_PFX);
if (volumeName != null) {
if (volume != null) {
volumes.add(volume);
@@ -420,7 +359,7 @@ public class GlusterUtil {
if (readVolumeType(volume, line))
continue;
- if (extractToken(line, VOLUME_NUMBER_OF_BRICKS) != null) {
+ if (StringUtil.extractToken(line, VOLUME_NUMBER_OF_BRICKS) != null) {
readReplicaOrStripeCount(volume, line);
}
if (readVolumeStatus(volume, line))
@@ -462,6 +401,10 @@ public class GlusterUtil {
return volumes;
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#addBricks(java.lang.String, java.util.List, java.lang.String)
+ */
+ @Override
public void addBricks(String volumeName, List<String> bricks, String knownServer) {
StringBuilder command = new StringBuilder("gluster volume add-brick " + volumeName);
for (String brickDir : bricks) {
@@ -471,6 +414,10 @@ public class GlusterUtil {
serverUtil.executeOnServer(knownServer, command.toString());
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getLogLocation(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
public String getLogLocation(String volumeName, String brickName, String knownServer) {
String command = "gluster volume log locate " + volumeName + " " + brickName;
String output = serverUtil.executeOnServer(knownServer, command, String.class);
@@ -482,6 +429,10 @@ public class GlusterUtil {
+ "] doesn't start with prefix [" + VOLUME_LOG_LOCATION_PFX + "]");
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getLogFileNameForBrickDir(java.lang.String)
+ */
+ @Override
public String getLogFileNameForBrickDir(String brickDir) {
String logFileName = brickDir;
if (logFileName.length() > 0 && logFileName.charAt(0) == '/') {
@@ -491,6 +442,10 @@ public class GlusterUtil {
return logFileName;
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#removeBricks(java.lang.String, java.util.List, java.lang.String)
+ */
+ @Override
public void removeBricks(String volumeName, List<String> bricks, String knownServer) {
StringBuilder command = new StringBuilder("gluster --mode=script volume remove-brick " + volumeName);
for (String brickDir : bricks) {
@@ -499,10 +454,18 @@ public class GlusterUtil {
serverUtil.executeOnServer(knownServer, command.toString());
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#removeServer(java.lang.String, java.lang.String)
+ */
+ @Override
public void removeServer(String existingServer, String serverName) {
serverUtil.executeOnServer(existingServer, "gluster --mode=script peer detach " + serverName);
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#checkRebalanceStatus(java.lang.String, java.lang.String)
+ */
+ @Override
public TaskStatus checkRebalanceStatus(String serverName, String volumeName) {
String command = "gluster volume rebalance " + volumeName + " status";
String output = serverUtil.executeOnServer(serverName, command, String.class).trim();
@@ -518,45 +481,117 @@ public class GlusterUtil {
return taskStatus;
}
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#stopRebalance(java.lang.String, java.lang.String)
+ */
+ @Override
public void stopRebalance(String serverName, String volumeName) {
String command = "gluster volume rebalance " + volumeName + " stop";
serverUtil.executeOnServer(serverName, command);
}
+
+ /**
+ * Performs given Brick Migration (replace-brick) Operation on given volume
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume on which the Brick Migration Operation is to be executed
+ * @param fromBrick
+ * The source Brick (being replaced)
+ * @param toBrick
+ * The destination Brick (which is replacing the source Brick)
+ * @param operation
+ * @return
+ */
+ private String performBrickMigrationOperation(String serverName, String volumeName, String fromBrick,
+ String toBrick, String operation) {
+ String command = "gluster volume replace-brick " + volumeName + " " + fromBrick + " " + toBrick + " "
+ + operation;
+ return serverUtil.executeOnServer(serverName, command, String.class);
+ }
- public TaskStatus getInitializingDeviceStatus(String serverName, String diskName) {
- InitDiskStatusResponse initDiskStatusResponse;
- TaskStatus taskStatus = new TaskStatus();
-
- try {
- initDiskStatusResponse = serverUtil.executeScriptOnServer(serverName, INITIALIZE_DISK_STATUS_SCRIPT + " "
- + diskName, InitDiskStatusResponse.class);
- } catch(RuntimeException e) {
- taskStatus.setCode(Status.STATUS_CODE_FAILURE);
- taskStatus.setMessage(e.getMessage());
- throw e;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#executeBrickMigration(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void startBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ performBrickMigrationOperation(serverName, volumeName, fromBrick, toBrick, "start");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#pauseBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void pauseBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ performBrickMigrationOperation(serverName, volumeName, fromBrick, toBrick, "pause");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#stopBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void stopBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ performBrickMigrationOperation(serverName, volumeName, fromBrick, toBrick, "abort");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#commitBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void commitBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ performBrickMigrationOperation(serverName, volumeName, fromBrick, toBrick, "commit");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#checkBrickMigrationStatus(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public TaskStatus checkBrickMigrationStatus(String serverName, String volumeName, String fromBrick, String toBrick) {
+ String output = performBrickMigrationOperation(serverName, volumeName, fromBrick, toBrick, "status");
- if (initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.COMPLETED) {
- taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
- } else if (initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.IN_PROGRESS) {
+ TaskStatus taskStatus = new TaskStatus();
+ if (output.matches("^Number of files migrated.*Migration complete$")
+ || output.matches("^Number of files migrated = 0 .*Current file=")) {
+ // Note: Workaround - if no file in the volume brick to migrate,
+ // Gluster CLI is not giving proper (complete) status
+ taskStatus.setCode(Status.STATUS_CODE_COMMIT_PENDING);
+ taskStatus.setMessage(output.replaceAll("Migration complete", "Commit pending"));
+ } else if (output.matches("^Number of files migrated.*Current file=.*")) {
taskStatus.setCode(Status.STATUS_CODE_RUNNING);
- taskStatus.setPercentCompleted(Math.round(initDiskStatusResponse.getCompletedBlocks()
- / initDiskStatusResponse.getTotalBlocks() * 100));
- } else if(initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.NOT_RUNNING) {
+ } else if (output.matches("^replace brick has been paused.*")) {
+ taskStatus.setCode(Status.STATUS_CODE_PAUSE);
+ } else {
taskStatus.setCode(Status.STATUS_CODE_FAILURE);
}
- taskStatus.setMessage(initDiskStatusResponse.getMessage());
+ taskStatus.setMessage(output);
return taskStatus;
}
-
- public String executeBrickMigration(String onlineServerName, String volumeName, String fromBrick,
- String toBrick, String operation) {
- String command = "gluster volume replace-brick " + volumeName + " " + fromBrick + " " + toBrick + " " + operation;
- return serverUtil.executeOnServer(onlineServerName, command, String.class).trim();
- }
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getVolumeOptionsInfo(java.lang.String)
+ */
+ @Override
public VolumeOptionInfoListResponse getVolumeOptionsInfo(String serverName) {
return serverUtil.executeOnServer(serverName, "gluster volume set help-xml", VolumeOptionInfoListResponse.class);
}
+
+ public void logRotate(String volumeName, List<String> brickList, String knownServer) {
+ if (brickList == null || brickList.size() > 0) {
+ for (String brickDir : brickList) {
+ serverUtil.executeOnServer(knownServer, "gluster volume log rotate " + volumeName + " " + brickDir);
+ }
+ } else {
+ serverUtil.executeOnServer(knownServer, "gluster volume log rotate " + volumeName);
+ }
+ }
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterface.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterface.java
new file mode 100644
index 00000000..2df24497
--- /dev/null
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterface.java
@@ -0,0 +1,358 @@
+package com.gluster.storage.management.gateway.services;
+
+import java.util.List;
+import java.util.Map;
+
+import com.gluster.storage.management.core.model.TaskStatus;
+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_TYPE;
+import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse;
+
+/**
+ * Interface for interacting with GlusterFS. Every version of GlusterFS supported by the Gluster Management Gateway will
+ * have a corresponding implementation of this interface.
+ */
+public interface GlusterInterface {
+
+ /**
+ * Returns the GlusterFS version on given server.
+ *
+ * @param serverName
+ * Server on which Gluster version is to be checked.
+ * @return
+ */
+ public abstract String getVersion(String serverName);
+
+ /**
+ * Adds the new server to an existing cluster.
+ *
+ * @param existingServer
+ * Server part of the existing cluster.
+ * @param newServer
+ * Server to be added to the cluster.
+ */
+ public abstract void addServer(String existingServer, String newServer);
+
+ /**
+ * Removes given server from the cluster by executing appropriate Gluster command on given server.
+ *
+ * @param existingServer
+ * Server part of the existing cluster.
+ * @param serverName
+ * Server to be removed from the cluster.
+ */
+ public abstract void removeServer(String existingServer, String serverName);
+
+ /**
+ * Starts the given volume by executing appropriate Gluster command on given server.
+ *
+ * @param volumeName
+ * Volume to be started.
+ * @param serverName
+ * Server on which the Gluster command is to be executed. This server must be part of the cluster to
+ * which the volume belongs.
+ */
+ public abstract void startVolume(String volumeName, String serverName);
+
+ /**
+ * Stops the given volume by executing appropriate Gluster command on given server.
+ *
+ * @param volumeName
+ * Volume to be stopped.
+ * @param serverName
+ * Server on which the Gluster command is to be executed. This server must be part of the cluster to
+ * which the volume belongs.
+ */
+ public abstract void stopVolume(String volumeName, String serverName);
+
+ /**
+ * Resets volume options on the given volume by executing appropriate Gluster command on given server.
+ *
+ * @param volumeName
+ * Volume on which options are to be reset.
+ * @param serverName
+ * Server on which the Gluster command is to be executed. This server must be part of the cluster to
+ * which the volume belongs.
+ */
+ public abstract void resetOptions(String volumeName, String serverName);
+
+ /**
+ * Creates a volume on given volume using given properties.
+ *
+ * @param serverName
+ * Server on which the Gluster command for creating the volume will be executed. This must be part of the
+ * cluster in which the volume is to be created.
+ * @param volumeName
+ * Name of the volume.
+ * @param volumeType
+ * Type of the volume e.g. DISTRIBUTE, REPLICATE, STRIPE, etc. See {@link VOLUME_TYPE} for full list of
+ * valid values.
+ * @param transportType
+ * Transport type of the volume e.g. ETHERNET. See {@link TRANSPORT_TYPE} for full list of valid values.
+ * @param replOrStripeCount
+ * Replica Count or Stripe count depending on the volume type. Ignored in case of pure distribute volumes
+ * (no replicate, no stripe).
+ * @param bricks
+ * Comma separated list of volume brick directories in following format: <br>
+ * server1:dir1,server2:dir2,server3:dir3,...,servern:dirn
+ * @param accessProtocols
+ * Optional parameter indicating access protocols to be enabled for the volume. If empty/null, GLUSTERFS
+ * and NFS will be enabled.
+ * @param options
+ * A comma separated list of volume options to be set on the newly created volume in following format: <br>
+ * key1=value1,key2=value2,key3=value3,...,keyn=valuen
+ */
+ public abstract void createVolume(String serverName, String volumeName, String volumeType, String transportType,
+ Integer replOrStripeCount, String bricks, String accessProtocols, String options);
+
+ /**
+ * Creates / Sets the given options on the given volume by executing appropriate Gluster command on the given
+ * server.
+ *
+ * @param volumeName
+ * Volume on which the options are to be set.
+ * @param options
+ * Map containing the volume options to be set. Key = option key, Value = option value.
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void createOptions(String volumeName, Map<String, String> options, String serverName);
+
+ /**
+ * Sets the given option on given volume by executing appropriate Gluster command on the given server.
+ *
+ * @param volumeName
+ * Volume on which the option is to be set.
+ * @param key
+ * Option key (name)
+ * @param value
+ * Option value
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void setOption(String volumeName, String key, String value, String serverName);
+
+ /**
+ * Deletes the given volume by executing appropriate Gluster command on the given server.
+ *
+ * @param volumeName
+ * Volume to be deleted.
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void deleteVolume(String volumeName, String serverName);
+
+ /**
+ * Fetches properties of the given Volume by executing appropriate Gluster command on the given server.
+ *
+ * @param volumeName
+ * Volume whose properties are to be fetched.
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @return A {@link Volume} object containing all properties of the given volume
+ */
+ public abstract Volume getVolume(String volumeName, String serverName);
+
+ /**
+ * Fetches the list of all volumes (along with their properties) by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @return A list of {@link Volume} objects representing every volume present in the cluster to which the given
+ * server belongs.
+ */
+ public abstract List<Volume> getAllVolumes(String serverName);
+
+ /**
+ * Adds given list of bricks to given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param volumeName
+ * Volume to which the bricks are to be added.
+ * @param bricks
+ * List of bricks to be added, each in the format serverName:brickDirectory
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void addBricks(String volumeName, List<String> bricks, String serverName);
+
+ /**
+ * Removes given list of bricks from given volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param volumeName
+ * Volume from which the bricks are to be removed
+ * @param bricks
+ * List of bricks to be removed, each in the format serverName:brickDirectory
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void removeBricks(String volumeName, List<String> bricks, String serverName);
+
+ /**
+ * Returns the log location of given brick of given volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param volumeName
+ * Volume for which log location is to be fetched.
+ * @param brickName
+ * Brick of the volume for which log location is to be fetched.
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @return Full path of the log file location (directory) for the given Volume Brick.
+ */
+ public abstract String getLogLocation(String volumeName, String brickName, String serverName);
+
+ /**
+ * Returns the log file name for given brick directory.
+ *
+ * @param brickDir
+ * Brick directory for which log file name is to be returned.
+ * @return The log file name (without path) for the given brick directory.
+ */
+ public abstract String getLogFileNameForBrickDir(String brickDir);
+
+ /**
+ * Checks the status of "Rebalance" operation on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose rebalance status is to be checked.
+ * @return Object of {@link TaskStatus} representing the status of Volume Rebalance.
+ */
+ public abstract TaskStatus checkRebalanceStatus(String serverName, String volumeName);
+
+ /**
+ * Stops "Rebalance" operation running on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Rebalance is to be stopped.
+ */
+ public abstract void stopRebalance(String serverName, String volumeName);
+
+ /**
+ * Starts Brick Migration (replace-brick) on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Brick is to be migrated/replaced.
+ * @param fromBrick
+ * The source Brick (to be replaced).
+ * @param toBrick
+ * The destination Brick (will replace the source Brick).
+ */
+ public abstract void startBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick);
+
+ /**
+ * Pauses Brick Migration (replace-brick) running on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Brick is being migrated/replaced.
+ * @param fromBrick
+ * The source Brick (being replaced).
+ * @param toBrick
+ * The destination Brick (which is replacing the source Brick).
+ */
+ public abstract void pauseBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick);
+
+ /**
+ * Aborts Brick Migration (replace-brick) running on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Brick is being migrated/replaced.
+ * @param fromBrick
+ * The source Brick (being replaced).
+ * @param toBrick
+ * The destination Brick (which is replacing the source Brick)
+ */
+ public abstract void stopBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick);
+
+ /**
+ * Commits Brick Migration (replace-brick) running on given Volume by executing appropriate Gluster command on the
+ * given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Brick is being migrated/replaced.
+ * @param fromBrick
+ * The source Brick (being replaced).
+ * @param toBrick
+ * The destination Brick (which is replacing the source Brick)
+ */
+ public abstract void commitBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick);
+
+ /**
+ * Checks status of Brick Migration (replace-brick) running on given Volume by executing appropriate Gluster command
+ * on the given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @param volumeName
+ * Volume whose Brick is being migrated/replaced.
+ * @param fromBrick
+ * The source Brick (being replaced).
+ * @param toBrick
+ * The destination Brick (which is replacing the source Brick)
+ * @return A {@link TaskStatus} object representing the status of Brick Migration
+ */
+ public abstract TaskStatus checkBrickMigrationStatus(String serverName, String volumeName, String fromBrick,
+ String toBrick);
+
+ /**
+ * Returns information about all the supported Volume Options by executing appropriate Gluster command
+ * on the given server.
+ *
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ * @return A {@link VolumeOptionInfoListResponse} object containing information about each and every supported
+ * Volume Option
+ */
+ public abstract VolumeOptionInfoListResponse getVolumeOptionsInfo(String serverName);
+
+ /**
+ * Rotates the logs for given Bricks of given Volume by executing appropriate Gluster command
+ * on the given server.
+ *
+ * @param volumeName
+ * Volume whose logs are to be rotated.
+ * @param brickList
+ * List of bricks whose logs are to be rotated, each in the format serverName:brickDirectory <br>
+ * This is an optional parameter. If null or empty, all logs of the Volume will be rotated.
+ * @param serverName
+ * The server on which the Gluster command will be executed. This must be part of the cluster to which
+ * the volume belongs.
+ */
+ public abstract void logRotate(String volumeName, List<String> brickList, String serverName);
+} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterfaceService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterfaceService.java
new file mode 100644
index 00000000..2da8d68e
--- /dev/null
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterInterfaceService.java
@@ -0,0 +1,256 @@
+/**
+ * GlusterInterfaceService.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.gateway.services;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.stereotype.Component;
+
+import com.gluster.storage.management.core.model.TaskStatus;
+import com.gluster.storage.management.core.model.Volume;
+import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse;
+
+@Component
+public class GlusterInterfaceService extends AbstractGlusterInterface {
+ private HashMap<String, GlusterInterface> glusterInterfaces = new HashMap<String, GlusterInterface>();
+
+ /**
+ * Returns an instance of the Gluster Interface for given version of GlusterFS
+ * @param glusterFsVersion
+ * @return
+ */
+ private GlusterInterface getGlusterInterfaceForVersion(String glusterFsVersion) {
+ GlusterInterface glusterInterface = glusterInterfaces.get(glusterFsVersion);
+ if(glusterInterface != null) {
+ return glusterInterface;
+ }
+
+ glusterInterface = new Gluster323InterfaceService();
+ glusterInterfaces.put(glusterFsVersion, glusterInterface);
+ return glusterInterface;
+ }
+
+ /**
+ * Returns an instance of Gluster Interface for the version of GlusterFS installed on given server.
+ *
+ * @param serverName
+ * @return
+ */
+ private GlusterInterface getGlusterInterface(String serverName) {
+ return getGlusterInterfaceForVersion(getVersion(serverName));
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#addServer(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void addServer(String existingServer, String newServer) {
+ getGlusterInterface(existingServer).addServer(existingServer, newServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#startVolume(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void startVolume(String volumeName, String knownServer) {
+ getGlusterInterface(knownServer).startVolume(volumeName, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#stopVolume(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void stopVolume(String volumeName, String knownServer) {
+ getGlusterInterface(knownServer).stopVolume(volumeName, knownServer);
+ }
+
+ public void logRotate(String volumeName, List<String> brickList, String knownServer) {
+ getGlusterInterface(knownServer).logRotate(volumeName, brickList, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#resetOptions(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void resetOptions(String volumeName, String knownServer) {
+ getGlusterInterface(knownServer).resetOptions(volumeName, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#createVolume(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void createVolume(String knownServer, String volumeName, String volumeTypeStr, String transportTypeStr,
+ Integer count, String bricks, String accessProtocols, String options) {
+ getGlusterInterface(knownServer).createVolume(knownServer, volumeName, volumeTypeStr, transportTypeStr, count,
+ bricks, accessProtocols, options);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#createOptions(java.lang.String, java.util.Map, java.lang.String)
+ */
+ @Override
+ public void createOptions(String volumeName, Map<String, String> options, String knownServer) {
+ getGlusterInterface(knownServer).createOptions(volumeName, options, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#setOption(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void setOption(String volumeName, String key, String value, String knownServer) {
+ getGlusterInterface(knownServer).setOption(volumeName, key, value, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#deleteVolume(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void deleteVolume(String volumeName, String knownServer) {
+ getGlusterInterface(knownServer).deleteVolume(volumeName, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getVolume(java.lang.String, java.lang.String)
+ */
+ @Override
+ public Volume getVolume(String volumeName, String knownServer) {
+ return getGlusterInterface(knownServer).getVolume(volumeName, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getAllVolumes(java.lang.String)
+ */
+ @Override
+ public List<Volume> getAllVolumes(String knownServer) {
+ return getGlusterInterface(knownServer).getAllVolumes(knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#addBricks(java.lang.String, java.util.List, java.lang.String)
+ */
+ @Override
+ public void addBricks(String volumeName, List<String> bricks, String knownServer) {
+ getGlusterInterface(knownServer).addBricks(volumeName, bricks, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getLogLocation(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getLogLocation(String volumeName, String brickName, String knownServer) {
+ return getGlusterInterface(knownServer).getLogLocation(volumeName, brickName, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getLogFileNameForBrickDir(java.lang.String)
+ */
+ @Override
+ public String getLogFileNameForBrickDir(String brickDir) {
+ return getGlusterInterface(brickDir.split(":")[0]).getLogFileNameForBrickDir(brickDir);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#removeBricks(java.lang.String, java.util.List, java.lang.String)
+ */
+ @Override
+ public void removeBricks(String volumeName, List<String> bricks, String knownServer) {
+ getGlusterInterface(knownServer).removeBricks(volumeName, bricks, knownServer);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#removeServer(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void removeServer(String existingServer, String serverName) {
+ getGlusterInterface(serverName).removeServer(existingServer, serverName);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#checkRebalanceStatus(java.lang.String, java.lang.String)
+ */
+ @Override
+ public TaskStatus checkRebalanceStatus(String serverName, String volumeName) {
+ return getGlusterInterface(serverName).checkRebalanceStatus(serverName, volumeName);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#stopRebalance(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void stopRebalance(String serverName, String volumeName) {
+ getGlusterInterface(serverName).stopRebalance(serverName, volumeName);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#executeBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void startBrickMigration(String onlineServerName, String volumeName, String fromBrick, String toBrick) {
+ getGlusterInterface(onlineServerName).startBrickMigration(onlineServerName, volumeName, fromBrick, toBrick);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#pauseBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void pauseBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ getGlusterInterface(serverName).pauseBrickMigration(serverName, volumeName, fromBrick, toBrick);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#stopBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void stopBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ getGlusterInterface(serverName).stopBrickMigration(serverName, volumeName, fromBrick, toBrick);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#commitBrickMigration(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void commitBrickMigration(String serverName, String volumeName, String fromBrick, String toBrick) {
+ getGlusterInterface(serverName).commitBrickMigration(serverName, volumeName, fromBrick, toBrick);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.services.GlusterInterface#checkBrickMigrationStatus(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public TaskStatus checkBrickMigrationStatus(String serverName, String volumeName, String fromBrick, String toBrick) {
+ return getGlusterInterface(serverName).checkBrickMigrationStatus(serverName, volumeName, fromBrick, toBrick);
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getVolumeOptionsInfo(java.lang.String)
+ */
+ @Override
+ public VolumeOptionInfoListResponse getVolumeOptionsInfo(String serverName) {
+ return getGlusterInterface(serverName).getVolumeOptionsInfo(serverName);
+ }
+}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
index 6cdcd377..da1a8487 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
@@ -34,11 +34,12 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.exceptions.GlusterValidationException;
import com.gluster.storage.management.core.model.GlusterServer;
import com.gluster.storage.management.core.model.Server;
+import com.gluster.storage.management.core.model.Server.SERVER_STATUS;
import com.gluster.storage.management.core.utils.GlusterCoreUtil;
import com.gluster.storage.management.core.utils.ProcessUtil;
+import com.gluster.storage.management.core.utils.StringUtil;
import com.gluster.storage.management.gateway.data.ClusterInfo;
import com.gluster.storage.management.gateway.data.ServerInfo;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
import com.gluster.storage.management.gateway.utils.ServerUtil;
import com.gluster.storage.management.gateway.utils.SshUtil;
@@ -47,6 +48,12 @@ import com.gluster.storage.management.gateway.utils.SshUtil;
*/
@Component
public class GlusterServerService {
+ private static final String HOSTNAME_PFX = "Hostname:";
+ private static final String UUID_PFX = "Uuid:";
+ private static final String STATE_PFX = "State:";
+ private static final String GLUSTER_SERVER_STATUS_ONLINE = "Peer in Cluster (Connected)";
+ private static final String GLUSTERD_INFO_FILE = "/etc/glusterd/glusterd.info";
+
@Autowired
protected ServerUtil serverUtil;
@@ -54,7 +61,7 @@ public class GlusterServerService {
private ClusterService clusterService;
@Autowired
- private GlusterUtil glusterUtil;
+ private GlusterInterfaceService glusterUtil;
@Autowired
private SshUtil sshUtil;
@@ -98,7 +105,7 @@ public class GlusterServerService {
Integer maxCount, String previousServerName) {
List<GlusterServer> glusterServers;
try {
- glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ glusterServers = getGlusterServers(onlineServer.getName());
} catch (Exception e) {
// check if online server has gone offline. If yes, try again one more time.
if (e instanceof ConnectionException || serverUtil.isServerOnline(onlineServer) == false) {
@@ -107,7 +114,7 @@ public class GlusterServerService {
if (onlineServer == null) {
throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
}
- glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ glusterServers = getGlusterServers(onlineServer.getName());
} else {
throw new GlusterRuntimeException(e.getMessage());
}
@@ -124,6 +131,85 @@ public class GlusterServerService {
}
return glusterServers;
}
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getGlusterServer(com.gluster.storage.management.core.model.GlusterServer, java.lang.String)
+ */
+ public GlusterServer getGlusterServer(String onlineServer, String serverName) {
+ List<GlusterServer> servers = getGlusterServers(onlineServer);
+ for (GlusterServer server : servers) {
+ if (server.getName().equalsIgnoreCase(serverName)) {
+ return server;
+ }
+ }
+ return null;
+ }
+
+ private String getUuid(String serverName) {
+ return serverUtil.executeOnServer(serverName, "cat " + GLUSTERD_INFO_FILE, String.class).split("=")[1];
+ }
+
+ /* (non-Javadoc)
+ * @see com.gluster.storage.management.gateway.utils.GlusterInterface#getGlusterServers(com.gluster.storage.management.core.model.GlusterServer)
+ */
+ public List<GlusterServer> getGlusterServers(String knownServerName) {
+ String output = getPeerStatus(knownServerName);
+
+ GlusterServer knownServer = new GlusterServer(knownServerName);
+ knownServer.setUuid(getUuid(knownServerName));
+
+ List<GlusterServer> glusterServers = new ArrayList<GlusterServer>();
+ glusterServers.add(knownServer);
+
+ GlusterServer server = null;
+ boolean foundHost = false;
+ boolean foundUuid = false;
+ for (String line : output.split(CoreConstants.NEWLINE)) {
+ if (foundHost && foundUuid) {
+ // Host and UUID is found, we should look for state
+ String state = StringUtil.extractToken(line, STATE_PFX);
+ if (state != null) {
+ server.setStatus(state.contains(GLUSTER_SERVER_STATUS_ONLINE) ? SERVER_STATUS.ONLINE
+ : SERVER_STATUS.OFFLINE);
+ // Completed populating current server. Add it to the list
+ // and reset all related variables.
+ glusterServers.add(server);
+
+ foundHost = false;
+ foundUuid = false;
+ server = null;
+ }
+ } else if (foundHost) {
+ // Host is found, look for UUID
+ String uuid = StringUtil.extractToken(line, UUID_PFX);
+ if (uuid != null) {
+ server.setUuid(uuid);
+ foundUuid = true;
+ }
+ } else {
+ // Look for the next host
+ if (server == null) {
+ server = new GlusterServer();
+ }
+ String hostName = StringUtil.extractToken(line, HOSTNAME_PFX);
+ if (hostName != null) {
+ server.setName(hostName);
+ foundHost = true;
+ }
+ }
+
+ }
+ return glusterServers;
+ }
+
+ /**
+ * @param knownServer
+ * A known server on which the gluster command will be executed to fetch peer status
+ * @return Outout of the "gluster peer status" command
+ */
+ private String getPeerStatus(String knownServer) {
+ return serverUtil.executeOnServer(knownServer, "gluster peer status", String.class);
+ }
private String fetchDetailsOfServers(List<GlusterServer> glusterServers) {
try {
@@ -138,16 +224,6 @@ public class GlusterServerService {
logger.error(errMsg, e);
throw new GlusterRuntimeException(errMsg, e);
}
-// String errMsg = "";
-//
-// for (GlusterServer server : glusterServers) {
-// try {
-// fetchServerDetails(server);
-// } catch (Exception e) {
-// errMsg += CoreConstants.NEWLINE + server.getName() + " : [" + e.getMessage() + "]";
-// }
-// }
-// return errMsg;
}
private String prepareErrorMessage(List<String> errors) {
@@ -238,7 +314,7 @@ public class GlusterServerService {
Boolean fetchDetails) {
GlusterServer server = null;
try {
- server = glusterUtil.getGlusterServer(onlineServer, serverName);
+ server = getGlusterServer(onlineServer.getName(), serverName);
} catch (Exception e) {
// check if online server has gone offline. If yes, try again one more time.
if (e instanceof ConnectionException || serverUtil.isServerOnline(onlineServer) == false) {
@@ -247,7 +323,7 @@ public class GlusterServerService {
if (onlineServer == null) {
throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
}
- server = glusterUtil.getGlusterServer(onlineServer, serverName);
+ server = getGlusterServer(onlineServer.getName(), serverName);
} else {
throw new GlusterRuntimeException(e.getMessage());
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
index eb585b98..df33d7ba 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
@@ -59,7 +59,6 @@ import com.gluster.storage.management.gateway.data.ClusterInfo;
import com.gluster.storage.management.gateway.resources.v1_0.TasksResource;
import com.gluster.storage.management.gateway.tasks.MigrateBrickTask;
import com.gluster.storage.management.gateway.tasks.RebalanceVolumeTask;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
import com.gluster.storage.management.gateway.utils.ServerUtil;
/**
@@ -84,7 +83,10 @@ public class VolumeService {
private ClusterService clusterService;
@Autowired
- private GlusterUtil glusterUtil;
+ private GlusterInterfaceService glusterUtil;
+
+ @Autowired
+ private GlusterServerService glusterServerService;
@Autowired
protected ServerUtil serverUtil;
@@ -251,7 +253,7 @@ public class VolumeService {
try {
GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
- List<GlusterServer> glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ List<GlusterServer> glusterServers = glusterServerService.getGlusterServers(onlineServer.getName());
File serversFile = new File(clusterServersListFile);
FileOutputStream fos = new FileOutputStream(serversFile);
for (GlusterServer server : glusterServers) {
@@ -686,6 +688,26 @@ public class VolumeService {
}
}
+ public void logRotate(String clusterName, String volumeName, List<String> brickList) {
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
+ try {
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+
+ glusterUtil.logRotate(volumeName, brickList, onlineServer.getName());
+ } catch (Exception e) {
+ // check if online server has gone offline. If yes, try again one more time.
+ if (e instanceof ConnectionException || serverUtil.isServerOnline(onlineServer) == false) {
+ // online server has gone offline! try with a different one.
+ onlineServer = clusterService.getNewOnlineServer(clusterName);
+ glusterUtil.logRotate(volumeName, brickList, onlineServer.getName());
+ } else {
+ throw new GlusterRuntimeException("Volume [" + volumeName + "] log rotation failed!", e);
+ }
+ }
+ }
+
public void performVolumeOperation(String clusterName, String volumeName, String operation) {
GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
try {
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java
index 7586795a..1fba4158 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java
@@ -25,24 +25,27 @@ import org.springframework.web.context.ContextLoader;
import com.gluster.storage.management.core.constants.GlusterConstants;
import com.gluster.storage.management.core.exceptions.ConnectionException;
+import com.gluster.storage.management.core.model.InitDiskStatusResponse;
import com.gluster.storage.management.core.model.Status;
import com.gluster.storage.management.core.model.TaskInfo;
+import com.gluster.storage.management.core.model.InitDiskStatusResponse.FORMAT_STATUS;
import com.gluster.storage.management.core.model.TaskInfo.TASK_TYPE;
import com.gluster.storage.management.core.model.TaskStatus;
import com.gluster.storage.management.gateway.services.ClusterService;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
+import com.gluster.storage.management.gateway.services.GlusterInterfaceService;
import com.gluster.storage.management.gateway.utils.ServerUtil;
import com.sun.jersey.core.util.Base64;
public class InitializeDiskTask extends Task {
private static final String INITIALIZE_DISK_SCRIPT = "format_device.py";
+ private static final String INITIALIZE_DISK_STATUS_SCRIPT = "get_format_device_status.py";
private String serverName;
private String diskName;
private String fsType;
private ServerUtil serverUtil;
- private GlusterUtil glusterUtil;
+ private GlusterInterfaceService glusterUtil;
public InitializeDiskTask(ClusterService clusterService, String clusterName, String serverName, String diskName,
String fsType) {
@@ -64,7 +67,7 @@ public class InitializeDiskTask extends Task {
private void init() {
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
- glusterUtil = ctx.getBean(GlusterUtil.class);
+ glusterUtil = ctx.getBean(GlusterInterfaceService.class);
serverUtil = ctx.getBean(ServerUtil.class);
}
@@ -130,13 +133,40 @@ public class InitializeDiskTask extends Task {
public TaskStatus checkStatus() {
try {
- return glusterUtil.getInitializingDeviceStatus(serverName, getDiskName());
+ return getInitializingDeviceStatus(serverName, getDiskName());
} catch(ConnectionException e) {
// online server might have gone offline. update the failure status
return new TaskStatus(new Status(Status.STATUS_CODE_FAILURE, e.getMessage()));
}
}
+ private TaskStatus getInitializingDeviceStatus(String serverName, String diskName) {
+ InitDiskStatusResponse initDiskStatusResponse;
+ TaskStatus taskStatus = new TaskStatus();
+
+ try {
+ initDiskStatusResponse = serverUtil.executeScriptOnServer(serverName, INITIALIZE_DISK_STATUS_SCRIPT + " "
+ + diskName, InitDiskStatusResponse.class);
+ } catch(RuntimeException e) {
+ taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ taskStatus.setMessage(e.getMessage());
+ throw e;
+ }
+
+ if (initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.COMPLETED) {
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ } else if (initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.IN_PROGRESS) {
+ taskStatus.setCode(Status.STATUS_CODE_RUNNING);
+ taskStatus.setPercentCompleted(Math.round(initDiskStatusResponse.getCompletedBlocks()
+ / initDiskStatusResponse.getTotalBlocks() * 100));
+ } else if(initDiskStatusResponse.getFormatStatus() == FORMAT_STATUS.NOT_RUNNING) {
+ taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ }
+
+ taskStatus.setMessage(initDiskStatusResponse.getMessage());
+ return taskStatus;
+ }
+
public void setDiskName(String diskName) {
this.diskName = diskName;
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java
index 5d321d71..e5cb17f1 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java
@@ -28,9 +28,8 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
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.TaskStatus;
-import com.gluster.storage.management.core.utils.ProcessResult;
import com.gluster.storage.management.gateway.services.ClusterService;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
+import com.gluster.storage.management.gateway.services.GlusterInterfaceService;
import com.gluster.storage.management.gateway.utils.ServerUtil;
import com.sun.jersey.core.util.Base64;
@@ -39,7 +38,7 @@ public class MigrateBrickTask extends Task {
private String fromBrick;
private String toBrick;
private Boolean autoCommit;
- private GlusterUtil glusterUtil;
+ private GlusterInterfaceService glusterInterface;
protected ServerUtil serverUtil;
public String getFromBrick() {
@@ -79,7 +78,7 @@ public class MigrateBrickTask extends Task {
private void init() {
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
- glusterUtil = ctx.getBean(GlusterUtil.class);
+ glusterInterface = ctx.getBean(GlusterInterfaceService.class);
serverUtil = ctx.getBean(ServerUtil.class);
}
@@ -106,12 +105,8 @@ public class MigrateBrickTask extends Task {
private void startMigration(String onlineServerName) {
String volumeName = getTaskInfo().getReference().split("#")[0];
- String output = glusterUtil.executeBrickMigration(onlineServerName, volumeName,
- getFromBrick(), getToBrick(), "start");
- if (output.matches(".*started successfully$")) {
- getTaskInfo().setStatus(
- new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, output)));
- }
+ glusterInterface.startBrickMigration(onlineServerName, volumeName, getFromBrick(), getToBrick());
+ getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, "Brick Migration Started.")));
}
@Override
@@ -131,15 +126,11 @@ public class MigrateBrickTask extends Task {
private void pauseMigration(String onlineServer) {
String volumeName = getTaskInfo().getReference().split("#")[0];
- String output = glusterUtil.executeBrickMigration(onlineServer, volumeName,
- getFromBrick(), getToBrick(), "pause");
+ glusterInterface.pauseBrickMigration(onlineServer, volumeName, getFromBrick(), getToBrick());
TaskStatus taskStatus = new TaskStatus();
- if (output.matches(".*paused successfully$")) {
- taskStatus.setCode(Status.STATUS_CODE_PAUSE);
- taskStatus.setMessage(output);
- getTaskInfo().setStatus(taskStatus);
- return;
- }
+ taskStatus.setCode(Status.STATUS_CODE_PAUSE);
+ taskStatus.setMessage("Brick Migration Paused");
+ getTaskInfo().setStatus(taskStatus);
}
@Override
@@ -164,14 +155,11 @@ public class MigrateBrickTask extends Task {
private void commitMigration(String serverName) {
String volumeName = getTaskInfo().getReference().split("#")[0];
- String output = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(), getToBrick(),
- "commit");
+ glusterInterface.commitBrickMigration(serverName, volumeName, getFromBrick(), getToBrick());
TaskStatus taskStatus = new TaskStatus();
- if (output.matches(".*commit successful$")) {
- taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
- taskStatus.setMessage(output);
- getTaskInfo().setStatus(taskStatus);
- }
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ taskStatus.setMessage("Brick Migration Committed.");
+ getTaskInfo().setStatus(taskStatus);
}
@Override
@@ -191,14 +179,11 @@ public class MigrateBrickTask extends Task {
private void stopMigration(String serverName) {
String volumeName = getTaskInfo().getReference().split("#")[0];
- String output = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(),
- getToBrick(), "abort");
+ glusterInterface.stopBrickMigration(serverName, volumeName, getFromBrick(), getToBrick());
TaskStatus taskStatus = new TaskStatus();
- if (output.matches(".*aborted successfully$")) {
- taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
- taskStatus.setMessage(output);
- getTaskInfo().setStatus(taskStatus);
- }
+ taskStatus.setCode(Status.STATUS_CODE_SUCCESS);
+ taskStatus.setMessage("Brick Migration Stopped");
+ getTaskInfo().setStatus(taskStatus);
}
@Override
@@ -217,34 +202,18 @@ public class MigrateBrickTask extends Task {
private TaskStatus checkMigrationStatus(String serverName) {
// For committed task, status command (CLI) is invalid, just return current status
- if (getTaskInfo().getStatus().getCode() == Status.STATUS_CODE_SUCCESS) {
- return getTaskInfo().getStatus();
+ if (taskInfo.getStatus().getCode() == Status.STATUS_CODE_SUCCESS) {
+ return taskInfo.getStatus();
}
- TaskStatus taskStatus = new TaskStatus();
String volumeName = getTaskInfo().getReference().split("#")[0];
- String output = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(),
- getToBrick(), "status");
-
- if (output.matches("^Number of files migrated.*Migration complete$")
- || output.matches("^Number of files migrated = 0 .*Current file=")) {
- // Note: Workaround - if no file in the volume brick to migrate,
- // Gluster CLI is not giving proper (complete) status
- taskStatus.setCode(Status.STATUS_CODE_COMMIT_PENDING);
- if (autoCommit) {
- commitMigration(serverName);
- return getTaskInfo().getStatus(); // return the committed status
- } else {
- taskStatus.setMessage(output.replaceAll("Migration complete", "Commit pending"));
- }
- } else if (output.matches("^Number of files migrated.*Current file=.*")) {
- taskStatus.setCode(Status.STATUS_CODE_RUNNING);
- } else if (output.matches("^replace brick has been paused.*")) {
- taskStatus.setCode(Status.STATUS_CODE_PAUSE);
- } else {
- taskStatus.setCode(Status.STATUS_CODE_FAILURE);
+ TaskStatus taskStatus = glusterInterface.checkBrickMigrationStatus(serverName, volumeName, getFromBrick(),
+ getToBrick());
+ if (autoCommit && taskStatus.isCommitPending()) {
+ commitMigration(serverName);
+ return taskInfo.getStatus(); // return the committed status
}
- taskStatus.setMessage(output);
+
taskInfo.setStatus(taskStatus); // Update the task status
return taskStatus;
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java
index d81ea4bf..410260ca 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java
@@ -29,7 +29,7 @@ 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.TaskStatus;
import com.gluster.storage.management.gateway.services.ClusterService;
-import com.gluster.storage.management.gateway.utils.GlusterUtil;
+import com.gluster.storage.management.gateway.services.GlusterInterfaceService;
import com.gluster.storage.management.gateway.utils.ServerUtil;
import com.sun.jersey.core.util.Base64;
@@ -38,7 +38,7 @@ public class RebalanceVolumeTask extends Task {
private String layout;
private String serverName;
private ServerUtil serverUtil;
- private GlusterUtil glusterUtil;
+ private GlusterInterfaceService glusterUtil;
public RebalanceVolumeTask(ClusterService clusterService, String clusterName, String volumeName, String layout) {
super(clusterService, clusterName, TASK_TYPE.VOLUME_REBALANCE, volumeName, "Volume " + volumeName
@@ -51,7 +51,7 @@ public class RebalanceVolumeTask extends Task {
private void init() {
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
serverUtil = ctx.getBean(ServerUtil.class);
- glusterUtil = ctx.getBean(GlusterUtil.class);
+ glusterUtil = ctx.getBean(GlusterInterfaceService.class);
}
@Override