Search in sources :

Example 91 with StringSetMap

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

the class CinderExportOperations method storeITLMappingInVolume.

/**
 * Create Initiator Target LUN Mapping as an extension in volume object
 *
 * @param volume
 *            - volume in which ITL to be added
 * @param exportMask
 *            - exportMask in which the volume is to be added
 * @param targetLunId
 *            - integer value of host LUN id on which volume is accessible.
 */
private void storeITLMappingInVolume(Map<URI, Integer> volumeToTargetLunMap, ExportMask exportMask) {
    log.debug("START - createITLMappingInVolume");
    for (URI volumeURI : volumeToTargetLunMap.keySet()) {
        Integer targetLunId = volumeToTargetLunMap.get(volumeURI);
        Volume volume = dbClient.queryObject(Volume.class, volumeURI);
        StringSetMap zoningMap = exportMask.getZoningMap();
        Set<String> zoningMapKeys = zoningMap.keySet();
        int initiatorIndex = 0;
        for (String initiator : zoningMapKeys) {
            Initiator initiatorObj = dbClient.queryObject(Initiator.class, URI.create(initiator));
            String initiatorWWPN = initiatorObj.getInitiatorPort().replaceAll(CinderConstants.COLON, "");
            StringSet targetPorts = zoningMap.get(initiator);
            int targetIndex = 0;
            for (String target : targetPorts) {
                StoragePort targetPort = dbClient.queryObject(StoragePort.class, URI.create(target));
                String targetPortWWN = targetPort.getPortNetworkId().replaceAll(CinderConstants.COLON, "");
                // Format is - <InitiatorWWPN>-<TargetWWPN>-<LunId>
                String itl = initiatorWWPN + "-" + targetPortWWN + "-" + String.valueOf(targetLunId);
                // ITL keys will be formed as ITL-00, ITL-01, ITL-10, ITL-11 so on
                String itlKey = CinderConstants.PREFIX_ITL + String.valueOf(initiatorIndex) + String.valueOf(targetIndex);
                log.info(String.format("Adding ITL %s with key %s", itl, itlKey));
                StringMap extensionsMap = volume.getExtensions();
                if (null == extensionsMap) {
                    extensionsMap = new StringMap();
                    extensionsMap.put(itlKey, itl);
                    volume.setExtensions(extensionsMap);
                } else {
                    volume.getExtensions().put(itlKey, itl);
                }
                targetIndex++;
            }
            initiatorIndex++;
        }
        dbClient.updateAndReindexObject(volume);
    }
    log.debug("END - createITLMappingInVolume");
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) Volume(com.emc.storageos.db.client.model.Volume) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Example 92 with StringSetMap

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

the class VPlexBackEndOrchestratorUtil method configureZoning.

public static StringSetMap configureZoning(Map<URI, List<List<StoragePort>>> portGroup, Map<String, Map<URI, Set<Initiator>>> initiatorGroup, Map<URI, NetworkLite> networkMap, StoragePortsAssigner assigner, Map<URI, String> initiatorSwitchMap, Map<URI, Map<String, List<StoragePort>>> switchStoragePortsMap, Map<URI, String> portSwitchMap) {
    StringSetMap zoningMap = new StringSetMap();
    // Set up a map to track port usage so that we can use all ports more or less equally.
    Map<StoragePort, Integer> portUsage = new HashMap<StoragePort, Integer>();
    // check if switch affinity is on
    boolean isSwitchAffinity = false;
    if (initiatorSwitchMap != null && !initiatorSwitchMap.isEmpty() && switchStoragePortsMap != null && !switchStoragePortsMap.isEmpty()) {
        isSwitchAffinity = true;
    }
    // with one port. This will ensure not to violate four paths per director.
    for (String director : initiatorGroup.keySet()) {
        for (URI networkURI : initiatorGroup.get(director).keySet()) {
            NetworkLite net = networkMap.get(networkURI);
            for (Initiator initiator : initiatorGroup.get(director).get(networkURI)) {
                // If there are no ports on the initiators network, too bad...
                if (portGroup.get(networkURI) == null) {
                    _log.info(String.format("%s -> no ports in network", initiator.getInitiatorPort()));
                    continue;
                }
                // find a port for the initiator
                List<StoragePort> assignablePorts = portGroup.get(networkURI).iterator().next();
                if (isSwitchAffinity) {
                    // find the ports with the same switch as the initiator
                    String switchName = initiatorSwitchMap.get(initiator.getId());
                    if (!switchName.equals(NullColumnValueGetter.getNullStr())) {
                        Map<String, List<StoragePort>> switchMap = switchStoragePortsMap.get(networkURI);
                        if (switchMap != null) {
                            List<StoragePort> switchPorts = switchMap.get(switchName);
                            if (switchPorts != null && !switchPorts.isEmpty()) {
                                _log.info(String.format("Found the same switch ports, switch is %s", switchName));
                                assignablePorts = switchPorts;
                            } else {
                                _log.info(String.format("Switch affinity is not honored, because no storage port from the switch %s for the initiator %s", switchName, initiator.getInitiatorPort()));
                            }
                        }
                    }
                }
                StoragePort storagePort = assignPortToInitiator(assigner, assignablePorts, net, initiator, portUsage, null);
                if (storagePort != null) {
                    _log.info(String.format("%s %s   %s %s -> %s  %s %s", director, net.getLabel(), initiator.getInitiatorPort(), initiatorSwitchMap.get(initiator.getId()), storagePort.getPortNetworkId(), storagePort.getPortName(), portSwitchMap.get(storagePort.getId())));
                    StringSet ports = new StringSet();
                    ports.add(storagePort.getId().toString());
                    zoningMap.put(initiator.getId().toString(), ports);
                } else {
                    _log.info(String.format("A port could not be assigned for %s %s   %s", director, net.getLabel(), initiator.getInitiatorPort()));
                }
            }
        }
    }
    return zoningMap;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List)

Example 93 with StringSetMap

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

the class VPlexVnxMaskingOrchestrator method configureZoning.

@Override
public StringSetMap configureZoning(Map<URI, List<List<StoragePort>>> portGroup, Map<String, Map<URI, Set<Initiator>>> initiatorGroup, Map<URI, NetworkLite> networkMap, StoragePortsAssigner assigner, Map<URI, String> initiatorSwitchMap, Map<URI, Map<String, List<StoragePort>>> switchStoragePortsMap, Map<URI, String> portSwitchMap) {
    StringSetMap zoningMap = new StringSetMap();
    // Set up a map to track port usage so that we can use all ports more or less equally.
    Map<StoragePort, Integer> portAUsage = new HashMap<StoragePort, Integer>();
    Map<StoragePort, Integer> portBUsage = new HashMap<StoragePort, Integer>();
    // check if switch affinity is on
    boolean isSwitchAffinity = false;
    if (initiatorSwitchMap != null && !initiatorSwitchMap.isEmpty() && switchStoragePortsMap != null && !switchStoragePortsMap.isEmpty()) {
        isSwitchAffinity = true;
    }
    // with one port.
    for (String director : initiatorGroup.keySet()) {
        for (URI networkURI : initiatorGroup.get(director).keySet()) {
            NetworkLite net = networkMap.get(networkURI);
            for (Initiator initiator : initiatorGroup.get(director).get(networkURI)) {
                // If there are no ports on the initiators network, too bad...
                if (portGroup.get(networkURI) == null) {
                    _log.info(String.format("%s -> no ports in network", initiator.getInitiatorPort()));
                    continue;
                }
                List<StoragePort> assignablePortsA = new ArrayList<StoragePort>();
                List<StoragePort> assignablePortsB = new ArrayList<StoragePort>();
                if (isSwitchAffinity) {
                    // find the ports with the same switch as the initiator
                    String switchName = initiatorSwitchMap.get(initiator.getId());
                    if (!switchName.equals(NullColumnValueGetter.getNullStr())) {
                        Map<String, List<StoragePort>> switchMap = switchStoragePortsMap.get(networkURI);
                        if (switchMap != null) {
                            List<StoragePort> switchPorts = switchMap.get(switchName);
                            if (switchPorts != null && !switchPorts.isEmpty()) {
                                _log.info(String.format("Found the same switch ports, switch is %s", switchName));
                                for (StoragePort port : switchPorts) {
                                    String groupId = port.getPortGroup();
                                    if (groupId != null && groupId.equals(SPA)) {
                                        assignablePortsA.add(port);
                                    } else if (groupId != null && groupId.equals(SPB)) {
                                        assignablePortsB.add(port);
                                    }
                                }
                            }
                        }
                    }
                }
                StringSet ports = new StringSet();
                // Get an A Port
                String aPortName = " ", bPortName = " ";
                if (assignablePortsA.isEmpty()) {
                    assignablePortsA = portGroup.get(networkURI).iterator().next();
                }
                StoragePort portA = VPlexBackEndOrchestratorUtil.assignPortToInitiator(assigner, assignablePortsA, net, initiator, portAUsage, SPA);
                if (portA != null) {
                    aPortName = portA.getPortName();
                    ports.add(portA.getId().toString());
                }
                // Get a B Port
                if (assignablePortsB.isEmpty()) {
                    assignablePortsB = portGroup.get(networkURI).iterator().next();
                }
                StoragePort portB = VPlexBackEndOrchestratorUtil.assignPortToInitiator(assigner, portGroup.get(networkURI).iterator().next(), net, initiator, portBUsage, SPB);
                if (portB != null) {
                    bPortName = portB.getPortName();
                    ports.add(portB.getId().toString());
                }
                _log.info(String.format("%s %s   %s %s -> %s  %s %s %s", director, net.getLabel(), initiator.getInitiatorPort(), initiatorSwitchMap.get(initiator.getId()), aPortName, portSwitchMap.get(portA.getId()), bPortName, portSwitchMap.get(portB.getId())));
                zoningMap.put(initiator.getId().toString(), ports);
            }
        }
    }
    return zoningMap;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 94 with StringSetMap

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

the class VolumeVpoolChangeTaskCompleter method rollbackMaskZoningMap.

/**
 * Restores the zonemaps of the export masks impacted by change vpool operation
 *
 * @param dbClient the DB client
 */
private void rollbackMaskZoningMap(DbClient dbClient) {
    if (maskToZoningMap == null || maskToZoningMap.isEmpty()) {
        _log.info("There are no masks' zonemaps to be restore.");
        return;
    }
    List<ExportMask> masks = dbClient.queryObject(ExportMask.class, maskToZoningMap.keySet());
    for (ExportMask mask : masks) {
        StringSetMap zoningMap = maskToZoningMap.get(mask.getId());
        mask.getZoningMap().clear();
        mask.addZoningMap(zoningMap);
    }
    dbClient.updateObject(masks);
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ExportMask(com.emc.storageos.db.client.model.ExportMask)

Example 95 with StringSetMap

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

the class ZoningAddPathsCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        if (status == Operation.Status.ready && !exportMaskAdjustedPathMap.isEmpty()) {
            log.info("Updating export mask zoning map in DB");
            for (Map.Entry<URI, Map<URI, List<URI>>> maskPathEntry : exportMaskAdjustedPathMap.entrySet()) {
                URI maskURI = maskPathEntry.getKey();
                Map<URI, List<URI>> newPaths = maskPathEntry.getValue();
                ExportMask exportMask = dbClient.queryObject(ExportMask.class, maskURI);
                // update zoning map
                StringSetMap zoningMap = exportMask.getZoningMap();
                if (zoningMap != null && !zoningMap.isEmpty()) {
                    for (Map.Entry<URI, List<URI>> entry : newPaths.entrySet()) {
                        URI initiator = entry.getKey();
                        List<URI> ports = entry.getValue();
                        StringSet existingPorts = zoningMap.get(initiator.toString());
                        Set<String> newPorts = StringSetUtil.uriListToSet(ports);
                        if (existingPorts != null) {
                            existingPorts.addAll(newPorts);
                        } else {
                            existingPorts = new StringSet(newPorts);
                        }
                        zoningMap.put(initiator.toString(), existingPorts);
                    }
                } else {
                    for (Map.Entry<URI, List<URI>> entry : newPaths.entrySet()) {
                        zoningMap.put(entry.getKey().toString(), StringSetUtil.uriListToStringSet(entry.getValue()));
                    }
                }
                dbClient.updateObject(exportMask);
            }
        }
    } catch (Exception e) {
        log.error(String.format("Failed updating status for ExportMaskAddPaths - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Map(java.util.Map)

Aggregations

StringSetMap (com.emc.storageos.db.client.model.StringSetMap)158 StringSet (com.emc.storageos.db.client.model.StringSet)95 URI (java.net.URI)72 ArrayList (java.util.ArrayList)68 List (java.util.List)49 HashMap (java.util.HashMap)43 StoragePort (com.emc.storageos.db.client.model.StoragePort)37 Map (java.util.Map)32 Initiator (com.emc.storageos.db.client.model.Initiator)31 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 StringMap (com.emc.storageos.db.client.model.StringMap)31 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)26 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)26 ExportMask (com.emc.storageos.db.client.model.ExportMask)25 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)25 HashSet (java.util.HashSet)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)18 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)17 Test (org.junit.Test)16