summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java1
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java18
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitializeDiskTask.java4
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/MigrateBrickTask.java76
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/RebalanceVolumeTask.java2
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/AbstractStatsFactory.java4
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java184
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java65
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java24
9 files changed, 121 insertions, 257 deletions
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/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 9b6af355..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
@@ -477,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);
@@ -589,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
@@ -782,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);
@@ -842,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" : ""));
}
}
@@ -947,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 591ddef0..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
@@ -119,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 35f9ba29..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
@@ -106,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)));
}
}
@@ -132,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;
}
@@ -165,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);
}
}
@@ -194,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);
}
}
@@ -225,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 19ae0383..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
@@ -78,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/GlusterUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/GlusterUtil.java
index f41dd989..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,13 +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;
@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:";
@@ -75,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>
@@ -117,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) {
@@ -174,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,
@@ -259,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);
@@ -308,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) {
@@ -426,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;
@@ -434,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;
}
}
@@ -542,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();
}
@@ -565,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;
}
@@ -580,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) {
@@ -627,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);
@@ -649,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/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
index e491a1e7..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
@@ -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 b871e376..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
@@ -54,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
@@ -76,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;
}
}
@@ -424,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();