Search in sources :

Example 91 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class XtremIOExportOperations method refreshExportMask.

/*
     * Refresh all export masks, not only the one passed in
     * @see com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#refreshExportMask(com.emc.storageos.db.client.model.StorageSystem, com.emc.storageos.db.client.model.ExportMask)
     */
@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
    ExportMask maskToReturn = null;
    try {
        _log.info("Refreshing volumes and initiator labels in ViPR.. ");
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        Set<String> igNameSet = new HashSet<>();
        Map<URI, Set<String>> maskToIGNameMap = new HashMap<>();
        String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        List<XtremIOInitiator> initiators = client.getXtremIOInitiatorsInfo(xioClusterName);
        List<Initiator> initiatorObjs = new ArrayList<Initiator>();
        for (XtremIOInitiator initiator : initiators) {
            URIQueryResultList initiatorResult = new URIQueryResultList();
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiator.getPortAddress()), initiatorResult);
            if (initiatorResult.iterator().hasNext()) {
                Initiator initiatorObj = dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
                _log.info("Updating Initiator label from {} to {} in ViPR DB", initiatorObj.getLabel(), initiator.getName());
                initiatorObj.setLabel(initiator.getName());
                initiatorObj.mapInitiatorName(storage.getSerialNumber(), initiator.getName());
                initiatorObjs.add(initiatorObj);
                List<ExportMask> results = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, ExportMask.class, ContainmentConstraint.Factory.getConstraint(ExportMask.class, "initiators", initiatorObj.getId()));
                String igName = initiator.getInitiatorGroup().get(1);
                for (ExportMask exportMask : results) {
                    if (exportMask != null && storage.getId().equals(exportMask.getStorageDevice())) {
                        igNameSet.add(igName);
                        // update export mask to IG name map
                        URI maskId = exportMask.getId();
                        Set<String> igNames = maskToIGNameMap.get(maskId);
                        if (igNames == null) {
                            igNames = new HashSet<String>();
                            maskToIGNameMap.put(maskId, igNames);
                        }
                        igNames.add(igName);
                    }
                }
            } else {
                _log.info("No initiator objects in vipr db for port address {}", initiator.getPortAddress());
            }
        }
        if (!initiatorObjs.isEmpty()) {
            dbClient.updateObject(initiatorObjs);
        }
        // get volumes for each IG
        Map<String, Map<String, Integer>> igNameToVolMap = new HashMap<>();
        boolean bulkApiCallFlag = Boolean.valueOf(ControllerUtils.getPropertyValueFromCoordinator(coordinator, XTREMIO_BULK_API_CALL));
        Map<String, List<XtremIOVolume>> igNameToVolumesMap = new HashMap<>();
        _log.debug("Bulk API Flag", bulkApiCallFlag);
        _log.debug("XtremIO Firmware Version", storage.getFirmwareVersion());
        if (client.isVersion2() && XtremIOProvUtils.isBulkAPISupported(storage.getFirmwareVersion(), client) && bulkApiCallFlag) {
            long starttime = System.nanoTime();
            if (!igNameSet.isEmpty())
                igNameToVolumesMap = XtremIOProvUtils.getLunMapAndVolumes(igNameSet, xioClusterName, client, igNameToVolumesMap);
            _log.debug("Time taken for Bulk API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime) / 1000000000.0) + " seconds");
            for (Map.Entry<String, List<XtremIOVolume>> entry : igNameToVolumesMap.entrySet()) {
                Map<String, Integer> discoveredVolumesMap = new HashMap<String, Integer>();
                for (XtremIOVolume volume : entry.getValue()) {
                    for (List<Object> lunMapEntries : volume.getLunMaps()) {
                        @SuppressWarnings("unchecked") List<Object> // This can't be null
                        igDetails = (List<Object>) lunMapEntries.get(0);
                        if (null == igDetails.get(1) || null == lunMapEntries.get(2)) {
                            continue;
                        }
                        String igNameToProcess = (String) igDetails.get(1);
                        if (!entry.getKey().equalsIgnoreCase(igNameToProcess)) {
                            continue;
                        }
                        Double hluNumber = (Double) lunMapEntries.get(2);
                        _log.info("Found HLU {} for volume {}", hluNumber, volume.getVolInfo().get(1));
                        discoveredVolumesMap.put(volume.getWwn(), Integer.valueOf(hluNumber.intValue()));
                    }
                }
                igNameToVolMap.put(entry.getKey(), discoveredVolumesMap);
            }
            _log.debug("Time taken for All iteration in BulK API  : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime) / 1000000000.0) + " seconds");
        } else {
            long totaltime = System.nanoTime();
            for (String igName : igNameSet) {
                Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
                long starttime1 = System.nanoTime();
                List<XtremIOVolume> igVolumes = XtremIOProvUtils.getInitiatorGroupVolumes(igName, xioClusterName, client);
                _log.debug("Time taken for each ig name normal API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime1) / 1000000000.0) + " seconds");
                for (XtremIOVolume igVolume : igVolumes) {
                    for (List<Object> lunMapEntries : igVolume.getLunMaps()) {
                        @SuppressWarnings("unchecked") List<Object> // This can't be null
                        igDetails = (List<Object>) lunMapEntries.get(0);
                        if (null == igDetails.get(1) || null == lunMapEntries.get(2)) {
                            _log.warn("IG Name or hlu is null in returned lun map response for volume {}", igVolume.toString());
                            continue;
                        }
                        String igNameToProcess = (String) igDetails.get(1);
                        if (!igName.equalsIgnoreCase(igNameToProcess)) {
                            continue;
                        }
                        Double hluNumber = (Double) lunMapEntries.get(2);
                        _log.info("Found HLU {} for volume {}", hluNumber, igVolume.getVolInfo().get(1));
                        // for each IG involved, the same volume is visible through different HLUs.
                        // TODO we might need a list of HLU for each Volume URI
                        discoveredVolumes.put(BlockObject.normalizeWWN(igVolume.getWwn()), Integer.valueOf(hluNumber.intValue()));
                    }
                }
                igNameToVolMap.put(igName, discoveredVolumes);
            }
            _log.debug("Time taken for all ig name normal API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - totaltime) / 1000000000.0) + " seconds");
        }
        // update each mask
        for (Entry<URI, Set<String>> entry : maskToIGNameMap.entrySet()) {
            URI maskId = entry.getKey();
            ExportMask exportMask = dbClient.queryObject(ExportMask.class, maskId);
            if (exportMask == null || exportMask.getInactive()) {
                continue;
            }
            Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
            for (String igName : entry.getValue()) {
                discoveredVolumes.putAll(igNameToVolMap.get(igName));
            }
            // Clear the existing volumes to update with the latest info
            if (exportMask.getExistingVolumes() != null && !exportMask.getExistingVolumes().isEmpty()) {
                exportMask.getExistingVolumes().clear();
            }
            // COP-27296 fix
            if (null == exportMask.getUserAddedVolumes()) {
                exportMask.setUserAddedVolumes(new StringMap());
            }
            // We need to look at all related initiators from the affected EM. We can use this list
            // to then find all related volumes across all EMs. This will allow us to properly
            // perform our validations.
            List<Initiator> relatedInitiators = new ArrayList<Initiator>();
            if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
                Collection<URI> relatedInitiatorURIs = Collections2.transform(exportMask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
                relatedInitiators.addAll(dbClient.queryObject(Initiator.class, relatedInitiatorURIs));
            }
            Set<URI> allRelatedVolumes = new HashSet<URI>();
            allRelatedVolumes.addAll(findAllRelatedExportMaskVolumesForInitiator(relatedInitiators, exportMask.getStorageDevice()));
            // If there are related volumes found, get the WWNs so we can diff against what has
            // been discovered on the array.
            Set<String> allRelatedVolumesWWN = new HashSet<String>();
            for (URI relatedVolumeURI : allRelatedVolumes) {
                BlockObject relatedObj = BlockObject.fetch(dbClient, relatedVolumeURI);
                if (relatedObj != null) {
                    allRelatedVolumesWWN.add(relatedObj.getWWN());
                }
            }
            Set<String> existingVolumes = Sets.difference(discoveredVolumes.keySet(), allRelatedVolumesWWN);
            _log.info(String.format("XtremIO discovered volumes: {%s}%n", Joiner.on(',').join(discoveredVolumes.keySet())));
            _log.info(String.format("%nXtremIO mask existing volumes: {%s}%n", Joiner.on(',').join(existingVolumes)));
            for (String wwn : existingVolumes) {
                exportMask.addToExistingVolumesIfAbsent(wwn, discoveredVolumes.get(wwn).toString());
            }
            // Update user added volume's HLU information in ExportMask and ExportGroup
            ExportMaskUtils.updateHLUsInExportMask(exportMask, discoveredVolumes, dbClient);
            dbClient.updateObject(exportMask);
            if (mask != null && maskId.equals(mask.getId())) {
                maskToReturn = exportMask;
            }
        }
    } catch (Exception e) {
        if (null != e.getMessage() && !e.getMessage().contains(XtremIOConstants.OBJECT_NOT_FOUND)) {
            String msg = String.format("Error when refreshing export masks for the system %s, details: %s", storage.forDisplay(), e.getMessage());
            throw XtremIOApiException.exceptions.refreshExistingMaskFailure(msg, e);
        } else {
            _log.warn("Error refreshing export masks for the system {}", storage.forDisplay());
        }
    }
    return maskToReturn;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) ExportMask(com.emc.storageos.db.client.model.ExportMask) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockObject(com.emc.storageos.db.client.model.BlockObject) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) XtremIOLunMap(com.emc.storageos.xtremio.restapi.model.response.XtremIOLunMap)

Example 92 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method refreshRESTExportMask.

/**
 * Refresh the export mask with the user added configuration
 *
 * @param storage
 *            XIV sotrage system
 * @param mask
 *            Export Mask instance
 * @param _networkDeviceController
 *            Network configuration instance
 */
public void refreshRESTExportMask(StorageSystem storage, ExportMask mask, NetworkDeviceController _networkDeviceController) {
    try {
        final String storageIP = storage.getSmisProviderIP();
        final String name = mask.getNativeId();
        XIVRestClient restExportOpr = getRestClient(storage);
        StringBuilder builder = new StringBuilder();
        Set<String> discoveredPorts = new HashSet<String>();
        Set<URI> hostURIs = new HashSet<URI>();
        Set<Initiator> exportMaskInits = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, mask, null);
        Iterator<Initiator> exportMaskInitsItr = exportMaskInits.iterator();
        while (exportMaskInitsItr.hasNext()) {
            hostURIs.add(exportMaskInitsItr.next().getHost());
        }
        // Check the initiators and update the lists as necessary
        List<Host> hostList = _dbClient.queryObject(Host.class, hostURIs);
        for (Host host : hostList) {
            discoveredPorts.addAll(restExportOpr.getHostPorts(storageIP, host.getLabel()));
        }
        boolean addInitiators = false;
        List<String> initiatorsToAdd = new ArrayList<String>();
        List<Initiator> initiatorIdsToAdd = new ArrayList<>();
        for (String port : discoveredPorts) {
            String normalizedPort = Initiator.normalizePort(port);
            if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                initiatorsToAdd.add(normalizedPort);
                Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                if (existingInitiator != null) {
                    initiatorIdsToAdd.add(existingInitiator);
                }
                addInitiators = true;
            }
        }
        boolean removeInitiators = false;
        List<String> initiatorsToRemove = new ArrayList<String>();
        List<URI> initiatorIdsToRemove = new ArrayList<>();
        if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
            initiatorsToRemove.addAll(mask.getExistingInitiators());
            initiatorsToRemove.removeAll(discoveredPorts);
        }
        removeInitiators = !initiatorsToRemove.isEmpty();
        // Get Volumes mapped to a Host on Array
        Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
        final String exportType = ExportMaskUtils.getExportType(_dbClient, mask);
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
            discoveredVolumes.putAll(restExportOpr.getVolumesMappedToHost(storageIP, mask.getLabel(), null));
        } else {
            for (Host host : hostList) {
                discoveredVolumes.putAll(restExportOpr.getVolumesMappedToHost(storageIP, null, host.getLabel()));
            }
        }
        // Check the volumes and update the lists as necessary
        Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
        boolean addVolumes = !volumesToAdd.isEmpty();
        boolean removeVolumes = false;
        List<String> volumesToRemove = new ArrayList<String>();
        if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
            volumesToRemove.addAll(mask.getExistingVolumes().keySet());
            volumesToRemove.removeAll(discoveredVolumes.keySet());
            removeVolumes = !volumesToRemove.isEmpty();
        }
        builder.append(String.format("XM refresh: %s initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAdd), Joiner.on(',').join(initiatorsToRemove)));
        builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
        if (addInitiators || removeInitiators || addVolumes || removeVolumes) {
            builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
            mask.removeFromExistingInitiators(initiatorsToRemove);
            if (initiatorIdsToRemove != null && !initiatorIdsToRemove.isEmpty()) {
                mask.removeInitiators(_dbClient.queryObject(Initiator.class, initiatorIdsToRemove));
            }
            List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorIdsToAdd, _dbClient);
            mask.addToUserCreatedInitiators(userAddedInitiators);
            mask.addToExistingInitiatorsIfAbsent(initiatorsToAdd);
            mask.addInitiators(initiatorIdsToAdd);
            mask.removeFromExistingVolumes(volumesToRemove);
            mask.setExistingVolumes(new StringMap());
            mask.addToExistingVolumesIfAbsent(volumesToAdd);
            ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
            _dbClient.updateObject(mask);
        } else {
            builder.append("XM refresh: There are no changes to the mask\n");
        }
        _networkDeviceController.refreshZoningMap(mask, initiatorsToRemove, Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
        _log.info(builder.toString());
    } catch (Exception e) {
        String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
        _log.error(MessageFormat.format("Encountered an error when attempting to refresh existing exports: {0}", msg), e);
        throw XIVRestException.exceptions.refreshExistingMaskFailure(msg);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) HashSet(java.util.HashSet)

Example 93 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method deleteRESTExportMask.

/**
 * Deletes the Export Mask and its attributes
 *
 * @param storage
 *            XIV storage system
 * @param exportMaskURI
 *            Export mask URI
 * @param volumeURIList
 *            Volume URI as list
 * @param targetURIList
 *            target port URI as list [ not used for xiv]
 * @param initiatorList
 *            Initiator port URI as list
 * @param taskCompleter
 *            task completer instance
 */
public void deleteRESTExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        final String storageIP = storage.getSmisProviderIP();
        final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
        final String name = exportMask.getNativeId();
        final StringSet emInitiatorURIs = exportMask.getInitiators();
        final StringMap emVolumeURIs = exportMask.getVolumes();
        XIVRestClient restExportOpr = getRestClient(storage);
        Set<URI> hostURIs = new HashSet<URI>();
        // Un export Volumes
        if (null != emVolumeURIs) {
            Iterator<Entry<String, String>> emVolumeURIItr = emVolumeURIs.entrySet().iterator();
            while (emVolumeURIItr.hasNext()) {
                URI volUri = URI.create(emVolumeURIItr.next().getKey());
                if (URIUtil.isType(volUri, Volume.class)) {
                    Volume volume = _dbClient.queryObject(Volume.class, volUri);
                    restExportOpr.unExportVolume(storageIP, exportType, name, volume.getLabel());
                }
            }
        }
        // Delete initiators
        if (null != emInitiatorURIs) {
            for (String initiatorURI : emInitiatorURIs) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorURI));
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                hostURIs.add(host.getId());
                String normalizedPort = Initiator.normalizePort(initiator.getInitiatorPort());
                restExportOpr.deleteHostPort(storageIP, host.getLabel(), normalizedPort, initiator.getProtocol().toLowerCase(), false);
            }
        }
        // Delete Host if there are no associated Initiators/Volume to it.
        for (URI hostURI : hostURIs) {
            Host host = _dbClient.queryObject(Host.class, hostURI);
            boolean hostDeleted = restExportOpr.deleteHost(storageIP, host.getLabel(), false);
            // Perform post-mask-delete cleanup steps
            if (hostDeleted && emVolumeURIs.size() > 0) {
                unsetTag(host, storage.getSerialNumber());
            }
        }
        // Delete Cluster if there is no associated hosts to it.
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
            restExportOpr.deleteCluster(storageIP, name);
        }
        ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
        exportMask.setMaskName(NullColumnValueGetter.getNullURI().toString());
        exportMask.setLabel(NullColumnValueGetter.getNullURI().toString());
        exportMask.setNativeId(NullColumnValueGetter.getNullURI().toString());
        exportMask.setResource(NullColumnValueGetter.getNullURI().toString());
        _dbClient.updateObject(exportMask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: deleteExportMask failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("createExportMask", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Entry(java.util.Map.Entry) Volume(com.emc.storageos.db.client.model.Volume) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) HashSet(java.util.HashSet)

Example 94 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class ExportMaskUtilsTest method testExportMaskUtils.

@Test
public void testExportMaskUtils() {
    // TODO add code to make this work
    ExportGroup egp = new ExportGroup();
    ExportMask e1 = new ExportMask();
    e1.setLabel("e1");
    ExportMask e2 = new ExportMask();
    e2.setLabel("e2");
    ExportMask e3 = new ExportMask();
    e3.setLabel("e3");
    ExportMask e4 = new ExportMask();
    e4.setLabel("e4");
    ExportMask e5 = new ExportMask();
    e5.setLabel("e5");
    StringMap e1vols = new StringMap();
    e1vols.put("k1", "v1");
    e1vols.put("k2", "v2");
    e1vols.put("k3", "v3");
    e1.setExistingVolumes(e1vols);
    StringMap e2vols = new StringMap();
    e2vols.put("k1", "v1");
    e2.setExistingVolumes(e2vols);
    StringMap e3vols = new StringMap();
    e3vols.put("k1", "v1");
    e3vols.put("k2", "v2");
    e3.setExistingVolumes(e3vols);
    StringMap e4vols = new StringMap();
    e4.setExistingVolumes(e4vols);
    StringMap e5vols = new StringMap();
    e5vols.put("k1", "v1");
    e5vols.put("k2", "v2");
    e5vols.put("k3", "v3");
    e5vols.put("k4", "v1");
    e5vols.put("k5", "v2");
    e5vols.put("k6", "v3");
    e5.setExistingVolumes(e5vols);
    List<ExportMask> sortedMasks = new ArrayList<ExportMask>();
    sortedMasks.add(e1);
    sortedMasks.add(e2);
    sortedMasks.add(e3);
    sortedMasks.add(e4);
    sortedMasks.add(e5);
    ExportMaskPolicy policy1 = new ExportMaskPolicy();
    Map<ExportMask, ExportMaskPolicy> maskPolicyMap = new HashMap<ExportMask, ExportMaskPolicy>();
    maskPolicyMap.put(e1, policy1);
    maskPolicyMap.put(e2, policy1);
    maskPolicyMap.put(e3, policy1);
    maskPolicyMap.put(e4, policy1);
    maskPolicyMap.put(e5, policy1);
    sortedMasks = ExportMaskUtils.sortMasksByEligibility(maskPolicyMap, egp);
    Assert.assertEquals(sortedMasks.get(0).getLabel(), "e4");
    Assert.assertEquals(sortedMasks.get(1).getLabel(), "e2");
    Assert.assertEquals(sortedMasks.get(2).getLabel(), "e3");
    Assert.assertEquals(sortedMasks.get(3).getLabel(), "e1");
    Assert.assertEquals(sortedMasks.get(4).getLabel(), "e5");
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) ExportMaskPolicy(com.emc.storageos.volumecontroller.impl.block.ExportMaskPolicy) Test(org.junit.Test)

Example 95 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class HDSVolumeDiscoverer method updateUnManagedVolumeInfo.

/**
 * Updates the UnManagedVolumeInfo.
 *
 * @param logicalUnit
 * @param system
 * @param pool
 * @param unManagedVolume
 * @param dbClient
 */
private void updateUnManagedVolumeInfo(LogicalUnit logicalUnit, StorageSystem system, StoragePool pool, UnManagedVolume unManagedVolume, DbClient dbClient) {
    StringSetMap unManagedVolumeInformation = new StringSetMap();
    Map<String, String> unManagedVolumeCharacteristics = new HashMap<String, String>();
    StringSet systemTypes = new StringSet();
    systemTypes.add(system.getSystemType());
    StringSet provCapacity = new StringSet();
    provCapacity.add(String.valueOf(Long.parseLong(logicalUnit.getCapacityInKB()) * 1024));
    unManagedVolumeInformation.put(SupportedVolumeInformation.PROVISIONED_CAPACITY.toString(), provCapacity);
    StringSet allocatedCapacity = new StringSet();
    allocatedCapacity.add(String.valueOf(Long.parseLong(logicalUnit.getCapacityInKB()) * 1024));
    unManagedVolumeInformation.put(SupportedVolumeInformation.ALLOCATED_CAPACITY.toString(), allocatedCapacity);
    unManagedVolumeInformation.put(SupportedVolumeInformation.SYSTEM_TYPE.toString(), systemTypes);
    StringSet deviceLabel = new StringSet();
    String luLabel = getLabelFromLogicalUnit(logicalUnit);
    if (null != luLabel) {
        deviceLabel.add(luLabel);
    }
    unManagedVolumeInformation.put(SupportedVolumeInformation.DEVICE_LABEL.toString(), deviceLabel);
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_INGESTABLE.toString(), Boolean.TRUE.toString());
    if (logicalUnit.getPath() == 1) {
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_VOLUME_EXPORTED.toString(), Boolean.TRUE.toString());
    } else {
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_VOLUME_EXPORTED.toString(), Boolean.FALSE.toString());
    }
    if (logicalUnit.getDpType().equals(HDSConstants.DPTYPE_THIN)) {
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.toString(), Boolean.TRUE.toString());
    } else if (logicalUnit.getDpType().equals(HDSConstants.DPTYPE_THICK)) {
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.toString(), Boolean.FALSE.toString());
    } else {
        log.info("Provisioning type not found for volume: {}", logicalUnit.getObjectID());
    }
    String raidType = logicalUnit.getRaidType();
    if (null != raidType) {
        StringSet raidLevels = new StringSet();
        raidLevels.add(raidType);
        unManagedVolumeInformation.put(SupportedVolumeInformation.RAID_LEVEL.toString(), raidLevels);
    }
    StringSet pools = new StringSet();
    pools.add(pool.getId().toString());
    unManagedVolumeInformation.put(SupportedVolumeInformation.STORAGE_POOL.toString(), pools);
    unManagedVolume.setWwn(HDSUtils.generateHitachiWWN(logicalUnit.getObjectID(), String.valueOf(logicalUnit.getDevNum())));
    StringSet nativeId = new StringSet();
    nativeId.add(String.valueOf(logicalUnit.getDevNum()));
    unManagedVolumeInformation.put(SupportedVolumeInformation.NATIVE_ID.toString(), nativeId);
    String luTieringPolicy = fetchLogicalUnitTieringPolicy(system, logicalUnit, dbClient);
    if (null != luTieringPolicy) {
        StringSet volumeTieringPolicy = new StringSet();
        volumeTieringPolicy.add(luTieringPolicy);
        unManagedVolumeInformation.put(SupportedVolumeInformation.AUTO_TIERING_POLICIES.toString(), volumeTieringPolicy);
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_AUTO_TIERING_ENABLED.toString(), Boolean.TRUE.toString());
    } else {
        unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_AUTO_TIERING_ENABLED.toString(), Boolean.FALSE.toString());
    }
    StringSet driveTypes = pool.getSupportedDriveTypes();
    if (null != driveTypes) {
        unManagedVolumeInformation.put(SupportedVolumeInformation.DISK_TECHNOLOGY.toString(), driveTypes);
    }
    StringSet matchedVPools = DiscoveryUtils.getMatchedVirtualPoolsForPool(dbClient, pool.getId(), unManagedVolumeCharacteristics.get(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.name()).toString(), unManagedVolume);
    log.debug("Matched Pools : {}", Joiner.on("\t").join(matchedVPools));
    if (null == matchedVPools || matchedVPools.isEmpty()) {
        // clear all matched vpools
        unManagedVolume.getSupportedVpoolUris().clear();
    } else {
        // replace with new StringSet
        unManagedVolume.getSupportedVpoolUris().replace(matchedVPools);
        log.info("Replaced Pools : {}", Joiner.on("\t").join(unManagedVolume.getSupportedVpoolUris()));
    }
    unManagedVolume.setVolumeInformation(unManagedVolumeInformation);
    if (unManagedVolume.getVolumeCharacterstics() == null) {
        unManagedVolume.setVolumeCharacterstics(new StringMap());
    }
    unManagedVolume.getVolumeCharacterstics().replace(unManagedVolumeCharacteristics);
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) StringSet(com.emc.storageos.db.client.model.StringSet)

Aggregations

StringMap (com.emc.storageos.db.client.model.StringMap)257 URI (java.net.URI)108 ArrayList (java.util.ArrayList)90 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)59 StringSet (com.emc.storageos.db.client.model.StringSet)57 HashMap (java.util.HashMap)57 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)48 ExportMask (com.emc.storageos.db.client.model.ExportMask)43 Volume (com.emc.storageos.db.client.model.Volume)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)41 StoragePool (com.emc.storageos.db.client.model.StoragePool)39 Initiator (com.emc.storageos.db.client.model.Initiator)38 List (java.util.List)34 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)33 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)31 HashSet (java.util.HashSet)30 Project (com.emc.storageos.db.client.model.Project)24 StoragePort (com.emc.storageos.db.client.model.StoragePort)23 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 Network (com.emc.storageos.db.client.model.Network)21