diff options
8 files changed, 249 insertions, 30 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java index b9a0ef56..a077c721 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java @@ -1,12 +1,15 @@ package com.gluster.storage.management.client;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import com.gluster.storage.management.client.utils.ClientUtil;
-import com.gluster.storage.management.core.constants.RESTConstants;
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
@@ -49,15 +52,25 @@ public abstract class AbstractClient { .get(responseClass);
}
- private Object downloadResource(WebResource res, MultivaluedMap<String, String> queryParams, Class responseClass) {
- return res.queryParams(queryParams).header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.TEXT_XML)
- .get(responseClass);
- }
-
- protected Object downloadResource(WebResource res) {
+ protected void downloadResource(WebResource res, String filePath) {
ClientResponse response = res.header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.APPLICATION_OCTET_STREAM)
.get(ClientResponse.class);
- return response;
+ try {
+ if(!response.hasEntity()) {
+ throw new GlusterRuntimeException("No entity in response!");
+ }
+
+ InputStream inputStream = response.getEntityInputStream();
+ byte[] data = new byte[inputStream.available()];
+ inputStream.read(data);
+ inputStream.close();
+
+ FileOutputStream os = new FileOutputStream(filePath);
+ os.write(data);
+ os.close();
+ } catch (IOException e) {
+ throw new GlusterRuntimeException("Error while downloading resource [" + res.getURI().getPath() + "]", e);
+ }
}
/**
@@ -104,8 +117,8 @@ public abstract class AbstractClient { return fetchResource(resource.path(subResourceName), NO_PARAMS, responseClass);
}
- protected Object downloadSubResource(String subResourceName) {
- return downloadResource(resource.path(subResourceName));
+ protected void downloadSubResource(String subResourceName, String filePath) {
+ downloadResource(resource.path(subResourceName), filePath);
}
/**
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java index f1464211..c0ce8620 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java @@ -141,8 +141,8 @@ public class VolumesClient extends AbstractClient { queryParams, LogMessageListResponse.class); } - public void downloadLogs(String volumeName) { - downloadSubResource((volumeName) + "/" + RESTConstants.SUBRESOURCE_LOGS + "/" + RESTConstants.SUBRESOURCE_DOWNLOAD); + public void downloadLogs(String volumeName, String filePath) { + downloadSubResource((volumeName) + "/" + RESTConstants.SUBRESOURCE_LOGS + "/" + RESTConstants.SUBRESOURCE_DOWNLOAD, filePath); } public Status removeBricks(String volumeName, List<Disk> diskList, boolean deleteOption) { @@ -258,7 +258,7 @@ public class VolumesClient extends AbstractClient { // // Status status = client.addDisks("Volume3", disks); // System.out.println(status.getMessage()); - client.downloadLogs("vol1"); + client.downloadLogs("vol1", "/tmp/temp1.tar.gz"); } } } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java index c6394a3e..8c77fbab 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java @@ -20,27 +20,32 @@ package com.gluster.storage.management.core.utils; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.UUID; +import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; public class FileUtil { public String readFileAsString(File file) { try { - FileInputStream fileInputStream = new FileInputStream(file); - byte[] data = new byte[fileInputStream.available()]; - fileInputStream.read(data); - fileInputStream.close(); - - return new String(data); + return new String(readFileAsByteArray(file), CoreConstants.ENCODING_UTF8); } catch (Exception e) { e.printStackTrace(); throw new GlusterRuntimeException("Could not read file [" + file + "]", e); } } + + public byte[] readFileAsByteArray(File file) throws FileNotFoundException, IOException { + FileInputStream fileInputStream = new FileInputStream(file); + byte[] data = new byte[fileInputStream.available()]; + fileInputStream.read(data); + fileInputStream.close(); + return data; + } public InputStream loadResource(String resourcePath) { return this.getClass().getClassLoader().getResourceAsStream(resourcePath); @@ -50,6 +55,7 @@ public class FileUtil { try { FileWriter writer = new FileWriter(fileName); writer.write(contents); + writer.close(); } catch (Exception e) { throw new GlusterRuntimeException("Exception while trying to create text file [" + fileName + "]", e); } diff --git a/src/com.gluster.storage.management.gui.feature/feature.xml b/src/com.gluster.storage.management.gui.feature/feature.xml index 06df1a47..426201bf 100644 --- a/src/com.gluster.storage.management.gui.feature/feature.xml +++ b/src/com.gluster.storage.management.gui.feature/feature.xml @@ -785,4 +785,116 @@ install-size="0" version="0.0.0"/> + <plugin + id="org.eclipse.help.ui" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.help.webapp" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.help.base" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.lucene.analysis" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.lucene" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.commons.el" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.commons.logging" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.jasper" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.equinox.http.registry" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.equinox.http.servlet" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.equinox.jsp.jasper" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.equinox.jsp.jasper.registry" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="javax.servlet.jsp" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.equinox.http.jetty" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.mortbay.jetty.server" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.mortbay.jetty.util" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature> diff --git a/src/com.gluster.storage.management.gui/plugin.xml b/src/com.gluster.storage.management.gui/plugin.xml index b208fc24..6c6983a3 100644 --- a/src/com.gluster.storage.management.gui/plugin.xml +++ b/src/com.gluster.storage.management.gui/plugin.xml @@ -526,6 +526,22 @@ </action> <action allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.DownloadVolumeLogsAction" + definitionId="com.gluster.storage.management.gui.commands.DownloadVolumeLogs" + icon="icons/logs.png" + id="com.gluster.storage.management.gui.actions.DownloadVolumeLogsAction" + label="Download &Logs" + menubarPath="com.gluster.storage.management.gui.menu.volume/volume" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Download all logs of the volume"> + </action> + <action + allowLabelUpdate="false" class="com.gluster.storage.management.gui.actions.ResetVolumeOptionsAction" definitionId="com.gluster.storage.management.gui.commands.ResetVolumeOptions" icon="icons/reset-options.png" diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DownloadVolumeLogsAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DownloadVolumeLogsAction.java new file mode 100644 index 00000000..88bbdf46 --- /dev/null +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/DownloadVolumeLogsAction.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + *******************************************************************************/ +package com.gluster.storage.management.gui.actions; + +import java.io.File; + +import org.eclipse.jface.action.IAction; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; + +import com.gluster.storage.management.client.GlusterDataModelManager; +import com.gluster.storage.management.client.VolumesClient; +import com.gluster.storage.management.core.model.Volume; + +/** + * + */ +public class DownloadVolumeLogsAction extends AbstractActionDelegate { + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see com.gluster.storage.management.gui.actions.AbstractActionDelegate#performAction(org.eclipse.jface.action.IAction) + */ + @Override + protected void performAction(IAction action) { + final Volume volume = (Volume)selectedEntity; + final VolumesClient client = new VolumesClient(GlusterDataModelManager.getInstance().getSecurityToken()); + + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); + dialog.setFilterNames(new String[] {"GZipped Tar"}); + dialog.setFilterExtensions(new String[] {"*.tar.gz"}); + dialog.open(); + + try { + client.downloadLogs(volume.getName(), dialog.getFilterPath() + File.separator + dialog.getFileName()); + } catch(Exception e) { + showErrorDialog("Download Volume Logs [" + volume.getName() + "]", e.getMessage()); + } + } + }); + } +} 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"; |
