Search in sources :

Example 1 with Snapshot

use of com.linbit.linstor.api.model.Snapshot in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) {
    s_logger.debug("Linstor: takeSnapshot with snapshot: " + snapshotInfo.getUuid());
    final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
    final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    long storagePoolId = volumeVO.getPoolId();
    final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    final DevelopersApi api = LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
    final String rscName = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
    Snapshot snapshot = new Snapshot();
    snapshot.setName(getSnapshotName(snapshotInfo.getUuid()));
    CreateCmdResult result;
    try {
        ApiCallRcList answers = api.resourceSnapshotCreate(rscName, snapshot);
        if (answers.hasError()) {
            final String errMsg = answers.get(0).getMessage();
            s_logger.error("Snapshot error: " + errMsg);
            result = new CreateCmdResult(null, new Answer(null, false, errMsg));
            result.setResult(errMsg);
        } else {
            s_logger.info(String.format("Successfully took snapshot from %s", rscName));
            SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO) snapshotInfo.getTO();
            snapshotObjectTo.setPath(rscName + "-" + snapshotInfo.getName());
            result = new CreateCmdResult(null, new CreateObjectAnswer(snapshotObjectTo));
            result.setResult(null);
        }
    } catch (ApiException apiExc) {
        s_logger.error(apiExc);
        result = new CreateCmdResult(null, new Answer(null, false, apiExc.getBestMessage()));
        result.setResult(apiExc.getBestMessage());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) DevelopersApi(com.linbit.linstor.api.DevelopersApi) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Snapshot(com.linbit.linstor.api.model.Snapshot) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) VolumeVO(com.cloud.storage.VolumeVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

Answer (com.cloud.agent.api.Answer)1 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 ApiException (com.linbit.linstor.api.ApiException)1 DevelopersApi (com.linbit.linstor.api.DevelopersApi)1 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)1 Snapshot (com.linbit.linstor.api.model.Snapshot)1 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)1 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)1 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)1