Search in sources :

Example 11 with ImageStore

use of com.cloud.storage.ImageStore in project cosmic by MissionCriticalCloud.

the class AddImageStoreCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    try {
        final ImageStore result = _storageService.discoverImageStore(getName(), getUrl(), getProviderName(), getZoneId(), getDetails());
        ImageStoreResponse storeResponse = null;
        if (result != null) {
            storeResponse = _responseGenerator.createImageStoreResponse(result);
            storeResponse.setResponseName(getCommandName());
            storeResponse.setObjectName("imagestore");
            setResponseObject(storeResponse);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (final DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ServerApiException(com.cloud.api.ServerApiException) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Example 12 with ImageStore

use of com.cloud.storage.ImageStore in project cosmic by MissionCriticalCloud.

the class AddSecondaryStorageCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    try {
        final ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), null);
        ImageStoreResponse storeResponse = null;
        if (result != null) {
            storeResponse = _responseGenerator.createImageStoreResponse(result);
            storeResponse.setResponseName(getCommandName());
            storeResponse.setObjectName("secondarystorage");
            setResponseObject(storeResponse);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (final DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ServerApiException(com.cloud.api.ServerApiException) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Example 13 with ImageStore

use of com.cloud.storage.ImageStore in project cloudstack by apache.

the class PrometheusExporterImpl method addStorageMetrics.

private void addStorageMetrics(final List<Item> metricsList, final long dcId, final String zoneName, final String zoneUuid) {
    for (final StoragePoolJoinVO pool : storagePoolJoinDao.listAll()) {
        if (pool == null || pool.getZoneId() != dcId) {
            continue;
        }
        final String poolName = pool.getName();
        final String poolPath = pool.getHostAddress() + ":" + pool.getPath();
        long usedCapacity = 0L;
        long allocatedCapacity = pool.getUsedCapacity() + pool.getReservedCapacity();
        final long totalCapacity = pool.getCapacityBytes();
        final StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
        if (stats != null) {
            usedCapacity = stats.getByteUsed();
        }
        final BigDecimal poolOverProvisioningFactor = BigDecimal.valueOf(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId()));
        final String poolFactor = poolOverProvisioningFactor.toString();
        metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, USED, usedCapacity));
        metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, ALLOCATED, allocatedCapacity));
        metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, UNALLOCATED, poolOverProvisioningFactor.multiply(BigDecimal.valueOf(totalCapacity)).longValue() - allocatedCapacity));
        metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, TOTAL, totalCapacity));
    }
    for (final ImageStore imageStore : imageStoreDao.findByZone(new ZoneScope(dcId), null)) {
        final StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(imageStore.getId());
        metricsList.add(new ItemPool(zoneName, zoneUuid, imageStore.getName(), imageStore.getUrl(), "secondary", null, USED, stats != null ? stats.getByteUsed() : 0));
        metricsList.add(new ItemPool(zoneName, zoneUuid, imageStore.getName(), imageStore.getUrl(), "secondary", null, TOTAL, stats != null ? stats.getCapacityBytes() : 0));
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) StorageStats(com.cloud.storage.StorageStats) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) BigDecimal(java.math.BigDecimal) ImageStore(com.cloud.storage.ImageStore)

Aggregations

ImageStore (com.cloud.storage.ImageStore)13 ImageStoreResponse (org.apache.cloudstack.api.response.ImageStoreResponse)8 DiscoveryException (com.cloud.exception.DiscoveryException)7 ServerApiException (org.apache.cloudstack.api.ServerApiException)7 ImageStoreResponse (com.cloud.api.response.ImageStoreResponse)4 ServerApiException (com.cloud.api.ServerApiException)3 StorageService (com.cloud.storage.StorageService)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 StoragePoolJoinVO (com.cloud.api.query.vo.StoragePoolJoinVO)1 StorageStats (com.cloud.storage.StorageStats)1 BigDecimal (java.math.BigDecimal)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)1