Search in sources :

Example 11 with DataStore

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

the class StorageCacheReplacementAlgorithmLRUTest method testSelectObjectFailed.

@Test
public void testSelectObjectFailed() {
    cacheReplacementAlgorithm.setUnusedTimeInterval(1);
    try {
        VMTemplateVO template = new VMTemplateVO();
        template.setTemplateType(Storage.TemplateType.USER);
        template.setUrl(UUID.randomUUID().toString());
        template.setUniqueName(UUID.randomUUID().toString());
        template.setName(UUID.randomUUID().toString());
        template.setPublicTemplate(true);
        template.setFeatured(true);
        template.setRequiresHvm(true);
        template.setBits(64);
        template.setFormat(Storage.ImageFormat.VHD);
        template.setEnablePassword(true);
        template.setEnableSshKey(true);
        template.setGuestOSId(1);
        template.setBootable(true);
        template.setPrepopulate(true);
        template.setCrossZones(true);
        template.setExtractable(true);
        template = templateDao.persist(template);
        VMTemplateVO template2 = new VMTemplateVO();
        template2.setTemplateType(Storage.TemplateType.USER);
        template2.setUrl(UUID.randomUUID().toString());
        template2.setUniqueName(UUID.randomUUID().toString());
        template2.setName(UUID.randomUUID().toString());
        template2.setPublicTemplate(true);
        template2.setFeatured(true);
        template2.setRequiresHvm(true);
        template2.setBits(64);
        template2.setFormat(Storage.ImageFormat.VHD);
        template2.setEnablePassword(true);
        template2.setEnableSshKey(true);
        template2.setGuestOSId(1);
        template2.setBootable(true);
        template2.setPrepopulate(true);
        template2.setCrossZones(true);
        template2.setExtractable(true);
        template2 = templateDao.persist(template2);
        ImageStoreVO imageStoreVO = new ImageStoreVO();
        imageStoreVO.setRole(DataStoreRole.ImageCache);
        imageStoreVO.setName(UUID.randomUUID().toString());
        imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
        imageStoreVO.setProtocol("nfs");
        imageStoreVO.setUrl(UUID.randomUUID().toString());
        imageStoreVO = imageStoreDao.persist(imageStoreVO);
        Date date = DateUtil.now();
        TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
        templateStoreVO1.setLastUpdated(date);
        templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO1.setDataStoreId(imageStoreVO.getId());
        templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO1.setCopy(true);
        templateStoreVO1.setTemplateId(template.getId());
        templateDataStoreDao.persist(templateStoreVO1);
        TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
        templateStoreVO2.setLastUpdated(date);
        templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO2.setDataStoreId(imageStoreVO.getId());
        templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO2.setCopy(true);
        templateStoreVO2.setTemplateId(template2.getId());
        templateDataStoreDao.persist(templateStoreVO2);
        DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
        Assert.assertNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date) Test(org.junit.Test)

Example 12 with DataStore

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

the class StorageSystemDataMotionStrategy method cacheSnapshotChain.

private DataObject cacheSnapshotChain(SnapshotInfo snapshot, Scope scope) {
    DataObject leafData = null;
    DataStore store = cacheMgr.getCacheStorage(snapshot, scope);
    while (snapshot != null) {
        DataObject cacheData = cacheMgr.createCacheObject(snapshot, store);
        if (leafData == null) {
            leafData = cacheData;
        }
        snapshot = snapshot.getParent();
    }
    return leafData;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 13 with DataStore

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

the class StorageSystemDataMotionStrategy method internalCanHandle.

/**
 * Handles migrating volumes on managed Storage.
 */
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
    Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
    for (VolumeInfo volumeInfo : volumeInfoSet) {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
        if (storagePoolVO.isManaged()) {
            return StrategyPriority.HIGHEST;
        }
    }
    Collection<DataStore> dataStores = volumeMap.values();
    for (DataStore dataStore : dataStores) {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStore.getId());
        if (storagePoolVO.isManaged()) {
            return StrategyPriority.HIGHEST;
        }
    }
    return StrategyPriority.CANT_HANDLE;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 14 with DataStore

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

the class StorageSystemDataMotionStrategy method isSourceAndDestinationPoolTypeOfNfs.

/**
 * Returns true if at least one of the entries on the map 'volumeDataStoreMap' has both source and destination storage pools of Network Filesystem (NFS).
 */
protected boolean isSourceAndDestinationPoolTypeOfNfs(Map<VolumeInfo, DataStore> volumeDataStoreMap) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeDataStoreMap.entrySet()) {
        VolumeInfo srcVolumeInfo = entry.getKey();
        DataStore destDataStore = entry.getValue();
        StoragePoolVO destStoragePool = _storagePoolDao.findById(destDataStore.getId());
        StoragePoolVO sourceStoragePool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
        if (sourceStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem && destStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
            return true;
        }
    }
    return false;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with DataStore

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

the class StorageSystemDataMotionStrategy method handleCreateNonManagedVolumeFromManagedSnapshot.

private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    if (!HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
        String errMsg = "Creating a volume on non-managed storage from a snapshot on managed storage is currently only supported with XenServer.";
        handleError(errMsg, callback);
    }
    long volumeStoragePoolId = volumeInfo.getDataStore().getId();
    StoragePoolVO volumeStoragePoolVO = _storagePoolDao.findById(volumeStoragePoolId);
    if (volumeStoragePoolVO.getClusterId() == null) {
        String errMsg = "To create a non-managed volume from a managed snapshot, the destination storage pool must be cluster scoped.";
        handleError(errMsg, callback);
    }
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    boolean usingBackendSnapshot = false;
    try {
        snapshotInfo.processEvent(Event.CopyingRequested);
        usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
        if (usingBackendSnapshot) {
            boolean computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(volumeStoragePoolVO.getClusterId());
            if (!computeClusterSupportsVolumeClone) {
                String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + volumeStoragePoolVO.getClusterId();
                LOGGER.warn(noSupportForResignErrMsg);
                throw new CloudRuntimeException(noSupportForResignErrMsg);
            }
            createVolumeFromSnapshot(snapshotInfo);
            HostVO hostVO = getHost(snapshotInfo.getDataCenterId(), HypervisorType.XenServer, true);
            copyCmdAnswer = performResignature(snapshotInfo, hostVO, null, true);
            verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
        }
        int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
        CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
        if (!usingBackendSnapshot) {
            long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
            DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
            _volumeService.grantAccess(snapshotInfo, hostVO, snapshotDataStore);
        }
        Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
        copyCommand.setOptions(srcDetails);
        copyCmdAnswer = (CopyCmdAnswer) agentManager.send(hostVO.getId(), copyCommand);
        if (!copyCmdAnswer.getResult()) {
            errMsg = copyCmdAnswer.getDetails();
            LOGGER.warn(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (Exception ex) {
        errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateNonManagedVolumeFromManagedSnapshot': " + ex.getMessage();
        throw new CloudRuntimeException(errMsg);
    } finally {
        try {
            HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
            long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
            DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotDataStore);
        } catch (Exception e) {
            LOGGER.debug("Failed to revoke access from dest volume", e);
        }
        if (usingBackendSnapshot) {
            deleteVolumeFromSnapshot(snapshotInfo);
        }
        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);
        }
        if (copyCmdAnswer == null) {
            copyCmdAnswer = new CopyCmdAnswer(errMsg);
        }
        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) HostVO(com.cloud.host.HostVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)221 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)81 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)71 ExecutionException (java.util.concurrent.ExecutionException)50 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)42 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)38 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)35 VolumeVO (com.cloud.storage.VolumeVO)34 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)30 VMTemplateVO (com.cloud.storage.VMTemplateVO)30 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)29 HostVO (com.cloud.host.HostVO)26 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)26 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)25 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)23 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)23 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)22 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22