Search in sources :

Example 1 with AttributeMatcher

use of com.emc.storageos.volumecontroller.AttributeMatcher in project coprhd-controller by CoprHD.

the class AttributeMatcherFramework method matchAttributes.

/**
 * Match all attributes of CoS container & volumeParam container values against the given pools.
 *
 * @param allPools : list of pools
 * @param cos : vpool
 * @param objValueToCompare : volumeParam container values.
 * @param dbClient
 * @param matcherGroupName : groupName to execute the matchers.matchers are grouped by its relativity
 * @param errorMessage : will contain error message
 * @return Returns list of matched StoragePool instances
 */
public List<StoragePool> matchAttributes(List<StoragePool> allPools, Map<String, Object> attributeMap, DbClient dbClient, CoordinatorClient coordinator, String matcherGroupName, StringBuffer errorMessage) {
    List<StoragePool> matchedPools = new ArrayList<StoragePool>();
    if (!CollectionUtils.isEmpty(allPools)) {
        matchedPools.addAll(allPools);
        try {
            _logger.info("Starting execution of {} group matchers .", matcherGroupName);
            @SuppressWarnings("unchecked") List<AttributeMatcher> attrMatcherList = (List<AttributeMatcher>) getBeanFromContext(matcherGroupName);
            ObjectLocalCache cache = new ObjectLocalCache(dbClient);
            initializeCommonReferencesForAllMatchers(cache, coordinator);
            // Clear the existing content before matcher
            errorMessage.setLength(0);
            for (AttributeMatcher matcher : attrMatcherList) {
                int poolSizeAtTheStart = matchedPools.size();
                if (!matchedPools.isEmpty()) {
                    _logger.debug("passing {} pools to match", matchedPools.size());
                    matchedPools = matcher.runMatchStoragePools(matchedPools, attributeMap, errorMessage);
                    if (matchedPools.isEmpty()) {
                        _logger.info(String.format("Failed to find match because of %s", matcher.getClass().getSimpleName()));
                    } else if (matchedPools.size() < poolSizeAtTheStart) {
                        _logger.info(String.format("%s eliminated %d pools from the matched list", matcher.getClass().getSimpleName(), poolSizeAtTheStart - matchedPools.size()));
                    }
                } else {
                    _logger.info("No storage pools found matching with attributeMap passed");
                    break;
                }
            }
            cache.clearCache();
        } catch (Exception ex) {
            // Clearing the matched pools as there is an exception occurred while processing.
            matchedPools.clear();
            _logger.error("Exception occurred while matching pools with vPools", ex);
        } finally {
            _logger.info("Ended execution of {} group matchers .", matcherGroupName);
        }
    } else {
        String message = "Virtual pool does not have matching Storage pool. ";
        if (errorMessage != null && !errorMessage.toString().contains(message)) {
            errorMessage.append(message);
        }
        _logger.error(errorMessage.toString());
    }
    return matchedPools;
}
Also used : AttributeMatcher(com.emc.storageos.volumecontroller.AttributeMatcher) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BeansException(org.springframework.beans.BeansException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)

Example 2 with AttributeMatcher

use of com.emc.storageos.volumecontroller.AttributeMatcher in project coprhd-controller by CoprHD.

the class AttributeMatcherFramework method initializeCommonReferencesForAllMatchers.

/**
 * Method will iterate through all AttributeMatchers (not a subset) and apply common references to them.
 *
 * @param cache [IN] - ObjectLocalCache to be applied to matchers
 * @param coordinator [IN] - Coordinator reference to be applied to matchers
 */
private void initializeCommonReferencesForAllMatchers(ObjectLocalCache cache, CoordinatorClient coordinator) {
    Map<String, AttributeMatcher> uniqueMatcherMap = new HashMap<>();
    @SuppressWarnings("unchecked") List<AttributeMatcher> vpoolMatchers = (List<AttributeMatcher>) getBeanFromContext(AttributeMatcher.VPOOL_MATCHERS);
    for (AttributeMatcher matcher : vpoolMatchers) {
        uniqueMatcherMap.put(matcher.getClass().getSimpleName(), matcher);
    }
    @SuppressWarnings("unchecked") List<AttributeMatcher> basicMatchers = (List<AttributeMatcher>) getBeanFromContext(AttributeMatcher.BASIC_PLACEMENT_MATCHERS);
    for (AttributeMatcher matcher : basicMatchers) {
        uniqueMatcherMap.put(matcher.getClass().getSimpleName(), matcher);
    }
    @SuppressWarnings("unchecked") List<AttributeMatcher> placementMatchers = (List<AttributeMatcher>) getBeanFromContext(AttributeMatcher.PLACEMENT_MATCHERS);
    for (AttributeMatcher matcher : placementMatchers) {
        uniqueMatcherMap.put(matcher.getClass().getSimpleName(), matcher);
    }
    // matchers. Now iterate through them applying there references ...
    for (AttributeMatcher matcher : uniqueMatcherMap.values()) {
        matcher.setCoordinatorClient(coordinator);
        matcher.setObjectCache(cache);
    }
}
Also used : AttributeMatcher(com.emc.storageos.volumecontroller.AttributeMatcher) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AttributeMatcher

use of com.emc.storageos.volumecontroller.AttributeMatcher in project coprhd-controller by CoprHD.

the class AttributeMatcherFramework method getAvailableAttributes.

/**
 * Find the available attributes in a given varray.
 *
 * @param vArrayId
 * @param neighborhoodPools
 * @param dbClient
 * @param matcherGroupName
 */
public Map<String, Set<String>> getAvailableAttributes(URI vArrayId, List<StoragePool> neighborhoodPools, ObjectLocalCache cache, String matcherGroupName) {
    Map<String, Set<String>> vArrayAvailableAttrs = new HashMap<String, Set<String>>();
    try {
        @SuppressWarnings("unchecked") List<AttributeMatcher> attrMatcherList = (List<AttributeMatcher>) getBeanFromContext(matcherGroupName);
        for (AttributeMatcher matcher : attrMatcherList) {
            matcher.setObjectCache(cache);
            Map<String, Set<String>> availableAttribute = matcher.getAvailableAttribute(neighborhoodPools, vArrayId);
            if (!availableAttribute.isEmpty()) {
                _logger.info("Found available attributes using matcher {}", matcher);
                vArrayAvailableAttrs.putAll(availableAttribute);
            }
        }
        _logger.info("Found {} available attributes for vArray {}", vArrayAvailableAttrs, vArrayId);
    } catch (Exception ex) {
        _logger.error("Exception occurred while getting available attributes for vArray {}", vArrayId, ex);
        vArrayAvailableAttrs.clear();
        throw new ServiceCodeException(ServiceCode.CONTROLLER_STORAGE_ERROR, "Exception occurred while getting available attributes for vArray.", new Object[] { vArrayId });
    }
    return vArrayAvailableAttrs;
}
Also used : AttributeMatcher(com.emc.storageos.volumecontroller.AttributeMatcher) Set(java.util.Set) HashMap(java.util.HashMap) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) ArrayList(java.util.ArrayList) List(java.util.List) BeansException(org.springframework.beans.BeansException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)

Aggregations

AttributeMatcher (com.emc.storageos.volumecontroller.AttributeMatcher)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ServiceCodeException (com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)2 HashMap (java.util.HashMap)2 BeansException (org.springframework.beans.BeansException)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 Set (java.util.Set)1