Search in sources :

Example 21 with NetworkLite

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

the class BlockStorageScheduler method getInitiatorsByNetwork.

/**
 * Creates a map of initiators grouped and keyed by their network.
 * Initiators which are not in any network are not returned.
 *
 * @param initiators the initiators
 * @param client
 * @return a map of network-to-initiators
 */
private Map<NetworkLite, List<Initiator>> getInitiatorsByNetwork(Collection<Initiator> initiators, StringSetMap zoninMap, DbClient dbClient) {
    Map<NetworkLite, List<Initiator>> map = new HashMap<NetworkLite, List<Initiator>>();
    NetworkLite network = null;
    for (Initiator initiator : initiators) {
        network = NetworkUtil.getEndpointNetworkLite(initiator.getInitiatorPort(), dbClient);
        if (network == null) {
            _log.info(String.format("Initiator %s (%s) is being removed from initiator list because it has no network association", initiator.getInitiatorPort(), initiator.getHostName()));
            continue;
        }
        StringMapUtil.addToListMap(map, network, initiator);
        _log.info(String.format("Processing initiator %s (%s) network %s", initiator.getInitiatorPort(), initiator.getHostName(), network.getLabel()));
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Initiator(com.emc.storageos.db.client.model.Initiator) NetworkLite(com.emc.storageos.util.NetworkLite) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 22 with NetworkLite

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

the class BlockStorageScheduler method getHostInitiatorsMapFromNetworkLite.

/**
 * Given a list of networks-to-initiators, further break down the map by host so
 * that the end result is a map of hosts-to-networks-to-initiators.
 *
 * @param net2InitiatorsMap networks-to-initiators map
 * @return a map of hosts-to-network-to-initiators
 */
private Map<URI, Map<URI, List<Initiator>>> getHostInitiatorsMapFromNetworkLite(Map<NetworkLite, List<Initiator>> net2InitiatorsMap) {
    Map<URI, Map<URI, List<Initiator>>> hostNetworkInitiatorsMap = new HashMap<URI, Map<URI, List<Initiator>>>();
    for (Map.Entry<NetworkLite, List<Initiator>> entry : net2InitiatorsMap.entrySet()) {
        List<Initiator> initiators = entry.getValue();
        for (Initiator initiator : initiators) {
            URI host = initiator.getHost();
            if (NullColumnValueGetter.isNullURI(host)) {
                host = StoragePortsAssigner.unknown_host_uri;
            }
            Map<URI, List<Initiator>> hostMap = hostNetworkInitiatorsMap.get(host);
            if (hostMap == null) {
                hostMap = new HashMap<URI, List<Initiator>>();
                hostNetworkInitiatorsMap.put(host, hostMap);
            }
            if (hostMap.get(entry.getKey().getId()) == null) {
                hostMap.put(entry.getKey().getId(), new ArrayList<Initiator>());
            }
            hostMap.get(entry.getKey().getId()).add(initiator);
        }
    }
    return hostNetworkInitiatorsMap;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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 23 with NetworkLite

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

the class BlockStorageScheduler method internalAssignStoragePorts.

/**
 * Allocates and assigns StoragePorts.
 *
 * @param system - The StorageSystem the ports will be assigned from.
 * @param varray - The VirtualArray (ex. Neighborhood) the initiators should be found in.
 * @param newInitiators - The new initiators to be provisioned.
 * @param volumeURIs - list of volumes
 * @param pathParams - Export path parameters (maxPaths, pathsPerInitiator)
 * @param existingZoningMap - A map of initiators to a set of previously allocated port URI strings.
 * @return Map<URI, List<URI>> Initiator URI to list of Target StoragePort URIs
 */
private Map<URI, List<URI>> internalAssignStoragePorts(StorageSystem system, URI varray, List<Initiator> newInitiators, 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));
    // Get the existing assignments in object form.
    Map<Initiator, List<StoragePort>> existingAssignments = generateInitiatorsToStoragePortsMap(existingZoningMap, varray);
    // Group the new initiators by their networks - filter out those not in a network
    Map<NetworkLite, List<Initiator>> initiatorsByNetwork = getInitiatorsByNetwork(newInitiators, existingZoningMap, _dbClient);
    Map<Initiator, NetworkLite> initiatorsToNetworkLiteMap = getInitiatorToNetworkLiteMap(initiatorsByNetwork);
    // Get the storage ports in the storage system that can be used in the initiators networks
    Map<NetworkLite, List<StoragePort>> portsByNetwork = selectStoragePortsInNetworks(system.getId(), initiatorsByNetwork.keySet(), varray, pathParams);
    // allocate ports balancing across networks and considering port metrics
    Map<NetworkLite, List<StoragePort>> allocatedPorts = allocatePorts(system, varray, initiatorsByNetwork, portsByNetwork, volumeURIs, pathParams, existingZoningMap);
    StoragePortsAssigner assigner = StoragePortsAssignerFactory.getAssigner(system.getSystemType());
    Map<Initiator, List<StoragePort>> assignments = new HashMap<Initiator, List<StoragePort>>();
    // Call StoragePortsAssigner once per host to do the assignments
    Map<URI, Map<URI, List<Initiator>>> hostsToNetToInitiators = getHostInitiatorsMapFromNetworkLite(initiatorsByNetwork);
    Map<URI, List<StoragePort>> allocatedPortsMap = getAllocatedPortsMap(allocatedPorts);
    // For each host, assign the ports to the appropriate initiators.
    for (URI hostURI : hostsToNetToInitiators.keySet()) {
        Map<URI, Map<String, List<Initiator>>> switchInitiatorsByNet = new HashMap<URI, Map<String, List<Initiator>>>();
        Map<URI, Map<String, List<StoragePort>>> switchStoragePortsByNet = new HashMap<URI, Map<String, List<StoragePort>>>();
        Map<URI, List<Initiator>> initiatorByNetMap = hostsToNetToInitiators.get(hostURI);
        PlacementUtils.getSwitchfoForInititaorsStoragePorts(initiatorByNetMap, allocatedPortsMap, _dbClient, system, switchInitiatorsByNet, switchStoragePortsByNet);
        assigner.assignPortsToHost(assignments, initiatorByNetMap, allocatedPortsMap, pathParams, existingAssignments, hostURI, initiatorsToNetworkLiteMap, switchInitiatorsByNet, switchStoragePortsByNet);
    }
    // Validate that minPaths was met across all assignments (existing and new).
    validateMinPaths(system, pathParams, existingAssignments, assignments, newInitiators);
    return convertAssignmentsToURIs(assignments);
}
Also used : 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) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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 24 with NetworkLite

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

the class BlockStorageScheduler method generateInitiatorsToStoragePortsMap.

/**
 * Given the existingZoningMap from the ExportMask, get a map of
 * Initiators to a List<StoragePort> of the StoragePorts assigned to that Initiator.
 *
 * Note: This is varray aware, so even if zoning map has storage ports for the initiator
 * but they are not in the varray that is been looked for then those ports are not returned
 * in the map. This will be the case where volumes from two different varrays are exported to
 * the same host and the storage ports in those varrays might be different.
 *
 * @param existingZoningMap -- StringSetMap
 * @return Map<Initiator, List<StoragePort>> existing assignment map with Objects
 */
public Map<Initiator, List<StoragePort>> generateInitiatorsToStoragePortsMap(StringSetMap existingZoningMap, URI varray) {
    Map<Initiator, List<StoragePort>> initiatorsToStoragePortsMap = new HashMap<Initiator, List<StoragePort>>();
    if (existingZoningMap == null) {
        return initiatorsToStoragePortsMap;
    }
    for (String initiatorId : existingZoningMap.keySet()) {
        Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorId));
        if (initiator == null || initiator.getInactive()) {
            continue;
        }
        NetworkLite network = getInitiatorNetwork(initiator, _dbClient);
        String networkLabel = (network != null ? network.getLabel() : "<unknown network>");
        StringSet ports = existingZoningMap.get(initiatorId);
        if (ports == null) {
            continue;
        }
        StringBuilder portNames = new StringBuilder();
        for (String portId : ports) {
            StoragePort port = _dbClient.queryObject(StoragePort.class, URI.create(portId));
            if (port != null && port.getTaggedVirtualArrays() != null && port.getTaggedVirtualArrays().contains(varray.toString()) && port.getRegistrationStatus().toString().equals(DiscoveredDataObject.RegistrationStatus.REGISTERED.name()) && DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name().equals(port.getCompatibilityStatus().toString()) && DiscoveryStatus.VISIBLE.name().equals(port.getDiscoveryStatus().toString())) {
                if (initiatorsToStoragePortsMap.get(initiator) == null) {
                    initiatorsToStoragePortsMap.put(initiator, new ArrayList<StoragePort>());
                }
                initiatorsToStoragePortsMap.get(initiator).add(port);
                portNames.append(port.getPortName() + " (" + port.getPortNetworkId() + ")  ");
            }
        }
        _log.info(String.format("Existing initiator %s (%s) network %s ports %s", initiator.getInitiatorPort(), initiator.getHostName(), networkLabel, portNames.toString()));
    }
    return initiatorsToStoragePortsMap;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 25 with NetworkLite

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

the class BlockStorageScheduler method assignSelectedStoragePorts.

/**
 * Assigns storage ports to initiators.
 *
 * @param system storage system which contains storage ports
 * @param storagePorts storage ports to assign
 * @param virtualArray virtual array which contains storage ports
 * @param initiators list of initiators
 * @param pathParams the export path parameters
 * @param existingZoningMap existing zoning map in the mask
 * @return assignments of storage ports to initiators
 * @throws DeviceControllerException
 */
public Map<URI, List<URI>> assignSelectedStoragePorts(StorageSystem system, List<StoragePort> storagePorts, URI virtualArray, List<Initiator> initiators, ExportPathParams pathParams, StringSetMap existingZoningMap) throws DeviceControllerException {
    Map<Initiator, List<StoragePort>> assignments = new HashMap<>();
    try {
        // Group the new initiators by their networks - filter out those not in a network
        Map<NetworkLite, List<Initiator>> initiatorsByNetwork = getInitiatorsByNetwork(initiators, existingZoningMap, _dbClient);
        Map<Initiator, NetworkLite> initiatorsToNetworkLiteMap = getInitiatorToNetworkLiteMap(initiatorsByNetwork);
        // Get the storage ports that can be used in the initiators networks
        Map<NetworkLite, List<StoragePort>> portsByNetwork = selectStoragePortsInNetworks(storagePorts, initiatorsByNetwork.keySet(), virtualArray, pathParams);
        StoragePortsAssigner assigner = StoragePortsAssignerFactory.getAssigner(system.getSystemType());
        // Call StoragePortsAssigner once per host to do the assignments
        Map<URI, Map<URI, List<Initiator>>> hostsToNetToInitiators = getHostInitiatorsMapFromNetworkLite(initiatorsByNetwork);
        Map<URI, List<StoragePort>> allocatedPortsMap = getAllocatedPortsMap(portsByNetwork);
        // Get the existing assignments in object form.
        Map<Initiator, List<StoragePort>> existingAssignments = generateInitiatorsToStoragePortsMap(existingZoningMap, virtualArray);
        // For each host, assign the ports to the appropriate initiators.
        for (URI hostURI : hostsToNetToInitiators.keySet()) {
            assigner.assignPortsToHost(assignments, hostsToNetToInitiators.get(hostURI), allocatedPortsMap, pathParams, existingAssignments, hostURI, initiatorsToNetworkLiteMap, null, null);
        }
        // Validate that minPaths was met across all assignments (existing and new).
        validateMinPaths(system, pathParams, existingAssignments, assignments, initiators);
        return convertAssignmentsToURIs(assignments);
    } catch (PlacementException e) {
        _log.error("Unable to assign storage Ports", e);
        throw DeviceControllerException.exceptions.exceptionAssigningStoragePorts(e.getMessage(), e);
    } catch (Exception e) {
        _log.error("Unable to assign Storage Ports", e);
        throw DeviceControllerException.exceptions.unexpectedExceptionAssigningPorts(e);
    }
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap)

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