Search in sources :

Example 91 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort 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 92 with StoragePort

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

the class VPlexHDSMaskingOrchestrator method allocatePorts.

/**
 * Allocates StoragePorts (in either the simulated or production modes).
 *
 * @param candidatePorts
 *            -- List of ports from which to choose
 * @param portsRequested
 *            -- Integer number of ports requested
 * @param net
 *            -- NetworkLite network
 * @param varrayURI
 *            -- URI of VirtualArray
 * @return List of StoragePorts allocated.
 */
private List<StoragePort> allocatePorts(StoragePortsAllocator allocator, List<StoragePort> candidatePorts, int portsRequested, NetworkLite net, URI varrayURI, Map<String, Integer> switchToPortNumber, PortAllocationContext context) {
    Collections.shuffle(candidatePorts);
    if (simulation) {
        if (context == null) {
            context = StoragePortsAllocator.getPortAllocationContext(net, "arrayX", allocator.getContext());
            for (StoragePort port : candidatePorts) {
                context.addPort(port, null, null, null, null);
            }
        }
        List<StoragePort> portsAllocated = allocator.allocatePortsForNetwork(portsRequested, context, false, null, false, switchToPortNumber);
        allocator.setContext(context);
        return portsAllocated;
    } else {
        Map<StoragePort, Long> sportMap = _blockScheduler.computeStoragePortUsage(candidatePorts);
        List<StoragePort> portsAllocated = allocator.selectStoragePorts(_dbClient, sportMap, net, varrayURI, portsRequested, null, false, switchToPortNumber);
        return portsAllocated;
    }
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort)

Example 93 with StoragePort

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

the class VPlexVnxMaskingOrchestrator method allocatePorts.

/**
 * Allocates StoragePorts (in either the simulated or production modes).
 *
 * @param candidatePorts
 *            -- List of ports from which to choose
 * @param portsRequested
 *            -- Integer number of ports requested
 * @param net
 *            -- NetworkLite network
 * @param varrayURI
 *            -- URI of VirtualArray
 * @return
 */
private List<StoragePort> allocatePorts(StoragePortsAllocator allocator, List<StoragePort> candidatePorts, int portsRequested, NetworkLite net, URI varrayURI, Map<String, Integer> switchToPortNumber, PortAllocationContext context) {
    Collections.shuffle(candidatePorts);
    if (simulation) {
        if (context == null) {
            context = StoragePortsAllocator.getPortAllocationContext(net, "arrayX", allocator.getContext());
            for (StoragePort port : candidatePorts) {
                context.addPort(port, null, null, null, null);
            }
        }
        List<StoragePort> portsAllocated = allocator.allocatePortsForNetwork(portsRequested, context, false, null, false, switchToPortNumber);
        allocator.setContext(context);
        return portsAllocated;
    } else {
        Map<StoragePort, Long> sportMap = _blockScheduler.computeStoragePortUsage(candidatePorts);
        List<StoragePort> portsAllocated = allocator.selectStoragePorts(_dbClient, sportMap, net, varrayURI, portsRequested, null, false, switchToPortNumber);
        return portsAllocated;
    }
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort)

Example 94 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort 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 95 with StoragePort

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

the class VPlexCommunicationInterface method setStorageProviderCompatibilityStatus.

/**
 * Sets the compatibility status on a VPLEX StorageProvider and all its underlying
 * StorageSystems and StoragePorts.
 *
 * @param provider the StorageProvider
 * @param status the CompatibilityStatus to set (COMPATIBLE or INCOMPATIBLE)
 */
private void setStorageProviderCompatibilityStatus(StorageProvider provider, CompatibilityStatus status) {
    if (provider == null) {
        s_logger.warn("The requested StorageProvider was null.");
        return;
    }
    if (status == null) {
        s_logger.warn("No updated CompatibilityStatus was provided for StorageProvider {}.", provider.getLabel());
        return;
    }
    s_logger.info("Setting compatibility status on Storage Provider {} to {}", provider.getLabel(), status.toString());
    provider.setCompatibilityStatus(status.toString());
    StringSet storageSystemURIStrs = provider.getStorageSystems();
    if (storageSystemURIStrs != null) {
        for (String storageSystemURIStr : storageSystemURIStrs) {
            // update storage system compatibility status
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, URI.create(storageSystemURIStr));
            if (storageSystem != null) {
                s_logger.info("- Setting compatibility status on Storage System {} to {}", storageSystem.getLabel(), status.toString());
                storageSystem.setCompatibilityStatus(status.toString());
                // update port compatibility status
                URIQueryResultList storagePortURIs = new URIQueryResultList();
                _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(storageSystem.getId()), storagePortURIs);
                Iterator<URI> storagePortIter = storagePortURIs.iterator();
                while (storagePortIter.hasNext()) {
                    StoragePort port = _dbClient.queryObject(StoragePort.class, storagePortIter.next());
                    if (port != null) {
                        s_logger.info("-- Setting compatibility status on Storage Port {} to {}", port.getLabel(), status.toString());
                        port.setCompatibilityStatus(status.name());
                        _dbClient.updateObject(port);
                    }
                }
                _dbClient.updateObject(storageSystem);
            }
        }
    }
    _dbClient.updateObject(provider);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

StoragePort (com.emc.storageos.db.client.model.StoragePort)477 URI (java.net.URI)285 ArrayList (java.util.ArrayList)261 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)143 HashMap (java.util.HashMap)134 List (java.util.List)130 NetworkLite (com.emc.storageos.util.NetworkLite)110 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 StringSet (com.emc.storageos.db.client.model.StringSet)92 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)84 HashSet (java.util.HashSet)81 Initiator (com.emc.storageos.db.client.model.Initiator)78 Map (java.util.Map)64 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)62 StoragePool (com.emc.storageos.db.client.model.StoragePool)51 IOException (java.io.IOException)48 StringMap (com.emc.storageos.db.client.model.StringMap)45 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)43 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)42 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)34