}
public static DescribeSnapshotsResponse toDescribeSnapshotsResponse(EC2DescribeSnapshotsResponse engineResponse) {
DescribeSnapshotsResponse response = new DescribeSnapshotsResponse();
DescribeSnapshotsResponseType param1 = new DescribeSnapshotsResponseType();
DescribeSnapshotsSetResponseType param2 = new DescribeSnapshotsSetResponseType();
EC2Snapshot[] snaps = engineResponse.getSnapshotSet();
for (EC2Snapshot snap : snaps) {
DescribeSnapshotsSetItemResponseType param3 = new DescribeSnapshotsSetItemResponseType();
param3.setSnapshotId(snap.getId());
param3.setVolumeId(snap.getVolumeId());
// our semantics are different than those ec2 uses
if (snap.getState().equalsIgnoreCase("backedup")) {
param3.setStatus("completed");
param3.setProgress("100%");
} else if (snap.getState().equalsIgnoreCase("creating")) {
param3.setStatus("pending");
param3.setProgress("33%");
} else if (snap.getState().equalsIgnoreCase("backingup")) {
param3.setStatus("pending");
param3.setProgress("66%");
} else {
// if we see anything besides: backedup/creating/backingup, we assume error
param3.setStatus("error");
param3.setProgress("0%");
}
// param3.setStatus( snap.getState());
String ownerId = snap.getDomainId() + ":" + snap.getAccountName();
// -> CloudStack seems to have issues with timestamp formats so just in case
Calendar cal = snap.getCreated();
if (null == cal) {
cal = Calendar.getInstance();
cal.set(1970, 1, 1);
}
param3.setStartTime(cal);
param3.setOwnerId(ownerId);
if (snap.getVolumeSize() == null)
param3.setVolumeSize("0");
else
param3.setVolumeSize(snap.getVolumeSize().toString());
param3.setDescription(snap.getName());
param3.setOwnerAlias(snap.getAccountName());
EC2TagKeyValue[] tags = snap.getResourceTags();
param3.setTagSet(setResourceTags(tags));
param2.addItem(param3);
}
param1.setSnapshotSet(param2);
param1.setRequestId(UUID.randomUUID().toString());
response.setDescribeSnapshotsResponse(param1);