diff options
Diffstat (limited to 'src')
4 files changed, 181 insertions, 156 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/LogMessage.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/LogMessage.java index 4f6347dc..15c758a1 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/LogMessage.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/LogMessage.java @@ -30,6 +30,7 @@ import com.gluster.storage.management.core.utils.StringUtil; @XmlRootElement public class LogMessage implements Filterable { private Date timestamp; + // TODO: Replace disk with brick, rename class as VolumeLogMessage private String disk; private String severity; private String message; diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java index d020a35e..9e7e8025 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java @@ -88,6 +88,7 @@ public class GlusterServersResource extends AbstractServersResource { ClusterInfo cluster = clusterDao.findBy("name = ?1", clusterName).get(0); for(ServerInfo serverInfo : cluster.getServers()) { GlusterServer server = new GlusterServer(serverInfo.getName()); + server.setStatus(SERVER_STATUS.ONLINE); try { fetchServerDetails(server); // server is online. add it to cache and return diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java index 9a5ee0c5..1a95fac5 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java @@ -110,8 +110,6 @@ public class VolumesResource { private FileUtil fileUtil = new FileUtil(); - private GlusterCoreUtil glusterCoreUtil = new GlusterCoreUtil(); - @InjectParam private VolumeOptionsDefaults volumeOptionsDefaults; @@ -140,12 +138,28 @@ public class VolumesResource { @Consumes(MediaType.TEXT_XML) @Produces(MediaType.TEXT_XML) public Status createVolume(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, Volume volume) { - // TODO: Create volume on given cluster - // Create the directories for the volume - List<String> brickDirectories = glusterCoreUtil.getQualifiedBrickList(volume.getBricks()); - Status status = glusterUtil.createVolume(volume, brickDirectories); + List<String> brickDirectories = GlusterCoreUtil.getQualifiedBrickList(volume.getBricks()); + + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + Status status = null; + try { + status = glusterUtil.createVolume(volume, brickDirectories, onlineServer.getName()); + } catch(ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + status = glusterUtil.createVolume(volume, brickDirectories, onlineServer.getName()); + } + if (status.isSuccess()) { - Status optionsStatus = glusterUtil.createOptions(volume); + // volume created. set the options. + Status optionsStatus = glusterUtil.createOptions(volume, onlineServer.getName()); if (!optionsStatus.isSuccess()) { status.setCode(Status.STATUS_CODE_PART_SUCCESS); status.setMessage("Error while setting volume options: " + optionsStatus); @@ -183,14 +197,31 @@ public class VolumesResource { @Produces(MediaType.TEXT_XML) public Status performOperation(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_OPERATION) String operation) { - // TODO: Perform the operation on given cluster - if (operation.equals(FORM_PARAM_VALUE_START)) { - return glusterUtil.startVolume(volumeName); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + try { + return performOperation(volumeName, operation, onlineServer); + } catch (ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + return performOperation(volumeName, operation, onlineServer); } - if (operation.equals(FORM_PARAM_VALUE_STOP)) { - return glusterUtil.stopVolume(volumeName); + } + + private Status performOperation(String volumeName, String operation, GlusterServer onlineServer) { + if (operation.equals(FORM_PARAM_VALUE_START)) { + return glusterUtil.startVolume(volumeName, onlineServer.getName()); + } else if (operation.equals(FORM_PARAM_VALUE_STOP)) { + return glusterUtil.stopVolume(volumeName, onlineServer.getName()); + } else { + return new Status(Status.STATUS_CODE_FAILURE, "Invalid operation code [" + operation + "]"); } - return new Status(Status.STATUS_CODE_FAILURE, "Invalid operation code [" + operation + "]"); } @DELETE @@ -238,16 +269,25 @@ public class VolumesResource { @QueryParam(QUERY_PARAM_DELETE_OPTION) boolean deleteFlag) { List<String> brickList = Arrays.asList(bricks.split(",")); // Convert from comma separated string (query parameter) - // TODO: pass clusterName to removeBricks - Status status = glusterUtil.removeBricks(volumeName, brickList); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } - String deleteOption = ""; - if (deleteFlag) { - deleteOption = "-d"; + Status status = null; + try { + status = glusterUtil.removeBricks(volumeName, brickList, onlineServer.getName()); + } catch(ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + status = glusterUtil.removeBricks(volumeName, brickList, onlineServer.getName()); } if (status.isSuccess()) { - Status cleanupStatus = cleanupDirectories(brickList, volumeName, brickList.size(), deleteOption); + Status cleanupStatus = cleanupDirectories(brickList, volumeName, brickList.size(), deleteFlag); if (!cleanupStatus.isSuccess()) { // append cleanup error to prepare brick error status.setMessage(status.getMessage() + CoreConstants.NEWLINE + cleanupStatus.getMessage()); @@ -279,8 +319,21 @@ public class VolumesResource { @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName, @FormParam(RESTConstants.FORM_PARAM_OPTION_KEY) String key, @FormParam(RESTConstants.FORM_PARAM_OPTION_VALUE) String value) { - // TODO: pass cluster name to setOption - return glusterUtil.setOption(volumeName, key, value); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + try { + return glusterUtil.setOption(volumeName, key, value, onlineServer.getName()); + } catch(ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + return glusterUtil.setOption(volumeName, key, value, onlineServer.getName()); + } } @PUT @@ -288,8 +341,22 @@ public class VolumesResource { @Produces(MediaType.TEXT_XML) public Status resetOptions(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(PATH_PARAM_VOLUME_NAME) String volumeName) { - // TODO: pass clusterName to resetOptions - return glusterUtil.resetOptions(volumeName); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if (onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + try { + return glusterUtil.resetOptions(volumeName, onlineServer.getName()); + } catch (ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if (onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + + "]"); + } + return glusterUtil.resetOptions(volumeName, onlineServer.getName()); + } } @GET @@ -302,56 +369,7 @@ public class VolumesResource { } @SuppressWarnings("rawtypes") - private Status prepareBrick(String serverName, String diskName, String volumeName) { - Object response = serverUtil.executeOnServer(true, serverName, PREPARE_BRICK_SCRIPT + " " + diskName + " " - + volumeName, GenericResponse.class); - if (response instanceof GenericResponse) { - return ((GenericResponse) response).getStatus(); - } else { - // in case of script failure on server, a Status object will be returned - return (Status) response; - } - } - - private Status createDirectories(List<String> disks, String volumeName) { - List<String> bricks = new ArrayList<String>(); - Status status = null; - for (int i = 0; i < disks.size(); i++) { - String disk = disks.get(i); - - String[] diskParts = disk.split(":"); - String serverName = diskParts[0]; - String diskName = diskParts[1]; - - status = prepareBrick(serverName, diskName, volumeName); - if (status.isSuccess()) { - String brickDir = status.getMessage().trim(); - bricks.add(serverName + ":" + brickDir); - } else { - // Brick preparation failed. Cleanup directories already created and return failure status - Status cleanupStatus = cleanupDirectories(disks, volumeName, i + 1, "-d"); // delete permanently - if (!cleanupStatus.isSuccess()) { - // append cleanup error to prepare brick error - status.setMessage(status.getMessage() + CoreConstants.NEWLINE + cleanupStatus.getMessage()); - } - return status; - } - } - status.setMessage(bricksAsString(bricks)); - return status; - } - - // TODO Can be removed and use StringUtil.ListToString(List<String> list, String delimiter) - private String bricksAsString(List<String> bricks) { - String bricksStr = ""; - for (String brickInfo : bricks) { - bricksStr += brickInfo + " "; - } - return bricksStr.trim(); - } - - @SuppressWarnings("rawtypes") - private Status cleanupDirectories(List<String> disks, String volumeName, int maxIndex, String deleteFlag) { + private Status cleanupDirectories(List<String> disks, String volumeName, int maxIndex, boolean deleteFlag) { String serverName, diskName, diskInfo[]; Status result; for (int i = 0; i < maxIndex; i++) { @@ -360,7 +378,7 @@ public class VolumesResource { diskName = diskInfo[1]; Object response = serverUtil.executeOnServer(true, serverName, VOLUME_DIRECTORY_CLEANUP_SCRIPT + " " - + diskName + " " + volumeName + " " + deleteFlag, GenericResponse.class); + + diskName + " " + volumeName + " " + (deleteFlag ? "-d" : ""), GenericResponse.class); if (response instanceof GenericResponse) { result = ((GenericResponse) response).getStatus(); if (!result.isSuccess()) { @@ -376,20 +394,15 @@ public class VolumesResource { return new Status(Status.STATUS_CODE_SUCCESS, "Directories cleaned up successfully!"); } - private List<LogMessage> getBrickLogs(Volume volume, String brickName, Integer lineCount) + private List<LogMessage> getBrickLogs(Volume volume, Brick brick, Integer lineCount) throws GlusterRuntimeException { - // brick name format is <serverName>:<brickDirectory> - String[] brickParts = brickName.split(":"); - String serverName = brickParts[0]; - String brickDir = brickParts[1]; - - String logDir = glusterUtil.getLogLocation(volume.getName(), brickName); - String logFileName = glusterUtil.getLogFileNameForBrickDir(brickDir); + String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getQualifiedName(), brick.getServerName()); + String logFileName = glusterUtil.getLogFileNameForBrickDir(brick.getBrickDirectory()); String logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; // Usage: get_volume_disk_log.py <volumeName> <diskName> <lineCount> - Object responseObj = serverUtil.executeOnServer(true, serverName, VOLUME_BRICK_LOG_SCRIPT + " " + logFilePath - + " " + lineCount, LogMessageListResponse.class); + Object responseObj = serverUtil.executeOnServer(true, brick.getServerName(), VOLUME_BRICK_LOG_SCRIPT + " " + + logFilePath + " " + lineCount, LogMessageListResponse.class); Status status = null; LogMessageListResponse response = null; if (responseObj instanceof LogMessageListResponse) { @@ -406,7 +419,7 @@ public class VolumesResource { // populate disk and trim other fields List<LogMessage> logMessages = response.getLogMessages(); for (LogMessage logMessage : logMessages) { - logMessage.setDisk(getDiskForBrick(volume, brickName)); + logMessage.setDisk(brick.getDiskName()); logMessage.setMessage(logMessage.getMessage().trim()); logMessage.setSeverity(logMessage.getSeverity().trim()); } @@ -442,7 +455,7 @@ public class VolumesResource { String tempDirPath = tempDir.getPath(); for (Brick brick : volume.getBricks()) { - String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getBrickDirectory()); + String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getBrickDirectory(), brick.getServerName()); String logFileName = glusterUtil.getLogFileNameForBrickDir(brick.getBrickDirectory()); String logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; @@ -478,7 +491,12 @@ public class VolumesResource { logMessages = getLogsForAllBricks(volume, lineCount); } else { // fetch logs for given brick of the volume - logMessages = getBrickLogs(volume, brickName, lineCount); + for(Brick brick : volume.getBricks()) { + if(brick.getQualifiedName().equals(brickName)) { + logMessages = getBrickLogs(volume, brick, lineCount); + break; + } + } } } catch (Exception e) { return new LogMessageListResponse(new Status(e), null); @@ -534,7 +552,7 @@ public class VolumesResource { logMessages = new ArrayList<LogMessage>(); // fetch logs for every brick of the volume for (Brick brick : volume.getBricks()) { - logMessages.addAll(getBrickLogs(volume, brick.getBrickDirectory(), lineCount)); + logMessages.addAll(getBrickLogs(volume, brick, lineCount)); } // Sort the log messages based on log timestamp @@ -552,7 +570,21 @@ public class VolumesResource { @Path("{" + QUERY_PARAM_VOLUME_NAME + "}/" + RESOURCE_DISKS) public Status addBricks(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_BRICKS) String bricks) { - return glusterUtil.addBricks(volumeName, Arrays.asList(bricks.split(","))); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + try { + return glusterUtil.addBricks(volumeName, Arrays.asList(bricks.split(",")), onlineServer.getName()); + } catch(ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + return glusterUtil.addBricks(volumeName, Arrays.asList(bricks.split(",")), onlineServer.getName()); + } } @PUT @@ -560,13 +592,21 @@ public class VolumesResource { public Status replaceDisk(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, @PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, @FormParam(FORM_PARAM_SOURCE) String diskFrom, @FormParam(FORM_PARAM_TARGET) String diskTo, @FormParam(FORM_PARAM_OPERATION) String operation) { - // TODO: Migrate disk on given cluster only - return glusterUtil.migrateDisk(volumeName, diskFrom, diskTo, operation); - } - - private String getDiskForBrick(Volume volume, String brickName) { - int index = volume.getBricks().indexOf(brickName); - return volume.getDisks().get(index); + GlusterServer onlineServer = glusterServersResource.getOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + + try { + return glusterUtil.migrateDisk(volumeName, diskFrom, diskTo, operation, onlineServer.getName()); + } catch(ConnectionException e) { + // online server has gone offline! try with a different one. + onlineServer = glusterServersResource.getNewOnlineServer(clusterName); + if(onlineServer == null) { + return new Status(Status.STATUS_CODE_FAILURE, "No online servers found in cluster [" + clusterName + "]"); + } + return glusterUtil.migrateDisk(volumeName, diskFrom, diskTo, operation, onlineServer.getName()); + } } public static void main(String[] args) throws ClassNotFoundException { diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java index 7991cfb0..a101b75d 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java @@ -63,7 +63,6 @@ public class GlusterUtil { private static final String VOLUME_LOG_LOCATION_PFX = "log file location:"; private static final String VOLUME_TYPE_DISTRIBUTE = "Distribute"; private static final String VOLUME_TYPE_REPLICATE = "Replicate"; - private static final ProcessUtil processUtil = new ProcessUtil(); @Autowired private SshUtil sshUtil; @@ -177,7 +176,6 @@ public class GlusterUtil { */ private String getPeerStatus(String knownServer) { String output; - // ProcessResult result = processUtil.executeCommand("gluster", "peer", "status"); ProcessResult result = getSshUtil().executeRemote(knownServer, "gluster peer status"); if (!result.isSuccess()) { output = null; @@ -190,19 +188,19 @@ public class GlusterUtil { return new Status(sshUtil.executeRemote(existingServer, "gluster peer probe " + newServer)); } - public Status startVolume(String volumeName) { - return new Status(processUtil.executeCommand("gluster", "volume", "start", volumeName)); + public Status startVolume(String volumeName, String knownServer) { + return new Status(sshUtil.executeRemote(knownServer, "gluster volume start " + volumeName)); } - public Status stopVolume(String volumeName) { - return new Status(processUtil.executeCommand("gluster", "--mode=script", "volume", "stop", volumeName)); + public Status stopVolume(String volumeName, String knownServer) { + return new Status(sshUtil.executeRemote(knownServer, "gluster --mode=script volume stop " + volumeName)); } - public Status resetOptions(String volumeName) { - return new Status(processUtil.executeCommand("gluster", "volume", "reset", volumeName)); + public Status resetOptions(String volumeName, String knownServer) { + return new Status(sshUtil.executeRemote(knownServer, "gluster volume reset " + volumeName)); } - public Status createVolume(Volume volume, List<String> brickDirectories) { + public Status createVolume(Volume volume, List<String> brickDirectories, String knownServer) { int count = 1; // replica or stripe count String volumeType = null; VOLUME_TYPE volType = volume.getVolumeType(); @@ -217,39 +215,35 @@ public class GlusterUtil { String transportTypeStr = null; TRANSPORT_TYPE transportType = volume.getTransportType(); transportTypeStr = (transportType == TRANSPORT_TYPE.ETHERNET) ? "tcp" : "rdma"; - List<String> command = prepareVolumeCreateCommand(volume, brickDirectories, count, volumeType, transportTypeStr); - ProcessResult result = processUtil.executeCommand(command); + String command = prepareVolumeCreateCommand(volume, brickDirectories, count, volumeType, transportTypeStr); + ProcessResult result = sshUtil.executeRemote(knownServer, command); if (!result.isSuccess()) { return new Status(result); } - return createOptions(volume); + return createOptions(volume, knownServer); } - private List<String> prepareVolumeCreateCommand(Volume volume, List<String> brickDirectories, int count, + private String prepareVolumeCreateCommand(Volume volume, List<String> brickDirectories, int count, String volumeType, String transportTypeStr) { - List<String> command = new ArrayList<String>(); - command.add("gluster"); - command.add("volume"); - command.add("create"); - command.add(volume.getName()); - if (volumeType != null) { - command.add(volumeType); - command.add("" + count); + StringBuilder command = new StringBuilder("gluster volume create " + volume.getName() + " "); + if(volumeType != null) { + command.append(volumeType + " " + count + " "); + } + command.append("transport " + transportTypeStr); + for(String brickDir : brickDirectories) { + command.append(" " + brickDir); } - command.add("transport"); - command.add(transportTypeStr); - command.addAll(brickDirectories); - return command; + return command.toString(); } - public Status createOptions(Volume volume) { + public Status createOptions(Volume volume, String knownServer) { Map<String, String> options = volume.getOptions(); if (options != null) { for (Entry<String, String> option : options.entrySet()) { String key = option.getKey(); String value = option.getValue(); - Status status = setOption(volume.getName(), key, value); + Status status = setOption(volume.getName(), key, value, knownServer); if (!status.isSuccess()) { return status; } @@ -258,16 +252,9 @@ public class GlusterUtil { return Status.STATUS_SUCCESS; } - public Status setOption(String volumeName, String key, String value) { - List<String> command = new ArrayList<String>(); - command.add("gluster"); - command.add("volume"); - command.add("set"); - command.add(volumeName); - command.add(key); - command.add(value); - - return new Status(processUtil.executeCommand(command)); + public Status setOption(String volumeName, String key, String value, String knownServer) { + return new Status(sshUtil.executeRemote(knownServer, "gluster volume set " + volumeName + " " + key + " " + + value)); } public Status deleteVolume(String volumeName, String knownServer) { @@ -464,19 +451,17 @@ public class GlusterUtil { return volumes; } - public Status addBricks(String volumeName, List<String> bricks) { - List<String> command = new ArrayList<String>(); - command.add("gluster"); - command.add("volume"); - command.add("add-brick"); - command.add(volumeName); - command.addAll(bricks); - return new Status(processUtil.executeCommand(command)); + public Status addBricks(String volumeName, List<String> bricks, String knownServer) { + StringBuilder command = new StringBuilder("gluster volume add-brick " + volumeName); + for(String brickDir : bricks) { + command.append(" " + brickDir); + } + return new Status(sshUtil.executeRemote(knownServer, command.toString())); } - public String getLogLocation(String volumeName, String brickName) { - ProcessResult result = new ProcessUtil().executeCommand("gluster", "volume", "log", "locate", volumeName, - brickName); + public String getLogLocation(String volumeName, String brickName, String knownServer) { + ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume log locate " + volumeName + " " + + brickName); if (!result.isSuccess()) { throw new GlusterRuntimeException("Command [gluster volume info] failed with error: [" + result.getExitValue() + "][" + result.getOutput() + "]"); @@ -499,19 +484,17 @@ public class GlusterUtil { return logFileName; } - public Status migrateDisk(String volumeName, String fromBrick, String toBrick, String operation) { - return new Status(processUtil.executeCommand("gluster", "volume", "replace-brick", volumeName, fromBrick, - toBrick, operation)); + public Status migrateDisk(String volumeName, String fromBrick, String toBrick, String operation, String knownServer) { + return new Status(sshUtil.executeRemote(knownServer, "gluster volume replace-brick " + volumeName + " " + + fromBrick + " " + toBrick + " " + operation)); } - public Status removeBricks(String volumeName, List<String> bricks) { - List<String> command = new ArrayList<String>(); - command.add("gluster"); - command.add("volume"); - command.add("remove-brick"); - command.add(volumeName); - command.addAll(bricks); - return new Status(processUtil.executeCommand(command)); + public Status removeBricks(String volumeName, List<String> bricks, String knownServer) { + StringBuilder command = new StringBuilder("gluster volume remove-brick " + volumeName); + for(String brickDir : bricks) { + command.append(" " + brickDir); + } + return new Status(sshUtil.executeRemote(knownServer, command.toString())); } public Status removeServer(String existingServer, String serverName) { @@ -524,7 +507,7 @@ public class GlusterUtil { List<String> disks = new ArrayList<String>(); disks.add("server1:sda"); disks.add("server1:sdb"); - Status status = new GlusterUtil().addBricks("Volume3", disks); + Status status = new GlusterUtil().addBricks("Volume3", disks, "localhost"); System.out.println(status); } } |
