Search in sources :

Example 31 with CreateCmdResult

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

the class VolumeServiceImpl method createManagedTemplateVolume.

/**
     * Creates a template volume on managed storage, which will be used for creating ROOT volumes by cloning.
     *
     * @param srcTemplateInfo Source template on secondary storage
     * @param destPrimaryDataStore Managed storage on which we need to create the volume
     */
private TemplateInfo createManagedTemplateVolume(TemplateInfo srcTemplateInfo, PrimaryDataStore destPrimaryDataStore) {
    // create a template volume on primary storage
    AsyncCallFuture<VolumeApiResult> createTemplateFuture = new AsyncCallFuture<>();
    TemplateInfo templateOnPrimary = (TemplateInfo) destPrimaryDataStore.create(srcTemplateInfo);
    VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId());
    if (templatePoolRef == null) {
        throw new CloudRuntimeException("Failed to find template " + srcTemplateInfo.getUniqueName() + " in storage pool " + destPrimaryDataStore.getId());
    }
    // At this point, we have an entry in the DB that points to our cached template.
    // We need to lock it as there may be other VMs that may get started using the same template.
    // We want to avoid having to create multiple cache copies of the same template.
    int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
    long templatePoolRefId = templatePoolRef.getId();
    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
    if (templatePoolRef == null) {
        throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
    }
    // Template already exists
    if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
        return templateOnPrimary;
    }
    try {
        // create a cache volume on the back-end
        templateOnPrimary.processEvent(Event.CreateOnlyRequested);
        CreateVolumeContext<CreateCmdResult> createContext = new CreateVolumeContext<>(null, templateOnPrimary, createTemplateFuture);
        AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> createCaller = AsyncCallbackDispatcher.create(this);
        createCaller.setCallback(createCaller.getTarget().createManagedTemplateImageCallback(null, null)).setContext(createContext);
        destPrimaryDataStore.getDriver().createAsync(destPrimaryDataStore, templateOnPrimary, createCaller);
        VolumeApiResult result = createTemplateFuture.get();
        if (result.isFailed()) {
            String errMesg = result.getResult();
            throw new CloudRuntimeException("Unable to create template " + templateOnPrimary.getId() + " on primary storage " + destPrimaryDataStore.getId() + ":" + errMesg);
        }
    } catch (Throwable e) {
        s_logger.debug("Failed to create template volume on storage", e);
        templateOnPrimary.processEvent(Event.OperationFailed);
        throw new CloudRuntimeException(e.getMessage());
    } finally {
        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
    }
    return templateOnPrimary;
}
Also used : CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 32 with CreateCmdResult

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

the class FakePrimaryDataStoreDriver method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = new CreateCmdResult(null, null);
    if (snapshotResult) {
        SnapshotObjectTO newSnap = new SnapshotObjectTO();
        newSnap.setPath(UUID.randomUUID().toString());
        CreateObjectAnswer answer = new CreateObjectAnswer(newSnap);
        result.setAnswer(answer);
    } else {
        result.setResult("Failed to create snapshot");
    }
    callback.complete(result);
    return;
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 33 with CreateCmdResult

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

the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.

protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, CreateContext<CreateCmdResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing image store createTemplate async callback");
    }
    DownloadAnswer answer = callback.getResult();
    DataObject obj = context.data;
    DataStore store = obj.getDataStore();
    TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
    if (tmpltStoreVO != null) {
        if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
        updateBuilder.setDownloadPercent(answer.getDownloadPct());
        updateBuilder.setDownloadState(answer.getDownloadStatus());
        updateBuilder.setLastUpdated(new Date());
        updateBuilder.setErrorString(answer.getErrorString());
        updateBuilder.setJobId(answer.getJobId());
        updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
        updateBuilder.setInstallPath(answer.getInstallPath());
        updateBuilder.setSize(answer.getTemplateSize());
        updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
        _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
        // update size in vm_template table
        VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
        tmlptUpdater.setSize(answer.getTemplateSize());
        _templateDao.update(obj.getId(), tmlptUpdater);
    }
    AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
    if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(answer.getErrorString());
        caller.complete(result);
        String msg = "Failed to register template: " + obj.getUuid() + " with error: " + answer.getErrorString();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, _vmTemplateZoneDao.listByTemplateId(obj.getId()).get(0).getZoneId(), null, msg, msg);
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        if (answer.getCheckSum() != null) {
            VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate();
            templateDaoBuilder.setChecksum(answer.getCheckSum());
            _templateDao.update(obj.getId(), templateDaoBuilder);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 34 with CreateCmdResult

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

the class DataObjectManagerImpl method deleteAsync.

@Override
public void deleteAsync(DataObject data, AsyncCompletionCallback<CommandResult> callback) {
    try {
        objectInDataStoreMgr.update(data, Event.DestroyRequested);
    } catch (NoTransitionException e) {
        s_logger.debug("destroy failed", e);
        CreateCmdResult res = new CreateCmdResult(null, null);
        callback.complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("destroy failed", e);
        CreateCmdResult res = new CreateCmdResult(null, null);
        callback.complete(res);
    }
    DeleteContext<CommandResult> context = new DeleteContext<CommandResult>(callback, data);
    AsyncCallbackDispatcher<DataObjectManagerImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteAsynCallback(null, null)).setContext(context);
    data.getDataStore().getDriver().deleteAsync(data.getDataStore(), data, caller);
    return;
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Example 35 with CreateCmdResult

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

the class DataObjectManagerImpl method createAsynCallback.

protected Void createAsynCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CreateCmdResult> callback, CreateContext<CreateCmdResult> context) {
    CreateCmdResult result = callback.getResult();
    DataObject objInStrore = context.objInStrore;
    CreateCmdResult upResult = new CreateCmdResult(null, null);
    if (result.isFailed()) {
        upResult.setResult(result.getResult());
        context.getParentCallback().complete(upResult);
        return null;
    }
    try {
        objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        try {
            objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to change state", e1);
        }
        upResult.setResult(e.toString());
        context.getParentCallback().complete(upResult);
        return null;
    } catch (ConcurrentOperationException e) {
        try {
            objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to change state", e1);
        }
        upResult.setResult(e.toString());
        context.getParentCallback().complete(upResult);
        return null;
    }
    context.getParentCallback().complete(result);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

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