CLOUDSTACK-5863: change response from SuccessResponse to SnapshotResponse

This commit is contained in:
Wei Zhou 2015-08-28 08:54:11 +02:00
parent 92344c006d
commit 312cb877b1
3 changed files with 10 additions and 9 deletions

View File

@ -106,7 +106,7 @@ public interface SnapshotApiService {
*/ */
Long getHostIdForSnapshotOperation(Volume vol); Long getHostIdForSnapshotOperation(Volume vol);
boolean revertSnapshot(Long snapshotId); Snapshot revertSnapshot(Long snapshotId);
SnapshotPolicy updateSnapshotPolicy(UpdateSnapshotPolicyCmd updateSnapshotPolicyCmd); SnapshotPolicy updateSnapshotPolicy(UpdateSnapshotPolicyCmd updateSnapshotPolicyCmd);
} }

View File

@ -29,7 +29,6 @@ import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.SnapshotResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -37,7 +36,7 @@ import com.cloud.event.EventTypes;
import com.cloud.storage.Snapshot; import com.cloud.storage.Snapshot;
import com.cloud.user.Account; import com.cloud.user.Account;
@APICommand(name = "revertSnapshot", description = "revert a volume snapshot.", responseObject = SuccessResponse.class, entityType = {Snapshot.class}, @APICommand(name = "revertSnapshot", description = "revert a volume snapshot.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class},
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class RevertSnapshotCmd extends BaseAsyncCmd { public class RevertSnapshotCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(RevertSnapshotCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(RevertSnapshotCmd.class.getName());
@ -99,9 +98,10 @@ public class RevertSnapshotCmd extends BaseAsyncCmd {
@Override @Override
public void execute() { public void execute() {
CallContext.current().setEventDetails("Snapshot Id: " + getId()); CallContext.current().setEventDetails("Snapshot Id: " + getId());
boolean result = _snapshotService.revertSnapshot(getId()); Snapshot snapshot = _snapshotService.revertSnapshot(getId());
if (result) { if (snapshot != null) {
SuccessResponse response = new SuccessResponse(getCommandName()); SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
setResponseObject(response); setResponseObject(response);
} else { } else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot");

View File

@ -246,7 +246,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
} }
@Override @Override
public boolean revertSnapshot(Long snapshotId) { public Snapshot revertSnapshot(Long snapshotId) {
SnapshotVO snapshot = _snapshotDao.findById(snapshotId); SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
if (snapshot == null) { if (snapshot == null) {
throw new InvalidParameterValueException("No such snapshot"); throw new InvalidParameterValueException("No such snapshot");
@ -277,7 +277,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
if (snapshotStrategy == null) { if (snapshotStrategy == null) {
s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshotId + "'"); s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshotId + "'");
return false; return null;
} }
boolean result = snapshotStrategy.revertSnapshot(snapshotInfo); boolean result = snapshotStrategy.revertSnapshot(snapshotInfo);
@ -287,8 +287,9 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
new Long(volume.getSize() - snapshot.getSize())); new Long(volume.getSize() - snapshot.getSize()));
volume.setSize(snapshot.getSize()); volume.setSize(snapshot.getSize());
_volsDao.update(volume.getId(), volume); _volsDao.update(volume.getId(), volume);
return snapshotInfo;
} }
return result; return null;
} }
@Override @Override