Search in sources :

Example 6 with CreateCmdResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method resize.

@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    s_logger.debug("Resize elastistor volume started");
    Boolean status = false;
    VolumeObject vol = (VolumeObject) data;
    StoragePool pool = (StoragePool) data.getDataStore();
    ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    CreateCmdResult result = new CreateCmdResult(null, null);
    StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
    if (!(poolVO.isManaged())) {
        super.resize(data, callback);
        return;
    }
    try {
        status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize);
    } catch (Throwable e) {
        s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e);
        result.setResult(e.toString());
        callback.complete(result);
    }
    if (status) {
        // now updating the cloudstack storagepool usedbytes and volume
        Long usedBytes = poolVO.getUsedBytes();
        Long currentVolumeSize = vol.getSize();
        Long newUsedBytes;
        if (currentVolumeSize < resizeParameter.newSize) {
            newUsedBytes = usedBytes + (resizeParameter.newSize - currentVolumeSize);
            poolVO.setUsedBytes(newUsedBytes);
        } else {
            newUsedBytes = usedBytes - (currentVolumeSize - resizeParameter.newSize);
            poolVO.setUsedBytes(newUsedBytes);
        }
        _storagePoolDao.update(pool.getId(), poolVO);
        vol.getVolume().setSize(resizeParameter.newSize);
        vol.update();
        callback.complete(result);
    } else {
        callback.complete(result);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject)

Example 7 with CreateCmdResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.

the class SnapshotServiceImpl method takeSnapshot.

@Override
public SnapshotResult takeSnapshot(SnapshotInfo snap) {
    SnapshotObject snapshot = (SnapshotObject) snap;
    SnapshotObject snapshotOnPrimary = null;
    try {
        snapshotOnPrimary = (SnapshotObject) snap.getDataStore().create(snapshot);
    } catch (Exception e) {
        s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
    } catch (Exception e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        try {
            snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
        throw new CloudRuntimeException(e);
    }
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    try {
        CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<CommandResult>(null, snap.getBaseVolume(), snapshotOnPrimary, future);
        AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
        PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver) snapshotOnPrimary.getDataStore().getDriver();
        primaryStore.takeSnapshot(snapshot, caller);
    } catch (Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change state for event: OperationFailed", e);
        }
        throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
    }
    SnapshotResult result;
    try {
        result = future.get();
        return result;
    } catch (InterruptedException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    }
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with CreateCmdResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.

the class TemplateServiceImpl method copyTemplateCrossZoneCallBack.

protected Void copyTemplateCrossZoneCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing copy template cross zone callback after completion");
    }
    TemplateInfo destTemplate = context.getTemplate();
    CreateCmdResult result = callback.getResult();
    AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (Exception e) {
        s_logger.debug("Failed to process copy template cross zones callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with CreateCmdResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.

the class TemplateServiceImpl method createTemplateCallback.

protected Void createTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
    TemplateObject template = context.getTemplate();
    AsyncCompletionCallback<TemplateApiResult> parentCallback = context.getParentCallback();
    TemplateApiResult result = new TemplateApiResult(template);
    CreateCmdResult callbackResult = callback.getResult();
    if (callbackResult.isFailed()) {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        result.setResult(callbackResult.getResult());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    try {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (Exception e) {
        result.setResult(e.toString());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    if (parentCallback != null) {
        parentCallback.complete(result);
    }
    return null;
}
Also used : CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 10 with CreateCmdResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.

the class TemplateServiceImpl method copyTemplate.

@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(TemplateInfo srcTemplate, DataStore destStore) {
    // Need to understand what is the background to use two different urls for copy and extract.
    if (srcTemplate.getFormat() == ImageFormat.OVA) {
        ImageStoreEntity tmpltStore = (ImageStoreEntity) srcTemplate.getDataStore();
        tmpltStore.createEntityExtractUrl(srcTemplate.getInstallPath(), srcTemplate.getFormat(), srcTemplate);
    }
    // generate a URL from source template ssvm to download to destination data store
    String url = generateCopyUrl(srcTemplate);
    if (url == null) {
        s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
        throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
    }
    TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting source template url to " + url);
    }
    tmplForCopy.setUrl(url);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Mark template_store_ref entry as Creating");
    }
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    DataObject templateOnStore = destStore.create(tmplForCopy);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
    }
    try {
        TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, (TemplateObject) templateOnStore, future);
        AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
        destStore.getDriver().createAsync(destStore, templateOnStore, caller);
    } catch (CloudRuntimeException ex) {
        // clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
        TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
        if (templateStoreVO != null) {
            TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ImageStoreEntity(org.apache.cloudstack.storage.image.datastore.ImageStoreEntity)

Aggregations

CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)38 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)12 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)9 Answer (com.cloud.agent.api.Answer)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)7 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 VolumeVO (com.cloud.storage.VolumeVO)6 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)6 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)6 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)4 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)3