Search in sources :

Example 26 with DataStoreProvider

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

the class StorageManagerImpl method getBytesRequiredForTemplate.

private long getBytesRequiredForTemplate(VMTemplateVO tmpl, StoragePool pool) {
    if (tmplFactory.isTemplateMarkedForDirectDownload(tmpl.getId())) {
        return tmpl.getSize();
    }
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver) {
        PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
        TemplateInfo templateInfo = tmplFactory.getReadyTemplateOnImageStore(tmpl.getId(), pool.getDataCenterId());
        return primaryStoreDriver.getBytesRequiredForTemplate(templateInfo, pool);
    }
    return tmpl.getSize();
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)

Example 27 with DataStoreProvider

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

the class StorageManagerImpl method createSecondaryStagingStore.

@Override
public ImageStore createSecondaryStagingStore(CreateSecondaryStagingStoreCmd cmd) {
    String providerName = cmd.getProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultCacheDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find cache store provider: " + providerName);
        }
    }
    Long dcId = cmd.getZoneId();
    ScopeType scopeType = null;
    String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
        } catch (Exception e) {
            throw new InvalidParameterValueException("invalid scope for cache store " + scope);
        }
        if (scopeType != ScopeType.ZONE) {
            throw new InvalidParameterValueException("Only zone wide cache storage is supported");
        }
    }
    if (scopeType == ScopeType.ZONE && dcId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }
    // Check if the zone exists in the system
    DataCenterVO zone = _dcDao.findById(dcId);
    if (zone == null) {
        throw new InvalidParameterValueException("Can't find zone by id " + dcId);
    }
    Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("zoneId", dcId);
    params.put("url", cmd.getUrl());
    params.put("name", cmd.getUrl());
    params.put("details", cmd.getDetails());
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.ImageCache);
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = null;
    try {
        store = lifeCycle.initialize(params);
    } catch (Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.ImageCache);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) 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) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) 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 28 with DataStoreProvider

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

the class VolumeServiceTest method testCreatePrimaryStorage.

@Test
public void testCreatePrimaryStorage() {
    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
    Map<String, Object> params = new HashMap<String, Object>();
    URI uri = null;
    try {
        uri = new URI(this.getPrimaryStorageUrl());
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    params.put("url", this.getPrimaryStorageUrl());
    params.put("server", uri.getHost());
    params.put("path", uri.getPath());
    params.put("protocol", 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();
    this.primaryStore = lifeCycle.initialize(params);
    ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
    lifeCycle.attachCluster(this.primaryStore, scope);
}
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) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 29 with DataStoreProvider

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

the class VolumeServiceTest method createImageStore.

private DataStore createImageStore() {
    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample image data store provider");
    Map<String, Object> params = new HashMap<String, Object>();
    String name = UUID.randomUUID().toString();
    params.put("name", name);
    params.put("uuid", name);
    params.put("protocol", "http");
    params.put("scope", ScopeType.GLOBAL.toString());
    params.put("providerName", name);
    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = lifeCycle.initialize(params);
    return store;
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) 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)

Example 30 with DataStoreProvider

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

the class DataStoreProviderManagerImpl method getImageDataStoreProviders.

public List<StorageProviderResponse> getImageDataStoreProviders() {
    List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>();
    for (DataStoreProvider provider : providerMap.values()) {
        if (provider.getTypes().contains(DataStoreProviderType.IMAGE)) {
            StorageProviderResponse response = new StorageProviderResponse();
            response.setName(provider.getName());
            response.setType(DataStoreProvider.DataStoreProviderType.IMAGE.toString());
            providers.add(response);
        }
    }
    return providers;
}
Also used : StorageProviderResponse(org.apache.cloudstack.api.response.StorageProviderResponse) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)33 DataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)13 PrimaryDataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 HashMap (java.util.HashMap)10 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)10 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ArrayList (java.util.ArrayList)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 ConnectionException (com.cloud.exception.ConnectionException)4 DiscoveryException (com.cloud.exception.DiscoveryException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4