Search in sources :

Example 21 with AsyncCallFuture

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

the class VolumeServiceImpl method expungeVolumeAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    VolumeApiResult result = new VolumeApiResult(volume);
    if (volume.getDataStore() == null) {
        s_logger.info("Expunge volume with no data store specified");
        if (canVolumeBeRemoved(volume.getId())) {
            s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
            volDao.remove(volume.getId());
        }
        future.complete(result);
        return future;
    }
    // Find out if the volume is at state of download_in_progress on secondary storage
    VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
    if (volumeStore != null) {
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
            future.complete(result);
            return future;
        }
    }
    VolumeVO vol = volDao.findById(volume.getId());
    if (vol == null) {
        s_logger.debug("Volume " + volume.getId() + " is not found");
        future.complete(result);
        return future;
    }
    if (!volumeExistsOnPrimary(vol)) {
        // not created on primary store
        if (volumeStore == null) {
            // also not created on secondary store
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Marking volume that was never created as destroyed: " + vol);
            }
            volDao.remove(vol.getId());
            future.complete(result);
            return future;
        }
    }
    VolumeObject vo = (VolumeObject) volume;
    if (volume.getDataStore().getRole() == DataStoreRole.Image) {
        // no need to change state in volumes table
        volume.processEventOnly(Event.DestroyRequested);
    } else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
        volume.processEvent(Event.ExpungeRequested);
    }
    DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<VolumeApiResult>(null, vo, future);
    AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
    volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Example 22 with AsyncCallFuture

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

the class TemplateServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<TemplateApiResult> syncToRegionStoreAsync(TemplateInfo template, DataStore store) {
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    // no need to create entry on template_store_ref here, since entries are already created when prepareSecondaryStorageForMigration is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    TemplateInfo templateOnStore = _templateFactory.getTemplate(template, store);
    String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + template.getAccountId() + "/" + template.getId() + "/" + template.getUniqueName();
    ((TemplateObject) templateOnStore).setInstallPath(installPath);
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, (TemplateObject) templateOnStore, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(template, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 23 with AsyncCallFuture

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

the class SnapshotServiceImpl method deleteSnapshot.

@Override
public boolean deleteSnapshot(SnapshotInfo snapInfo) {
    snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null, snapInfo, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
    DataStore store = snapInfo.getDataStore();
    store.getDriver().deleteAsync(store, snapInfo, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (InterruptedException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 24 with AsyncCallFuture

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

the class SnapshotServiceImpl method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
    SnapshotObject snapObj = (SnapshotObject) snapshot;
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    SnapshotResult result = new SnapshotResult(snapshot, null);
    try {
        snapObj.processEvent(Snapshot.Event.BackupToSecondary);
        DataStore imageStore = findSnapshotImageStore(snapshot);
        if (imageStore == null) {
            throw new CloudRuntimeException("can not find an image stores");
        }
        SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
        snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
        CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnImageStore, future);
        AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
    } catch (Exception e) {
        s_logger.debug("Failed to copy snapshot", e);
        result.setResult("Failed to copy snapshot:" + e.toString());
        try {
            snapObj.processEvent(Snapshot.Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change state: " + e1.toString());
        }
        future.complete(result);
    }
    try {
        SnapshotResult res = future.get();
        if (res.isFailed()) {
            throw new CloudRuntimeException(res.getResult());
        }
        SnapshotInfo destSnapshot = res.getSnapshot();
        return destSnapshot;
    } catch (InterruptedException e) {
        s_logger.debug("failed copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    }
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 25 with AsyncCallFuture

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

the class S3TemplateTest method registerTemplate.

@Test(priority = 1)
public void registerTemplate() {
    TemplateInfo template = templateFactory.getTemplate(templateId, DataStoreRole.Image);
    DataStore store = dataStoreMgr.getImageStore(dcId);
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    templateSvr.createTemplateAsync(template, store, future);
    try {
        TemplateApiResult result = future.get();
        assertTrue(result.isSuccess(), "failed to register template: " + result.getResult());
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        assertTrue(false, e.getMessage());
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        assertTrue(false, e.getMessage());
    }
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutionException(java.util.concurrent.ExecutionException) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) Test(org.testng.annotations.Test)

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