Search in sources :

Example 11 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method registerVolumeCallback.

protected Void registerVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
    final CreateCmdResult result = callback.getResult();
    final VolumeObject vo = (VolumeObject) context.volume;
    try {
        if (result.isFailed()) {
            vo.processEvent(Event.OperationFailed);
            // delete the volume entry from volumes table in case of failure
            final VolumeVO vol = volDao.findById(vo.getId());
            if (vol != null) {
                volDao.remove(vo.getId());
            }
        } else {
            vo.processEvent(Event.OperationSuccessed, result.getAnswer());
            if (vo.getSize() != null) {
                // publish usage events
                // get physical size from volume_store_ref table
                final DataStore ds = vo.getDataStore();
                final VolumeDataStoreVO volStore = _volumeStoreDao.findByStoreVolume(ds.getId(), vo.getId());
                if (volStore == null) {
                    s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!");
                }
                final Scope dsScope = ds.getScope();
                if (dsScope.getScopeType() == ScopeType.REGION) {
                    _resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
                }
            }
        }
        final VolumeApiResult res = new VolumeApiResult(vo);
        context.future.complete(res);
        return null;
    } catch (final Exception e) {
        s_logger.error("register volume failed: ", e);
        // delete the volume entry from volumes table in case of failure
        final VolumeVO vol = volDao.findById(vo.getId());
        if (vol != null) {
            volDao.remove(vo.getId());
        }
        final VolumeApiResult res = new VolumeApiResult(null);
        context.future.complete(res);
        return null;
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Scope(com.cloud.engine.subsystem.api.storage.Scope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method takeSnapshot.

@Override
public void takeSnapshot(final SnapshotInfo snapshot, final AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = null;
    try {
        final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
        final Object payload = snapshot.getPayload();
        if (payload != null && payload instanceof CreateSnapshotPayload) {
            final CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload) payload;
            snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
        }
        final CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
        final EndPoint ep = epSelector.select(snapshot, StorageAction.TAKESNAPSHOT);
        Answer answer = null;
        if (ep == null) {
            final String errMsg = "No remote endpoint to send createObjectCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        result = new CreateCmdResult(null, answer);
        if (answer != null && !answer.getResult()) {
            result.setResult(answer.getDetails());
        }
        callback.complete(result);
        return;
    } catch (final Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        result = new CreateCmdResult(null, null);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(com.cloud.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) VolumeObject(com.cloud.storage.volume.VolumeObject) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) CreateObjectCommand(com.cloud.storage.command.CreateObjectCommand) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 13 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createVolumeAsync.

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

Example 14 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createBaseImageAsync.

@DB
protected void createBaseImageAsync(final VolumeInfo volume, final PrimaryDataStore dataStore, final TemplateInfo template, final AsyncCallFuture<VolumeApiResult> future) {
    final 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());
        }
    }
    final long templatePoolRefId = templatePoolRef.getId();
    final CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId);
    final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context);
    final 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);
    } finally {
        if (s_logger.isDebugEnabled()) {
            s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
        }
        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
    }
    return;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) DB(com.cloud.utils.db.DB)

Example 15 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method resize.

@Override
public void resize(final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
    final VolumeObject vol = (VolumeObject) data;
    final StoragePool pool = (StoragePool) data.getDataStore();
    final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
    final CreateCmdResult result = new CreateCmdResult(null, null);
    try {
        final ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
        if (answer != null && answer.getResult()) {
            final long finalSize = answer.getNewSize();
            s_logger.debug("Resize: volume started at size " + vol.getSize() + " and ended at size " + finalSize);
            vol.setSize(finalSize);
            vol.update();
        } else if (answer != null) {
            result.setResult(answer.getDetails());
        } else {
            s_logger.debug("return a null answer, mark it as failed for unknown reason");
            result.setResult("return a null answer, mark it as failed for unknown reason");
        }
    } catch (final Exception e) {
        s_logger.debug("sending resize command failed", e);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : StoragePool(com.cloud.storage.StoragePool) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(com.cloud.storage.volume.VolumeObject) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Aggregations

CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)4 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)3 TemplateObject (com.cloud.storage.image.store.TemplateObject)3 Answer (com.cloud.agent.api.Answer)2 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2