Search in sources :

Example 16 with StorageGroupPolicyLimitsParam

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

the class SmisCommandHelper method groupVolumesByStorageGroup.

/**
 * Algo : FastPolicy F1 ---> V1, V2 FastPolicy F2 ---> V3, V4 Use case : Add these volumes to
 * existing Storage Group S1. 1. Find out the child Groups for given parent Group S1. 2. For
 * each child Group, if its associated with Fast, get its policy name. CH1 --->F1 Now the
 * resultant group would be CH1--->V1,V2 3. After looping through all child Storage Groups, if
 * you still didn't encounter F2, then it means we need to create a new Storage Group CH2 and
 * associate with F2. 4. Final result would be Volumes get grouped by child Storage Group Names.
 *
 * @param storage
 *            storage system
 * @param parentGroupName
 *            parent storage group name
 * @param policyToVolumeMap
 *            map of FAST policy to volume objects
 * @return group of storage group to volume objects
 * @throws Exception
 */
public Map<String, Collection<VolumeURIHLU>> groupVolumesByStorageGroup(StorageSystem storage, String parentGroupName, DataSource sgDataSource, String sgCustomTemplateName, ListMultimap<StorageGroupPolicyLimitsParam, VolumeURIHLU> policyLimitsParamToVolumeGroup, CustomConfigHandler customConfigHandler) throws Exception {
    Map<String, Collection<VolumeURIHLU>> volumeGroup = new HashMap<String, Collection<VolumeURIHLU>>();
    CloseableIterator<CIMInstance> cimInstanceItr = null;
    try {
        boolean isVmax3 = storage.checkIfVmax3();
        CIMObjectPath maskingGroupPath = _cimPath.getMaskingGroupPath(storage, parentGroupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
        // Make sure the policy matches ours, if so grab the volumes.
        if (!isCascadedSG(storage, maskingGroupPath)) {
            // TODO: Add VMAX3 check and get fast policy for VMAX3 volume.
            String policyName = getAutoTieringPolicyNameAssociatedWithVolumeGroup(storage, maskingGroupPath);
            volumeGroup.put(parentGroupName, new ArrayList<VolumeURIHLU>());
            for (Entry<StorageGroupPolicyLimitsParam, Collection<VolumeURIHLU>> policyToVolumeEntry : policyLimitsParamToVolumeGroup.asMap().entrySet()) {
                if (policyName != null && policyName.equalsIgnoreCase(Constants.NONE.toString())) {
                    policyName = null;
                }
                String volumePolicy = policyToVolumeEntry.getKey().getAutoTierPolicyName();
                if (volumePolicy != null && volumePolicy.equalsIgnoreCase(Constants.NONE.toString())) {
                    volumePolicy = null;
                }
                if ((policyName == null && volumePolicy == null) || (policyName != null && policyName.equalsIgnoreCase(volumePolicy))) {
                    volumeGroup.get(parentGroupName).addAll(policyToVolumeEntry.getValue());
                }
                // We want to be in the map as well.
                if (volumePolicy != null && policyName == null) {
                    volumeGroup.get(parentGroupName).addAll(policyToVolumeEntry.getValue());
                }
            }
            if (!volumeGroup.get(parentGroupName).isEmpty()) {
                _log.info("Storage Group  {} is not a cascading group, hence grouping all volumes under parent group.", parentGroupName);
                return volumeGroup;
            }
        }
        _log.info("Trying to find child Storage Groups for given Parent Group {}", parentGroupName);
        /**
         * get list of child storage groups
         */
        if (isVmax3) {
            cimInstanceItr = getAssociatorInstances(storage, maskingGroupPath, null, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup.name(), null, null, PS_V3_STORAGE_GROUP_PROPERTIES);
        } else {
            cimInstanceItr = getAssociatorInstances(storage, maskingGroupPath, null, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup.name(), null, null, new String[] { CP_ELEMENT_NAME, EMC_MAX_BANDWIDTH, EMC_MAX_IO });
        }
        Set<StorageGroupPolicyLimitsParam> storageGroupPolicyLimitsParamSet = new HashSet<StorageGroupPolicyLimitsParam>();
        /**
         * Loop through each Storage Group, find if its associated with fast Policy, limit bandwidth, and limit IO.
         * Try to look
         * up the given policyToVolumeMap data, to find out the right storage group bucket for
         * these volumes
         */
        Map<String, Integer> preferedChildGroupMap = new HashMap<String, Integer>();
        Map<StorageGroupPolicyLimitsParam, String> preferedPolicyLimitsParamToChildGroup = new HashMap<StorageGroupPolicyLimitsParam, String>();
        while (cimInstanceItr.hasNext()) {
            CIMInstance childGroupInstance = cimInstanceItr.next();
            String groupName = CIMPropertyFactory.getPropertyValue(childGroupInstance, CP_ELEMENT_NAME);
            /**
             * Get the properties (policyName, Bandwidth,IOPS) associated with this Storage Group
             */
            StorageGroupPolicyLimitsParam storageGroupPolicyLimitsParam = createStorageGroupPolicyLimitsParam(storage, childGroupInstance);
            _log.info("Group Name {} is associated with Fast Policy : {}", groupName, storageGroupPolicyLimitsParam.getAutoTierPolicyName());
            // Count the number of volumes in this group. Lowest number of volumes in the storage
            // group for that child storage group wins.
            Integer numVolumes = getVMAXStorageGroupVolumeCount(storage, groupName);
            String policyLimitAttribute = storageGroupPolicyLimitsParam.toString();
            // for that group name.
            if ((preferedChildGroupMap.get(policyLimitAttribute) == null) || ((preferedChildGroupMap.get(policyLimitAttribute) != null) && (numVolumes < preferedChildGroupMap.get(policyLimitAttribute)))) {
                preferedChildGroupMap.put(policyLimitAttribute, numVolumes);
                preferedPolicyLimitsParamToChildGroup.put(storageGroupPolicyLimitsParam, groupName);
            }
        }
        // Now place the volumes in the respective storage group.
        for (StorageGroupPolicyLimitsParam storageGroupPolicyLimitsParam : preferedPolicyLimitsParamToChildGroup.keySet()) {
            if (policyLimitsParamToVolumeGroup.containsKey(storageGroupPolicyLimitsParam) && !storageGroupPolicyLimitsParamSet.contains(storageGroupPolicyLimitsParam)) {
                volumeGroup.put(preferedPolicyLimitsParamToChildGroup.get(storageGroupPolicyLimitsParam), policyLimitsParamToVolumeGroup.get(storageGroupPolicyLimitsParam));
                storageGroupPolicyLimitsParamSet.add(storageGroupPolicyLimitsParam);
            }
        }
        _log.info("Storage Group exists already for given volume's fast Policies -->{}", Joiner.on("\t").join(storageGroupPolicyLimitsParamSet));
        Set<String> existingGroupNames = getExistingStorageGroupsFromArray(storage);
        /**
         * At this point, we have the list of the volume groups (FP + bandwidth+IOPS), which has a Storage Group.
         * For the remaining volume groups, we need to create a new Storage Group.
         *
         * No changes needed
         */
        for (Entry<StorageGroupPolicyLimitsParam, Collection<VolumeURIHLU>> policyToVolumeEntry : policyLimitsParamToVolumeGroup.asMap().entrySet()) {
            StorageGroupPolicyLimitsParam storageGroupPolicyLimitsParam = policyToVolumeEntry.getKey();
            if (!storageGroupPolicyLimitsParamSet.contains(storageGroupPolicyLimitsParam)) {
                _log.debug("Policy {} to which new Storage Group needs to be created", storageGroupPolicyLimitsParam);
                ListMultimap<String, VolumeURIHLU> expectedVolumeHluMap = ControllerUtils.getVolumeNativeGuids(policyToVolumeEntry.getValue(), _dbClient);
                if (!StringUtils.equalsIgnoreCase(storageGroupPolicyLimitsParam.getAutoTierPolicyName(), Constants.NONE)) {
                    _log.info("Running Storage Group Selection Process to find out if any groups can be reused");
                    Map<String, Set<String>> existingReusableGroups = findAnyStorageGroupsCanBeReUsed(storage, expectedVolumeHluMap, storageGroupPolicyLimitsParam);
                    // add existing group names, use later to add these
                    // groups to parent Cascaded Group.
                    _log.info("Existing Reusable Storage Groups Found {}", Joiner.on("\t").join(existingReusableGroups.keySet()));
                    for (String group : existingReusableGroups.keySet()) {
                        volumeGroup.put(group, null);
                    }
                    // find out remaining volumes which doesn't have any
                    // groups to fit into
                    Set<String> volumesInReusableStorageGroups = constructVolumeNativeGuids(existingReusableGroups.values());
                    Set<String> volumesNotPartOfAnyGroup = Sets.difference(expectedVolumeHluMap.asMap().keySet(), volumesInReusableStorageGroups);
                    _log.debug("Volumes not part of any Existing Storage Groups {}", Joiner.on("\t").join(volumesNotPartOfAnyGroup));
                    // right storage groups
                    if (!volumesNotPartOfAnyGroup.isEmpty()) {
                        _log.info("Creating an new Volume Group for these Volumes");
                        VolumeURIHLU[] volumeURIHLU = ControllerUtils.constructVolumeUriHLUs(volumesNotPartOfAnyGroup, expectedVolumeHluMap);
                        sgDataSource.addProperty(CustomConfigConstants.AUTO_TIERING_POLICY_NAME, storageGroupPolicyLimitsParam.toString());
                        String storageGroupName = customConfigHandler.getComputedCustomConfigValue(sgCustomTemplateName, storage.getSystemType(), sgDataSource);
                        String generatedGroupName = generateGroupName(existingGroupNames, storageGroupName);
                        volumeGroup.put(generatedGroupName, Arrays.asList(volumeURIHLU));
                    }
                } else {
                    // TODO check if this need to taken care off for VMAX3 as volumes will have policy name
                    _log.info("Creating a new Storage Group always, as non fast");
                    sgDataSource.addProperty(CustomConfigConstants.AUTO_TIERING_POLICY_NAME, StorageGroupPolicyLimitsParam.NON_FAST_POLICY);
                    String storageGroupName = customConfigHandler.getComputedCustomConfigValue(sgCustomTemplateName, storage.getSystemType(), sgDataSource);
                    String generatedGroupName = generateGroupName(existingGroupNames, storageGroupName);
                    volumeGroup.put(generatedGroupName, policyToVolumeEntry.getValue());
                }
            }
        }
    } finally {
        closeCIMIterator(cimInstanceItr);
    }
    return volumeGroup;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) CIMInstance(javax.cim.CIMInstance) Collection(java.util.Collection) StorageGroupPolicyLimitsParam(com.emc.storageos.volumecontroller.impl.StorageGroupPolicyLimitsParam) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU) HashSet(java.util.HashSet)

Example 17 with StorageGroupPolicyLimitsParam

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

the class SmisCommandHelper method createStorageGroupPolicyLimitsParam.

/**
 * Construct a storage group policy limits object from a volumeURIHLU object.
 *
 * @param volumeUriHLUs
 * @param dbClient
 * @return
 */
public StorageGroupPolicyLimitsParam createStorageGroupPolicyLimitsParam(Collection<VolumeURIHLU> volumeUriHLUs, StorageSystem storage, DbClient dbClient) {
    StorageGroupPolicyLimitsParam policyQuota = new StorageGroupPolicyLimitsParam(Constants.NONE);
    for (VolumeURIHLU volumeUriHLU : volumeUriHLUs) {
        String policyName = null;
        if (storage.checkIfVmax3()) {
            policyName = getVMAX3FastSettingForVolume(volumeUriHLU.getVolumeURI(), volumeUriHLU.getAutoTierPolicyName());
        } else {
            policyName = volumeUriHLU.getAutoTierPolicyName();
        }
        policyQuota = new StorageGroupPolicyLimitsParam(policyName, volumeUriHLU.getHostIOLimitBandwidth(), volumeUriHLU.getHostIOLimitIOPs(), storage);
        break;
    }
    return policyQuota;
}
Also used : StorageGroupPolicyLimitsParam(com.emc.storageos.volumecontroller.impl.StorageGroupPolicyLimitsParam) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 18 with StorageGroupPolicyLimitsParam

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

the class SmisCommandHelper method groupVolumesBasedOnFastPolicy.

/**
 * Group volumes based on policy, bandwidth, and IOPs as dictated by the ViPR database objects.
 *
 * @param storage
 *            storage device
 * @param volumeUris
 *            volume URIs
 * @return a map of storage groups to volumes using that policy, bandwidth, and IOPs
 * @throws Exception
 */
public Map<StorageGroupPolicyLimitsParam, List<URI>> groupVolumesBasedOnFastPolicy(StorageSystem storage, List<URI> volumeUris) throws Exception {
    Map<StorageGroupPolicyLimitsParam, List<URI>> volumeGroup = new HashMap<StorageGroupPolicyLimitsParam, List<URI>>();
    Map<URI, VirtualPool> uriVirtualPoolMap = new HashMap<URI, VirtualPool>();
    for (URI volumeURI : volumeUris) {
        String policyName = Constants.NONE;
        Integer hostIOLimitBandwidth = null;
        Integer hostIOLimitIOPs = null;
        if (URIUtil.isType(volumeURI, Volume.class)) {
            Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
            VirtualPool virtualPool = uriVirtualPoolMap.get(volume.getVirtualPool());
            if (virtualPool == null) {
                virtualPool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
                uriVirtualPoolMap.put(volume.getVirtualPool(), virtualPool);
            }
            String volumePolicyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), _dbClient);
            if (volumePolicyName != null) {
                policyName = volumePolicyName;
            }
            hostIOLimitBandwidth = virtualPool.getHostIOLimitBandwidth();
            hostIOLimitIOPs = virtualPool.getHostIOLimitIOPs();
        }
        StorageGroupPolicyLimitsParam storageGroupPolicyLimitsParam = new StorageGroupPolicyLimitsParam(policyName, hostIOLimitBandwidth, hostIOLimitIOPs, storage);
        if (volumeGroup.get(storageGroupPolicyLimitsParam) == null) {
            volumeGroup.put(storageGroupPolicyLimitsParam, new ArrayList<URI>());
        }
        volumeGroup.get(storageGroupPolicyLimitsParam).add(volumeURI);
        _log.info("Adding volumeURI {} to policy {}", volumeURI, storageGroupPolicyLimitsParam);
    }
    return volumeGroup;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Volume(com.emc.storageos.db.client.model.Volume) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) StorageGroupPolicyLimitsParam(com.emc.storageos.volumecontroller.impl.StorageGroupPolicyLimitsParam) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI)

Aggregations

StorageGroupPolicyLimitsParam (com.emc.storageos.volumecontroller.impl.StorageGroupPolicyLimitsParam)18 CIMObjectPath (javax.cim.CIMObjectPath)14 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)10 StringSet (com.emc.storageos.db.client.model.StringSet)9 Set (java.util.Set)9 URI (java.net.URI)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 ExportMask (com.emc.storageos.db.client.model.ExportMask)7 VolumeURIHLU (com.emc.storageos.volumecontroller.impl.VolumeURIHLU)7 HashMap (java.util.HashMap)7 List (java.util.List)7 CIMInstance (javax.cim.CIMInstance)7 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)6 WBEMException (javax.wbem.WBEMException)6 BlockObject (com.emc.storageos.db.client.model.BlockObject)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 WBEMClient (javax.wbem.client.WBEMClient)5 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)4