From c55864548de5d1b5b75893a411cd3aff8443aebb Mon Sep 17 00:00:00 2001 From: Selvasundaram Date: Sun, 24 Jul 2011 20:10:47 +0530 Subject: Export key file handling exceptions captured --- .../server/resources/v1_0/KeysResource.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src') 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 5ac37bd1..af64af47 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 @@ -82,16 +82,33 @@ public class KeysResource extends AbstractResource { String targetPemFile = targetDir + File.separator + SshUtil.PEM_FILE.getName(); String targetPubKeyFile = targetDir + File.separator + SshUtil.PUBLIC_KEY_FILE.getName(); + if (!SshUtil.PEM_FILE.isFile()) { + throw new GlusterRuntimeException("No private key file [" + SshUtil.PEM_FILE.getName() + "] found!" ); + } + + if (!SshUtil.PUBLIC_KEY_FILE.isFile()) { + throw new GlusterRuntimeException("No public key file [" + SshUtil.PUBLIC_KEY_FILE.getName() + "] found!" ); + } + // Copy keys to temp folder - processUtil.executeCommand("cp", sourcePemFile, targetPemFile); - processUtil.executeCommand("cp", sourcePubKeyFile, targetPubKeyFile); - - // To zip the key files - processUtil.executeCommand("tar", "cvf", zipFile, "-C", "/tmp", SshUtil.PEM_FILE.getName(), + ProcessResult result = processUtil.executeCommand("cp", sourcePemFile, targetPemFile); + if (!result.isSuccess()) { + throw new GlusterRuntimeException("Failed to copy key files! [" + result.getOutput() + "]"); + } + result = processUtil.executeCommand("cp", sourcePubKeyFile, targetPubKeyFile); + if (!result.isSuccess()) { + throw new GlusterRuntimeException("Failed to copy key files! [" + result.getOutput() + "]"); + } + + // To compress the key files + result = processUtil.executeCommand("tar", "cvf", zipFile, "-C", "/tmp", SshUtil.PEM_FILE.getName(), SshUtil.PUBLIC_KEY_FILE.getName()); + if (!result.isSuccess()) { + throw new GlusterRuntimeException("Failed to compress key files! [" + result.getOutput() + "]"); + } // To remove the copied key files - processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile); + processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile); // Ignore the errors if any return zipFile; } -- cgit