Search in sources :

Example 31 with CopyCommandResult

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

the class TemplateServiceImpl method copyTemplateCallBack.

protected Void copyTemplateCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateInfo destTemplate = context.getTemplate();
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process copy template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 32 with CopyCommandResult

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

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(final SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        final SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        final AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    }
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    volumeInfo.processEvent(Event.MigrationRequested);
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        final Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        try {
            _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    String errMsg = null;
    if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
        if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
            errMsg = copyCmdAnswer.getDetails();
        } else {
            errMsg = "Unable to perform host-side operation";
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CopyCommand(com.cloud.storage.command.CopyCommand) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 33 with CopyCommandResult

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

the class StorageCacheManagerImpl method createCacheObject.

@Override
public DataObject createCacheObject(final DataObject data, final DataStore store) {
    DataObject objOnCacheStore = null;
    final Object lock;
    final DataObjectType type = data.getType();
    final String typeName;
    final long storeId = store.getId();
    final long dataId = data.getId();
    /*
         * Make sure any thread knows own lock type.
         */
    if (type == DataObjectType.TEMPLATE) {
        lock = templateLock;
        typeName = "template";
    } else if (type == DataObjectType.VOLUME) {
        lock = volumeLock;
        typeName = "volume";
    } else if (type == DataObjectType.SNAPSHOT) {
        lock = snapshotLock;
        typeName = "snapshot";
    } else {
        final String msg = "unsupported DataObject comes, then can't acquire correct lock object";
        throw new CloudRuntimeException(msg);
    }
    s_logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
    DataObject existingDataObj = null;
    synchronized (lock) {
        DataObjectInStore obj = objectInStoreMgr.findObject(data, store);
        if (obj != null) {
            State st = obj.getState();
            final long miliSeconds = 10000;
            final long timeoutSeconds = 3600;
            final long timeoutMiliSeconds = timeoutSeconds * 1000;
            Date now = new Date();
            final long expiredEpoch = now.getTime() + timeoutMiliSeconds;
            final Date expiredDate = new Date(expiredEpoch);
            /*
                 * Waiting for completion of cache copy.
                 */
            while (st == ObjectInDataStoreStateMachine.State.Allocated || st == ObjectInDataStoreStateMachine.State.Creating || st == ObjectInDataStoreStateMachine.State.Copying) {
                /*
                     * Threads must release lock within waiting for cache copy and
                     * must be waken up at completion.
                     */
                s_logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode());
                try {
                    lock.wait(miliSeconds);
                } catch (final InterruptedException e) {
                    s_logger.debug("[ignored] interupted while waiting for cache copy completion.");
                }
                s_logger.debug("waken up");
                now = new Date();
                if (now.after(expiredDate)) {
                    final String msg = "Waiting time exceeds timeout limit(" + timeoutSeconds + " s)";
                    throw new CloudRuntimeException(msg);
                }
                obj = objectInStoreMgr.findObject(data, store);
                st = obj.getState();
            }
            if (st == ObjectInDataStoreStateMachine.State.Ready) {
                s_logger.debug("there is already one in the cache store");
                final DataObject dataObj = objectInStoreMgr.get(data, store);
                dataObj.incRefCount();
                existingDataObj = dataObj;
            }
        }
        if (existingDataObj == null) {
            s_logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
            objOnCacheStore = store.create(data);
        }
        lock.notifyAll();
    }
    if (existingDataObj != null) {
        return existingDataObj;
    }
    if (objOnCacheStore == null) {
        s_logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed");
        return null;
    }
    final AsyncCallFuture<CopyCommandResult> future = new AsyncCallFuture<>();
    CopyCommandResult result = null;
    try {
        objOnCacheStore.processEvent(Event.CreateOnlyRequested);
        dataMotionSvr.copyAsync(data, objOnCacheStore, future);
        result = future.get();
        if (result.isFailed()) {
            objOnCacheStore.processEvent(Event.OperationFailed);
        } else {
            objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
            objOnCacheStore.incRefCount();
            return objOnCacheStore;
        }
    } catch (final InterruptedException e) {
        s_logger.debug("create cache storage failed: " + e.toString());
        throw new CloudRuntimeException(e);
    } catch (final ExecutionException e) {
        s_logger.debug("create cache storage failed: " + e.toString());
        throw new CloudRuntimeException(e);
    } finally {
        if (result == null) {
            objOnCacheStore.processEvent(Event.OperationFailed);
        }
        synchronized (lock) {
            /*
                 * Wake up all threads waiting for cache copy.
                 */
            s_logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")");
            lock.notifyAll();
        }
    }
    return null;
}
Also used : DataObjectInStore(com.cloud.engine.subsystem.api.storage.DataObjectInStore) Date(java.util.Date) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) State(com.cloud.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ExecutionException(java.util.concurrent.ExecutionException) DataObjectType(com.cloud.agent.api.to.DataObjectType) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 34 with CopyCommandResult

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

the class AbstractHyperVisorStorageMotionStrategy method copyAsync.

@Override
public Void copyAsync(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
    Answer answer = null;
    String errMsg = null;
    try {
        final VMInstanceVO instance = instanceDao.findById(vmTo.getId());
        if (instance != null) {
            if (srcHost.getClusterId().equals(destHost.getClusterId())) {
                answer = migrateVmWithVolumesWithinCluster(instance, vmTo, srcHost, destHost, volumeMap);
            } else {
                answer = migrateVmWithVolumesAcrossCluster(instance, vmTo, srcHost, destHost, volumeMap);
            }
        } else {
            throw new CloudRuntimeException("Unsupported operation requested for moving data.");
        }
    } catch (final Exception e) {
        s_logger.error("copy failed", e);
        errMsg = e.toString();
    }
    final CopyCommandResult result = new CopyCommandResult(null, answer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException)

Example 35 with CopyCommandResult

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

the class AbstractHyperVisorStorageMotionStrategy method copyAsync.

@Override
public Void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final CopyCommandResult result = new CopyCommandResult(null, null);
    result.setResult("Unsupported operation requested for copying data.");
    callback.complete(result);
    return null;
}
Also used : CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)37 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ExecutionException (java.util.concurrent.ExecutionException)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)14 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)12 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)12 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)5 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)5 Answer (com.cloud.agent.api.Answer)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)4 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)4 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 CommandResult (com.cloud.storage.command.CommandResult)4 DB (com.cloud.utils.db.DB)4 CopyCommand (com.cloud.storage.command.CopyCommand)3