Search in sources :

Example 31 with DataTO

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;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) Command(com.cloud.legacymodel.communication.command.Command) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson)

Example 32 with DataTO

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());
    }
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 33 with DataTO

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;
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataTO(com.cloud.legacymodel.to.DataTO) ArrayList(java.util.ArrayList) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo)

Example 34 with DataTO

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;
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO)

Example 35 with DataTO

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);
    }
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) DataTO(com.cloud.legacymodel.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) Volume(com.cloud.legacymodel.storage.Volume) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) DiskTO(com.cloud.legacymodel.to.DiskTO)

Aggregations

DataTO (com.cloud.legacymodel.to.DataTO)49 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)30 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)29 NfsTO (com.cloud.legacymodel.to.NfsTO)26 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)25 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)20 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)19 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 Connection (com.xensource.xenapi.Connection)17 VDI (com.xensource.xenapi.VDI)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)16 SR (com.xensource.xenapi.SR)12 Answer (com.cloud.legacymodel.communication.answer.Answer)11 DiskTO (com.cloud.legacymodel.to.DiskTO)11 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)11 URI (java.net.URI)10 SnapshotObjectTO (com.cloud.legacymodel.to.SnapshotObjectTO)9 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)7 IOException (java.io.IOException)5