Search in sources :

Example 16 with DataObject

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

the class DataObjectManagerImpl method createAsync.

@Override
public void createAsync(DataObject data, DataStore store, AsyncCompletionCallback<CreateCmdResult> callback, boolean noCopy) {
    DataObjectInStore obj = objectInDataStoreMgr.findObject(data, store);
    DataObject objInStore = null;
    boolean freshNewTemplate = false;
    if (obj == null) {
        try {
            objInStore = objectInDataStoreMgr.create(data, store);
            freshNewTemplate = true;
        } catch (Throwable e) {
            obj = objectInDataStoreMgr.findObject(data, store);
            if (obj == null) {
                CreateCmdResult result = new CreateCmdResult(null, null);
                result.setSuccess(false);
                result.setResult(e.toString());
                callback.complete(result);
                return;
            }
        }
    }
    if (!freshNewTemplate && obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
        try {
            objInStore = waitingForCreated(data, store);
        } catch (Exception e) {
            CreateCmdResult result = new CreateCmdResult(null, null);
            result.setSuccess(false);
            result.setResult(e.toString());
            callback.complete(result);
            return;
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        callback.complete(result);
        return;
    }
    try {
        ObjectInDataStoreStateMachine.Event event = null;
        if (noCopy) {
            event = ObjectInDataStoreStateMachine.Event.CreateOnlyRequested;
        } else {
            event = ObjectInDataStoreStateMachine.Event.CreateRequested;
        }
        objectInDataStoreMgr.update(objInStore, event);
    } catch (NoTransitionException e) {
        try {
            objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("state transation failed", e1);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(e.toString());
        callback.complete(result);
        return;
    } catch (ConcurrentOperationException e) {
        try {
            objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("state transation failed", e1);
        }
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(e.toString());
        callback.complete(result);
        return;
    }
    CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, objInStore);
    AsyncCallbackDispatcher<DataObjectManagerImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createAsynCallback(null, null)).setContext(context);
    store.getDriver().createAsync(store, objInStore, caller);
    return;
}
Also used : DataObjectInStore(org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore) 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) ObjectInDataStoreStateMachine(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) Event(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event)

Example 17 with DataObject

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

the class DataObjectManagerImpl method createInternalStateOnly.

@Override
public DataObject createInternalStateOnly(DataObject data, DataStore store) {
    DataObjectInStore obj = objectInDataStoreMgr.findObject(data, store);
    DataObject objInStore = null;
    if (obj == null) {
        objInStore = objectInDataStoreMgr.create(data, store);
    }
    try {
        ObjectInDataStoreStateMachine.Event event = null;
        event = ObjectInDataStoreStateMachine.Event.CreateRequested;
        objectInDataStoreMgr.update(objInStore, event);
        objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to update state", e);
        throw new CloudRuntimeException("Failed to update state", e);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("Failed to update state", e);
        throw new CloudRuntimeException("Failed to update state", e);
    }
    return objInStore;
}
Also used : ObjectInDataStoreStateMachine(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) DataObjectInStore(org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Event(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event)

Example 18 with DataObject

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

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
    DataStore store = destData.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
            //For CLVM, we need to copy template to primary storage at all, just fake the copy result.
            TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(Storage.ImageFormat.RAW);
            CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        } else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
            //For CLVM, we need to pass template on secondary storage to hypervisor
            String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
            int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
            StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
            EndPoint ep = epSelector.select(srcData, destData);
            Answer answer = null;
            if (ep == null) {
                String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new Answer(cmd, false, errMsg);
            } else {
                answer = ep.sendMessage(cmd);
            }
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 19 with DataObject

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

the class VolumeServiceImpl method createVolumeCallback.

protected Void createVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> context) {
    CreateCmdResult result = callback.getResult();
    DataObject vo = context.getVolume();
    String errMsg = null;
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        errMsg = result.getResult();
    }
    VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (errMsg != null) {
        volResult.setResult(errMsg);
    }
    context.getFuture().complete(volResult);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 20 with DataObject

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

the class VolumeServiceImpl method copyBaseImageCallback.

@DB
protected Void copyBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateBaseImageContext<VolumeApiResult> context) {
    CopyCommandResult result = callback.getResult();
    VolumeApiResult res = new VolumeApiResult(context.getVolume());
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    DataObject templateOnPrimaryStoreObj = context.destObj;
    if (!result.isSuccess()) {
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
        res.setResult(result.getResult());
        future.complete(res);
        return null;
    }
    templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
    createVolumeFromBaseImageAsync(context.volume, templateOnPrimaryStoreObj, context.dataStore, future);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

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