From 41443888c6cfbc9d5debb675df9f484d1a9131bb Mon Sep 17 00:00:00 2001 From: Dhandapani Date: Wed, 28 Sep 2011 15:51:45 +0530 Subject: Story #41: Volume Log Rotate --- .../storage/management/client/VolumesClient.java | 7 +++ .../plugin.xml | 18 ++++++ .../console/actions/VolumeLogRotateAction.java | 69 ++++++++++++++++++++++ .../management/core/constants/RESTConstants.java | 1 + .../gateway/resources/v1_0/VolumesResource.java | 5 +- .../management/gateway/services/VolumeService.java | 21 +++++++ .../management/gateway/utils/GlusterUtil.java | 10 ++++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java (limited to 'src') 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..e5741151 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,13 @@ public class VolumesClient extends AbstractClient { putRequest(volumeName, form); } + public void volumeLogRotate(String volumeName, String bricks) { + Form form = new Form(); + form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_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..abf5c33e 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"> + + @@ -520,6 +525,19 @@ id="com.gluster.storage.management.console.actionsets.volume" label="Volume Actions" visible="false"> + + bricks; + + @Override + public void dispose() { + + } + + @Override + protected void performAction(IAction action) { + final String actionDesc = action.getDescription(); + String brick; + boolean confirmed = showConfirmDialog(actionDesc, + "Are you sure you want to rotate log for volume [" + volume.getName() + "] ? "); + if (!confirmed) { + return; + } + + if (bricks == null) { + brick = ""; + } else { + brick = StringUtil.collectionToString(GlusterCoreUtil.getQualifiedBrickList(bricks), ","); + } + try { + new VolumesClient().volumeLogRotate(volume.getName(), brick); + showInfoDialog(actionDesc, "Volume log for [" + volume.getName() + "] rotated successfully!"); + } catch (Exception e) { + showErrorDialog(actionDesc, "Volume log rotate for [" + volume.getName() + + "] could not be rotate! Error: [" + e.getMessage() + "]"); + } + } + + @Override + public void selectionChanged(IAction action, ISelection selection) { + super.selectionChanged(action, selection); + volume = (Volume) guiHelper.getSelectedEntity(window, Volume.class); + + if (volume != null) { + // a volume is selected on navigation tree. Let's check if the currently open view is volume disks view + IWorkbenchPart view = guiHelper.getActiveView(); + if (view instanceof VolumeBricksView) { + // volume disks view is open. check if any brick is selected + bricks = GUIHelper.getInstance().getSelectedEntities(getWindow(), Brick.class); + } + + } + } + +} 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..8addb896 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 @@ -68,6 +68,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.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..d26f6acb 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 @@ -193,7 +193,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 brickList) { if (clusterName == null || clusterName.isEmpty()) { throw new GlusterValidationException("Cluster name must not be empty!"); } @@ -228,6 +229,8 @@ public class VolumesResource extends AbstractResource { } volumeService.deleteCifsUsers(clusterName, volumeName); } + } else if (operation.equals(RESTConstants.FORM_PARAM_LOG_ROTATE)) { + 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/VolumeService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java index eb585b98..6a8d75a4 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 @@ -686,6 +686,27 @@ public class VolumeService { } } + public void logRotate(String clusterName, String volumeName, String bricks) { + GlusterServer onlineServer = clusterService.getOnlineServer(clusterName); + List brickList = Arrays.asList(bricks.split(",")); + 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(e.getMessage()); + } + } + } + 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/utils/GlusterUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java index 3bcd5826..a7a96ccd 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java @@ -180,6 +180,16 @@ public class GlusterUtil { public void stopVolume(String volumeName, String knownServer) { serverUtil.executeOnServer(knownServer, "gluster --mode=script volume stop " + volumeName); } + + public void logRotate(String volumeName, List brickList, String knownServer) { + if (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); + } + } public void resetOptions(String volumeName, String knownServer) { serverUtil.executeOnServer(knownServer, "gluster volume reset " + volumeName); -- cgit