summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server
diff options
context:
space:
mode:
Diffstat (limited to 'src/com.gluster.storage.management.server')
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractResource.java18
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GenericExceptionMapper.java45
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java82
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/VolumesResource.java67
4 files changed, 58 insertions, 154 deletions
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractResource.java
index c28c0da0..21b95877 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractResource.java
@@ -18,22 +18,17 @@
*******************************************************************************/
package com.gluster.storage.management.server.resources.v1_0;
+import java.io.IOException;
+import java.io.OutputStream;
import java.net.URI;
-import java.util.ArrayList;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriInfo;
-import com.gluster.storage.management.core.constants.RESTConstants;
-import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
-import com.gluster.storage.management.core.model.Volume;
-import com.gluster.storage.management.core.response.VolumeListResponse;
-
/**
*
*/
@@ -170,4 +165,13 @@ public class AbstractResource {
protected Response streamingOutputResponse(StreamingOutput output) {
return Response.ok(output).type(MediaType.APPLICATION_OCTET_STREAM).build();
}
+
+ protected StreamingOutput createStreamingOutput(final byte[] data) {
+ return new StreamingOutput() {
+ @Override
+ public void write(OutputStream output) throws IOException {
+ output.write(data);
+ }
+ };
+ }
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GenericExceptionMapper.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GenericExceptionMapper.java
deleted file mode 100644
index 4cd7f4f9..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GenericExceptionMapper.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * 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.server.resources.v1_0;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-
-import com.gluster.storage.management.core.exceptions.GlusterValidationException;
-
-@Provider
-public class GenericExceptionMapper implements ExceptionMapper<Exception> {
-
- /* (non-Javadoc)
- * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
- */
- @Override
- public Response toResponse(Exception exception) {
- ResponseBuilder builder;
- if (exception instanceof GlusterValidationException) {
- builder = Response.status(Response.Status.BAD_REQUEST);
- } else {
- builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
- }
- return builder.entity(exception.getMessage()).type(MediaType.TEXT_PLAIN).build();
- }
-}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
index af64af47..f04fc5da 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
@@ -35,10 +35,10 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
+
+import org.apache.log4j.Logger;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.utils.FileUtil;
@@ -49,31 +49,18 @@ import com.sun.jersey.multipart.FormDataParam;
@Path(RESOURCE_PATH_KEYS)
public class KeysResource extends AbstractResource {
- ProcessUtil processUtil = new ProcessUtil();
+ private static final Logger logger = Logger.getLogger(KeysResource.class);
+ private ProcessUtil processUtil = new ProcessUtil();
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportSshkeys() {
- try {
- StreamingOutput output = new StreamingOutput() {
-
- @Override
- public void write(OutputStream output) throws IOException, WebApplicationException {
- try {
- File archiveFile = new File(createSskKeyZipFile());
- output.write(FileUtil.readFileAsByteArray(archiveFile));
- archiveFile.delete();
- } catch (Exception e) {
- output.write(("Exception while archiving SSH Key files : " + e.getMessage()).getBytes());
- }
- }
- };
- return streamingOutputResponse(output);
- } catch (Exception e) {
- return errorResponse("Exporting SSH keys failed! [" + e.getMessage() + "]");
- }
+ File archiveFile = new File(createSskKeyZipFile());
+ byte[] data = FileUtil.readFileAsByteArray(archiveFile);
+ archiveFile.delete();
+ return streamingOutputResponse(createStreamingOutput(data));
}
-
+
private String createSskKeyZipFile() {
String targetDir = System.getProperty("java.io.tmpdir");
String zipFile = targetDir + "ssh-keys.tar";
@@ -108,8 +95,11 @@ public class KeysResource extends AbstractResource {
}
// To remove the copied key files
- processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile); // Ignore the errors if any
-
+ try {
+ processUtil.executeCommand("rm", "-f", targetPemFile, targetPubKeyFile); // Ignore the errors if any
+ } catch (Exception e) {
+ logger.warn(e.toString());
+ }
return zipFile;
}
@@ -118,36 +108,32 @@ public class KeysResource extends AbstractResource {
public Response importSshKeys(@FormDataParam("file") InputStream uploadedInputStream) {
File uploadedFile = new File(System.getProperty("java.io.tmpdir") + File.separator + "keys.tar");
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- try {
- writeToFile(uploadedInputStream, uploadedFile.getAbsolutePath());
- // To backup existing SSH pem and public keys
- if (SshUtil.PEM_FILE.isFile()) {
- if (!SshUtil.PEM_FILE.renameTo(new File(SshUtil.PEM_FILE.getAbsolutePath() + "-" + timestamp))) {
- throw new GlusterRuntimeException("Unable to backup pem key!");
- }
- }
+ writeToFile(uploadedInputStream, uploadedFile.getAbsolutePath());
- if (SshUtil.PUBLIC_KEY_FILE.isFile()) {
- if (!SshUtil.PUBLIC_KEY_FILE.renameTo(new File(SshUtil.PUBLIC_KEY_FILE.getAbsolutePath() + "-"
- + timestamp))) {
- throw new GlusterRuntimeException("Unable to backup public key!");
- }
+ // To backup existing SSH pem and public keys, if exist.
+ if (SshUtil.PEM_FILE.isFile()) {
+ if (!SshUtil.PEM_FILE.renameTo(new File(SshUtil.PEM_FILE.getAbsolutePath() + "-" + timestamp))) {
+ throw new GlusterRuntimeException("Unable to backup pem key!");
}
- // Extract SSH pem and public key files.
- ProcessResult output = processUtil.executeCommand("tar", "xvf", uploadedFile.getName(), "-C",
- SshUtil.SSH_AUTHORIZED_KEYS_DIR);
- uploadedFile.delete();
- if (output.isSuccess()) {
- return createdResponse("SSH Key imported successfully");
- } else {
- return errorResponse(output.getOutput());
+ }
+
+ if (SshUtil.PUBLIC_KEY_FILE.isFile()) {
+ if (!SshUtil.PUBLIC_KEY_FILE
+ .renameTo(new File(SshUtil.PUBLIC_KEY_FILE.getAbsolutePath() + "-" + timestamp))) {
+ throw new GlusterRuntimeException("Unable to backup public key!");
}
- } catch (Exception e) {
- return errorResponse(e.getMessage());
}
+ // Extract SSH pem and public key files.
+ ProcessResult output = processUtil.executeCommand("tar", "xvf", uploadedFile.getName(), "-C",
+ SshUtil.SSH_AUTHORIZED_KEYS_DIR);
+ uploadedFile.delete();
+ if (!output.isSuccess()) {
+ throw new GlusterRuntimeException(output.getOutput());
+ }
+ return createdResponse("SSH Key imported successfully");
}
-
+
// save uploaded file to the file (with path)
private void writeToFile(InputStream inputStream, String toFile) {
try {
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/VolumesResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/VolumesResource.java
index fb3923fc..1d0963eb 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/VolumesResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/VolumesResource.java
@@ -59,8 +59,6 @@ import static com.gluster.storage.management.core.constants.RESTConstants.TASK_S
import static com.gluster.storage.management.core.constants.RESTConstants.TASK_STOP;
import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -77,10 +75,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
+
+import org.apache.log4j.Logger;
import com.gluster.storage.management.core.constants.CoreConstants;
import com.gluster.storage.management.core.constants.RESTConstants;
@@ -114,6 +112,7 @@ import com.sun.jersey.spi.resource.Singleton;
public class VolumesResource extends AbstractResource {
private static final String VOLUME_DIRECTORY_CLEANUP_SCRIPT = "clear_volume_directory.py";
private static final String VOLUME_BRICK_LOG_SCRIPT = "get_volume_brick_log.py";
+ private static final Logger logger = Logger.getLogger(VolumesResource.class);
@InjectParam
private ServerUtil serverUtil;
@@ -687,30 +686,20 @@ public class VolumesResource extends AbstractResource {
if (clusterService.getCluster(clusterName) == null) {
return notFoundResponse("Cluster [" + clusterName + "] not found!");
}
-
+
try {
final Volume volume = getVolume(clusterName, volumeName);
- StreamingOutput output = new StreamingOutput() {
-
- @Override
- public void write(OutputStream output) throws IOException, WebApplicationException {
- try {
- File archiveFile = new File(downloadLogs(volume));
- output.write(FileUtil.readFileAsByteArray(archiveFile));
- archiveFile.delete();
- } catch (Exception e) {
- // TODO: Log the exception
- e.printStackTrace();
- String errMsg = "Exception while downloading/archiving volume log files : " + e.getMessage();
- output.write(errMsg.getBytes());
- }
- }
- };
- return streamingOutputResponse(output);
- } catch(Exception e) {
- return errorResponse("Volume [" + volumeName + "] doesn't exist in cluster [" + clusterName + "]!");
+ File archiveFile = new File(downloadLogs(volume));
+ byte[] data = FileUtil.readFileAsByteArray(archiveFile);
+ archiveFile.delete();
+ return streamingOutputResponse(createStreamingOutput(data));
+ } catch (Exception e) {
+ logger.error("Volume [" + volumeName + "] doesn't exist in cluster [" + clusterName + "]! ["
+ + e.getStackTrace() + "]");
+ throw (GlusterRuntimeException) e;
}
}
+
private String downloadLogs(Volume volume) {
// create temporary directory
@@ -996,34 +985,4 @@ public class VolumesResource extends AbstractResource {
taskResource.getTask(taskId).stop();
}
-
- public static void main(String[] args) throws ClassNotFoundException {
- VolumesResource vr = new VolumesResource();
- // VolumeListResponse response = vr.getAllVolumes();
- // for (Volume volume : response.getVolumes()) {
- // System.out.println("\nName:" + volume.getName() + "\nType: " + volume.getVolumeTypeStr() + "\nStatus: "
- // + volume.getStatusStr());
- // }
- // Volume volume = new Volume();
- // volume.setName("vol3");
- // volume.setTransportType(TRANSPORT_TYPE.ETHERNET);
- // List<String> disks = new ArrayList<String>();
- // disks.add("192.168.1.210:sdb");
- // volume.addDisks(disks);
- // volume.setAccessControlList("192.168.*");
- // // Status status = vr.createVolume(volume);
- // // System.out.println(status.getMessage());
- // Form form = new Form();
- // form.add("volumeName", volume.getName());
- // form.add(RESTConstants.FORM_PARAM_DELETE_OPTION, 1);
- // Status status = vr.deleteVolume("Vol2", true);
- // System.out.println("Code : " + status.getCode());
- // System.out.println("Message " + status.getMessage());
-
- // vr.removeBricks("testCluster", "test", "192.168.1.210:sdb", true);
-
- String taskId = vr.migrateBrickStart("myGluster", "students", "devserver1:/export/sdc/students",
- "devserver2:/export/sdb/students", true);
-
- }
}