use of com.cloud.storage.command.CreateObjectAnswer in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method createSnapshot.
@Override
public Answer createSnapshot(final CreateObjectCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
final long snapshotId = snapshotTO.getId();
final String snapshotName = snapshotTO.getName();
String details = "create snapshot operation Failed for snapshotId: " + snapshotId;
String snapshotUUID = null;
try {
final String volumeUUID = snapshotTO.getVolume().getPath();
final VDI volume = VDI.getByUuid(conn, volumeUUID);
final VDI snapshot = volume.snapshot(conn, new HashMap<>());
if (snapshotName != null) {
snapshot.setNameLabel(conn, snapshotName);
}
snapshotUUID = snapshot.getUuid(conn);
final String preSnapshotUUID = snapshotTO.getParentSnapshotPath();
// check if it is a empty snapshot
if (preSnapshotUUID != null) {
final SR sr = volume.getSR(conn);
final String srUUID = sr.getUuid(conn);
final String type = sr.getType(conn);
final Boolean isISCSI = IsISCSI(type);
final String snapshotParentUUID = getVhdParent(conn, srUUID, snapshotUUID, isISCSI);
try {
final String preSnapshotParentUUID = getVhdParent(conn, srUUID, preSnapshotUUID, isISCSI);
if (snapshotParentUUID != null && snapshotParentUUID.equals(preSnapshotParentUUID)) {
// this is empty snapshot, remove it
snapshot.destroy(conn);
snapshotUUID = preSnapshotUUID;
}
} catch (final Exception e) {
s_logger.debug("Failed to get parent snapshot", e);
}
}
final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotUUID);
return new CreateObjectAnswer(newSnapshot);
} catch (final XenAPIException e) {
details += ", reason: " + e.toString();
s_logger.warn(details, e);
} catch (final Exception e) {
details += ", reason: " + e.toString();
s_logger.warn(details, e);
}
return new CreateObjectAnswer(details);
}
use of com.cloud.storage.command.CreateObjectAnswer in project cosmic by MissionCriticalCloud.
the class XenserverSnapshotStrategy method backupSnapshot.
@Override
public SnapshotInfo backupSnapshot(final SnapshotInfo snapshot) {
final SnapshotInfo parentSnapshot = snapshot.getParent();
if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
s_logger.debug("backup an empty snapshot");
// don't need to backup this snapshot
final SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
final DataStore store = dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole());
final SnapshotInfo snapshotOnImageStore = (SnapshotInfo) store.create(snapshot);
snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
final SnapshotObjectTO snapTO = new SnapshotObjectTO();
snapTO.setPath(parentSnapshotOnBackupStore.getInstallPath());
final CreateObjectAnswer createSnapshotAnswer = new CreateObjectAnswer(snapTO);
snapshotOnImageStore.processEvent(Event.OperationSuccessed, createSnapshotAnswer);
final SnapshotObject snapObj = (SnapshotObject) snapshot;
try {
snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
} catch (final NoTransitionException e) {
s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
throw new CloudRuntimeException(e.toString());
}
return snapshotDataFactory.getSnapshot(snapObj.getId(), store);
} else {
s_logger.debug("parent snapshot hasn't been backed up yet");
}
}
// determine full snapshot backup or not
boolean fullBackup = true;
SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Image);
final SnapshotDataStoreVO parentSnapshotOnPrimaryStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
final HypervisorType hypervisorType = snapshot.getBaseVolume().getHypervisorType();
if (parentSnapshotOnPrimaryStore != null && parentSnapshotOnBackupStore != null && hypervisorType == Hypervisor.HypervisorType.XenServer) {
// CS does incremental backup
// only for XenServer
// In case of volume migration from one pool to other pool, CS should take full snapshot to avoid any issues with delta chain,
// to check if this is a migrated volume, compare the current pool id of volume and store_id of oldest snapshot on primary for this volume.
// Why oldest? Because at this point CS has two snapshot on primary entries for same volume, one with old pool_id and other one with
// current pool id. So, verify and if volume found to be migrated, delete snapshot entry with previous pool store_id.
final SnapshotDataStoreVO oldestSnapshotOnPrimary = snapshotStoreDao.findOldestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
final VolumeVO volume = volumeDao.findById(snapshot.getVolumeId());
if (oldestSnapshotOnPrimary != null) {
if (oldestSnapshotOnPrimary.getDataStoreId() == volume.getPoolId()) {
final int _deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), SnapshotManager.DELTAMAX);
final int deltaSnap = _deltaSnapshotMax;
int i;
for (i = 1; i < deltaSnap; i++) {
final Long prevBackupId = parentSnapshotOnBackupStore.getParentSnapshotId();
if (prevBackupId == 0) {
break;
}
parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(prevBackupId, DataStoreRole.Image);
if (parentSnapshotOnBackupStore == null) {
break;
}
}
if (i >= deltaSnap) {
fullBackup = true;
} else {
fullBackup = false;
}
} else {
// if there is an snapshot entry for previousPool(primary storage) of migrated volume, delete it becasue CS created one more snapshot entry for current pool
snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
}
}
}
snapshot.addPayload(fullBackup);
return snapshotSvr.backupSnapshot(snapshot);
}
use of com.cloud.storage.command.CreateObjectAnswer in project cosmic by MissionCriticalCloud.
the class VolumeObject method processEventOnly.
@Override
public void processEventOnly(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
try {
if (dataStore.getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
final VolumeVO vol = volumeDao.findById(getId());
final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
} else if (answer instanceof CreateObjectAnswer) {
final CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
final VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
final VolumeVO vol = volumeDao.findById(getId());
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
}
} else {
// image store or imageCache store
if (answer instanceof DownloadAnswer) {
final DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
volStore.setInstallPath(dwdAnswer.getInstallPath());
volStore.setChecksum(dwdAnswer.getCheckSum());
volumeStoreDao.update(volStore.getId(), volStore);
} else if (answer instanceof CopyCmdAnswer) {
final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
volStore.setInstallPath(newVol.getPath());
if (newVol.getSize() != null) {
volStore.setSize(newVol.getSize());
}
volumeStoreDao.update(volStore.getId(), volStore);
}
}
} catch (final RuntimeException ex) {
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
objectInStoreMgr.deleteIfNotReady(this);
}
throw ex;
}
this.processEventOnly(event);
}
Aggregations