From c2fcd1775f60ddf7f3a3be39d7d9b70fa00da90a 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 | 8 +++ .../plugin.xml | 18 ++++++ .../console/actions/VolumeLogRotateAction.java | 64 ++++++++++++++++++++++ .../management/core/constants/RESTConstants.java | 1 + .../gateway/resources/v1_0/VolumesResource.java | 7 ++- .../management/gateway/services/VolumeService.java | 21 +++++++ .../management/gateway/utils/GlusterUtil.java | 10 ++++ 7 files changed, 128 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..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 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"> + + @@ -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(); + List selectedBricks = new ArrayList(); + 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 = (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.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..3db8bf90 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"; 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 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/VolumeService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java index eb585b98..b0894a5c 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, List 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/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