Search in sources :

Example 1 with Scope

use of org.apache.cloudstack.engine.subsystem.api.storage.Scope in project cloudstack by apache.

the class AncientDataMotionStrategy method copyObject.

protected Answer copyObject(DataObject srcData, DataObject destData, Host destHost) {
    String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    Answer answer = null;
    DataObject cacheData = null;
    DataObject srcForCopy = srcData;
    try {
        if (needCacheStorage(srcData, destData)) {
            Scope destScope = pickCacheScopeForCopy(srcData, destData);
            srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
        }
        CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData);
        if (ep == null) {
            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);
        }
        if (cacheData != null) {
            final Long cacheId = cacheData.getId();
            final String cacheType = cacheData.getType().toString();
            final String cacheUuid = cacheData.getUuid().toString();
            if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
                // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
                // Delete cache in order to certainly transfer a latest image.
                s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                cacheMgr.deleteCacheObject(srcForCopy);
            } else {
                // for template, we want to leave it on cache for performance reason
                if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
                    // cache object created by this copy, not already there
                    s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.deleteCacheObject(srcForCopy);
                } else {
                    s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.releaseCacheObject(srcForCopy);
                }
            }
        }
        return answer;
    } catch (Exception e) {
        s_logger.debug("copy object failed: ", e);
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with Scope

use of org.apache.cloudstack.engine.subsystem.api.storage.Scope in project cloudstack by apache.

the class AncientDataMotionStrategy method copyVolumeBetweenPools.

protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.CopyVolumeWait.key());
    int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
    Scope destScope = getZoneScope(destData.getDataStore().getScope());
    DataStore cacheStore = cacheMgr.getCacheStorage(destScope);
    if (cacheStore == null) {
        // need to find a nfs or cifs image store, assuming that can't copy volume
        // directly to s3
        ImageStoreEntity imageStore = (ImageStoreEntity) dataStoreMgr.getImageStore(destScope.getScopeId());
        if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
            s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
            return null;
        }
        DataObject objOnImageStore = imageStore.create(srcData);
        objOnImageStore.processEvent(Event.CreateOnlyRequested);
        Answer answer = copyObject(srcData, objOnImageStore);
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to image store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed, answer);
        objOnImageStore.processEvent(Event.CopyingRequested);
        CopyCommand cmd = new CopyCommand(objOnImageStore.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = selector.select(objOnImageStore, destData);
        if (ep == null) {
            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);
        }
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to primary store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed);
        imageStore.delete(objOnImageStore);
        return answer;
    } else {
        DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
        CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = selector.select(cacheData, destData);
        Answer answer = null;
        if (ep == null) {
            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);
        }
        // delete volume on cache store
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    }
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ImageStoreEntity(org.apache.cloudstack.storage.image.datastore.ImageStoreEntity) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Example 3 with Scope

use of org.apache.cloudstack.engine.subsystem.api.storage.Scope in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCopyDataToSecondaryStorage.

/**
     * This function is responsible for copying a volume from the managed store to a secondary store. This is used in two cases
     * 1) When creating a template from a snapshot
     * 2) When createSnapshot is called with location=SECONDARY
     *
     * @param snapshotInfo Source snapshot
     * @param destData destination (can be template or snapshot)
     * @param callback callback for async
     */
private void handleCopyDataToSecondaryStorage(SnapshotInfo snapshotInfo, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        snapshotInfo.processEvent(Event.CopyingRequested);
    } catch (Exception ex) {
        throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
    }
    HostVO hostVO = getHost(snapshotInfo);
    boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
    boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
    boolean needCache = needCacheStorage(snapshotInfo, destData);
    DataObject destOnStore = destData;
    if (needCache) {
        // creates an object in the DB for data to be cached
        Scope selectedScope = pickCacheScopeForCopy(snapshotInfo, destData);
        destOnStore = cacheMgr.getCacheObject(snapshotInfo, selectedScope);
        destOnStore.processEvent(Event.CreateOnlyRequested);
    }
    if (usingBackendSnapshot && !computeClusterSupportsResign) {
        String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
        LOGGER.warn(noSupportForResignErrMsg);
        throw new CloudRuntimeException(noSupportForResignErrMsg);
    }
    try {
        if (usingBackendSnapshot) {
            createVolumeFromSnapshot(hostVO, snapshotInfo, true);
        }
        DataStore srcDataStore = snapshotInfo.getDataStore();
        String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
        int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
        CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), destOnStore.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        String errMsg = null;
        CopyCmdAnswer copyCmdAnswer = null;
        try {
            // (because we passed in true as the third parameter to createVolumeFromSnapshot above).
            if (!usingBackendSnapshot) {
                _volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
            }
            Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
            copyCommand.setOptions(srcDetails);
            copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
            if (!copyCmdAnswer.getResult()) {
                // We were not able to copy. Handle it.
                errMsg = copyCmdAnswer.getDetails();
                throw new CloudRuntimeException(errMsg);
            }
            if (needCache) {
                // If cached storage was needed (in case of object store as secondary
                // storage), at this point, the data has been copied from the primary
                // to the NFS cache by the hypervisor. We now invoke another copy
                // command to copy this data from cache to secondary storage. We
                // then cleanup the cache
                destOnStore.processEvent(Event.OperationSuccessed, copyCmdAnswer);
                CopyCommand cmd = new CopyCommand(destOnStore.getTO(), destData.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
                EndPoint ep = selector.select(destOnStore, destData);
                if (ep == null) {
                    errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                    LOGGER.error(errMsg);
                    copyCmdAnswer = new CopyCmdAnswer(errMsg);
                } else {
                    copyCmdAnswer = (CopyCmdAnswer) ep.sendMessage(cmd);
                }
                // clean up snapshot copied to staging
                cacheMgr.deleteCacheObject(destOnStore);
            }
        } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
            String msg = "Failed to create template from snapshot (Snapshot ID = " + snapshotInfo.getId() + ") : ";
            LOGGER.warn(msg, ex);
            throw new CloudRuntimeException(msg + ex.getMessage());
        } finally {
            _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
            if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
                if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
                    errMsg = copyCmdAnswer.getDetails();
                    if (needCache) {
                        cacheMgr.deleteCacheObject(destOnStore);
                    }
                } else {
                    errMsg = "Unable to create template from snapshot";
                }
            }
            try {
                if (StringUtils.isEmpty(errMsg)) {
                    snapshotInfo.processEvent(Event.OperationSuccessed);
                } else {
                    snapshotInfo.processEvent(Event.OperationFailed);
                }
            } catch (Exception ex) {
                LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex);
            }
        }
        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
        result.setResult(errMsg);
        callback.complete(result);
    } finally {
        if (usingBackendSnapshot) {
            deleteVolumeFromSnapshot(snapshotInfo);
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) TimeoutException(java.util.concurrent.TimeoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) HostVO(com.cloud.host.HostVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 4 with Scope

use of org.apache.cloudstack.engine.subsystem.api.storage.Scope in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method pickCacheScopeForCopy.

private Scope pickCacheScopeForCopy(DataObject srcData, DataObject destData) {
    Scope srcScope = srcData.getDataStore().getScope();
    Scope destScope = destData.getDataStore().getScope();
    Scope selectedScope = null;
    if (srcScope.getScopeId() != null) {
        selectedScope = getZoneScope(srcScope);
    } else if (destScope.getScopeId() != null) {
        selectedScope = getZoneScope(destScope);
    } else {
        LOGGER.warn("Cannot find a zone-wide scope for movement that needs a cache storage");
    }
    return selectedScope;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)

Example 5 with Scope

use of org.apache.cloudstack.engine.subsystem.api.storage.Scope in project cloudstack by apache.

the class DefaultEndPointSelector method findEndpointForImageStorage.

protected EndPoint findEndpointForImageStorage(DataStore store) {
    Long dcId = null;
    Scope storeScope = store.getScope();
    if (storeScope.getScopeType() == ScopeType.ZONE) {
        dcId = storeScope.getScopeId();
    }
    // find ssvm that can be used to download data to store. For zone-wide
    // image store, use SSVM for that zone. For region-wide store,
    // we can arbitrarily pick one ssvm to do that task
    List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
    if (ssAHosts == null || ssAHosts.isEmpty()) {
        return null;
    }
    Collections.shuffle(ssAHosts);
    HostVO host = ssAHosts.get(0);
    return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
}
Also used : Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostVO(com.cloud.host.HostVO)

Aggregations

Scope (org.apache.cloudstack.engine.subsystem.api.storage.Scope)13 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)9 HostScope (org.apache.cloudstack.engine.subsystem.api.storage.HostScope)7 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)6 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)4 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)4 Answer (com.cloud.agent.api.Answer)3 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)3 HostVO (com.cloud.host.HostVO)3 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)3 PublishScope (org.apache.cloudstack.framework.messagebus.PublishScope)3 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)2 NfsTO (com.cloud.agent.api.to.NfsTO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1