Search in sources :

Example 31 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method managedCopyBaseImageCallback.

protected Void managedCopyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final ManagedCreateBaseImageContext<VolumeApiResult> context) {
    final CopyCommandResult result = callback.getResult();
    final VolumeInfo volumeInfo = context.getVolumeInfo();
    final VolumeApiResult res = new VolumeApiResult(volumeInfo);
    if (result.isSuccess()) {
        // volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer());
        final VolumeVO volume = volDao.findById(volumeInfo.getId());
        final CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
        final TemplateObjectTO templateObjectTo = (TemplateObjectTO) answer.getNewData();
        volume.setPath(templateObjectTo.getPath());
        if (templateObjectTo.getFormat() != null) {
            volume.setFormat(templateObjectTo.getFormat());
        }
        volDao.update(volume.getId(), volume);
    } else {
        volumeInfo.processEvent(Event.DestroyRequested);
        res.setResult(result.getResult());
    }
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(res);
    return null;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 32 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.

@DB
protected Void createVolumeFromBaseImageCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    final DataObject vo = context.vo;
    final DataObject tmplOnPrimary = context.templateOnStore;
    final CopyCommandResult result = callback.getResult();
    final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        volResult.setResult(result.getResult());
        // hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
        // template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
        final Answer ans = result.getAnswer();
        if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
            if (tmplOnPrimary != null) {
                s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
                VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
                if (templatePoolRef != null) {
                    final long templatePoolRefId = templatePoolRef.getId();
                    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
                    try {
                        if (templatePoolRef == null) {
                            s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
                        } else {
                            templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
                            templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
                            _tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
                        }
                    } finally {
                        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
                    }
                }
            }
        }
    }
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(volResult);
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DB(com.cloud.utils.db.DB)

Example 33 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(final DataObject srcdata, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final 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.
            final TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(Storage.ImageFormat.RAW);
            final CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            final 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
            final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
            final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
            final StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            final DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            final DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
            final EndPoint ep = epSelector.select(srcData, destData);
            Answer answer = null;
            if (ep == null) {
                final 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);
            }
            final CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 34 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class TemplateObject method processEvent.

@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
    try {
        if (getDataStore().getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final TemplateObjectTO newTemplate = (TemplateObjectTO) cpyAnswer.getNewData();
                final VMTemplateStoragePoolVO templatePoolRef = templatePoolDao.findByPoolTemplate(getDataStore().getId(), getId());
                templatePoolRef.setDownloadPercent(100);
                if (newTemplate.getSize() != null) {
                    templatePoolRef.setTemplateSize(newTemplate.getSize());
                }
                templatePoolRef.setDownloadState(Status.DOWNLOADED);
                templatePoolRef.setLocalDownloadPath(newTemplate.getPath());
                templatePoolRef.setInstallPath(newTemplate.getPath());
                templatePoolDao.update(templatePoolRef.getId(), templatePoolRef);
            }
        } else if (getDataStore().getRole() == DataStoreRole.Image || getDataStore().getRole() == DataStoreRole.ImageCache) {
            if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final TemplateObjectTO newTemplate = (TemplateObjectTO) cpyAnswer.getNewData();
                final TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), getId());
                templateStoreRef.setInstallPath(newTemplate.getPath());
                templateStoreRef.setDownloadPercent(100);
                templateStoreRef.setDownloadState(Status.DOWNLOADED);
                templateStoreRef.setSize(newTemplate.getSize());
                if (newTemplate.getPhysicalSize() != null) {
                    templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize());
                }
                templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
                if (getDataStore().getRole() == DataStoreRole.Image) {
                    final VMTemplateVO templateVO = imageDao.findById(getId());
                    if (newTemplate.getFormat() != null) {
                        templateVO.setFormat(newTemplate.getFormat());
                    }
                    if (newTemplate.getName() != null) {
                        // For template created from snapshot, template name is determine by resource code.
                        templateVO.setUniqueName(newTemplate.getName());
                    }
                    if (newTemplate.getHypervisorType() != null) {
                        templateVO.setHypervisorType(newTemplate.getHypervisorType());
                    }
                    templateVO.setSize(newTemplate.getSize());
                    imageDao.update(templateVO.getId(), templateVO);
                }
            }
        }
        objectInStoreMgr.update(this, event);
    } catch (final NoTransitionException e) {
        s_logger.debug("failed to update state", e);
        throw new CloudRuntimeException("Failed to update state" + e.toString());
    } catch (final Exception ex) {
        s_logger.debug("failed to process event and answer", ex);
        objectInStoreMgr.delete(this);
        throw new CloudRuntimeException("Failed to process event", ex);
    } finally {
        // in case of OperationFailed, expunge the entry
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 35 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method copySnapshotAsyncCallback.

protected Void copySnapshotAsyncCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
    final CopyCommandResult result = callback.getResult();
    final SnapshotInfo destSnapshot = context.destSnapshot;
    final SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
    final AsyncCallFuture<SnapshotResult> future = context.future;
    SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
    if (result.isFailed()) {
        try {
            destSnapshot.processEvent(Event.OperationFailed);
            // if backup snapshot failed, mark srcSnapshot in snapshot_store_ref as failed also
            srcSnapshot.processEvent(Event.DestroyRequested);
            srcSnapshot.processEvent(Event.OperationSuccessed);
            srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
            _snapshotDao.remove(srcSnapshot.getId());
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to update state: " + e.toString());
        }
        snapResult.setResult(result.getResult());
        future.complete(snapResult);
        return null;
    }
    try {
        final CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) result.getAnswer();
        destSnapshot.processEvent(Event.OperationSuccessed, copyCmdAnswer);
        srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
        snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer);
        future.complete(snapResult);
    } catch (final Exception e) {
        s_logger.debug("Failed to update snapshot state", e);
        snapResult.setResult(e.toString());
        future.complete(snapResult);
    }
    return null;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)38 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)33 NfsTO (com.cloud.agent.api.to.NfsTO)22 InternalErrorException (com.cloud.exception.InternalErrorException)22 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)20 DataTO (com.cloud.agent.api.to.DataTO)19 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)19 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)18 Connection (com.xensource.xenapi.Connection)18 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 SR (com.xensource.xenapi.SR)17 VDI (com.xensource.xenapi.VDI)17 TemplateObjectTO (com.cloud.storage.to.TemplateObjectTO)15 URI (java.net.URI)15 SnapshotObjectTO (com.cloud.storage.to.SnapshotObjectTO)11 Task (com.xensource.xenapi.Task)7 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)6 ConfigurationException (javax.naming.ConfigurationException)5 VolumeVO (com.cloud.storage.VolumeVO)4