Search in sources :

Example 46 with DataStoreTO

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());
    }
}
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 47 with DataStoreTO

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);
        }
    }
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) StoragePool(com.cloud.legacymodel.storage.StoragePool) CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.legacymodel.to.NfsTO) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 48 with DataStoreTO

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

Example 49 with DataStoreTO

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());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) GetStorageStatsCommand(com.cloud.legacymodel.communication.command.GetStorageStatsCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)49 NfsTO (com.cloud.legacymodel.to.NfsTO)36 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)30 DataTO (com.cloud.legacymodel.to.DataTO)30 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)25 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)24 Answer (com.cloud.legacymodel.communication.answer.Answer)19 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)15 XenAPIException (com.xensource.xenapi.Types.XenAPIException)15 XmlRpcException (org.apache.xmlrpc.XmlRpcException)15 Connection (com.xensource.xenapi.Connection)14 SR (com.xensource.xenapi.SR)13 VDI (com.xensource.xenapi.VDI)13 URI (java.net.URI)12 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)11 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)9 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)9 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)8 ListTemplateAnswer (com.cloud.legacymodel.communication.answer.ListTemplateAnswer)8