Search in sources :

Example 76 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class BlockStorageScheduler method selectStoragePortsInNetworks.

/**
 * Return list of storage ports from the given storage ports connected
 * to the given network and with connectivity to the passed virtual
 * array.
 *
 * @param storagePorts storage ports to process
 * @param networks collection of networks
 * @param varrayURI The URI of the virtual array.
 * @param pathParams The ExportPathParameter settings which may contain a set of allowed ports.
 *              Optional, can be null.
 *
 * @return The list of storage ports.
 */
public Map<NetworkLite, List<StoragePort>> selectStoragePortsInNetworks(List<StoragePort> storagePorts, Collection<NetworkLite> networks, URI varrayURI, ExportPathParams pathParams) {
    Map<NetworkLite, List<StoragePort>> portsInNetwork = new HashMap<>();
    for (NetworkLite networkLite : networks) {
        URI networkURI = networkLite.getId();
        _log.info("Selecting ports for network {} {}", networkLite.getLabel(), networkLite.getId());
        // The list of storage ports in networkURI
        List<StoragePort> spList = new ArrayList<StoragePort>();
        // The list of storage ports in networks that are routed to networkURI
        List<StoragePort> rspList = new ArrayList<StoragePort>();
        List<String> unroutedPorts = new ArrayList<String>();
        List<String> routedPorts = new ArrayList<String>();
        List<String> wrongNetwork = new ArrayList<String>();
        for (StoragePort sp : storagePorts) {
            // Make sure the storage port is in the passed network.
            if (sp.getNetwork().equals(networkURI) || (networkLite != null && networkLite.hasRoutedNetworks(sp.getNetwork()))) {
                // to the passed virtual array.
                if (sp.getNetwork().equals(networkURI)) {
                    spList.add(sp);
                    unroutedPorts.add(portName(sp));
                } else {
                    _log.debug("Storage port {} is not in the requested network {} " + "but it is routed to it.", sp.getNativeGuid(), networkURI);
                    rspList.add(sp);
                    // Duplicate list with just name for better error message.
                    routedPorts.add(portName(sp));
                }
            } else {
                _log.debug("Storage port {} not selected because its network {} " + "is not the requested network {}", new Object[] { sp.getNativeGuid(), sp.getNetwork(), networkURI });
                wrongNetwork.add(portName(sp));
            }
        }
        if (!wrongNetwork.isEmpty()) {
            _log.info("Ports not selected because they are not in the requested network: " + networkURI + " " + Joiner.on(" ").join(wrongNetwork));
        }
        if (!rspList.isEmpty() && !spList.isEmpty()) {
            _log.info("Ports not selected because they are routed and local ports are available: " + networkURI + " " + Joiner.on(" ").join(routedPorts));
        }
        _log.info("Ports that were selected: " + (spList.isEmpty() ? Joiner.on(" ").join(routedPorts) : Joiner.on(" ").join(unroutedPorts)));
        portsInNetwork.put(networkLite, spList.isEmpty() ? rspList : spList);
    }
    return portsInNetwork;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI)

Example 77 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class BlockStorageScheduler method logPortUsageMap.

private void logPortUsageMap(Map<URI, Map<StoragePort, Long>> portUsageMap) {
    // Print up the resulting port usage map.
    StringBuilder sb = new StringBuilder();
    sb.append("filterStoragePortsForRPVMAX - Resulting storage port map: ");
    for (Map.Entry<URI, Map<StoragePort, Long>> entry : portUsageMap.entrySet()) {
        if (entry.getValue().keySet() == null) {
            continue;
        }
        NetworkLite nl = NetworkUtil.getNetworkLite(entry.getKey(), _dbClient);
        Collection<String> portNames = transform(entry.getValue().keySet(), CommonTransformerFunctions.fctnStoragePortToPortName());
        sb.append(String.format("Network: %s, Ports: %s", nl.getLabel(), Joiner.on(',').join(portNames)));
    }
    _log.info(sb.toString());
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap) URI(java.net.URI)

Example 78 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class BlockStorageScheduler method computeStoragePortUsageMapForPorts.

/**
 * Compute the ports available and their usage.
 *
 * @param storageUri -- StorageSystem URI
 * @param networkMap -- a map of Network URI to NetworkLite indicating networks to process
 * @param varrayURI -- the Virtual Array URI
 * @param storagePortsMap a map of network-to-ports of ports that can be allocated
 * @return -- a Map of Network URI to a Map of Storage Port to Long usage factor
 */
private Map<URI, Map<StoragePort, Long>> computeStoragePortUsageMapForPorts(URI storageUri, Map<URI, NetworkLite> networkMap, URI varrayURI, Map<NetworkLite, List<StoragePort>> storagePortsMap) throws PlacementException {
    Map<URI, Map<StoragePort, Long>> result = new HashMap<URI, Map<StoragePort, Long>>();
    // Then put them in the result map and the usageQueue.
    for (URI networkURI : networkMap.keySet()) {
        NetworkLite network = networkMap.get(networkURI);
        List<StoragePort> spList = storagePortsMap.get(network);
        if (spList == null || spList.isEmpty()) {
            throw PlacementException.exceptions.noStoragePortsInNetwork(network.getLabel());
        }
        if (network.getTransportType().equals(StorageProtocol.Transport.FC.name()) || network.getTransportType().equals(StorageProtocol.Transport.IP.name())) {
            Map<StoragePort, Long> portUsage = computeStoragePortUsage(spList);
            // If there are no ports in the requested network, throw an error
            if (portUsage.isEmpty()) {
                throw PlacementException.exceptions.noStoragePortsInNetwork(network.getLabel());
            }
            result.put(networkURI, portUsage);
        } else {
            Map<StoragePort, Long> portUsage = new HashMap<StoragePort, Long>();
            for (StoragePort sp : spList) {
                portUsage.put(sp, 0L);
            }
            result.put(networkURI, portUsage);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap)

Example 79 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class BlockStorageScheduler method allocatePorts.

/**
 * Given a collection of storage ports on a storage system, a given list of initiators
 * belonging to a host or cluster, and given an export for which some port may already
 * be allocated ('add initiator' use case), apply the port selection algorithm to find
 * the ports that should be used by (or 'added to' for 'add initiator' use case).
 *
 * @param system the storage system of the export
 * @param varray the export varray
 * @param initiatorsByNetwork the initiators to which the ports will be assigned,
 *            grouped by network
 * @param portsByNetwork the ports from which the allocation will be made. Note
 *            this function can be called to select ports from pre-zoned ports, in
 *            which can be a subset of all the available ports on the storage system.
 * @param volumeURIs all the export volumes, new and existing
 * @param pathParams the export path parameter which accounts for the paths
 *            requirement for all the volumes vpools.
 * @param existingZoningMap existing allocations, null is no allocations exist.
 * @return the selected ports to be used in the export.
 */
public Map<NetworkLite, List<StoragePort>> allocatePorts(StorageSystem system, URI varray, Map<NetworkLite, List<Initiator>> initiatorsByNetwork, Map<NetworkLite, List<StoragePort>> portsByNetwork, Collection<URI> volumeURIs, ExportPathParams pathParams, StringSetMap existingZoningMap) {
    // Make reasonable defaults for the path parameters.
    checkPathParams(pathParams, system);
    _log.info(String.format("Assigning Ports for Array %s params %s Varray %s", system.getNativeGuid(), pathParams.toString(), varray));
    boolean isSwitchLocalityEnabled = isSwitchAffinityAllocationEnabled(system.getSystemType());
    _log.info(String.format("The switch affinity is %s .", isSwitchLocalityEnabled));
    // Get the existing assignments in object form.
    Map<Initiator, List<StoragePort>> existingAssignments = generateInitiatorsToStoragePortsMap(existingZoningMap, varray);
    // Get a map of Network URIs to Initiators for the existing Initiators.
    Map<URI, Set<Initiator>> existingInitiatorsMap = generateNetworkToInitiatorsMap(existingAssignments, _dbClient);
    // Get a map of Network URIs to StoragePorts for the existing Storage Ports.
    Map<URI, Set<StoragePort>> existingPortsMap = generateNetworkToStoragePortsMap(existingAssignments, existingInitiatorsMap);
    // Make Net to Initiators Map and URI to Network map.
    Map<URI, List<Initiator>> net2InitiatorsMap = new HashMap<URI, List<Initiator>>();
    Map<URI, NetworkLite> networkMap = new HashMap<URI, NetworkLite>();
    for (NetworkLite network : initiatorsByNetwork.keySet()) {
        if (!networkMap.containsKey(network.getId())) {
            networkMap.put(network.getId(), network);
            net2InitiatorsMap.put(network.getId(), initiatorsByNetwork.get(network));
        }
    }
    // Filter Initiators by access - if a host has local access to the storage system
    // remove initiators that are routed to it - Should this be done when initiators are added or is this an override?
    filterRemoteInitiators(system, varray, net2InitiatorsMap, networkMap);
    // Compute the number of Ports needed for each Network, and get the network ordering for allocation.
    List<URI> orderedNetworks = new ArrayList<URI>();
    StoragePortsAssigner assigner = StoragePortsAssignerFactory.getAssigner(system.getSystemType());
    Map<URI, Integer> net2PortsNeeded = assigner.getPortsNeededPerNetwork(net2InitiatorsMap, pathParams, existingPortsMap, existingInitiatorsMap, isSwitchLocalityEnabled, orderedNetworks);
    for (Map.Entry<URI, Integer> entry : net2PortsNeeded.entrySet()) {
        if (networkMap.get(entry.getKey()) != null) {
            _log.info(String.format("Network %s (%s) requested ports %d", networkMap.get(entry.getKey()).getLabel(), entry.getKey().toString(), entry.getValue()));
        }
    }
    // For each Network, allocate the ports required, and then assign the ports.
    StoragePortsAllocator allocator = new StoragePortsAllocator();
    // in a different network.
    for (URI netURI : existingPortsMap.keySet()) {
        NetworkLite network = networkMap.get(netURI);
        Set<StoragePort> existingPorts = existingPortsMap.get(netURI);
        allocator.addPortsToAlreadyAllocatedContext(_dbClient, network, existingPorts);
    }
    // Compute the StoragePort usage map.
    Map<URI, Map<StoragePort, Long>> portUsageMap = computeStoragePortUsageMapForPorts(system.getId(), networkMap, varray, portsByNetwork);
    // Filter out the ports in the case of VMAX and RP splitting: (CTRL-7288)
    // https://support.emc.com/docu10627_RecoverPoint-Deploying-with-Symmetrix-Arrays-and-Splitter-Technical-Notes.pdf?language=en_US
    // We need to align the masking of volumes to hosts to the same ports as the RP masking view.
    portUsageMap = filterStoragePortsForRPVMAX(system.getId(), networkMap, varray, portUsageMap, volumeURIs);
    // Loop through all the required Networks, allocating ports as necessary.
    Map<NetworkLite, List<StoragePort>> portsAllocated = new HashMap<NetworkLite, List<StoragePort>>();
    for (URI netURI : orderedNetworks) {
        // This is the network of the initiator
        NetworkLite network = networkMap.get(netURI);
        Integer portsNeeded = net2PortsNeeded.get(netURI);
        if (portsNeeded == null || portsNeeded == 0) {
            _log.info("No ports to be assigned for network: " + netURI);
            continue;
        }
        List<Initiator> initiators = net2InitiatorsMap.get(netURI);
        // needed for when initiators were eliminate by #filterRemoteInitiators
        if (initiators == null || initiators.isEmpty()) {
            _log.info("No initiators to be assigned for network: " + netURI);
            continue;
        }
        if (portUsageMap.get(netURI).isEmpty()) {
            _log.warn(String.format("No ports available for network: %s. Hence skipping allocation of ports in this network", netURI));
            continue;
        }
        Map<String, Integer> switchToMaxPortNumber = null;
        if (isSwitchLocalityEnabled) {
            switchToMaxPortNumber = getSwitchToMaxPortNumberMap(initiators, pathParams);
        }
        // Allocate the storage ports.
        portsAllocated.put(network, allocatePortsFromNetwork(system.getId(), network, varray, portsNeeded, portUsageMap.get(netURI), allocator, existingPortsMap.get(netURI), true, switchToMaxPortNumber));
    }
    return portsAllocated;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap)

Example 80 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class BlockStorageScheduler method generateNetworkToInitiatorsMap.

/**
 * Creates a map of Network URI to a Set<Initiator> initiators in that Network.
 *
 * @param existingAssignments -- Map of Initiator to a list of Storage Port assignments
 * @return Map of Network URI to a set of Initiators in that Network
 */
private static Map<URI, Set<Initiator>> generateNetworkToInitiatorsMap(Map<Initiator, List<StoragePort>> existingAssignments, DbClient dbClient) {
    Map<URI, Set<Initiator>> network2InitiatorsMap = new HashMap<URI, Set<Initiator>>();
    if (existingAssignments == null) {
        return network2InitiatorsMap;
    }
    NetworkLite network = null;
    for (Initiator initiator : existingAssignments.keySet()) {
        network = getInitiatorNetwork(initiator, dbClient);
        if (network == null) {
            continue;
        }
        if (network2InitiatorsMap.get(network.getId()) == null) {
            network2InitiatorsMap.put(network.getId(), new HashSet<Initiator>());
        }
        network2InitiatorsMap.get(network.getId()).add(initiator);
    }
    return network2InitiatorsMap;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) Initiator(com.emc.storageos.db.client.model.Initiator) NetworkLite(com.emc.storageos.util.NetworkLite) URI(java.net.URI)

Aggregations

NetworkLite (com.emc.storageos.util.NetworkLite)130 StoragePort (com.emc.storageos.db.client.model.StoragePort)110 URI (java.net.URI)86 ArrayList (java.util.ArrayList)85 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)82 HashMap (java.util.HashMap)48 List (java.util.List)44 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)25 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 Map (java.util.Map)22 HashSet (java.util.HashSet)20 Initiator (com.emc.storageos.db.client.model.Initiator)19 StringSet (com.emc.storageos.db.client.model.StringSet)19 TreeMap (java.util.TreeMap)10 Set (java.util.Set)9 SortedMap (java.util.SortedMap)9 StringMap (com.emc.storageos.db.client.model.StringMap)7 StoragePortsAllocator (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator)6 DummyDbClient (com.emc.storageos.util.DummyDbClient)4 PortAllocatorTestContext (com.emc.storageos.volumecontroller.placement.PortAllocatorTestContext)4