Skip to content

Commit ad20a9b

Browse files
committed
CLOUDSTACK-3748:AddS3Cmd NPE.
1 parent 838c972 commit ad20a9b

2 files changed

Lines changed: 42 additions & 37 deletions

File tree

‎api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class AddImageStoreCmd extends BaseCmd {
6060

6161

6262
@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")
63-
private Map<String, String> details;
63+
private Map details;
6464

6565

6666

@@ -81,19 +81,19 @@ public Long getZoneId() {
8181
return zoneId;
8282
}
8383

84-
public Map<String, String> getDetails() {
85-
Map<String, String> detailsMap = null;
86-
if (details != null && !details.isEmpty()) {
87-
detailsMap = new HashMap<String, String>();
88-
Collection<?> props = details.values();
89-
Iterator<?> iter = props.iterator();
90-
while (iter.hasNext()) {
91-
HashMap<String, String> detail = (HashMap<String, String>) iter.next();
92-
String key = detail.get("key");
93-
String value = detail.get("value");
94-
detailsMap.put(key, value);
95-
}
96-
}
84+
public Map<String, String> getDetails() {
85+
Map<String, String> detailsMap = null;
86+
if (details != null && !details.isEmpty()) {
87+
detailsMap = new HashMap<String, String>();
88+
Collection<?> props = details.values();
89+
Iterator<?> iter = props.iterator();
90+
while (iter.hasNext()) {
91+
HashMap<String, String> detail = (HashMap<String, String>) iter.next();
92+
String key = detail.get("key");
93+
String value = detail.get("value");
94+
detailsMap.put(key, value);
95+
}
96+
}
9797
return detailsMap;
9898
}
9999

@@ -139,10 +139,10 @@ public void execute(){
139139
ImageStore result = _storageService.discoverImageStore(this);
140140
ImageStoreResponse storeResponse = null;
141141
if (result != null ) {
142-
storeResponse = _responseGenerator.createImageStoreResponse(result);
143-
storeResponse.setResponseName(getCommandName());
144-
storeResponse.setObjectName("imagestore");
145-
this.setResponseObject(storeResponse);
142+
storeResponse = _responseGenerator.createImageStoreResponse(result);
143+
storeResponse.setResponseName(getCommandName());
144+
storeResponse.setObjectName("imagestore");
145+
this.setResponseObject(storeResponse);
146146
} else {
147147
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
148148
}

‎api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,30 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
9494
ServerApiException, ConcurrentOperationException, ResourceAllocationException,
9595
NetworkRuleConflictException {
9696

97-
AddImageStoreCmd cmd = new AddImageStoreCmd();
97+
AddImageStoreCmd cmd = new AddImageStoreCmd() {
98+
@Override
99+
public Map<String, String> getDetails() {
100+
Map<String, String> dm = new HashMap<String, String>();
101+
dm.put(ApiConstants.S3_ACCESS_KEY, getAccessKey());
102+
dm.put(ApiConstants.S3_SECRET_KEY, getSecretKey());
103+
dm.put(ApiConstants.S3_END_POINT, getEndPoint());
104+
dm.put(ApiConstants.S3_BUCKET_NAME, getBucketName());
105+
if (getHttpsFlag() != null) {
106+
dm.put(ApiConstants.S3_HTTPS_FLAG, getHttpsFlag().toString());
107+
}
108+
if (getConnectionTimeout() != null) {
109+
dm.put(ApiConstants.S3_CONNECTION_TIMEOUT, getConnectionTimeout().toString());
110+
}
111+
if (getMaxErrorRetry() != null) {
112+
dm.put(ApiConstants.S3_MAX_ERROR_RETRY, getMaxErrorRetry().toString());
113+
}
114+
if (getSocketTimeout() != null) {
115+
dm.put(ApiConstants.S3_SOCKET_TIMEOUT, getSocketTimeout().toString());
116+
}
117+
return dm;
118+
}
119+
};
98120
cmd.setProviderName("S3");
99-
Map<String, String> details = new HashMap<String, String>();
100-
details.put(ApiConstants.S3_ACCESS_KEY, this.getAccessKey());
101-
details.put(ApiConstants.S3_SECRET_KEY, this.getSecretKey());
102-
details.put(ApiConstants.S3_END_POINT, this.getEndPoint());
103-
details.put(ApiConstants.S3_BUCKET_NAME, this.getBucketName());
104-
if (this.getHttpsFlag() != null) {
105-
details.put(ApiConstants.S3_HTTPS_FLAG, this.getHttpsFlag().toString());
106-
}
107-
if (this.getConnectionTimeout() != null) {
108-
details.put(ApiConstants.S3_CONNECTION_TIMEOUT, this.getConnectionTimeout().toString());
109-
}
110-
if (this.getMaxErrorRetry() != null) {
111-
details.put(ApiConstants.S3_MAX_ERROR_RETRY, this.getMaxErrorRetry().toString());
112-
}
113-
if (this.getSocketTimeout() != null) {
114-
details.put(ApiConstants.S3_SOCKET_TIMEOUT, this.getSocketTimeout().toString());
115-
}
116121

117122
try{
118123
ImageStore result = _storageService.discoverImageStore(cmd);
@@ -123,7 +128,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
123128
storeResponse.setObjectName("secondarystorage");
124129
this.setResponseObject(storeResponse);
125130
} else {
126-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
131+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 secondary storage");
127132
}
128133
} catch (DiscoveryException ex) {
129134
s_logger.warn("Exception: ", ex);

0 commit comments

Comments
 (0)