Search in sources :

Example 1 with ClusterScope

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

the class EndpointSelectorTest method testMixZonePrimaryStorages.

@Test
public void testMixZonePrimaryStorages() {
    Long srcStoreId = null;
    Long destStoreId = imageStore.getId();
    DataStore store = createPrimaryDataStore(ScopeType.ZONE);
    srcStoreId = store.getId();
    HostVO host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.ZONE);
    host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    Long xenStoreId = null;
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    xenStoreId = store.getId();
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    ZoneScope srcScope = new ZoneScope(dcId);
    DataStore srcStore = mock(DataStore.class);
    DataStore destStore = mock(DataStore.class);
    when(srcStore.getScope()).thenReturn(srcScope);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getId()).thenReturn(srcStoreId);
    when(destStore.getScope()).thenReturn(srcScope);
    when(destStore.getRole()).thenReturn(DataStoreRole.Image);
    when(destStore.getId()).thenReturn(destStoreId);
    DataObject srcObj = mock(DataObject.class);
    DataObject destObj = mock(DataObject.class);
    when(srcObj.getDataStore()).thenReturn(srcStore);
    when(destObj.getDataStore()).thenReturn(destStore);
    EndPoint ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    Long hostId = ep.getId();
    HostVO newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
    when(srcStore.getId()).thenReturn(destStoreId);
    when(destStore.getId()).thenReturn(srcStoreId);
    when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
    ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    hostId = ep.getId();
    newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getScope()).thenReturn(clusterScope);
    when(srcStore.getId()).thenReturn(xenStoreId);
    ep = endPointSelector.select(srcStore);
    Assert.assertTrue(ep != null);
    newHost = hostDao.findById(ep.getId());
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) Test(org.junit.Test)

Example 2 with ClusterScope

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

the class VolumeServiceTest method createPrimaryDataStore.

public DataStore createPrimaryDataStore() {
    try {
        DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
        Map<String, Object> params = new HashMap<String, Object>();
        URI uri = new URI(this.getPrimaryStorageUrl());
        params.put("url", this.getPrimaryStorageUrl());
        params.put("server", uri.getHost());
        params.put("path", uri.getPath());
        params.put("protocol", Storage.StoragePoolType.NetworkFilesystem);
        params.put("dcId", dcId.toString());
        params.put("hypervisorType", HypervisorType.None);
        params.put("clusterId", clusterId.toString());
        params.put("name", this.primaryName);
        params.put("port", "1");
        params.put("roles", DataStoreRole.Primary.toString());
        params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
        params.put("providerName", String.valueOf(provider.getName()));
        DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        DataStore store = lifeCycle.initialize(params);
        ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
        lifeCycle.attachCluster(store, scope);
        /*
             * PrimaryDataStoreProvider provider =
             * primaryDataStoreProviderMgr.getDataStoreProvider
             * ("sample primary data store provider");
             * primaryDataStoreProviderMgr.configure("primary data store mgr",
             * new HashMap<String, Object>());
             *
             * List<PrimaryDataStoreVO> ds =
             * primaryStoreDao.findPoolByName(this.primaryName); if (ds.size()
             * >= 1) { PrimaryDataStoreVO store = ds.get(0); if
             * (store.getRemoved() == null) { return
             * provider.getDataStore(store.getId()); } }
             *
             *
             * Map<String, String> params = new HashMap<String, String>();
             * params.put("url", this.getPrimaryStorageUrl());
             * params.put("dcId", dcId.toString()); params.put("clusterId",
             * clusterId.toString()); params.put("name", this.primaryName);
             * PrimaryDataStoreInfo primaryDataStoreInfo =
             * provider.registerDataStore(params); PrimaryDataStoreLifeCycle lc
             * = primaryDataStoreInfo.getLifeCycle(); ClusterScope scope = new
             * ClusterScope(clusterId, podId, dcId); lc.attachCluster(scope);
             * return primaryDataStoreInfo;
             */
        return store;
    } catch (Exception e) {
        return null;
    }
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with ClusterScope

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

the class StorageManagerImpl method createPool.

@Override
public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
    String providerName = cmd.getStorageProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find storage provider: " + providerName);
        }
    }
    Long clusterId = cmd.getClusterId();
    Long podId = cmd.getPodId();
    Long zoneId = cmd.getZoneId();
    ScopeType scopeType = ScopeType.CLUSTER;
    String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
        } catch (Exception e) {
            throw new InvalidParameterValueException("invalid scope for pool " + scope);
        }
    }
    if (scopeType == ScopeType.CLUSTER && clusterId == null) {
        throw new InvalidParameterValueException("cluster id can't be null, if scope is cluster");
    } else if (scopeType == ScopeType.ZONE && zoneId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }
    HypervisorType hypervisorType = HypervisorType.KVM;
    if (scopeType == ScopeType.ZONE) {
        // ignore passed clusterId and podId
        clusterId = null;
        podId = null;
        String hypervisor = cmd.getHypervisor();
        if (hypervisor != null) {
            try {
                hypervisorType = HypervisorType.getType(hypervisor);
            } catch (Exception e) {
                throw new InvalidParameterValueException("invalid hypervisor type " + hypervisor);
            }
        } else {
            throw new InvalidParameterValueException("Missing parameter hypervisor. Hypervisor type is required to create zone wide primary storage.");
        }
        Set<HypervisorType> supportedHypervisorTypes = Sets.newHashSet(HypervisorType.KVM, HypervisorType.VMware, HypervisorType.Hyperv, HypervisorType.LXC, HypervisorType.Any, HypervisorType.Simulator);
        if (!supportedHypervisorTypes.contains(hypervisorType)) {
            throw new InvalidParameterValueException("Zone wide storage pool is not supported for hypervisor type " + hypervisor);
        }
    } else {
        ClusterVO clusterVO = _clusterDao.findById(clusterId);
        hypervisorType = clusterVO.getHypervisorType();
    }
    Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
    DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
    if (zone == null) {
        throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
    }
    // Check if zone is disabled
    Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("zoneId", zone.getId());
    params.put("clusterId", clusterId);
    params.put("podId", podId);
    params.put("hypervisorType", hypervisorType);
    params.put("url", cmd.getUrl());
    params.put("tags", cmd.getTags());
    params.put("name", cmd.getStoragePoolName());
    params.put("details", details);
    params.put("providerName", storeProvider.getName());
    params.put("managed", cmd.isManaged());
    params.put("capacityBytes", cmd.getCapacityBytes());
    params.put("capacityIops", cmd.getCapacityIops());
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = null;
    try {
        store = lifeCycle.initialize(params);
        if (scopeType == ScopeType.CLUSTER) {
            ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
            lifeCycle.attachCluster(store, clusterScope);
        } else if (scopeType == ScopeType.ZONE) {
            ZoneScope zoneScope = new ZoneScope(zoneId);
            lifeCycle.attachZone(store, zoneScope, hypervisorType);
        }
    } catch (Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        try {
            // not deleting data store.
            if (store != null) {
                lifeCycle.deleteDataStore(store);
            }
        } catch (Exception ex) {
            s_logger.debug("Failed to clean up storage pool: " + ex.getMessage());
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 4 with ClusterScope

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

the class CloudStackPrimaryDataStoreLifeCycleImplTest method testAttachCluster.

@Test
public void testAttachCluster() throws Exception {
    _cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L));
    verify(storagePoolHostDao, times(2)).persist(Mockito.any(StoragePoolHostVO.class));
}
Also used : ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) Test(org.junit.Test)

Example 5 with ClusterScope

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

the class AncientDataMotionStrategy method getZoneScope.

private Scope getZoneScope(Scope destScope) {
    ZoneScope zoneScope = null;
    if (destScope instanceof ClusterScope) {
        ClusterScope clusterScope = (ClusterScope) destScope;
        zoneScope = new ZoneScope(clusterScope.getZoneId());
    } else if (destScope instanceof HostScope) {
        HostScope hostScope = (HostScope) destScope;
        zoneScope = new ZoneScope(hostScope.getZoneId());
    } else {
        zoneScope = (ZoneScope) destScope;
    }
    return zoneScope;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope)

Aggregations

ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)8 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)5 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)3 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)3 DataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle)3 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)3 HostScope (org.apache.cloudstack.engine.subsystem.api.storage.HostScope)3 URI (java.net.URI)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 ClusterVO (com.cloud.dc.ClusterVO)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConnectionException (com.cloud.exception.ConnectionException)1 DiscoveryException (com.cloud.exception.DiscoveryException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1