Github user karuturi commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/1600#discussion_r70425148
--- Diff:
api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java
---
@@ -195,24 +196,37 @@ public void create() throws
ResourceAllocationException {
@Override
public void execute() {
- s_logger.info("VOLSS: createSnapshotCmd starts:" +
System.currentTimeMillis());
- CallContext.current().setEventDetails("Volume Id: " +
getVolumeUuid());
Snapshot snapshot;
try {
snapshot =
- _volumeService.takeSnapshot(getVolumeId(), getPolicyId(),
getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm());
+ _volumeService.takeSnapshot(getVolumeId(), getPolicyId(),
getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm(),
getLocationType());
+
if (snapshot != null) {
SnapshotResponse response =
_responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to create snapshot due to an internal error creating snapshot for
volume " + volumeId);
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to create snapshot due to an internal error creating snapshot for
volume " + getVolumeId());
}
} catch (Exception e) {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to create snapshot due to an internal error creating snapshot for
volume " + volumeId);
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to create snapshot due to an internal error creating snapshot for
volume " + getVolumeId());
}
}
+ private Snapshot.LocationType getLocationType() {
+ if (Snapshot.LocationType.values() == null ||
Snapshot.LocationType.values().length == 0) {
+ return null;
+ }
+
+ Snapshot.LocationType locationTypeToReturn =
Snapshot.LocationType.values()[0];
+
+ if (locationType != null && locationType >= 1 && locationType <=
Snapshot.LocationType.values().length) {
+ locationTypeToReturn =
Snapshot.LocationType.values()[locationType-1];
--- End diff --
I would suggest keeping the enum values all upper case, make locationType
string in cmd and use LocationType.valueOf(cmd.locationType.toUpperCase())
https://books.google.co.in/books?id=ka2VUBqHiWkC&lpg=PA158&dq=Never%20derive%20a%20value%20associated%20with%20an%20enum%20from%20its%20ordinal&pg=PA158#v=onepage&q&f=false
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---