Add quiencevm option on createsnapshotcmd

This commit is contained in:
Edison Su 2013-11-07 14:56:51 -08:00
parent 2014866afa
commit c233492bfc
10 changed files with 50 additions and 10 deletions

View File

@ -79,7 +79,7 @@ public interface VolumeApiService {
Volume detachVolumeFromVM(DetachVolumeCmd cmmd);
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account)
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm)
throws ResourceAllocationException;
Snapshot allocSnapshot(Long volumeId, Long policyId)

View File

@ -210,6 +210,7 @@ public class ApiConstants {
public static final String SNAPSHOT_ID = "snapshotid";
public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";
public static final String SNAPSHOT_TYPE = "snapshottype";
public static final String SNAPSHOT_QUIESCEVM = "quiescevm";
public static final String SOURCE_ZONE_ID = "sourcezoneid";
public static final String START_DATE = "startdate";
public static final String START_IP = "startip";

View File

@ -65,12 +65,22 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
description = "policy id of the snapshot, if this is null, then use MANUAL_POLICY.")
private Long policyId;
@Parameter(name = ApiConstants.SNAPSHOT_QUIESCEVM, type = CommandType.BOOLEAN, required = false, description = "quiesce vm if true")
private Boolean quiescevm;
private String syncObjectType = BaseAsyncCmd.snapshotHostSyncObject;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Boolean getQuiescevm() {
if (quiescevm == null) {
return false;
} else {
return quiescevm;
}
}
public String getAccountName() {
return accountName;

View File

@ -33,6 +33,7 @@ public class SnapshotObjectTO implements DataTO {
private String name;
private HypervisorType hypervisorType;
private long id;
private boolean quiescevm;
public SnapshotObjectTO() {
@ -54,6 +55,7 @@ public class SnapshotObjectTO implements DataTO {
this.dataStore = snapshot.getDataStore().getTO();
this.setName(snapshot.getName());
this.hypervisorType = snapshot.getHypervisorType();
this.quiescevm = false;
}
@Override
@ -129,6 +131,14 @@ public class SnapshotObjectTO implements DataTO {
this.hypervisorType = hypervisorType;
}
public boolean getquiescevm() {
return this.quiescevm;
}
public void setQuiescevm(boolean quiescevm) {
this.quiescevm = quiescevm;
}
@Override
public String toString() {
return new StringBuilder("SnapshotTO[datastore=").append(dataStore).append("|volume=").append(volume).append("|path")

View File

@ -28,6 +28,7 @@ public interface SnapshotInfo extends DataObject, Snapshot {
VolumeInfo getBaseVolume();
void addPayload(Object data);
Object getPayload();
Long getDataCenterId();

View File

@ -62,6 +62,7 @@ public class SnapshotObject implements SnapshotInfo {
private static final Logger s_logger = Logger.getLogger(SnapshotObject.class);
private SnapshotVO snapshot;
private DataStore store;
private Object payload;
@Inject
protected SnapshotDao snapshotDao;
@Inject
@ -358,6 +359,12 @@ public class SnapshotObject implements SnapshotInfo {
@Override
public void addPayload(Object data) {
this.payload = data;
}
@Override
public Object getPayload() {
return this.payload;
}
@Override

View File

@ -22,6 +22,8 @@ import java.util.UUID;
import javax.inject.Inject;
import com.cloud.storage.*;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
@ -58,11 +60,6 @@ import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.configuration.Config;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ResizeVolumePayload;
import com.cloud.storage.Storage;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.VMTemplateDao;
@ -249,8 +246,12 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateCmdResult result = null;
try {
DataTO snapshotTO = snapshot.getTO();
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)snapshot.getTO();
Object payload = snapshot.getPayload();
if (payload != null && payload instanceof CreateSnapshotPayload) {
CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload)payload;
snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
}
CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
EndPoint ep = epSelector.select(snapshot);

View File

@ -22,6 +22,7 @@ public class CreateSnapshotPayload {
private Long snapshotPolicyId;
private Long snapshotId;
private Account account;
private boolean quiescevm;
public Long getSnapshotPolicyId() {
return snapshotPolicyId;
@ -47,4 +48,12 @@ public class CreateSnapshotPayload {
this.account = account;
}
public void setQuiescevm(boolean quiescevm) {
this.quiescevm = quiescevm;
}
public boolean getQuiescevm() {
return this.quiescevm;
}
}

View File

@ -1383,7 +1383,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
}
@Override
public Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account) throws ResourceAllocationException {
public Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm) throws ResourceAllocationException {
VolumeInfo volume = volFactory.getVolume(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
@ -1397,6 +1397,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
payload.setSnapshotId(snapshotId);
payload.setSnapshotPolicyId(policyId);
payload.setAccount(account);
payload.setQuiescevm(quiescevm);
volume.addPayload(payload);
return volService.takeSnapshot(volume);
}

View File

@ -940,7 +940,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
Long snapshotId = payload.getSnapshotId();
Account snapshotOwner = payload.getAccount();
SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, volume.getDataStore());
snapshot.addPayload(payload);
try {
SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);