Search in sources :

Example 1 with CreateObjectAnswer

use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.

the class VmwareStorageProcessor method createSnapshot.

@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
    // snapshot operation (create or destroy) is handled inside BackupSnapshotCommand(), we just fake
    // a success return here
    String snapshotUUID = UUID.randomUUID().toString();
    SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
    newSnapshot.setPath(snapshotUUID);
    return new CreateObjectAnswer(newSnapshot);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer)

Example 2 with CreateObjectAnswer

use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = null;
    try {
        s_logger.info("taking elastistor volume snapshot");
        SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
        String volumeid = snapshotTO.getVolume().getUuid();
        String snapshotname = snapshotTO.getName();
        Answer answer = ElastistorUtil.createElastistorVolumeSnapshot(volumeid, snapshotname);
        if (answer.getResult() == false) {
            s_logger.info("elastistor volume snapshot failed");
            throw new CloudRuntimeException("elastistor volume snapshot failed");
        } else {
            s_logger.info("elastistor volume snapshot succesfull");
            snapshotTO.setPath(answer.getDetails());
            CreateObjectAnswer createObjectAnswer = new CreateObjectAnswer(snapshotTO);
            result = new CreateCmdResult(null, createObjectAnswer);
            result.setResult(null);
        }
    } catch (Throwable e) {
        s_logger.debug("Failed to take snapshot: " + e.getMessage());
        result = new CreateCmdResult(null, null);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 3 with CreateObjectAnswer

use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.

the class SnapshotObject method processEvent.

@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
    try {
        SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(getDataStore().getRole(), getDataStore().getId(), getId());
        if (answer instanceof CreateObjectAnswer) {
            SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
            snapshotStore.setInstallPath(snapshotTO.getPath());
            snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
        } else if (answer instanceof CopyCmdAnswer) {
            SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
            snapshotStore.setInstallPath(snapshotTO.getPath());
            if (snapshotTO.getPhysicalSize() != null) {
                // For S3 delta snapshot, physical size is currently not set
                snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize());
            }
            if (snapshotTO.getParentSnapshotPath() == null) {
                snapshotStore.setParentSnapshotId(0L);
            }
            snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
            // update side-effect of snapshot operation
            if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) {
                VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
                if (vol != null) {
                    s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath());
                    vol.setPath(snapshotTO.getVolume().getPath());
                    volumeDao.update(vol.getId(), vol);
                } else {
                    s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
                }
            }
        } else {
            throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
        }
    } catch (RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEvent(event);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 4 with CreateObjectAnswer

use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.

the class Ovm3StorageProcessor method createVolume.

/**
     * Creates a volume, just a normal empty volume.
     */
@Override
public Answer createVolume(CreateObjectCommand cmd) {
    LOGGER.debug("execute createVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        /*
             * public Boolean storagePluginCreate(String uuid, String ssuuid,
             * String host, String file, Integer size)
             */
        String poolUuid = data.getDataStore().getUuid();
        String storeUrl = data.getDataStore().getUrl();
        URI uri = new URI(storeUrl);
        String host = uri.getHost();
        String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
        Long size = volume.getSize();
        StoragePlugin sp = new StoragePlugin(c);
        FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
        if (!fp.getName().equals(file)) {
            return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
        }
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setName(volume.getName());
        newVol.setSize(fp.getSize());
        newVol.setPath(volume.getUuid());
        return new CreateObjectAnswer(newVol);
    } catch (Ovm3ResourceException | URISyntaxException e) {
        LOGGER.info("Volume creation failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 5 with CreateObjectAnswer

use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.

the class Ovm3StorageProcessor method deleteSnapshot.

/**
     * Is not used in normal operation, the SSVM takes care of this.
     */
@Override
public Answer deleteSnapshot(DeleteCommand cmd) {
    LOGGER.debug("execute deleteSnapshot: " + cmd.getClass());
    DataTO data = cmd.getData();
    SnapshotObjectTO snap = (SnapshotObjectTO) data;
    String storeUrl = data.getDataStore().getUrl();
    String snapUuid = snap.getPath();
    try {
        // snapshots/accountid/volumeid
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw";
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, filePath);
        LOGGER.debug("Snapshot deletion success: " + filePath);
        return new Answer(cmd, true, "Deleted Snapshot " + filePath);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Snapshot deletion failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Aggregations

CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)11 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)10 DataTO (com.cloud.agent.api.to.DataTO)6 VolumeVO (com.cloud.storage.VolumeVO)5 InternalErrorException (com.cloud.exception.InternalErrorException)4 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)4 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)4 Answer (com.cloud.agent.api.Answer)3 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)3 URISyntaxException (java.net.URISyntaxException)3 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)3 RadosException (com.ceph.rados.exceptions.RadosException)2 RbdException (com.ceph.rbd.RbdException)2 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)2 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2 Connection (com.xensource.xenapi.Connection)2