diff options
author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-10-01 00:21:16 -0700 |
---|---|---|
committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-10-01 00:21:16 -0700 |
commit | 6a8feefaa097a58240d064580d26275c3542fd7b (patch) | |
tree | 810c7499c5f2934f9eabaceb50f7d964240206d2 | |
parent | db6d1cb16d6e0c751ee2f8733d2d29906199c977 (diff) | |
parent | 68fd8e965a10831272bfd3ee050a070ea4caa88c (diff) |
Merge pull request #284 from Dhandapani/master
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..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&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..0e697b73 --- /dev/null +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/VolumeLogRotateAction.java @@ -0,0 +1,66 @@ +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.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(); + 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 = (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..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.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/VolumeService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java index eb585b98..eaf99c9c 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,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/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); |