Search in sources :

Example 1 with NeighborhoodsMatcher

use of com.emc.storageos.volumecontroller.impl.utils.attrmatchers.NeighborhoodsMatcher in project coprhd-controller by CoprHD.

the class CapacityUtils method getCapacityForVirtualPoolAndVirtualArray.

public static CapacityResponse getCapacityForVirtualPoolAndVirtualArray(VirtualPool vPool, URI vArrayId, DbClient dbClient, CoordinatorClient coordinator) {
    List<StoragePool> validPoolsOfvPool = VirtualPool.getValidStoragePools(vPool, dbClient, false);
    List<StoragePool> invalidPoolsOfvPool = VirtualPool.getInvalidStoragePools(vPool, dbClient);
    Map<String, Object> attributeMap = new ProvisioningAttributeMapBuilder(0L, vArrayId.toString(), 0L).buildMap();
    NeighborhoodsMatcher matcher = new NeighborhoodsMatcher();
    matcher.setCoordinatorClient(coordinator);
    matcher.setObjectCache(new ObjectLocalCache(dbClient));
    StringBuffer errorMessageForValidPools = new StringBuffer();
    StringBuffer errorMessageForInValidPools = new StringBuffer();
    validPoolsOfvPool = matcher.runMatchStoragePools(validPoolsOfvPool, attributeMap, errorMessageForValidPools);
    invalidPoolsOfvPool = matcher.runMatchStoragePools(invalidPoolsOfvPool, attributeMap, errorMessageForInValidPools);
    List<StoragePool> validPools = new ArrayList<StoragePool>();
    for (StoragePool pool : validPoolsOfvPool) {
        if (StoragePool.RegistrationStatus.REGISTERED.toString().equals(pool.getRegistrationStatus()) && CompatibilityStatus.COMPATIBLE.toString().equals(pool.getCompatibilityStatus()) && DiscoveryStatus.VISIBLE.toString().equals(pool.getDiscoveryStatus())) {
            validPools.add(pool);
        } else {
            invalidPoolsOfvPool.add(pool);
        }
    }
    Map<String, BigInteger> rawCapacityMetrics = getPoolCapacityMetrics(validPools, vPool, dbClient, coordinator);
    Set<String> poolSet = new HashSet<String>();
    for (StoragePool pool : validPools) {
        poolSet.add(pool.getId().toString());
    }
    Capacity capacity = getVirtualPoolCapacityForPools(dbClient, vPool.getId(), VirtualPool.Type.valueOf(vPool.getType()), poolSet);
    poolSet.clear();
    for (StoragePool pool : invalidPoolsOfvPool) {
        poolSet.add(pool.getId().toString());
    }
    Capacity invalidPoolCapacity = getVirtualPoolCapacityForPools(dbClient, vPool.getId(), VirtualPool.Type.valueOf(vPool.getType()), poolSet);
    // Free Capacity is rounded down
    BigInteger freeCapacity = rawCapacityMetrics.get(StorageMetrics.FREE.toString());
    freeCapacity = freeCapacity.divide(kbToGB_BI);
    long freeCapacityGb = freeCapacity.longValue();
    BigInteger netFreeCapacity = rawCapacityMetrics.get(StorageMetrics.NET_FREE.toString());
    netFreeCapacity = netFreeCapacity.divide(kbToGB_BI);
    long netFreeCapacityGb = netFreeCapacity.longValue();
    // 4) Check netFreeCapacity against Quota
    if (vPool.getQuotaEnabled()) {
        long netFreeQuota = vPool.getQuota() - (long) ((capacity._provisionedCapacity + invalidPoolCapacity._provisionedCapacity) / GB);
        if (netFreeQuota < 0) {
            netFreeCapacityGb = 0;
        } else if (netFreeQuota < netFreeCapacityGb) {
            netFreeCapacityGb = netFreeQuota;
        }
    }
    // Used Capacity is rounded up.
    BigDecimal[] result = new BigDecimal(capacity._usedCapacity + invalidPoolCapacity._usedCapacity).divideAndRemainder(new BigDecimal(GB));
    long usedCapacityGb = result[0].longValue();
    if (!result[1].equals(BigDecimal.ZERO)) {
        usedCapacityGb += 1;
    }
    // Subscribed Capacity is rounded up.
    result = new BigDecimal(capacity._provisionedCapacity + invalidPoolCapacity._provisionedCapacity).divideAndRemainder(new BigDecimal(GB));
    long subscribedCapacityGb = result[0].longValue();
    if (!result[1].equals(BigDecimal.ZERO)) {
        subscribedCapacityGb += 1;
    }
    long totalCapacityGB = freeCapacityGb + usedCapacityGb;
    CapacityResponse response = new CapacityResponse();
    response.setFreeGb(Long.toString(freeCapacityGb));
    response.setNetFreeGb(Long.toString(netFreeCapacityGb));
    response.setProvissionedGb(Long.toString(subscribedCapacityGb));
    response.setUsedGb(Long.toString(usedCapacityGb));
    if (totalCapacityGB != 0) {
        result = new BigDecimal(subscribedCapacityGb * 100).divideAndRemainder(new BigDecimal(totalCapacityGB));
        int percentage = result[0].intValue();
        if (!result[1].equals(BigDecimal.ZERO)) {
            percentage += 1;
        }
        response.setPercentProvisioned(Integer.toString(percentage));
        result = new BigDecimal(usedCapacityGb * 100).divideAndRemainder(new BigDecimal(totalCapacityGB));
        percentage = result[0].intValue();
        if (!result[1].equals(BigDecimal.ZERO)) {
            percentage += 1;
        }
        response.setPercentUsed(Integer.toString(percentage));
    }
    return response;
}
Also used : ProvisioningAttributeMapBuilder(com.emc.storageos.volumecontroller.impl.utils.ProvisioningAttributeMapBuilder) StoragePool(com.emc.storageos.db.client.model.StoragePool) ObjectLocalCache(com.emc.storageos.volumecontroller.impl.utils.ObjectLocalCache) ArrayList(java.util.ArrayList) NeighborhoodsMatcher(com.emc.storageos.volumecontroller.impl.utils.attrmatchers.NeighborhoodsMatcher) BigDecimal(java.math.BigDecimal) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) CapacityResponse(com.emc.storageos.model.vpool.CapacityResponse) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet)

Aggregations

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 CapacityResponse (com.emc.storageos.model.vpool.CapacityResponse)1 ObjectLocalCache (com.emc.storageos.volumecontroller.impl.utils.ObjectLocalCache)1 ProvisioningAttributeMapBuilder (com.emc.storageos.volumecontroller.impl.utils.ProvisioningAttributeMapBuilder)1 NeighborhoodsMatcher (com.emc.storageos.volumecontroller.impl.utils.attrmatchers.NeighborhoodsMatcher)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1