Search in sources :

Example 6 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = null;
    try {
        SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
        Object payload = snapshot.getPayload();
        if (payload != null && payload instanceof CreateSnapshotPayload) {
            CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload) payload;
            snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
        }
        CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
        EndPoint ep = epSelector.select(snapshot, StorageAction.TAKESNAPSHOT);
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send createObjectCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        result = new CreateCmdResult(null, answer);
        if (answer != null && !answer.getResult()) {
            result.setResult(answer.getDetails());
        }
        callback.complete(result);
        return;
    } catch (Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        result = new CreateCmdResult(null, null);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 7 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method revertSnapshot.

@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
    RevertSnapshotCommand cmd = new RevertSnapshotCommand(snapshotTO);
    CommandResult result = new CommandResult();
    try {
        EndPoint ep = epSelector.select(snapshotOnPrimaryStore);
        if (ep == null) {
            String errMsg = "No remote endpoint to send RevertSnapshotCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            result.setResult(errMsg);
        } else {
            Answer answer = ep.sendMessage(cmd);
            if (answer != null && !answer.getResult()) {
                result.setResult(answer.getDetails());
            }
        }
    } catch (Exception ex) {
        s_logger.debug("Unable to revert snapshot " + snapshot.getId(), ex);
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RevertSnapshotCommand(org.apache.cloudstack.storage.command.RevertSnapshotCommand) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 8 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO 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 9 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO 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 10 with SnapshotObjectTO

use of org.apache.cloudstack.storage.to.SnapshotObjectTO 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

SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)44 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 DataTO (com.cloud.agent.api.to.DataTO)22 NfsTO (com.cloud.agent.api.to.NfsTO)21 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)20 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)19 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)16 InternalErrorException (com.cloud.exception.InternalErrorException)14 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)14 Answer (com.cloud.agent.api.Answer)12 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)11 Connection (com.xensource.xenapi.Connection)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)9 VDI (com.xensource.xenapi.VDI)9 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 SR (com.xensource.xenapi.SR)8 URI (java.net.URI)7 ConfigurationException (javax.naming.ConfigurationException)7 S3TO (com.cloud.agent.api.to.S3TO)6