use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class GsonHelper method setDefaultGsonConfig.
static Gson setDefaultGsonConfig(final GsonBuilder builder) {
final InterfaceTypeAdaptor<DataStoreTO> dsAdaptor = new InterfaceTypeAdaptor<>();
builder.registerTypeAdapter(DataStoreTO.class, dsAdaptor);
final InterfaceTypeAdaptor<DataTO> dtAdaptor = new InterfaceTypeAdaptor<>();
builder.registerTypeAdapter(DataTO.class, dtAdaptor);
final ArrayTypeAdaptor<Command> cmdAdaptor = new ArrayTypeAdaptor<>();
builder.registerTypeAdapter(new TypeToken<Command[]>() {
}.getType(), cmdAdaptor);
final ArrayTypeAdaptor<Answer> ansAdaptor = new ArrayTypeAdaptor<>();
builder.registerTypeAdapter(new TypeToken<Answer[]>() {
}.getType(), ansAdaptor);
final Gson gson = builder.create();
dsAdaptor.initGson(gson);
dtAdaptor.initGson(gson);
cmdAdaptor.initGson(gson);
ansAdaptor.initGson(gson);
return gson;
}
use of com.cloud.legacymodel.to.DataTO 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.DataTO in project cosmic by MissionCriticalCloud.
the class SnapshotObject method getTO.
@Override
public DataTO getTO() {
final DataTO to = store.getDriver().getTO(this);
if (to == null) {
SnapshotObjectTO snapshotObjectTO = new SnapshotObjectTO();
snapshotObjectTO.setPath(this.getPath());
snapshotObjectTO.setId(this.getId());
final VolumeInfo vol = this.getBaseVolume();
if (vol != null) {
snapshotObjectTO.setVolume((VolumeObjectTO) vol.getTO());
snapshotObjectTO.setVmName(vol.getAttachedVmName());
}
SnapshotInfo parentSnapshot = this.getParent();
final ArrayList<String> parentsArry = new ArrayList<>();
if (parentSnapshot != null) {
snapshotObjectTO.setParentSnapshotPath(parentSnapshot.getPath());
while (parentSnapshot != null) {
parentsArry.add(parentSnapshot.getPath());
parentSnapshot = parentSnapshot.getParent();
}
snapshotObjectTO.setParents(parentsArry.toArray(new String[parentsArry.size()]));
ArrayUtils.reverse(snapshotObjectTO.getParents());
}
snapshotObjectTO.setDataStore(this.getDataStore().getTO());
snapshotObjectTO.setName(this.getName());
snapshotObjectTO.setHypervisorType(this.getHypervisorType());
snapshotObjectTO.setQuiescevm(false);
return snapshotObjectTO;
}
return to;
}
use of com.cloud.legacymodel.to.DataTO 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.DataTO in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method prepare.
@Override
public void prepare(final VirtualMachineProfile vm, final DeployDestination dest) throws StorageUnavailableException, ConcurrentOperationException {
if (dest == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: " + vm);
}
throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination is null, vm:" + vm);
}
// don't allow to start vm that doesn't have a root volume
if (this._volsDao.findByInstanceAndType(vm.getId(), VolumeType.ROOT).isEmpty()) {
throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
}
final List<VolumeVO> vols = this._volsDao.findUsableVolumesForInstance(vm.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking if we need to prepare " + vols.size() + " volumes for " + vm);
}
final List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
Volume vol = null;
StoragePool pool = null;
for (final VolumeTask task : tasks) {
if (task.type == VolumeTaskType.NOP) {
pool = (StoragePool) this.dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
vol = task.volume;
} else if (task.type == VolumeTaskType.MIGRATE) {
pool = (StoragePool) this.dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
vol = migrateVolume(task.volume, pool);
} else if (task.type == VolumeTaskType.RECREATE) {
final Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
pool = (StoragePool) this.dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
vol = result.first();
}
final DataTO volumeTO = this.volFactory.getVolume(vol.getId()).getTO();
final DiskTO disk = new DiskTO(volumeTO, vol.getDeviceId(), vol.getPath(), vol.getVolumeType(), vol.getDiskController(), vol.getFormat());
final VolumeInfo volumeInfo = this.volFactory.getVolume(vol.getId());
final DataStore dataStore = this.dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
disk.setDetails(getDetails(volumeInfo, dataStore));
vm.addDisk(disk);
}
}
Aggregations