diff options
author | Dhandapani <dhandapani@gluster.com> | 2011-09-28 15:51:45 +0530 |
---|---|---|
committer | Dhandapani <dhandapani@gluster.com> | 2011-09-28 15:52:39 +0530 |
commit | 41443888c6cfbc9d5debb675df9f484d1a9131bb (patch) | |
tree | a48d9336666610b3924e1e040d6f94d4152f0f19 | |
parent | db1784e5e95ea4c4a2b0ab41da862868834099d0 (diff) |
Story #41: Volume Log Rotate
7 files changed, 130 insertions, 1 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..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"> </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="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&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/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..a0c9e515 --- /dev/null +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java @@ -0,0 +1,69 @@ +package com.gluster.storage.management.console.actions; +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.actions.AbstractActionDelegate; +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; +import com.gluster.storage.management.core.utils.StringUtil; + + +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(); + 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<String> 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<String> 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); |