Search in sources :

Example 21 with DataObject

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

the class VolumeServiceImpl method createBaseImageAsync.

@DB
protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStore, TemplateInfo template, AsyncCallFuture<VolumeApiResult> future) {
    DataObject templateOnPrimaryStoreObj = dataStore.create(template);
    VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
    if (templatePoolRef == null) {
        throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId());
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId());
        }
    }
    long templatePoolRefId = templatePoolRef.getId();
    CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<CreateCmdResult>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId);
    AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context);
    int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds");
    }
    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
    if (templatePoolRef == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId);
        }
        templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
        if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
            s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
            createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
            return;
        }
        throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId);
    }
    try {
        if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
            s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
            createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
            return;
        }
        templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
        motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller);
    } catch (Throwable e) {
        s_logger.debug("failed to create template on storage", e);
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
        // make sure that template_spool_ref entry is still present so that the second thread can acquire the lock
        dataStore.create(template);
        VolumeApiResult result = new VolumeApiResult(volume);
        result.setResult(e.toString());
        future.complete(result);
    } finally {
        if (s_logger.isDebugEnabled()) {
            s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
        }
        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
    }
    return;
}
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) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Example 22 with DataObject

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

the class VolumeServiceImpl method registerVolume.

@Override
public AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataStore store) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    DataObject volumeOnStore = store.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().registerVolumeCallback(null, null));
        caller.setContext(context);
        store.getDriver().createAsync(store, volumeOnStore, caller);
    } catch (CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
        if (volStoreVO != null) {
            VolumeInfo volObj = volFactory.getVolume(volume, store);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        VolumeApiResult res = new VolumeApiResult((VolumeObject) volumeOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    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 23 with DataObject

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

the class VolumeServiceImpl method registerVolumeForPostUpload.

@Override
public Pair<EndPoint, DataObject> registerVolumeForPostUpload(VolumeInfo volume, DataStore store) {
    EndPoint ep = _epSelector.select(store);
    if (ep == null) {
        String errorMessage = "There is no secondary storage VM for image store " + store.getName();
        s_logger.warn(errorMessage);
        throw new CloudRuntimeException(errorMessage);
    }
    DataObject volumeOnStore = store.create(volume);
    return new Pair<>(ep, volumeOnStore);
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) Pair(com.cloud.utils.Pair)

Example 24 with DataObject

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

the class VolumeServiceImpl method copyManagedTemplateCallback.

protected Void copyManagedTemplateCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateBaseImageContext<VolumeApiResult> context) {
    CopyCommandResult result = callback.getResult();
    VolumeApiResult res = new VolumeApiResult(context.getVolume());
    res.setResult(result.getResult());
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    DataObject templateOnPrimaryStoreObj = context.destObj;
    if (result.isSuccess()) {
        templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
    }
    future.complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 25 with DataObject

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

the class VolumeServiceImpl method createVolumeFromBaseImageAsync.

@DB
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
    DataObject volumeOnPrimaryStorage = pd.create(volume);
    volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
    CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
    AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
    caller.setContext(context);
    motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
    return;
}
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