Search in sources :

Example 1 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext in project coprhd-controller by CoprHD.

the class VplexCinderMaskingOrchestrator 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) {
    _log.debug("START - getPortGroups");
    Set<Map<URI, List<List<StoragePort>>>> portGroups = new HashSet<Map<URI, List<List<StoragePort>>>>();
    Map<URI, Integer> portsAllocatedPerNetwork = new HashMap<URI, Integer>();
    // Port Group is always 1 for Cinder as of now.
    for (URI netURI : allocatablePorts.keySet()) {
        Integer nports = allocatablePorts.get(netURI).size() / CINDER_NUM_PORT_GROUP;
        portsAllocatedPerNetwork.put(netURI, nports);
    }
    StoragePortsAllocator allocator = new StoragePortsAllocator();
    for (int i = 0; i < CINDER_NUM_PORT_GROUP; 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: port names in the port group {%s}", i, portNames.toString()));
    }
    _log.debug("END - getPortGroups");
    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)

Example 2 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext in project coprhd-controller by CoprHD.

the class VPlexHDSMaskingOrchestrator 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>>>>();
    // Group the networks into sets based on the number of ports they have.
    StringSet netNames = new StringSet();
    Map<Integer, Set<URI>> numPortsToNetworkSet = new HashMap<Integer, Set<URI>>();
    for (URI networkURI : allocatablePorts.keySet()) {
        int numPorts = allocatablePorts.get(networkURI).size();
        if (numPorts > MAX_PORTS_PER_NETWORK) {
            numPorts = MAX_PORTS_PER_NETWORK;
        }
        if (numPortsToNetworkSet.get(numPorts) == null) {
            numPortsToNetworkSet.put(Integer.valueOf(numPorts), new HashSet<URI>());
        }
        numPortsToNetworkSet.get(Integer.valueOf(numPorts)).add(networkURI);
        netNames.add(networkMap.get(networkURI).getLabel());
    }
    _log.info("Calculating PortGroups for Networks %s: " + netNames.toString());
    // Eliminate ports from the same cpus, which are in the same portGroup.
    // This is to avoid the 4096 LUN limit per cpu.
    // Start with networks with fewest ports and work up. THis is because
    // in the case of duplicate us of a cpu by two ports, we want to eliminate
    // the port in the Network containing the most ports. So by starting with
    // the Network with the fewest ports to populate the cpusUsed set, we will
    // end up eliminating the port that is in the Network with a higher number of
    // ports.
    Set<String> cpusUsed = new HashSet<String>();
    for (Integer numPorts = 1; numPorts < MAX_PORTS_PER_NETWORK; numPorts++) {
        Set<URI> networkURIs = numPortsToNetworkSet.get(numPorts);
        if (networkURIs == null) {
            continue;
        }
        for (URI networkURI : networkURIs) {
            List<StoragePort> nonConflictedPorts = new ArrayList<StoragePort>();
            for (StoragePort port : allocatablePorts.get(networkURI)) {
                if (!cpusUsed.contains(port.getPortGroup())) {
                    cpusUsed.add(port.getPortGroup());
                    nonConflictedPorts.add(port);
                } else {
                    _log.info(String.format("Eliminating port %s because cpu already used", port.getPortName()));
                }
            }
            allocatablePorts.put(networkURI, nonConflictedPorts);
        }
    }
    // 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:
    // 1-3 ports, use 1 port per MV, unless there's only one Network, then use 2.
    // If it has 8 or more ports, use 2 ports per network, 4 for MV.
    // If it has 18 or more ports, use 3 ports per network, 6 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;
    int portsPerPG = oneNetwork ? 2 : 1;
    if (minPorts >= 8) {
        portsPerPG = 2;
    }
    if (minPorts >= 18) {
        portsPerPG = 3;
    }
    int numPG = minPorts / portsPerPG;
    if (numPG == 0) {
        return portGroups;
    }
    _log.info(String.format("Number Port Groups %d Per Network Ports Per Group %d", numPG, portsPerPG));
    // 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 * portsPerPG)) {
            nports = 2 * portsPerPG;
        }
        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 : HashSet(java.util.HashSet) Set(java.util.Set) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) HashSet(java.util.HashSet) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) HashMap(java.util.HashMap) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 3 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext in project coprhd-controller by CoprHD.

the class VPlexVnxMaskingOrchestrator method getPortGroups.

/**
 * Returns the set of port groups that should be used.
 * Each port group is a map of Network to a list of Storage Ports in that Network.
 * Since at most we can construct two InitiatorGroups, we try to construct
 * two PortGroups.
 *
 * @return Sets of PortGroups, where each Port Group is a map of Network URI
 *         to a List of Storage Ports.
 */
@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>>>>();
    // Determine the network with the fewest ports. It will determine how many
    // port groups can be made.
    int minPorts = Integer.MAX_VALUE;
    for (URI networkURI : allocatablePorts.keySet()) {
        int numPorts = allocatablePorts.get(networkURI).size();
        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,
    // which will always be one or two.
    boolean oneNetwork = allocatablePorts.keySet().size() == 1;
    int numPG = 1;
    if (nInitiatorGroups == 2 && minPorts >= 2 && !oneNetwork) {
        numPG = 2;
    }
    if (numPG == 0) {
        return portGroups;
    }
    _log.info(String.format("Number Port Groups %d", numPG));
    // Make a map per Network of number of ports to allocate.
    Map<URI, Integer> portsAllocatedPerNetwork = new HashMap<URI, Integer>();
    for (URI netURI : allocatablePorts.keySet()) {
        // Calculate the number of ports to be allocated for this net. It is:
        // the number of allocatable ports / numPG.
        Integer nports = allocatablePorts.get(netURI).size() / numPG;
        portsAllocatedPerNetwork.put(netURI, nports);
    }
    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)

Example 4 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext in project coprhd-controller by CoprHD.

the class VPlexHDSMaskingOrchestratorTest method getNet8Ports.

private static PortAllocationContext getNet8Ports(Map<URI, NetworkLite> networkMap, Map<URI, List<StoragePort>> allocatablePorts) {
    String label = "net8";
    URI id = URI.create(label);
    NetworkLite net = new NetworkLite(id, label);
    networkMap.put(id, net);
    PortAllocationContext context = new PortAllocationContext(net, label);
    StoragePort port = null;
    List<StoragePort> ports = new ArrayList<StoragePort>();
    port = createFCPort("FA-1F:0", "50:00:00:00:00:00:00:1F:00");
    ports.add(port);
    port = createFCPort("FA-2F:0", "50:00:00:00:00:00:00:2F:00");
    ports.add(port);
    port = createFCPort("FA-3F:0", "50:00:00:00:00:00:00:3F:00");
    ports.add(port);
    port = createFCPort("FA-4F:0", "50:00:00:00:00:00:00:4F:00");
    ports.add(port);
    port = createFCPort("FA-5F:0", "50:00:00:00:00:00:00:5F:00");
    ports.add(port);
    port = createFCPort("FA-6F:0", "50:00:00:00:00:00:00:6F:00");
    ports.add(port);
    port = createFCPort("FA-7F:0", "50:00:00:00:00:00:00:7F:00");
    ports.add(port);
    port = createFCPort("FA-8F:0", "50:00:00:00:00:00:00:8F:00");
    ports.add(port);
    port = createFCPort("FA-9F:0", "50:00:00:00:00:00:00:9F:00");
    ports.add(port);
    port = createFCPort("FA-10F:0", "50:00:00:00:00:00:00:AF:00");
    ports.add(port);
    port = createFCPort("FA-11F:0", "50:00:00:00:00:00:00:BF:00");
    ports.add(port);
    port = createFCPort("FA-1H:0", "50:00:00:00:00:00:00:12:00");
    ports.add(port);
    port = createFCPort("FA-2H:0", "50:00:00:00:00:00:00:22:00");
    ports.add(port);
    port = createFCPort("FA-3H:0", "50:00:00:00:00:00:00:32:00");
    ports.add(port);
    port = createFCPort("FA-4H:0", "50:00:00:00:00:00:00:42:00");
    ports.add(port);
    port = createFCPort("FA-5H:0", "50:00:00:00:00:00:00:52:00");
    ports.add(port);
    port = createFCPort("FA-6H:0", "50:00:00:00:00:00:00:62:00");
    ports.add(port);
    port = createFCPort("FA-7H:0", "50:00:00:00:00:00:00:72:00");
    ports.add(port);
    port = createFCPort("FA-8H:0", "50:00:00:00:00:00:00:82:00");
    ports.add(port);
    port = createFCPort("FA-9H:0", "50:00:00:00:00:00:00:92:00");
    ports.add(port);
    port = createFCPort("FA-10H:0", "50:00:00:00:00:00:00:A2:00");
    ports.add(port);
    // duplicate cpu
    port = createFCPort("FA-11G:1", "50:00:00:00:00:00:00:B1:01");
    ports.add(port);
    port = createFCPort("FA-12H:0", "50:00:00:00:00:00:00:C2:00");
    ports.add(port);
    allocatablePorts.put(id, ports);
    return context;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 5 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext in project coprhd-controller by CoprHD.

the class VPlexHDSMaskingOrchestratorTest method getNet573BPorts.

private static PortAllocationContext getNet573BPorts(Map<URI, NetworkLite> networkMap, Map<URI, List<StoragePort>> allocatablePorts) {
    String label = "net573B";
    URI id = URI.create(label);
    NetworkLite net = new NetworkLite(id, label);
    networkMap.put(id, net);
    PortAllocationContext context = new PortAllocationContext(net, label);
    StoragePort port = null;
    List<StoragePort> ports = new ArrayList<StoragePort>();
    port = createFCPort("FA-7E:0", "50:00:09:73:00:18:95:18");
    ports.add(port);
    port = createFCPort("FA-9E:1", "50:00:09:73:00:18:95:21");
    ports.add(port);
    allocatablePorts.put(id, ports);
    return context;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Aggregations

PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)95 StoragePort (com.emc.storageos.db.client.model.StoragePort)84 NetworkLite (com.emc.storageos.util.NetworkLite)82 URI (java.net.URI)65 ArrayList (java.util.ArrayList)65 HashMap (java.util.HashMap)28 List (java.util.List)27 Map (java.util.Map)20 Initiator (com.emc.storageos.db.client.model.Initiator)13 HashSet (java.util.HashSet)13 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)10 Set (java.util.Set)7 StringMap (com.emc.storageos.db.client.model.StringMap)6 StringSet (com.emc.storageos.db.client.model.StringSet)6 StoragePortsAllocator (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator)6 DummyDbClient (com.emc.storageos.util.DummyDbClient)5 PortAllocatorTestContext (com.emc.storageos.volumecontroller.placement.PortAllocatorTestContext)4 VPlexBackendManager (com.emc.storageos.vplexcontroller.VPlexBackendManager)4 ExportPathParams (com.emc.storageos.db.client.model.ExportPathParams)2