CLOUDSTACK-2347: Zone filter for listSnapshots API

Added new optional parameter zone id in listSnapshots API which allows to list snapshots with additional criteria.
   Signed off by :- Nitin Mehta <nitin.mehta@citrix.com>
This commit is contained in:
Harikrishna Patnala 2013-06-12 13:35:16 +05:30 committed by Nitin Mehta
parent e73aafc09a
commit 215b638e8e
4 changed files with 23 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.SnapshotResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
@ -62,6 +63,9 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd {
@Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
private String zoneType;
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "list snapshots by zone id")
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -89,6 +93,10 @@ public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd {
public String getZoneType() {
return zoneType;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -93,6 +93,10 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe
@Param(description = "the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage")
private Snapshot.State state;
@SerializedName(ApiConstants.ZONE_ID)
@Param(description = "id of the availability zone")
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME)
@Param(description = "name of the availability zone")
private String zoneName;
@ -181,6 +185,9 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe
this.projectName = projectName;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}

View File

@ -439,7 +439,8 @@ public class ApiResponseHelper implements ResponseGenerator {
DataCenter zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
if (zone != null) {
snapshotResponse.setZoneName(zone.getName());
snapshotResponse.setZoneType(zone.getNetworkType().toString());
snapshotResponse.setZoneType(zone.getNetworkType().toString());
snapshotResponse.setZoneId(zone.getUuid());
}
}
snapshotResponse.setCreated(snapshot.getCreated());

View File

@ -574,6 +574,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
String intervalTypeStr = cmd.getIntervalType();
String zoneType = cmd.getZoneType();
Map<String, String> tags = cmd.getTags();
Long zoneId = cmd.getZoneId();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
@ -602,6 +603,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("snapshotTypeEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.IN);
sb.and("snapshotTypeNEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.NEQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
@ -641,6 +643,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");