diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-05-09 15:20:04 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-05-11 16:22:25 +0530 |
| commit | f0fa48ec79fde432cf06e212aedf5d638f01cf56 (patch) | |
| tree | dc782ca27902f3c623251fdf070fc3ff7f7c07df /src/com.gluster.storage.management.server | |
| parent | 2668c28ff8a4bb678304e73b156c34dc889aea8b (diff) | |
Story #42 - Volume logs download
Diffstat (limited to 'src/com.gluster.storage.management.server')
2 files changed, 12 insertions, 11 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 fe03fffd..521c6175 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 @@ -102,7 +102,11 @@ public class VolumesResource { @InjectParam private static ServerUtil serverUtil; - private final GlusterUtil glusterUtil = new GlusterUtil(); + + @InjectParam + private static GlusterUtil glusterUtil; + + private static final FileUtil fileUtil = new FileUtil(); @InjectParam private VolumeOptionsDefaults volumeOptionsDefaults; @@ -386,13 +390,9 @@ public class VolumesResource { public void write(OutputStream output) throws IOException, WebApplicationException { Volume volume = getVolume(volumeName); try { - String archiveFileName = downloadLogs(volume); - FileInputStream inputStream = new FileInputStream(archiveFileName); - int size = inputStream.available(); - byte[] data = new byte[size]; - inputStream.read(data); - inputStream.close(); - output.write(data); + File archiveFile = new File(downloadLogs(volume)); + output.write(fileUtil.readFileAsByteArray(archiveFile)); + archiveFile.delete(); } catch (Exception e) { e.printStackTrace(); throw new GlusterRuntimeException("Exception while downloading/archiving volume log files!", e); @@ -402,8 +402,6 @@ public class VolumesResource { } private String downloadLogs(Volume volume) { - FileUtil fileUtil = new FileUtil(); - // create temporary directory File tempDir = fileUtil.createTempDir(); String tempDirPath = tempDir.getPath(); @@ -423,7 +421,7 @@ public class VolumesResource { } String gzipPath = fileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR + volume.getName() + "-logs.tar.gz"; - new ProcessUtil().executeCommand("tar", "czvf", gzipPath, tempDirPath); + new ProcessUtil().executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName()); // delete the temp directory fileUtil.recursiveDelete(tempDir); 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 476b5a14..14117aff 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 @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.springframework.stereotype.Component; + import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.constants.RESTConstants; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; @@ -38,6 +40,7 @@ import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; import com.gluster.storage.management.core.utils.ProcessResult; import com.gluster.storage.management.core.utils.ProcessUtil; +@Component public class GlusterUtil { private static final String glusterFSminVersion = "3.1"; |
