Search in sources :

Example 56 with NetworkLite

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

the class StoragePortsAssignerTest method createVNXNet1.

protected static PortAllocationContext createVNXNet1() {
    NetworkLite tz = new NetworkLite(URI.create("net1"), "net1");
    PortAllocationContext context = new PortAllocationContext(tz, "test");
    StoragePort port;
    port = createFCPort("SP_A:0", "50:00:00:00:00:00:00:00");
    addPort(context, port, "mds-a");
    port = createFCPort("SP_A:1", "50:00:00:00:00:00:00:01");
    addPort(context, port, "mds-b");
    port = createFCPort("SP_A:2", "50:00:00:00:00:00:00:02");
    addPort(context, port, "mds-a");
    port = createFCPort("SP_A:3", "50:00:00:00:00:00:00:03");
    addPort(context, port, "mds-b");
    port = createFCPort("SP_B:0", "50:00:00:00:00:00:01:00");
    addPort(context, port, "mds-a");
    port = createFCPort("SP_B:1", "50:00:00:00:00:00:01:01");
    addPort(context, port, "mds-b");
    port = createFCPort("SP_B:2", "50:00:00:00:00:00:01:02");
    addPort(context, port, "mds-a");
    port = createFCPort("SP_B:3", "50:00:00:00:00:00:01:03");
    addPort(context, port, "mds-b");
    return context;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 57 with NetworkLite

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

the class StoragePortsAssignerTest method createVNXNet4.

protected static PortAllocationContext createVNXNet4() {
    NetworkLite tz = new NetworkLite(URI.create("net2"), "net2");
    PortAllocationContext context = new PortAllocationContext(tz, "test");
    StoragePort port;
    port = createFCPort("SP_A:4", "50:00:00:00:00:00:00:04");
    addPort(context, port, "mds-a");
    port = createFCPort("SP_B:4", "50:00:00:00:00:00:01:04");
    addPort(context, port, "mds-a");
    return context;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 58 with NetworkLite

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

the class HDSExportOperations method getHostGroupNetworkIdMap.

/**
 * Constructs a map of [Host Group => Network Id] for the given storage ports.
 *
 * @param sports
 * @param hsds
 * @param dbClient
 * @return
 */
private static Map<HostStorageDomain, URI> getHostGroupNetworkIdMap(List<StoragePort> sports, List<HostStorageDomain> hsds, DbClient dbClient) {
    Map<HostStorageDomain, URI> networkToHSDMap = new HashMap<HostStorageDomain, URI>();
    for (StoragePort sport : sports) {
        NetworkLite network = NetworkUtil.getEndpointNetworkLite(sport.getPortNetworkId(), dbClient);
        if (null != network) {
            if (network != null && network.getInactive() == false && network.getTransportType().equals(sport.getTransportType())) {
                HostStorageDomain hsd = findStoragePortOfHSD(hsds, sport);
                if (null != hsd) {
                    log.info("Found a matching network {} for HSD {}", network.getLabel(), sport.getNativeGuid());
                    networkToHSDMap.put(hsd, network.getId());
                } else {
                    log.error("Couldn't find the HSD configured for port: {}", sport.getNativeGuid());
                }
            }
        }
    }
    return networkToHSDMap;
}
Also used : HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Example 59 with NetworkLite

use of com.emc.storageos.util.NetworkLite 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 60 with NetworkLite

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

the class VPlexVmaxMaskingOrchestrator method getPortGroups.

@Override
public Set<Map<URI, List<List<StoragePort>>>> getPortGroups(Map<URI, List<StoragePort>> allocatablePorts, Map<URI, NetworkLite> networkMap, URI varrayURI, int nInitiatorGroups, Map<URI, Map<String, Integer>> switchToPortNumber, Map<URI, PortAllocationContext> contextMap, StringBuilder errorMessages) {
    Set<Map<URI, List<List<StoragePort>>>> portGroups = new HashSet<Map<URI, List<List<StoragePort>>>>();
    StringSet netNames = new StringSet();
    // Order the networks from those with fewest ports to those with the most ports.
    List<URI> orderedNetworks = orderNetworksByNumberOfPorts(allocatablePorts);
    for (URI networkURI : orderedNetworks) {
        netNames.add(networkMap.get(networkURI).getLabel());
    }
    _log.info("Calculating PortGroups for Networks: " + netNames.toString());
    Set<String> cpusUsed = new HashSet<String>();
    Map<URI, List<StoragePort>> useablePorts = new HashMap<URI, List<StoragePort>>();
    Set<String> eliminatedPorts = new HashSet<String>();
    Set<String> usedPorts = new HashSet<String>();
    // Eliminate ports from the same cpus, which are in the same portGroup.
    // This is to avoid the 4096 LUN limit per cpu.
    // Cycle through the networks, picking ports that can be used while considering cpus.
    // Pick one port from each network, then cycle through them again.
    boolean portWasPicked;
    do {
        portWasPicked = false;
        for (URI networkURI : orderedNetworks) {
            if (!useablePorts.containsKey(networkURI)) {
                useablePorts.put(networkURI, new ArrayList<StoragePort>());
            }
            // Pick a port if possible
            for (StoragePort port : allocatablePorts.get(networkURI)) {
                // Do not choose a port that has already been chosen
                if (usedPorts.contains(port.getPortName())) {
                    continue;
                }
                if (!cpusUsed.contains(port.getPortGroup())) {
                    // Choose this port, it has a new cpu.
                    cpusUsed.add(port.getPortGroup());
                    usedPorts.add(port.getPortName());
                    useablePorts.get(networkURI).add(port);
                    portWasPicked = true;
                    break;
                } else {
                    // This port shares a cpu, don't choose it.
                    eliminatedPorts.add(port.getPortName());
                }
            }
        }
    } while (portWasPicked);
    // If all networks have some ports remaining, use the filtered ports.
    // If not, emit a warning and do not use the filtered port configuration.
    boolean useFilteredPorts = true;
    for (URI networkURI : orderedNetworks) {
        if (useablePorts.get(networkURI).isEmpty()) {
            useFilteredPorts = false;
            break;
        }
    }
    if (useFilteredPorts) {
        String message = String.format("Ports successfully selected are %s. Ports eliminated because of sharing a cpu with an already-selected port are %s.", usedPorts.toString(), eliminatedPorts.toString());
        _log.info(message);
        if (errorMessages != null) {
            errorMessages.append(message);
        }
        allocatablePorts = useablePorts;
    } else {
        _log.info("Some networks have zero remaining ports after cpu filtering, will use duplicate ports on some cpus. " + "This is not a recommended configuration.");
    }
    // Determine the network with the lowest number of allocatable ports.
    int minPorts = Integer.MAX_VALUE;
    for (URI networkURI : allocatablePorts.keySet()) {
        int numPorts = allocatablePorts.get(networkURI).size();
        if (numPorts > MAX_PORTS_PER_NETWORK) {
            numPorts = MAX_PORTS_PER_NETWORK;
        }
        if (numPorts < minPorts) {
            minPorts = numPorts;
        }
    }
    // Figure out the number of ports in each network per port group (PG).
    // Then figure out the number of port groups to be generated.
    // HEURISTIC:
    // If the smallest network has 1 port, then allow 1 port per Network unless there's only 1 Network.
    // If there is only one network, require two ports per network in the Port Group.
    // If it has 2 or more ports per network, use 2 ports per network per MV.
    // If there are one or two networks, if it has 9 or more ports, use 3 ports per network per MV.
    // If there are one or two networks, if it has 16 or more ports, use 4 ports per network per MV.
    // oneNetwork indicates if there is only one Network available.
    // portsPerPG is the number of ports to be allocated per PortGroup from the
    // network with the fewest ports.
    // numPG is the number of Port Groups that will be configured.
    boolean oneNetwork = allocatablePorts.keySet().size() == 1;
    boolean moreThanTwoNetworks = allocatablePorts.keySet().size() > 2;
    int portsPerNetPerPG = oneNetwork ? 2 : 1;
    // But if "morePortGroups" is set, will make additional portGroups if there are fewer ports.
    if (morePortGroups) {
        // This can be set true for testing environments
        if (minPorts >= 4) {
            // Makes at least two Port Groups if there are two ports
            portsPerNetPerPG = 2;
        }
    } else {
        if (minPorts >= 2) {
            // Default is to require at least two ports per Port Group
            portsPerNetPerPG = 2;
        }
    }
    if (!moreThanTwoNetworks) {
        if (minPorts >= 9) {
            portsPerNetPerPG = 3;
        }
        if (minPorts >= 16) {
            portsPerNetPerPG = 4;
        }
    }
    int numPG = minPorts / portsPerNetPerPG;
    String message = String.format("Min Ports: %d. Number Port Groups: %d. Ports Per Network Per Port Group: %d.", minPorts, numPG, portsPerNetPerPG);
    _log.info(message);
    if (errorMessages != null) {
        errorMessages.append(message);
    }
    if (numPG == 0) {
        return portGroups;
    }
    // Make a map per Network of number of ports to allocate.
    Map<URI, Integer> portsAllocatedPerNetwork = new HashMap<URI, Integer>();
    for (URI netURI : allocatablePorts.keySet()) {
        Integer nports = allocatablePorts.get(netURI).size() / numPG;
        // ports from the network with the fewest ports, i.e. do not exceed 2x portsPerPG.
        if (nports > (2 * portsPerNetPerPG)) {
            nports = 2 * portsPerNetPerPG;
        }
        portsAllocatedPerNetwork.put(netURI, nports);
    }
    // Now call the StoragePortsAllocator for each Network, assigning required number of ports.
    StoragePortsAllocator allocator = new StoragePortsAllocator();
    for (int i = 0; i < numPG; i++) {
        Map<URI, List<List<StoragePort>>> portGroup = new HashMap<URI, List<List<StoragePort>>>();
        StringSet portNames = new StringSet();
        for (URI netURI : allocatablePorts.keySet()) {
            NetworkLite net = networkMap.get(netURI);
            Map<String, Integer> switchCountMap = null;
            if (switchToPortNumber != null) {
                switchCountMap = switchToPortNumber.get(netURI);
            }
            PortAllocationContext context = null;
            if (contextMap != null) {
                context = contextMap.get(netURI);
            }
            List<StoragePort> allocatedPorts = allocatePorts(allocator, allocatablePorts.get(netURI), portsAllocatedPerNetwork.get(netURI), net, varrayURI, switchCountMap, context);
            if (portGroup.get(netURI) == null) {
                portGroup.put(netURI, new ArrayList<List<StoragePort>>());
            }
            portGroup.get(netURI).add(allocatedPorts);
            allocatablePorts.get(netURI).removeAll(allocatedPorts);
            for (StoragePort port : allocatedPorts) {
                portNames.add(port.getPortName());
            }
        }
        portGroups.add(portGroup);
        _log.info(String.format("Port Group %d: %s", i, portNames.toString()));
        // Reinitialize the context in the allocator; we want redundancy within PG
        if (allocator.getContext() != null) {
            allocator.getContext().reinitialize();
        }
    }
    return portGroups;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) StoragePortsAllocator(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

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