diff options
| author | Dhandapani <dhandapani@gluster.com> | 2011-05-25 18:16:49 +0530 |
|---|---|---|
| committer | Dhandapani <dhandapani@gluster.com> | 2011-05-25 18:16:49 +0530 |
| commit | 9130557ab0d8f0910cedc6eac17b5879ebb57be8 (patch) | |
| tree | 4ada3d7cecaf309802fde9f18a6d1a2114e0e355 /src/com.gluster.storage.management.server | |
| parent | 4d229fb2c145a9ed6905760d1481cef965c5b44d (diff) | |
| parent | 5b70e0e1270ba91fef2fe28f50b1fb87cc1e9b27 (diff) | |
Merge branch 'disk-to-brick'
Conflicts:
src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/AbstractServersResource.java
Diffstat (limited to 'src/com.gluster.storage.management.server')
2 files changed, 43 insertions, 46 deletions
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 4af22814..f84f3ef6 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 @@ -21,13 +21,14 @@ package com.gluster.storage.management.server.resources; import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_OPERATION; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_SOURCE; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_SOURCE; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_BRICKS; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_TARGET; import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_START; import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_STOP; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VALUE_TARGET; import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_VOLUME_NAME; +import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_BRICKS; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DELETE_OPTION; -import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DISKS; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DISK_NAME; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DOWNLOAD; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_FROM_TIMESTAMP; @@ -186,10 +187,10 @@ public class VolumesResource { @Path("{" + QUERY_PARAM_VOLUME_NAME + "}/" + SUBRESOURCE_DISKS) @Produces(MediaType.TEXT_XML) public Status removeBricks(@PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, - @QueryParam(QUERY_PARAM_DISKS) String disks, @QueryParam(QUERY_PARAM_DELETE_OPTION) boolean deleteFlag) { - List<String> bricks = Arrays.asList(disks.split(",")); // Convert from comma separated string (query parameter) + @QueryParam(QUERY_PARAM_BRICKS) String bricks, @QueryParam(QUERY_PARAM_DELETE_OPTION) boolean deleteFlag) { + List<String> brickList = Arrays.asList(bricks.split(",")); // Convert from comma separated string (query parameter) - Status status = glusterUtil.removeBricks(volumeName, bricks); + Status status = glusterUtil.removeBricks(volumeName, brickList); String deleteOption = ""; if (deleteFlag) { @@ -197,7 +198,7 @@ public class VolumesResource { } if (status.isSuccess()) { - Status cleanupStatus = cleanupDirectories(bricks, volumeName, bricks.size(), deleteOption); + Status cleanupStatus = cleanupDirectories(brickList, volumeName, brickList.size(), deleteOption); if (!cleanupStatus.isSuccess()) { // append cleanup error to prepare brick error status.setMessage(status.getMessage() + CoreConstants.NEWLINE + cleanupStatus.getMessage()); @@ -385,17 +386,12 @@ public class VolumesResource { File tempDir = fileUtil.createTempDir(); String tempDirPath = tempDir.getPath(); - for (String brickName : glusterCoreUtil.getQualifiedBrickList(volume.getBricks())) { - // 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); + for (Brick brick : volume.getBricks()) { + String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getBrickDirectory()); + String logFileName = glusterUtil.getLogFileNameForBrickDir(brick.getBrickDirectory()); String logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; - String logContents = serverUtil.getFileFromServer(serverName, logFilePath); + String logContents = serverUtil.getFileFromServer(brick.getServerName(), logFilePath); fileUtil.createTextFile(tempDirPath + CoreConstants.FILE_SEPARATOR + logFileName, logContents); } @@ -478,8 +474,8 @@ public class VolumesResource { List<LogMessage> logMessages; logMessages = new ArrayList<LogMessage>(); // fetch logs for every brick of the volume - for (String brick : glusterCoreUtil.getQualifiedBrickList(volume.getBricks())) { - logMessages.addAll(getBrickLogs(volume, brick, lineCount)); + for (Brick brick : volume.getBricks()) { + logMessages.addAll(getBrickLogs(volume, brick.getBrickDirectory(), lineCount)); } // Sort the log messages based on log timestamp @@ -495,15 +491,15 @@ public class VolumesResource { @POST @Path("{" + QUERY_PARAM_VOLUME_NAME + "}/" + SUBRESOURCE_DISKS) - public Status addDisks(@PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, - @FormParam(QUERY_PARAM_DISKS) String disks) { - return glusterUtil.addBricks(volumeName, Arrays.asList(disks)); + public Status addBricks(@PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, + @FormParam(FORM_PARAM_BRICKS) String bricks) { + return glusterUtil.addBricks(volumeName, Arrays.asList(bricks.split(","))); } @PUT @Path("{" + QUERY_PARAM_VOLUME_NAME + "}/" + SUBRESOURCE_DISKS) public Status replaceDisk(@PathParam(QUERY_PARAM_VOLUME_NAME) String volumeName, - @FormParam(FORM_PARAM_VALUE_SOURCE) String diskFrom, @FormParam(FORM_PARAM_VALUE_TARGET) String diskTo, + @FormParam(FORM_PARAM_SOURCE) String diskFrom, @FormParam(FORM_PARAM_TARGET) String diskTo, @FormParam(FORM_PARAM_OPERATION) String operation) { return glusterUtil.migrateDisk(volumeName, diskFrom, diskTo, operation); } 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 a7ce9bc5..b7cfd2ea 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 @@ -32,6 +32,7 @@ import org.springframework.stereotype.Component; import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Brick; +import com.gluster.storage.management.core.model.Brick.BRICK_STATUS; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS; import com.gluster.storage.management.core.model.Status; @@ -63,7 +64,7 @@ public class GlusterUtil { 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; @@ -183,7 +184,7 @@ public class GlusterUtil { */ private String getPeerStatus(String knownServer) { String output; - //ProcessResult result = processUtil.executeCommand("gluster", "peer", "status"); + // ProcessResult result = processUtil.executeCommand("gluster", "peer", "status"); ProcessResult result = getSshUtil().executeRemote(knownServer, "gluster peer status"); if (!result.isSuccess()) { output = null; @@ -354,30 +355,30 @@ public class GlusterUtil { String[] brickParts = line.split(":"); String serverName = brickParts[1].trim(); String brickDir = brickParts[2].trim(); - Brick brick = new Brick(serverName, brickDir.split("/")[2].trim(), brickDir); - volume.addBrick(brick); - detectAndAddDiskToVolume(volume, serverName, brickDir); + addBrickToVolume(volume, serverName, brickDir); return true; } return false; } - private void detectAndAddDiskToVolume(Volume volume, String serverName, String brickDir) { - // brick directory should be of the form /export/<diskname>/volume-name - try { - volume.addDisk(serverName + ":" + brickDir.split("/")[2].trim()); - } catch (ArrayIndexOutOfBoundsException e) { - // brick directory of a different form, most probably created manually - // connect to the server and get disk for the brick directory - Status status = new ServerUtil().getDiskForDir(serverName, brickDir); - if (status.isSuccess()) { - volume.addDisk(serverName + ":" + status.getMessage()); - } else { - // Couldn't fetch disk for the brick directory. Log error and add "unknown" as disk name. - System.out.println("Couldn't fetch disk name for brick [" + serverName + ":" + brickDir + "]"); - volume.addDisk(serverName + ":unknown"); - } - } + private void addBrickToVolume(Volume volume, String serverName, String brickDir) { + // TODO: Brick status should be same as the server status (online/offline) + volume.addBrick(new Brick(serverName, BRICK_STATUS.ONLINE, brickDir.split("/")[2].trim(), brickDir)); + // + // try { + // volume.addDisk(serverName + ":" + brickDir.split("/")[2].trim()); + // } catch (ArrayIndexOutOfBoundsException e) { + // // brick directory of a different form, most probably created manually + // // connect to the server and get disk for the brick directory + // Status status = new ServerUtil().getDiskForDir(serverName, brickDir); + // if (status.isSuccess()) { + // volume.addDisk(serverName + ":" + status.getMessage()); + // } else { + // // Couldn't fetch disk for the brick directory. Log error and add "unknown" as disk name. + // System.out.println("Couldn't fetch disk name for brick [" + serverName + ":" + brickDir + "]"); + // volume.addDisk(serverName + ":unknown"); + // } + // } } private boolean readBrickGroup(String line) { @@ -506,9 +507,9 @@ public class GlusterUtil { return logFileName; } - public Status migrateDisk(String volumeName, String diskFrom, String diskTo, String operation) { - return new Status(processUtil.executeCommand("gluster", "volume", "replace-brick", volumeName, diskFrom, - diskTo, operation)); + 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 removeBricks(String volumeName, List<String> bricks) { |
