Search in sources :

Example 6 with AsyncCallFuture

use of org.apache.cloudstack.framework.async.AsyncCallFuture in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateOnPrimary.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateOnPrimary(TemplateInfo template, StoragePool pool) {
    TemplateObject templateObject = (TemplateObject) _templateFactory.getTemplate(template.getId(), (DataStore) pool);
    templateObject.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    DataStore dataStore = _storeMgr.getPrimaryDataStore(pool.getId());
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, templateObject, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    dataStore.getDriver().deleteAsync(dataStore, templateObject, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 7 with AsyncCallFuture

use of org.apache.cloudstack.framework.async.AsyncCallFuture 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)

Example 8 with AsyncCallFuture

use of org.apache.cloudstack.framework.async.AsyncCallFuture in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateAsync.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateAsync(TemplateInfo template) {
    TemplateObject to = (TemplateObject) template;
    // update template_store_ref status
    to.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, to, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    to.getDataStore().getDriver().deleteAsync(to.getDataStore(), to, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 9 with AsyncCallFuture

use of org.apache.cloudstack.framework.async.AsyncCallFuture in project cloudstack by apache.

the class VolumeServiceImpl method copyVolumeFromPrimaryToImage.

protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(VolumeInfo srcVolume, DataStore destStore) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    VolumeApiResult res = new VolumeApiResult(srcVolume);
    VolumeInfo destVolume = null;
    try {
        destVolume = (VolumeInfo) destStore.create(srcVolume);
        // this is just used for locking that src volume record in DB to avoid using lock
        srcVolume.processEvent(Event.MigrationRequested);
        destVolume.processEventOnly(Event.CreateOnlyRequested);
        CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<VolumeApiResult>(null, future, srcVolume, destVolume, destStore);
        AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
        return future;
    } catch (Exception e) {
        s_logger.error("failed to copy volume to image store", e);
        if (destVolume != null) {
            destVolume.getDataStore().delete(destVolume);
        }
        // unlock source volume record
        srcVolume.processEvent(Event.OperationFailed);
        res.setResult(e.toString());
        future.complete(res);
        return future;
    }
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with AsyncCallFuture

use of org.apache.cloudstack.framework.async.AsyncCallFuture in project cloudstack by apache.

the class VolumeServiceImpl method createVolumeFromTemplateAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(VolumeInfo volume, long dataStoreId, TemplateInfo template) {
    PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
    TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId());
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    if (templateOnPrimaryStore == null) {
        createBaseImageAsync(volume, pd, template, future);
        return future;
    }
    createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Aggregations

AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)28 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)19 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)9 CommandResult (org.apache.cloudstack.storage.command.CommandResult)9 ExecutionException (java.util.concurrent.ExecutionException)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)7 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)7 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)7 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)7 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)6 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)6 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)5 TemplateObject (org.apache.cloudstack.storage.image.store.TemplateObject)4 HashMap (java.util.HashMap)3 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)3 TemplateApiResult (org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)2