Search in sources :

Example 36 with PortAllocationContext

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

the class StoragePortsAssignerTest method createVmaxNet3.

// NBS VSAN 10
protected static PortAllocationContext createVmaxNet3() {
    NetworkLite tz = new NetworkLite(URI.create("net3"), "net3");
    PortAllocationContext context = new PortAllocationContext(tz, "test");
    StoragePort port;
    port = createFCPort("FA-1E:0", "50:00:09:75:10:04:95:00");
    addPort(context, port, "mds-a");
    port = createFCPort("FA-1F:0", "50:00:09:75:10:04:95:40");
    addPort(context, port, "mds-a");
    port = createFCPort("FA-1G:0", "50:00:09:75:10:04:95:80");
    addPort(context, port, "mds-a");
    port = createFCPort("FA-2E:0", "50:00:09:75:10:04:95:04");
    addPort(context, port, "mds-a");
    port = createFCPort("FA-2F:0", "50:00:09:75:10:04:95:44");
    addPort(context, port, "mds-a");
    port = createFCPort("FA-2G:0", "50:00:09:75:10:04:95:84");
    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 37 with PortAllocationContext

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

the class StoragePortsAssignerTest method testVNX2NetAllocIncrementalAssign.

public static void testVNX2NetAllocIncrementalAssign(Map<URI, List<Initiator>> net2InitiatorsMapA, Map<URI, List<Initiator>> net2InitiatorsMapB, int maxPaths, int pathsPerInitiator) throws Exception {
    Map<URI, Map<URI, List<Initiator>>> hostToNetToInitiatorsMap = new HashMap<URI, Map<URI, List<Initiator>>>();
    URI hostA = getHostURI(net2InitiatorsMapA);
    hostToNetToInitiatorsMap.put(hostA, net2InitiatorsMapA);
    PortAllocationContext net1ctx = createVNXNet1();
    PortAllocationContext net2ctx = createVNXNet2();
    PortAllocationContext[] contexts = new PortAllocationContext[] { net1ctx, net2ctx };
    // Allocate initial assignments
    System.out.println("Initial assignments:");
    Map<Initiator, List<StoragePort>> assignments = testAllocationAssignment(contexts, hostToNetToInitiatorsMap, maxPaths, 0, pathsPerInitiator, 1, "vnxblock", null);
    URI hostB = getHostURI(net2InitiatorsMapB);
    if (hostA.equals(hostB)) {
        Map<URI, List<Initiator>> mergedNet2Initiators = new HashMap<URI, List<Initiator>>();
        for (URI netA : net2InitiatorsMapA.keySet()) {
            mergedNet2Initiators.put(netA, new ArrayList<Initiator>(net2InitiatorsMapA.get(netA)));
        }
        for (URI netb : net2InitiatorsMapB.keySet()) {
            if (mergedNet2Initiators.containsKey(netb)) {
                mergedNet2Initiators.get(netb).addAll(net2InitiatorsMapB.get(netb));
            } else {
                mergedNet2Initiators.put(netb, new ArrayList<Initiator>(net2InitiatorsMapB.get(netb)));
            }
        }
        hostToNetToInitiatorsMap.clear();
        hostToNetToInitiatorsMap.put(hostA, mergedNet2Initiators);
    } else {
        hostToNetToInitiatorsMap.put(hostB, net2InitiatorsMapB);
    }
    // Allocate incremental assignments
    System.out.println("Incremental assignments:");
    assignments = testAllocationAssignment(contexts, hostToNetToInitiatorsMap, maxPaths, 0, pathsPerInitiator, 1, "vnxblock", assignments);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 38 with PortAllocationContext

use of com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext 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 39 with PortAllocationContext

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

the class StoragePortsAssignerTest method testAllocationAssignment.

/**
 * Test port allocation and assignment.
 *
 * @param contexts -- Array of PortAllocationContext structures, one for each Network.
 * @param hostToNetToInitiators -- Map of host to map of network URI to Initiators
 * @param maxPaths -- max_paths variable
 * @param minPaths -- mininmum number of paths to provision
 * @param pathsPerInitiator -- desired number of paths per initiator
 * @param initiatorsPerPort -- maximum number of initiators in a host using same port
 * @param arrayType -- String array type
 * @param existingAssignments - previously assigned Initiator to StoragePort list mappings
 */
public static Map<Initiator, List<StoragePort>> testAllocationAssignment(PortAllocationContext[] contexts, Map<URI, Map<URI, List<Initiator>>> hostToNetToInitiators, int maxPaths, int minPaths, int pathsPerInitiator, int initiatorsPerPort, String arrayType, Map<Initiator, List<StoragePort>> existingAssignments) throws Exception {
    Map<URI, List<Initiator>> net2InitiatorsMap = makeNet2InitiatorsMap(hostToNetToInitiators);
    Map<Initiator, List<StoragePort>> assignments = new HashMap<Initiator, List<StoragePort>>();
    if (pathsPerInitiator > maxPaths) {
        return assignments;
    }
    ExportPathParams pathParams = new ExportPathParams(maxPaths, minPaths, pathsPerInitiator);
    pathParams.setMaxInitiatorsPerPort(initiatorsPerPort);
    try {
        for (int i = 0; i < contexts.length; i++) {
            contexts[i].reinitialize();
        }
        Map<URI, PortAllocationContext> net2ContextMap = new HashMap<URI, PortAllocationContext>();
        for (int i = 0; i < contexts.length; i++) {
            PortAllocationContext context = contexts[i];
            net2ContextMap.put(context._initiatorNetwork.getId(), context);
        }
        // Map the existing (already allocated) StoragePorts to their Networks.
        Map<URI, Set<StoragePort>> existingPortsMap = generateNetworkToStoragePortsMap(existingAssignments);
        // Make a Map of Network to existing Initiators
        Map<URI, Set<Initiator>> existingInitiatorsMap = generateNetworkToInitiatorsMap(existingAssignments);
        // Compute the number of Ports needed for each Network
        StoragePortsAssigner assigner = StoragePortsAssignerFactory.getAssigner(arrayType);
        List<URI> networkOrder = new ArrayList<URI>();
        Map<URI, Integer> net2PortsNeeded = assigner.getPortsNeededPerNetwork(net2InitiatorsMap, pathParams, existingPortsMap, existingInitiatorsMap, false, networkOrder);
        // For each Network, allocate the ports required, and then assign the ports.
        StoragePortsAllocator allocator = new StoragePortsAllocator();
        Map<URI, List<StoragePort>> netToPortsAllocated = new HashMap<URI, List<StoragePort>>();
        PortAllocationContext previousContext = null;
        for (URI netURI : networkOrder) {
            Integer portsNeeded = net2PortsNeeded.get(netURI);
            if (portsNeeded == 0) {
                System.out.println("No ports to be assigned for net: " + netURI);
                continue;
            }
            // Get the context for this network.
            PortAllocationContext context = net2ContextMap.get(netURI);
            // Copy context from the previous allocation.
            if (previousContext != null) {
                context.copyPreviousNetworkContext(previousContext);
            }
            previousContext = context;
            List<StoragePort> portsAllocated = allocator.allocatePortsForNetwork(portsNeeded, context, false, existingPortsMap.get(netURI), true, null);
            netToPortsAllocated.put(netURI, portsAllocated);
        }
        // Now for each host, do the port assignment.
        for (Map.Entry<URI, Map<URI, List<Initiator>>> entry : hostToNetToInitiators.entrySet()) {
            System.out.println("Assign ports for host " + entry.getKey());
            assigner.assignPortsToHost(assignments, entry.getValue(), netToPortsAllocated, pathParams, existingAssignments, entry.getKey(), null, null, null);
        }
        List<String> assignmentStrings = new ArrayList<String>();
        for (Initiator initiator : assignments.keySet()) {
            StringBuilder buf = new StringBuilder();
            buf.append(initiator.getHostName() + "-" + initiator.getInitiatorPort() + " -> ");
            List<StoragePort> ports = assignments.get(initiator);
            if (ports == null) {
                buf.append("<ignored>");
            } else {
                for (StoragePort port : assignments.get(initiator)) {
                    buf.append(port.getPortName() + " ");
                }
            }
            buf.append(" ");
            assignmentStrings.add(buf.toString());
        }
        Collections.sort(assignmentStrings);
        for (String line : assignmentStrings) {
            System.out.println(line);
        }
        verifyAssignments(assignments, arrayType, maxPaths, pathsPerInitiator, initiatorsPerPort, net2InitiatorsMap, existingAssignments);
    } catch (PlacementException ex) {
        System.out.println("PlacementException: " + ex.getMessage());
    } catch (Exception ex) {
        System.out.println("ERROR: " + ex.getMessage());
        throw ex;
    }
    return assignments;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) List(java.util.List) StoragePort(com.emc.storageos.db.client.model.StoragePort) HashMap(java.util.HashMap) Map(java.util.Map) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) PortAllocationContext(com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)

Example 40 with PortAllocationContext

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

the class StoragePortsAssignerTest method getSwitchPortsByNetMap.

public static Map<URI, Map<String, List<StoragePort>>> getSwitchPortsByNetMap(Map<URI, List<StoragePort>> netToPortsAllocated, Map<URI, PortAllocationContext> net2ContextMap) {
    Map<URI, Map<String, List<StoragePort>>> result = new HashMap<URI, Map<String, List<StoragePort>>>();
    for (Map.Entry<URI, List<StoragePort>> entry : netToPortsAllocated.entrySet()) {
        URI net = entry.getKey();
        PortAllocationContext ctx = net2ContextMap.get(net);
        List<StoragePort> ports = entry.getValue();
        Map<String, List<StoragePort>> switchPortMap = result.get(net);
        if (switchPortMap == null) {
            switchPortMap = new HashMap<String, List<StoragePort>>();
            result.put(net, switchPortMap);
        }
        for (StoragePort port : ports) {
            String switchName = ctx._storagePortToSwitchName.get(port);
            if (switchName == null || switchName.isEmpty()) {
                switchName = "switch?";
            }
            List<StoragePort> portsInMap = switchPortMap.get(switchName);
            if (portsInMap == null) {
                portsInMap = new ArrayList<>();
                switchPortMap.put(switchName, portsInMap);
            }
            portsInMap.add(port);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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