diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-04-26 20:09:44 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-04-28 20:40:49 +0530 |
| commit | 636888037a6fced0753e0095b61edf5fde771a2a (patch) | |
| tree | 7d3be83529bfaa1f5a675ca8f26cc61453782f57 /src/com.gluster.storage.management.server | |
| parent | beb2b3893fcde1be5fe1f272637dbdf3e7840287 (diff) | |
Story#34 - Volume logs
Diffstat (limited to 'src/com.gluster.storage.management.server')
3 files changed, 83 insertions, 39 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 e30462f2..11e12977 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 @@ -24,10 +24,10 @@ import static com.gluster.storage.management.core.constants.RESTConstants.FORM_P 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.PATH_PARAM_VOLUME_NAME; +import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DELETE_OPTION; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DISK_NAME; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_LINE_COUNT; import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_VOLUME_NAME; -import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DELETE_OPTION; import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_VOLUMES; import static com.gluster.storage.management.core.constants.RESTConstants.SUBRESOURCE_DEFAULT_OPTIONS; import static com.gluster.storage.management.core.constants.RESTConstants.SUBRESOURCE_LOGS; @@ -72,7 +72,7 @@ import com.sun.jersey.spi.resource.Singleton; public class VolumesResource { private static final String PREPARE_BRICK_SCRIPT = "create_volume_directory.py"; private static final String VOLUME_DIRECTORY_CLEANUP_SCRIPT = "clear_volume_directory.py"; - private static final String VOLUME_DISK_LOG_SCRIPT = "get_volume_disk_log.py"; + private static final String VOLUME_BRICK_LOG_SCRIPT = "get_volume_brick_log.py"; @InjectParam private static ServerUtil serverUtil; @@ -261,28 +261,32 @@ public class VolumesResource { return new Status(Status.STATUS_CODE_SUCCESS, "Directories cleaned up successfully!"); } - private List<LogMessage> getDiskLogs(String volumeName, String diskName, Integer lineCount) + private List<LogMessage> getBrickLogs(Volume volume, String brickName, Integer lineCount) throws GlusterRuntimeException { - String[] diskParts = diskName.split(":"); - String server = diskParts[0]; - String disk = diskParts[1]; + // 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 logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; // Usage: get_volume_disk_log.py <volumeName> <diskName> <lineCount> - Status logStatus = (Status) serverUtil.executeOnServer(true, server, VOLUME_DISK_LOG_SCRIPT + " " + volumeName - + " " + disk + " " + lineCount, Status.class); - if (!logStatus.isSuccess()) { - throw new GlusterRuntimeException(logStatus.toString()); + LogMessageListResponse response = ((LogMessageListResponse) serverUtil.executeOnServer(true, serverName, VOLUME_BRICK_LOG_SCRIPT + + " " + logFilePath + " " + lineCount, LogMessageListResponse.class)); + Status status = response.getStatus(); + if (!response.getStatus().isSuccess()) { + throw new GlusterRuntimeException(status.toString()); } - return extractLogMessages(logStatus.getMessage()); - } - - private List<LogMessage> extractLogMessages(String logContent) { - List<LogMessage> logMessages = new ArrayList<LogMessage>(); - for (String logMessage : logContent.split(CoreConstants.NEWLINE)) { - logMessages.add(new LogMessage(logMessage)); + // populate disk and trim other fields + List<LogMessage> logMessages = response.getLogMessages(); + for(LogMessage logMessage : logMessages) { + logMessage.setDisk(getDiskForBrick(volume, brickName)); + logMessage.setMessage(logMessage.getMessage().trim()); + logMessage.setSeverity(logMessage.getSeverity().trim()); } - return logMessages; } @@ -293,16 +297,16 @@ public class VolumesResource { List<LogMessage> logMessages = null; try { + Volume volume = getVolume(volumeName); if (diskName == null || diskName.isEmpty()) { logMessages = new ArrayList<LogMessage>(); // fetch logs for every brick of the volume - Volume volume = getVolume(volumeName); - for (String volumeDisk : volume.getDisks()) { - logMessages.addAll(getDiskLogs(volumeName, volumeDisk, lineCount)); + for (String brick : volume.getBricks()) { + logMessages.addAll(getBrickLogs(volume, brick, lineCount)); } } else { // fetch logs for given brick of the volume - logMessages = getDiskLogs(volumeName, diskName, lineCount); + logMessages = getBrickLogs(volume, getBrickForDisk(volume, diskName), lineCount); } } catch (Exception e) { return new LogMessageListResponse(new Status(e), null); @@ -311,6 +315,16 @@ public class VolumesResource { return new LogMessageListResponse(Status.STATUS_SUCCESS, logMessages); } + private String getBrickForDisk(Volume volume, String diskName) { + int index = volume.getDisks().indexOf(diskName); + return volume.getBricks().get(index); + } + + private String getDiskForBrick(Volume volume, String brickName) { + int index = volume.getBricks().indexOf(brickName); + return volume.getDisks().get(index); + } + public static void main(String[] args) throws ClassNotFoundException { VolumesResource vr = new VolumesResource(); // VolumeListResponse response = vr.getAllVolumes(); 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 6a60962f..6e6e7e14 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 @@ -52,6 +52,7 @@ public class GlusterUtil { private static final String VOLUME_BRICKS_GROUP_PFX = "Bricks"; private static final String VOLUME_OPTIONS_RECONFIG_PFX = "Options Reconfigured"; private static final String VOLUME_OPTION_AUTH_ALLOW = "auth.allow:"; + private static final String VOLUME_LOG_LOCATION_PFX = "log file location:"; private static final ProcessUtil processUtil = new ProcessUtil(); @@ -289,25 +290,31 @@ public class GlusterUtil { String[] brickParts = line.split(":"); String serverName = brickParts[1].trim(); String brickDir = brickParts[2].trim(); - // 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"); - } - } + + volume.addBrick(serverName + ":" + brickDir); + detectAndAddDiskToVolume(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 boolean readBrickGroup(String line) { return extractToken(line, VOLUME_BRICKS_GROUP_PFX) != null; @@ -399,6 +406,31 @@ public class GlusterUtil { return volumes; } + public String getLogLocation(String volumeName, String brickName) { + ProcessResult result = new ProcessUtil().executeCommand("gluster", "volume", "log", "locate", volumeName, + brickName); + if (!result.isSuccess()) { + throw new GlusterRuntimeException("Command [gluster volume info] failed with error: [" + + result.getExitValue() + "][" + result.getOutput() + "]"); + } + String output = result.getOutput(); + if (output.startsWith(VOLUME_LOG_LOCATION_PFX)) { + return output.substring(VOLUME_LOG_LOCATION_PFX.length()).trim(); + } + + throw new GlusterRuntimeException("Couldn't parse output of [volume log locate] command. [" + output + + "] doesn't start with prefix [" + VOLUME_LOG_LOCATION_PFX + "]"); + } + + public String getLogFileNameForBrickDir(String brickDir) { + String logFileName = brickDir; + if(logFileName.startsWith(CoreConstants.FILE_SEPARATOR)) { + logFileName = logFileName.replaceFirst(CoreConstants.FILE_SEPARATOR, ""); + } + logFileName = logFileName.replaceAll(CoreConstants.FILE_SEPARATOR, "-") + ".log"; + return logFileName; + } + public static void main(String args[]) { // List<String> names = new GlusterUtil().getGlusterServerNames(); // System.out.println(names); diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java index 47657c2a..5e423f1c 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java @@ -93,8 +93,6 @@ public class ServerUtil { } connection.close(); - System.out.println("The ouput string is : " + output.toString()); - return unmarshal(expectedClass, output.toString(), expectedClass != Status.class); } catch(Exception e) { // any other exception means unexpected error. return status with error from exception. |
