Search in sources :

Example 26 with DataObject

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

the class VolumeServiceImpl method createVolumeAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(VolumeInfo volume, DataStore dataStore) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    DataObject volumeOnStore = dataStore.create(volume);
    volumeOnStore.processEvent(Event.CreateOnlyRequested);
    try {
        CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volumeOnStore, future);
        AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
        dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
    } catch (CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
        if (volStoreVO != null) {
            VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
        volResult.setResult(ex.getMessage());
        future.complete(volResult);
    }
    return future;
}
Also used : VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 27 with DataObject

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

the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.

@DB
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    DataObject vo = context.vo;
    DataObject tmplOnPrimary = context.templateOnStore;
    CopyCommandResult result = callback.getResult();
    VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        volResult.setResult(result.getResult());
        // hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
        // template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
        Answer ans = result.getAnswer();
        if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
            if (tmplOnPrimary != null) {
                s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
                VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
                if (templatePoolRef != null) {
                    long templatePoolRefId = templatePoolRef.getId();
                    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
                    try {
                        if (templatePoolRef == null) {
                            s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
                        } else {
                            templatePoolRef.setTemplateSize(0);
                            templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
                            templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
                            _tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
                        }
                    } finally {
                        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
                    }
                }
            }
        }
    }
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(volResult);
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) DB(com.cloud.utils.db.DB)

Example 28 with DataObject

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

the class StorageSystemDataMotionStrategy method performCopyOfVdi.

/**
     * Copies data from secondary storage to a primary volume
     * @param volumeInfo The primary volume
     * @param snapshotInfo  destination of the copy
     * @param hostVO the host used to copy the data
     * @return result of the copy
     */
private CopyCmdAnswer performCopyOfVdi(VolumeInfo volumeInfo, SnapshotInfo snapshotInfo, HostVO hostVO) {
    Snapshot.LocationType locationType = snapshotInfo.getLocationType();
    String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    DataObject srcData = snapshotInfo;
    CopyCmdAnswer copyCmdAnswer = null;
    DataObject cacheData = null;
    boolean needCacheStorage = needCacheStorage(snapshotInfo, volumeInfo);
    if (needCacheStorage) {
        cacheData = cacheSnapshotChain(snapshotInfo, new ZoneScope(volumeInfo.getDataCenterId()));
        srcData = cacheData;
    }
    CopyCommand copyCommand = new CopyCommand(srcData.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    try {
        if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
            _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
            Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
            copyCommand.setOptions(srcDetails);
        }
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
        String msg = "Failed to perform VDI copy : ";
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        }
        _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        if (needCacheStorage && copyCmdAnswer != null && copyCmdAnswer.getResult()) {
            cacheMgr.deleteCacheObject(cacheData);
        }
    }
    return copyCmdAnswer;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Snapshot(com.cloud.storage.Snapshot) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 29 with DataObject

use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject 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)

Example 30 with DataObject

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

the class DataObjectManagerImpl method copyCallback.

protected Void copyCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, CopyContext<CreateCmdResult> context) {
    CopyCommandResult result = callback.getResult();
    DataObject destObj = context.destObj;
    if (result.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("Failed to update copying state", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("Failed to update copying state", e);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult(result.getResult());
        context.getParentCallback().complete(res);
    }
    try {
        objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    }
    CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
    context.getParentCallback().complete(res);
    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) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)36 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)13 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)12 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)11 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)11 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)7 Answer (com.cloud.agent.api.Answer)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)6 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)6 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)5 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)4 HostVO (com.cloud.host.HostVO)4 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)4 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 DB (com.cloud.utils.db.DB)3