diff options
Diffstat (limited to 'src')
23 files changed, 143 insertions, 290 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java index e6ca0457..3d27afb2 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java @@ -30,7 +30,6 @@ import javax.ws.rs.core.MultivaluedMap; import com.gluster.storage.management.core.constants.RESTConstants; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.ServerStats; -import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.response.GlusterServerListResponse; import com.gluster.storage.management.core.utils.GlusterCoreUtil; import com.sun.jersey.api.representation.Form; diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/AbstractActionDelegate.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/AbstractActionDelegate.java index 0893952f..29481286 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/AbstractActionDelegate.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/AbstractActionDelegate.java @@ -22,7 +22,6 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ExportSshKeysAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ExportSshKeysAction.java index ac61709d..51cf49c1 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ExportSshKeysAction.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/ExportSshKeysAction.java @@ -22,8 +22,6 @@ package com.gluster.storage.management.console.actions; import org.eclipse.jface.action.IAction; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import com.gluster.storage.management.client.KeysClient; 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 aeed223f..5ae93ede 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 @@ -21,7 +21,6 @@ package com.gluster.storage.management.console.actions; import java.net.URI; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import com.gluster.storage.management.client.TasksClient; diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/CreateVolumeWizard.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/CreateVolumeWizard.java index 87f8ccd4..227c60b7 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/CreateVolumeWizard.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/dialogs/CreateVolumeWizard.java @@ -29,7 +29,6 @@ import com.gluster.storage.management.console.IImageKeys; 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; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS; import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; 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 2f271186..0dc06f6d 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 @@ -49,7 +49,6 @@ import com.gluster.storage.management.console.TableLabelProviderAdapter; import com.gluster.storage.management.console.utils.GUIHelper; import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.Device; -import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.utils.NumberUtil; diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/ClusterSummaryView.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/ClusterSummaryView.java index 48cec9f8..6187d5ad 100644 --- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/ClusterSummaryView.java +++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/views/ClusterSummaryView.java @@ -47,9 +47,9 @@ import com.gluster.storage.management.console.IImageKeys; import com.gluster.storage.management.console.actions.ActionConstants; import com.gluster.storage.management.console.preferences.PreferenceConstants; import com.gluster.storage.management.console.utils.ChartUtil; +import com.gluster.storage.management.console.utils.ChartUtil.ChartPeriodLinkListener; import com.gluster.storage.management.console.utils.ChartViewerComposite; import com.gluster.storage.management.console.utils.GUIHelper; -import com.gluster.storage.management.console.utils.ChartUtil.ChartPeriodLinkListener; import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.constants.GlusterConstants; import com.gluster.storage.management.core.model.Alert; 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 9fefc034..43853752 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 @@ -53,7 +53,6 @@ import com.gluster.storage.management.core.model.Disk; import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.Event; import com.gluster.storage.management.core.model.Event.EVENT_TYPE; -import com.gluster.storage.management.core.model.GlusterDataModel; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskInfo; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java index 11b0e6a6..b0121213 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java @@ -18,8 +18,6 @@ *******************************************************************************/ package com.gluster.storage.management.core.model; -import java.io.File; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java index ad2599a6..3662188c 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java @@ -199,7 +199,6 @@ public class Server extends Entity { * * @param server */ - @SuppressWarnings("unchecked") public void copyFrom(Server server) { setName(server.getName()); setParent(server.getParent()); diff --git a/src/com.gluster.storage.management.gateway/.settings/org.eclipse.core.resources.prefs b/src/com.gluster.storage.management.gateway/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..d159aeca --- /dev/null +++ b/src/com.gluster.storage.management.gateway/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue Sep 20 14:10:09 IST 2011 +eclipse.preferences.version=1 +encoding//src/rebel.xml=UTF-8 diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java index b495ec12..8d3784e9 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java @@ -55,11 +55,8 @@ import javax.ws.rs.core.Response; import org.springframework.stereotype.Component; -import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.constants.GlusterConstants; import com.gluster.storage.management.core.constants.RESTConstants; -import com.gluster.storage.management.core.exceptions.ConnectionException; -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.ServerStats; @@ -67,16 +64,12 @@ import com.gluster.storage.management.core.model.TaskStatus; import com.gluster.storage.management.core.response.GlusterServerListResponse; import com.gluster.storage.management.core.response.ServerNameListResponse; import com.gluster.storage.management.gateway.data.ClusterInfo; -import com.gluster.storage.management.gateway.data.ServerInfo; import com.gluster.storage.management.gateway.services.ClusterService; import com.gluster.storage.management.gateway.services.GlusterServerService; import com.gluster.storage.management.gateway.tasks.InitializeDiskTask; import com.gluster.storage.management.gateway.utils.CpuStatsFactory; -import com.gluster.storage.management.gateway.utils.GlusterUtil; import com.gluster.storage.management.gateway.utils.MemoryStatsFactory; import com.gluster.storage.management.gateway.utils.NetworkStatsFactory; -import com.gluster.storage.management.gateway.utils.ServerUtil; -import com.gluster.storage.management.gateway.utils.SshUtil; import com.gluster.storage.management.gateway.utils.StatsFactory; import com.sun.jersey.api.core.InjectParam; import com.sun.jersey.spi.resource.Singleton; 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 c0872384..eb585b98 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 @@ -42,9 +42,8 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.exceptions.GlusterValidationException; import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.GlusterServer; -import com.gluster.storage.management.core.model.Volume; -import com.gluster.storage.management.core.model.VolumeOptionInfo; import com.gluster.storage.management.core.model.Server.SERVER_STATUS; +import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.model.Volume.NAS_PROTOCOL; import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS; import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; @@ -478,7 +477,7 @@ public class VolumeService { } String gzipPath = FileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR + volume.getName() + "-logs.tar.gz"; - new ProcessUtil().executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName()); + ProcessUtil.executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName()); // delete the temp directory FileUtil.recursiveDelete(tempDir); @@ -590,7 +589,7 @@ public class VolumeService { String logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; // Usage: get_volume_disk_log.py <volumeName> <diskName> <lineCount> - LogMessageListResponse response = serverUtil.executeScriptOnServer(true, brick.getServerName(), + LogMessageListResponse response = serverUtil.executeScriptOnServer(brick.getServerName(), VOLUME_BRICK_LOG_SCRIPT + " " + logFilePath + " " + lineCount, LogMessageListResponse.class); // populate disk and trim other fields @@ -783,8 +782,8 @@ public class VolumeService { String brickDirectory = brickInfo[1]; try { - serverUtil.executeScriptOnServer(true, serverName, VOLUME_DIRECTORY_CLEANUP_SCRIPT + " " - + brickDirectory + " " + (deleteFlag ? "-d" : ""), String.class); + serverUtil.executeScriptOnServer(serverName, VOLUME_DIRECTORY_CLEANUP_SCRIPT + " " + + brickDirectory + " " + (deleteFlag ? "-d" : "")); } catch(Exception e) { logger.error("Error while cleaning brick [" + serverName + ":" + brickDirectory + "] of volume [" + volumeName + "] : " + e.getMessage(), e); @@ -843,9 +842,8 @@ public class VolumeService { String brickDirectory = brick.getBrickDirectory(); // String mountPoint = brickDirectory.substring(0, brickDirectory.lastIndexOf("/")); - serverUtil.executeScriptOnServer(true, brick.getServerName(), - VOLUME_DIRECTORY_CLEANUP_SCRIPT + " " + brickDirectory + " " + (deleteFlag ? "-d" : ""), - String.class); + serverUtil.executeScriptOnServer(brick.getServerName(), VOLUME_DIRECTORY_CLEANUP_SCRIPT + " " + + brickDirectory + " " + (deleteFlag ? "-d" : "")); } } @@ -948,14 +946,13 @@ public class VolumeService { throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]"); } - String command = "gluster volume set help-xml"; try { - return serverUtil.executeOnServer(true, onlineServer.getName(), command, VolumeOptionInfoListResponse.class); + return glusterUtil.getVolumeOptionsInfo(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) { onlineServer = clusterService.getNewOnlineServer(clusterName); - return serverUtil.executeOnServer(true, onlineServer.getName(), command, VolumeOptionInfoListResponse.class); + return glusterUtil.getVolumeOptionsInfo(onlineServer.getName()); } else { throw new GlusterRuntimeException("Fetching volume options info failed! [" + e.getMessage() + "]"); } 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 be167133..7586795a 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,16 +25,13 @@ 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.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskInfo; 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.utils.ServerUtil; -import com.gluster.storage.management.gateway.utils.SshUtil; import com.sun.jersey.core.util.Base64; public class InitializeDiskTask extends Task { @@ -122,8 +119,8 @@ public class InitializeDiskTask extends Task { private void startInitializeDisk(String serverName) { String fsTypeCommand = (getFsType().equals(GlusterConstants.FSTYPE_DEFAULT)) ? "" : " -t " + getFsType(); - String output = serverUtil.executeScriptOnServer(true, serverName, INITIALIZE_DISK_SCRIPT - + fsTypeCommand + " " + getDiskName(), String.class); + String output = serverUtil.executeScriptOnServer(serverName, INITIALIZE_DISK_SCRIPT + fsTypeCommand + " " + + getDiskName()); TaskStatus taskStatus = new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, output)); taskStatus.setPercentageSupported((getFsType().equals(GlusterConstants.FSTYPE_XFS)) ? false : true); getTaskInfo().setStatus(taskStatus); 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 4d63e872..5d321d71 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 @@ -20,7 +20,6 @@ */ package com.gluster.storage.management.gateway.tasks; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.web.context.ContextLoader; @@ -107,12 +106,11 @@ public class MigrateBrickTask extends Task { private void startMigration(String onlineServerName) { String volumeName = getTaskInfo().getReference().split("#")[0]; - ProcessResult processResult = glusterUtil.executeBrickMigration(onlineServerName, volumeName, + String output = glusterUtil.executeBrickMigration(onlineServerName, volumeName, getFromBrick(), getToBrick(), "start"); - if (processResult.getOutput().trim().matches(".*started successfully$")) { + if (output.matches(".*started successfully$")) { getTaskInfo().setStatus( - new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput().trim()))); - return; + new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, output))); } } @@ -133,12 +131,12 @@ public class MigrateBrickTask extends Task { private void pauseMigration(String onlineServer) { String volumeName = getTaskInfo().getReference().split("#")[0]; - ProcessResult processResult = glusterUtil.executeBrickMigration(onlineServer, volumeName, + String output = glusterUtil.executeBrickMigration(onlineServer, volumeName, getFromBrick(), getToBrick(), "pause"); TaskStatus taskStatus = new TaskStatus(); - if (processResult.getOutput().trim().matches(".*paused successfully$")) { + if (output.matches(".*paused successfully$")) { taskStatus.setCode(Status.STATUS_CODE_PAUSE); - taskStatus.setMessage(processResult.getOutput()); + taskStatus.setMessage(output); getTaskInfo().setStatus(taskStatus); return; } @@ -166,15 +164,13 @@ public class MigrateBrickTask extends Task { private void commitMigration(String serverName) { String volumeName = getTaskInfo().getReference().split("#")[0]; - ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, volumeName, - getFromBrick(), getToBrick(), "commit"); + String output = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(), getToBrick(), + "commit"); TaskStatus taskStatus = new TaskStatus(); - if (processResult.isSuccess()) { - if (processResult.getOutput().trim().matches(".*commit successful$")) { - taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - taskStatus.setMessage(processResult.getOutput()); - getTaskInfo().setStatus(taskStatus); - } + if (output.matches(".*commit successful$")) { + taskStatus.setCode(Status.STATUS_CODE_SUCCESS); + taskStatus.setMessage(output); + getTaskInfo().setStatus(taskStatus); } } @@ -195,12 +191,12 @@ public class MigrateBrickTask extends Task { private void stopMigration(String serverName) { String volumeName = getTaskInfo().getReference().split("#")[0]; - ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(), + String output = glusterUtil.executeBrickMigration(serverName, volumeName, getFromBrick(), getToBrick(), "abort"); TaskStatus taskStatus = new TaskStatus(); - if (processResult.getOutput().trim().matches(".*aborted successfully$")) { + if (output.matches(".*aborted successfully$")) { taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - taskStatus.setMessage(processResult.getOutput()); + taskStatus.setMessage(output); getTaskInfo().setStatus(taskStatus); } } @@ -226,34 +222,29 @@ public class MigrateBrickTask extends Task { } TaskStatus taskStatus = new TaskStatus(); - try { - String volumeName = getTaskInfo().getReference().split("#")[0]; - ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, volumeName, - getFromBrick(), getToBrick(), "status"); - String output = processResult.getOutput().trim(); - 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); + 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.setCode(Status.STATUS_CODE_FAILURE); + taskStatus.setMessage(output.replaceAll("Migration complete", "Commit pending")); } - taskStatus.setMessage(output); - } catch (Exception e) { + } 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.setMessage(e.getMessage()); } + 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 89636fdf..d81ea4bf 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 @@ -28,11 +28,9 @@ 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.utils.ServerUtil; -import com.gluster.storage.management.gateway.utils.SshUtil; import com.sun.jersey.core.util.Base64; public class RebalanceVolumeTask extends Task { @@ -80,7 +78,7 @@ public class RebalanceVolumeTask extends Task { private void startRebalance(String serverName) { String command = "gluster volume rebalance " + getTaskInfo().getReference() + " " + getLayout() + " start"; - String output = serverUtil.executeOnServer(true, serverName, command, String.class); + String output = serverUtil.executeOnServer(serverName, command); getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, output))); } diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/AbstractStatsFactory.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/AbstractStatsFactory.java index d5167e21..7f3045ba 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/AbstractStatsFactory.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/AbstractStatsFactory.java @@ -154,8 +154,8 @@ public abstract class AbstractStatsFactory implements StatsFactory { argsStr += " " + arg; } } - return serverUtil.executeScriptOnServer(true, serverName, getStatsScriptName() + argsStr + " " - + period, ServerStats.class); + return serverUtil.executeScriptOnServer(serverName, getStatsScriptName() + argsStr + " " + period, + ServerStats.class); } public abstract String getStatsScriptName(); diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java index e224b4cb..ca4821d1 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java @@ -21,7 +21,6 @@ package com.gluster.storage.management.gateway.utils; import java.sql.DriverManager; import java.sql.SQLException; -import org.apache.derby.jdbc.EmbeddedDriver; import org.apache.log4j.Logger; import com.gluster.storage.management.core.constants.CoreConstants; 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 d2366899..3bcd5826 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 @@ -20,12 +20,12 @@ */ package com.gluster.storage.management.gateway.utils; -import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -44,14 +44,11 @@ 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_STATUS; import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; -import com.gluster.storage.management.core.utils.ProcessResult; +import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse; import com.gluster.storage.management.core.utils.StringUtil; -import com.gluster.storage.management.gateway.resources.v1_0.TasksResource; @Component public class GlusterUtil { - private static final String glusterFSminVersion = "3.1"; - private static final String HOSTNAME_PFX = "Hostname:"; private static final String UUID_PFX = "Uuid:"; private static final String STATE_PFX = "State:"; @@ -76,20 +73,11 @@ public class GlusterUtil { private static final String INITIALIZE_DISK_STATUS_SCRIPT = "get_format_device_status.py"; private static final String BRICK_STATUS_SCRIPT = "get_brick_status.py"; - @Autowired - private SshUtil sshUtil; + private static final Logger logger = Logger.getLogger(GlusterUtil.class); @Autowired private ServerUtil serverUtil; - public void setSshUtil(SshUtil sshUtil) { - this.sshUtil = sshUtil; - } - - public SshUtil getSshUtil() { - return sshUtil; - } - /** * 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> @@ -118,12 +106,7 @@ public class GlusterUtil { } private String getUuid(String serverName) { - ProcessResult result = getSshUtil().executeRemote(serverName, "cat " + GLUSTERD_INFO_FILE); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't read file [" + GLUSTERD_INFO_FILE + "]. Error: " - + result.toString()); - } - return result.getOutput().split("=")[1]; + return serverUtil.executeOnServer(serverName, "cat " + GLUSTERD_INFO_FILE, String.class).split("=")[1]; } public List<GlusterServer> getGlusterServers(GlusterServer knownServer) { @@ -175,71 +158,31 @@ public class GlusterUtil { return glusterServers; } - public List<String> getGlusterServerNames(String knownServer) { - String output = getPeerStatus(knownServer); - if (output == null) { - return null; - } - - List<String> glusterServerNames = new ArrayList<String>(); - for (String line : output.split(CoreConstants.NEWLINE)) { - String hostName = extractToken(line, HOSTNAME_PFX); - if (hostName != null) { - glusterServerNames.add(hostName); - } - } - return glusterServerNames; - } - /** * @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) { - ProcessResult result = getSshUtil().executeRemote(knownServer, "gluster peer status"); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't get peer status on server [" + knownServer + "]. Error: " - + result); - } - return result.getOutput(); + return serverUtil.executeOnServer(knownServer, "gluster peer status", String.class); } public void addServer(String existingServer, String newServer) { - ProcessResult result = sshUtil.executeRemote(existingServer, "gluster peer probe " + newServer); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't probe server [" + newServer + "] from [" + existingServer - + "]. Error: " + result); - } - + serverUtil.executeOnServer(existingServer, "gluster peer probe " + newServer); // reverse peer probe to ensure that host names appear in peer status on both sides - result = sshUtil.executeRemote(newServer, "gluster peer probe " + existingServer); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't _reverse_ probe server [" + existingServer + "] from [" - + newServer + "]. Error: " + result); - } + serverUtil.executeOnServer(newServer, "gluster peer probe " + existingServer); } public void startVolume(String volumeName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume start " + volumeName); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't start volume [" + volumeName + "]! Error: " + result.toString()); - } + serverUtil.executeOnServer(knownServer, "gluster volume start " + volumeName); } public void stopVolume(String volumeName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster --mode=script volume stop " + volumeName); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't stop volume [" + volumeName + "]! Error: " + result.toString()); - } + serverUtil.executeOnServer(knownServer, "gluster --mode=script volume stop " + volumeName); } public void resetOptions(String volumeName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume reset " + volumeName); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't reset options for volume [" + volumeName + "]! Error: " - + result); - } + serverUtil.executeOnServer(knownServer, "gluster volume reset " + volumeName); } public void createVolume(String knownServer, String volumeName, String volumeTypeStr, String transportTypeStr, @@ -260,10 +203,7 @@ public class GlusterUtil { String command = prepareVolumeCreateCommand(volumeName, StringUtil.extractList(bricks, ","), count, volTypeArg, transportTypeArg); - ProcessResult result = sshUtil.executeRemote(knownServer, command); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Error in creating volume [" + volumeName + "]: " + result); - } + serverUtil.executeOnServer(knownServer, command); try { createOptions(volumeName, StringUtil.extractMap(options, ",", "="), knownServer); @@ -309,37 +249,20 @@ public class GlusterUtil { } public void setOption(String volumeName, String key, String value, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume set " + volumeName + " " + key + " " - + "\"" + value + "\""); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Volume [" + volumeName + "] set [" + key + "=" + value + "] => " - + result); - } + serverUtil.executeOnServer(knownServer, "gluster volume set " + volumeName + " " + key + " " + "\"" + + value + "\""); } public void deleteVolume(String volumeName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster --mode=script volume delete " + volumeName); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't delete volume [" + volumeName + "]! Error: " + result); - } + serverUtil.executeOnServer(knownServer, "gluster --mode=script volume delete " + volumeName); } private String getVolumeInfo(String volumeName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume info " + volumeName); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Command [gluster volume info " + volumeName + "] failed on [" - + knownServer + "] with error: " + result); - } - return result.getOutput(); + return serverUtil.executeOnServer(knownServer, "gluster volume info " + volumeName, String.class); } private String getVolumeInfo(String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume info "); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Command [gluster volume info] failed on [" + knownServer - + "] with error: " + result); - } - return result.getOutput(); + return serverUtil.executeOnServer(knownServer, "gluster volume info", String.class); } private boolean readVolumeType(Volume volume, String line) { @@ -427,7 +350,7 @@ public class GlusterUtil { // Do not throw exception, Gracefully handle as Offline brick. private BRICK_STATUS getBrickStatus(String serverName, String volumeName, String brick){ try { - String output = serverUtil.executeScriptOnServer(true, serverName, BRICK_STATUS_SCRIPT + " " + volumeName + String output = serverUtil.executeScriptOnServer(serverName, BRICK_STATUS_SCRIPT + " " + volumeName + " " + brick, String.class); if (output.equals(CoreConstants.ONLINE)) { return BRICK_STATUS.ONLINE; @@ -435,6 +358,8 @@ public class GlusterUtil { return BRICK_STATUS.OFFLINE; } } catch(Exception e) { // Particularly interested on ConnectionExecption, if the server is offline + logger.warn("Exception while fetching brick status for [" + volumeName + "][" + brick + + "]. Marking it as offline!", e); return BRICK_STATUS.OFFLINE; } } @@ -543,21 +468,12 @@ public class GlusterUtil { command.append(" " + brickDir); } - ProcessResult result = sshUtil.executeRemote(knownServer, command.toString()); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Error in volume [" + volumeName + "] add-brick [" + bricks + "]: " - + result); - } + serverUtil.executeOnServer(knownServer, command.toString()); } public String getLogLocation(String volumeName, String brickName, String knownServer) { String command = "gluster volume log locate " + volumeName + " " + brickName; - ProcessResult result = sshUtil.executeRemote(knownServer, command); - if (!result.isSuccess()) { - throw new GlusterRuntimeException("Command [" + command + "] failed with error: [" + result.getExitValue() - + "][" + result.getOutput() + "]"); - } - String output = result.getOutput(); + String output = serverUtil.executeOnServer(knownServer, command, String.class); if (output.startsWith(VOLUME_LOG_LOCATION_PFX)) { return output.substring(VOLUME_LOG_LOCATION_PFX.length()).trim(); } @@ -566,13 +482,12 @@ public class GlusterUtil { + "] doesn't start with prefix [" + VOLUME_LOG_LOCATION_PFX + "]"); } - //TODO File.separator should be changed if gateway runs on windows/mac public String getLogFileNameForBrickDir(String brickDir) { String logFileName = brickDir; - if (logFileName.startsWith(File.separator)) { - logFileName = logFileName.replaceFirst(File.separator, ""); + if (logFileName.length() > 0 && logFileName.charAt(0) == '/') { + logFileName = logFileName.replaceFirst("/", ""); } - logFileName = logFileName.replaceAll(File.separator, "-") + ".log"; + logFileName = logFileName.replaceAll("/", "-") + ".log"; return logFileName; } @@ -581,46 +496,31 @@ public class GlusterUtil { for (String brickDir : bricks) { command.append(" " + brickDir); } - ProcessResult result = sshUtil.executeRemote(knownServer, command.toString()); - if(!result.isSuccess()) { - throw new GlusterRuntimeException(result.toString()); - } + serverUtil.executeOnServer(knownServer, command.toString()); } public void removeServer(String existingServer, String serverName) { - ProcessResult result = sshUtil.executeRemote(existingServer, "gluster --mode=script peer detach " + serverName); - if(!result.isSuccess()) { - throw new GlusterRuntimeException("Couldn't remove server [" + serverName + "]! Error: " + result); - } + serverUtil.executeOnServer(existingServer, "gluster --mode=script peer detach " + serverName); } public TaskStatus checkRebalanceStatus(String serverName, String volumeName) { String command = "gluster volume rebalance " + volumeName + " status"; - ProcessResult processResult = sshUtil.executeRemote(serverName, command); + String output = serverUtil.executeOnServer(serverName, command, String.class).trim(); TaskStatus taskStatus = new TaskStatus(); - if (processResult.isSuccess()) { - if (processResult.getOutput().trim().matches("^rebalance completed.*")) { - taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - } else if(processResult.getOutput().trim().matches(".*in progress.*")) { - taskStatus.setCode(Status.STATUS_CODE_RUNNING); - } else { - taskStatus.setCode(Status.STATUS_CODE_FAILURE); - } + if (output.matches("^rebalance completed.*")) { + taskStatus.setCode(Status.STATUS_CODE_SUCCESS); + } else if (output.matches(".*in progress.*")) { + taskStatus.setCode(Status.STATUS_CODE_RUNNING); } else { taskStatus.setCode(Status.STATUS_CODE_FAILURE); } - taskStatus.setMessage(processResult.getOutput()); // Common + taskStatus.setMessage(output); return taskStatus; } public void stopRebalance(String serverName, String volumeName) { String command = "gluster volume rebalance " + volumeName + " stop"; - ProcessResult processResult = sshUtil.executeRemote(serverName, command); - TaskStatus taskStatus = new TaskStatus(); - if (processResult.isSuccess()) { - taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - taskStatus.setMessage(processResult.getOutput()); - } + serverUtil.executeOnServer(serverName, command); } public TaskStatus getInitializingDeviceStatus(String serverName, String diskName) { @@ -628,7 +528,7 @@ public class GlusterUtil { TaskStatus taskStatus = new TaskStatus(); try { - initDiskStatusResponse = serverUtil.executeScriptOnServer(true, serverName, INITIALIZE_DISK_STATUS_SCRIPT + " " + initDiskStatusResponse = serverUtil.executeScriptOnServer(serverName, INITIALIZE_DISK_STATUS_SCRIPT + " " + diskName, InitDiskStatusResponse.class); } catch(RuntimeException e) { taskStatus.setCode(Status.STATUS_CODE_FAILURE); @@ -650,22 +550,13 @@ public class GlusterUtil { return taskStatus; } - public ProcessResult executeBrickMigration(String onlineServerName, String volumeName, String fromBrick, + public String executeBrickMigration(String onlineServerName, String volumeName, String fromBrick, String toBrick, String operation) { String command = "gluster volume replace-brick " + volumeName + " " + fromBrick + " " + toBrick + " " + operation; - ProcessResult processResult = sshUtil.executeRemote(onlineServerName, command); - if (!processResult.isSuccess()) { - throw new GlusterRuntimeException(processResult.toString()); - } - return processResult; + return serverUtil.executeOnServer(onlineServerName, command, String.class).trim(); } - public static void main(String args[]) { - // List<String> names = new GlusterUtil().getGlusterServerNames(); - // System.out.println(names); - List<String> disks = new ArrayList<String>(); - disks.add("server1:sda"); - disks.add("server1:sdb"); - new GlusterUtil().addBricks("Volume3", disks, "localhost"); + public VolumeOptionInfoListResponse getVolumeOptionsInfo(String serverName) { + return serverUtil.executeOnServer(serverName, "gluster volume set help-xml", VolumeOptionInfoListResponse.class); } } diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java index a3593d0c..6af08049 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java @@ -18,9 +18,6 @@ *******************************************************************************/ package com.gluster.storage.management.gateway.utils; -import java.sql.DriverManager; -import java.sql.SQLException; - import org.apache.derby.jdbc.EmbeddedDriver; import org.springframework.jdbc.datasource.SimpleDriverDataSource; import org.springframework.security.authentication.dao.ReflectionSaltSource; diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java index d31411ec..7211a086 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java @@ -40,8 +40,8 @@ import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.exceptions.ConnectionException; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Server; -import com.gluster.storage.management.core.model.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.utils.ProcessResult; import com.gluster.storage.management.core.utils.ProcessUtil; @@ -98,22 +98,19 @@ public class ServerUtil { */ public void fetchServerDetails(Server server) { try { - Server serverDetails = (Server)fetchServerDetails(server.getName()); + Server serverDetails = fetchServerDetails(server.getName()); server.copyFrom(serverDetails); // Update the details in <Server> object server.setDisks(serverDetails.getDisks()); } catch (ConnectionException e) { + logger.warn("Couldn't connect to server [" + server.getName() + "]. Marking it offline!", e); server.setStatus(SERVER_STATUS.OFFLINE); } } public boolean isServerOnline(Server server) { // fetch latest details and check if server is still online - try { - fetchServerDetails(server); - return server.isOnline(); - } catch (Exception e) { - return false; - } + fetchServerDetails(server); + return server.isOnline(); } public String fetchHostName(String serverName) { @@ -123,7 +120,7 @@ public class ServerUtil { private Server fetchServerDetails(String serverName) { // fetch standard server details like cpu, disk, memory details - return executeScriptOnServer(true, serverName, REMOTE_SCRIPT_GET_SERVER_DETAILS, Server.class); + return executeScriptOnServer(serverName, REMOTE_SCRIPT_GET_SERVER_DETAILS, Server.class); } /** @@ -202,7 +199,7 @@ public class ServerUtil { @Override public void run() { try { - result.add(executeOnServer(true, serverName, commandWithArgs, expectedClass)); + result.add(executeOnServer(serverName, commandWithArgs, expectedClass)); } catch(Exception e) { String errMsg = "Couldn't execute command [" + commandWithArgs + "] on [" + serverName + "]!"; logger.error(errMsg, e); @@ -218,7 +215,23 @@ public class ServerUtil { * Executes given script on given server. Since the remote server may contain multiple versions of backend, this * method will invoke the script present in directory of same version as the gateway. * - * @param runInForeground + * @param serverName + * @param scriptWithArgs + * The script name followed by arguments to be passed. Note that the script name should not contain path + * as it will be automatically identified by the method. + * @param expectedClass + * Class of the object expected from script execution + * @return Output (console/error) from the script execution + * @throws GlusterRuntimeException in case the remote execution fails. + */ + public String executeScriptOnServer(String serverName, String scriptWithArgs) { + return executeOnServer(serverName, getRemoteScriptDir() + File.separator + scriptWithArgs, String.class); + } + + /** + * Executes given script on given server. Since the remote server may contain multiple versions of backend, this + * method will invoke the script present in directory of same version as the gateway. + * * @param serverName * @param scriptWithArgs * The script name followed by arguments to be passed. Note that the script name should not contain path @@ -228,16 +241,15 @@ public class ServerUtil { * @return Object of the expected class from remote execution of the command. * @throws GlusterRuntimeException in case the remote execution fails. */ - public <T> T executeScriptOnServer(boolean runInForeground, String serverName, String scriptWithArgs, + public <T> T executeScriptOnServer(String serverName, String scriptWithArgs, Class<T> expectedClass) { - return executeOnServer(runInForeground, serverName, getRemoteScriptDir() + File.separator + scriptWithArgs, + return executeOnServer(serverName, getRemoteScriptDir() + File.separator + scriptWithArgs, expectedClass); } /** * Executes given command on given server * - * @param runInForeground * @param serverName * @param commandWithArgs * @param expectedClass @@ -246,7 +258,7 @@ public class ServerUtil { * ungracefully, an object of class {@link Status} will be returned. */ @SuppressWarnings("unchecked") - public <T> T executeOnServer(boolean runInForeground, String serverName, String commandWithArgs, + public <T> T executeOnServer(String serverName, String commandWithArgs, Class<T> expectedClass) { String output = executeOnServer(serverName, commandWithArgs); if (expectedClass == String.class) { @@ -256,7 +268,7 @@ public class ServerUtil { return unmarshal(expectedClass, output); } - private String executeOnServer(String serverName, String commandWithArgs) { + public String executeOnServer(String serverName, String commandWithArgs) { ProcessResult result = sshUtil.executeRemote(serverName, commandWithArgs); if (!result.isSuccess()) { @@ -316,7 +328,6 @@ public class ServerUtil { * Input string * @return Object of given expected class */ - @SuppressWarnings("unchecked") public <T> T unmarshal(Class<T> expectedClass, String input) { try { // create JAXB context and instantiate marshaller @@ -339,26 +350,6 @@ public class ServerUtil { * @return Status object containing the disk name, or error message in case the remote script fails. */ public Status getDiskForDir(String serverName, String brickDir) { - return executeScriptOnServer(true, serverName, REMOTE_SCRIPT_GET_DISK_FOR_DIR + " " + brickDir, Status.class); - } - - public static void main(String[] args) { -// ServerStats stats = new ServerUtil().fetchCPUUsageData("s1", "1d"); -// for(ServerStatsRow row : stats.getRows()) { -// System.out.println(row.getUsageData().get(2)); -// } -// JAXBContext context; -// try { -// context = JAXBContext.newInstance(ServerStats.class); -// Marshaller m = context.createMarshaller(); -// ByteArrayOutputStream out = new ByteArrayOutputStream(); -// m.marshal(stats, out); -// ServerStats stats1 = (ServerStats)new ServerUtil().unmarshal(ServerStats.class, out.toString(), false); -// for(ServerStatsRow row : stats1.getRows()) { -// System.out.println(row.getUsageData().get(2)); -// } -// } catch (JAXBException e) { -// e.printStackTrace(); -// } + return executeScriptOnServer(serverName, REMOTE_SCRIPT_GET_DISK_FOR_DIR + " " + brickDir, Status.class); } } diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java index 8222ea34..706fef31 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java @@ -23,7 +23,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.net.NoRouteToHostException; import java.util.Arrays; import org.apache.log4j.Logger; @@ -55,7 +54,6 @@ public class SshUtil { private static final String SSH_AUTHORIZED_KEYS_PATH_REMOTE = SSH_AUTHORIZED_KEYS_DIR_REMOTE + SSH_AUTHORIZED_KEYS_FILE; public static final File PRIVATE_KEY_FILE = new File(SSH_AUTHORIZED_KEYS_DIR_LOCAL + "gluster.pem"); public static final File PUBLIC_KEY_FILE = new File(SSH_AUTHORIZED_KEYS_DIR_LOCAL + "gluster.pub"); -// private static final String SCRIPT_DISABLE_SSH_PASSWORD_AUTH = "disable-ssh-password-auth.sh"; private LRUCache<String, Connection> sshConnCache = new LRUCache<String, Connection>(10); // TODO: Make user name configurable @@ -77,15 +75,23 @@ public class SshUtil { getConnectionWithPassword(serverName).close(); return true; } catch(Exception e) { + logger.warn("Couldn't connect to [" + serverName + "] with default password!", e); return false; } } + /** + * Checks if public key of management gateway is configured on given server + * + * @param serverName + * @return true if public key is configured, else false + */ public boolean isPublicKeyInstalled(String serverName) { try { getConnectionWithPubKey(serverName).close(); return true; } catch(ConnectionException e) { + logger.warn("Couldn't connect to [" + serverName + "] with public key!", e); return false; } } @@ -425,21 +431,6 @@ public class SshUtil { return executeCommand(getConnection(serverName), command); } - /** - * Checks if public key of management gateway is configured on given server - * - * @param serverName - * @return true if public key is configured, else false - */ - public boolean isPublicKeySetup(String serverName) { - try { - getConnectionWithPubKey(serverName); - return true; - } catch (Exception e) { - return false; - } - } - public void cleanup() { for (Connection conn : sshConnCache.values()) { conn.close(); diff --git a/src/com.gluster.storage.management.gateway/src/rebel.xml b/src/com.gluster.storage.management.gateway/src/rebel.xml new file mode 100644 index 00000000..0f2140c9 --- /dev/null +++ b/src/com.gluster.storage.management.gateway/src/rebel.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd"> + + <classpath> + <dir name="${rebel.workspace.path}/console/src/com.gluster.storage.management.gateway/WebContent/WEB-INF/classes"> + </dir> + </classpath> + + <web> + <link target="/"> + <dir name="${rebel.workspace.path}/console/src/com.gluster.storage.management.gateway/WebContent"> + </dir> + </link> + </web> + +</application> |