use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method createVolumeFromSnapshot.
@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
try {
final DataTO srcData = cmd.getSrcTO();
final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
final DataTO destData = cmd.getDestTO();
final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
final DataStoreTO imageStore = srcData.getDataStore();
final VolumeObjectTO volume = snapshot.getVolume();
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
final NfsTO nfsImageStore = (NfsTO) imageStore;
final String snapshotFullPath = snapshot.getPath();
final int index = snapshotFullPath.lastIndexOf("/");
final String snapshotPath = snapshotFullPath.substring(0, index);
final String snapshotName = snapshotFullPath.substring(index + 1);
final KvmStoragePool secondaryPool = this.storagePoolMgr.getStoragePoolByUri(nfsImageStore.getUrl() + File.separator + snapshotPath);
final KvmPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
if (volume.getFormat() == ImageFormat.RAW) {
snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
} else if (volume.getFormat() == ImageFormat.QCOW2) {
snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
}
final String primaryUuid = pool.getUuid();
final KvmStoragePool primaryPool = this.storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
final String volUuid = UUID.randomUUID().toString();
final KvmPhysicalDisk disk = this.storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool, cmd.getWaitInMillSeconds());
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(disk.getName());
newVol.setSize(disk.getVirtualSize());
newVol.setFormat(ImageFormat.valueOf(disk.getFormat().toString().toUpperCase()));
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
this.logger.debug("Failed to createVolumeFromSnapshot: ", e);
return new CopyCmdAnswer(e.toString());
}
}
use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.
the class AncientDataMotionStrategy method copyVolumeFromSnapshot.
protected Answer copyVolumeFromSnapshot(final DataObject snapObj, final DataObject volObj) {
final SnapshotInfo snapshot = (SnapshotInfo) snapObj;
final StoragePool pool = (StoragePool) volObj.getDataStore();
final String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
final DataStore store = snapObj.getDataStore();
final DataStoreTO storTO = store.getTO();
DataObject srcData = snapObj;
try {
if (!(storTO instanceof NfsTO)) {
// cache snapshot to zone-wide staging store for the volume to be created
srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
}
final String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
final int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(volObj);
} else {
ep = selector.select(srcData, volObj);
}
final CopyCommand cmd = new CopyCommand(srcData.getTO(), volObj.getTO(), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
Answer answer = null;
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
return answer;
} catch (final Exception e) {
s_logger.error(basicErrMsg, e);
throw new CloudRuntimeException(basicErrMsg);
} finally {
if (!(storTO instanceof NfsTO)) {
// still keep snapshot on cache which may be migrated from previous secondary storage
releaseSnapshotCacheChain((SnapshotInfo) srcData);
}
}
}
use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.
the class TemplateObject method getTO.
@Override
public DataTO getTO() {
DataTO to = null;
DataStoreTO dataStoreTO = null;
if (this.getDataStore() != null) {
dataStoreTO = this.getDataStore().getTO();
}
if (dataStore == null) {
to = new TemplateObjectTO(this.getInstallPath(), this.getUrl(), this.getUuid(), this.getId(), this.getFormat(), this.getAccountId(), this.getChecksum(), this.getDisplayText(), dataStoreTO, this.getName(), this.getUniqueName(), null, null, null, this.getHypervisorType());
} else {
to = dataStore.getDriver().getTO(this);
if (to == null) {
to = new TemplateObjectTO(this.getInstallPath(), this.getUrl(), this.getUuid(), this.getId(), this.getFormat(), this.getAccountId(), this.getChecksum(), this.getDisplayText(), dataStoreTO, this.getName(), this.getUniqueName(), null, null, null, this.getHypervisorType());
}
}
return to;
}
use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testGetStorageStatsCommand.
@Test
public void testGetStorageStatsCommand() {
final XsHost xsHost = Mockito.mock(XsHost.class);
final DataStoreTO store = Mockito.mock(DataStoreTO.class);
final GetStorageStatsCommand storageStatsCommand = new GetStorageStatsCommand(store);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(storageStatsCommand, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations