From 9f3f13f70a9d4c2c2fc3058cde425cdde2bb43a0 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Fri, 2 Aug 2013 11:51:56 -0700 Subject: [PATCH] CLOUDSTACK-3748:AddS3Cmd NPE. --- .../admin/storage/AddImageStoreCmd.java | 36 ++++++++-------- .../api/command/admin/storage/AddS3Cmd.java | 43 +++++++++++-------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java index 7e4409895c4..1552e0520a8 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java @@ -60,7 +60,7 @@ public class AddImageStoreCmd extends BaseCmd { @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the image store. Example: details[0].key=accesskey&details[0].value=s389ddssaa&details[1].key=secretkey&details[1].value=8dshfsss") - private Map details; + private Map details; @@ -81,19 +81,19 @@ public class AddImageStoreCmd extends BaseCmd { return zoneId; } - public Map getDetails() { - Map detailsMap = null; - if (details != null && !details.isEmpty()) { - detailsMap = new HashMap(); - Collection props = details.values(); - Iterator iter = props.iterator(); - while (iter.hasNext()) { - HashMap detail = (HashMap) iter.next(); - String key = detail.get("key"); - String value = detail.get("value"); - detailsMap.put(key, value); - } - } + public Map getDetails() { + Map detailsMap = null; + if (details != null && !details.isEmpty()) { + detailsMap = new HashMap(); + Collection props = details.values(); + Iterator iter = props.iterator(); + while (iter.hasNext()) { + HashMap detail = (HashMap) iter.next(); + String key = detail.get("key"); + String value = detail.get("value"); + detailsMap.put(key, value); + } + } return detailsMap; } @@ -139,10 +139,10 @@ public class AddImageStoreCmd extends BaseCmd { ImageStore result = _storageService.discoverImageStore(this); ImageStoreResponse storeResponse = null; if (result != null ) { - storeResponse = _responseGenerator.createImageStoreResponse(result); - storeResponse.setResponseName(getCommandName()); - storeResponse.setObjectName("imagestore"); - this.setResponseObject(storeResponse); + storeResponse = _responseGenerator.createImageStoreResponse(result); + storeResponse.setResponseName(getCommandName()); + storeResponse.setObjectName("imagestore"); + this.setResponseObject(storeResponse); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java index 70cde7892f4..0af1a85051f 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java @@ -94,25 +94,30 @@ public final class AddS3Cmd extends BaseCmd { ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { - AddImageStoreCmd cmd = new AddImageStoreCmd(); + AddImageStoreCmd cmd = new AddImageStoreCmd() { + @Override + public Map getDetails() { + Map dm = new HashMap(); + dm.put(ApiConstants.S3_ACCESS_KEY, getAccessKey()); + dm.put(ApiConstants.S3_SECRET_KEY, getSecretKey()); + dm.put(ApiConstants.S3_END_POINT, getEndPoint()); + dm.put(ApiConstants.S3_BUCKET_NAME, getBucketName()); + if (getHttpsFlag() != null) { + dm.put(ApiConstants.S3_HTTPS_FLAG, getHttpsFlag().toString()); + } + if (getConnectionTimeout() != null) { + dm.put(ApiConstants.S3_CONNECTION_TIMEOUT, getConnectionTimeout().toString()); + } + if (getMaxErrorRetry() != null) { + dm.put(ApiConstants.S3_MAX_ERROR_RETRY, getMaxErrorRetry().toString()); + } + if (getSocketTimeout() != null) { + dm.put(ApiConstants.S3_SOCKET_TIMEOUT, getSocketTimeout().toString()); + } + return dm; + } + }; cmd.setProviderName("S3"); - Map details = new HashMap(); - details.put(ApiConstants.S3_ACCESS_KEY, this.getAccessKey()); - details.put(ApiConstants.S3_SECRET_KEY, this.getSecretKey()); - details.put(ApiConstants.S3_END_POINT, this.getEndPoint()); - details.put(ApiConstants.S3_BUCKET_NAME, this.getBucketName()); - if (this.getHttpsFlag() != null) { - details.put(ApiConstants.S3_HTTPS_FLAG, this.getHttpsFlag().toString()); - } - if (this.getConnectionTimeout() != null) { - details.put(ApiConstants.S3_CONNECTION_TIMEOUT, this.getConnectionTimeout().toString()); - } - if (this.getMaxErrorRetry() != null) { - details.put(ApiConstants.S3_MAX_ERROR_RETRY, this.getMaxErrorRetry().toString()); - } - if (this.getSocketTimeout() != null) { - details.put(ApiConstants.S3_SOCKET_TIMEOUT, this.getSocketTimeout().toString()); - } try{ ImageStore result = _storageService.discoverImageStore(cmd); @@ -123,7 +128,7 @@ public final class AddS3Cmd extends BaseCmd { storeResponse.setObjectName("secondarystorage"); this.setResponseObject(storeResponse); } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex);