Search in sources :

Example 16 with Initiator

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

the class ExportUtils method cleanStaleHostReferences.

/**
 * Cleans stale host references from export group instance
 *
 * @param exportGroup {@link ExportGroup}
 * @param dbClient {@link DbClient}
 */
private static void cleanStaleHostReferences(ExportGroup exportGroup, DbClient dbClient) {
    if (null == exportGroup || exportGroup.getInactive()) {
        return;
    }
    StringSet exportGroupInitiators = exportGroup.getInitiators();
    // not be empty
    if (!CollectionUtils.isEmpty(exportGroup.getHosts()) && !CollectionUtils.isEmpty(exportGroupInitiators)) {
        Set<String> egHosts = new HashSet<>();
        Collection<Initiator> initiators = Collections2.transform(exportGroupInitiators, CommonTransformerFunctions.fctnStringToInitiator(dbClient));
        for (Initiator initiator : initiators) {
            // upgrade.
            if (null != initiator && initiator.getHost() != null) {
                egHosts.add(initiator.getHost().toString());
            }
        }
        Set<String> staleHosts = new HashSet<>(Sets.difference(exportGroup.getHosts(), egHosts));
        if (!CollectionUtils.isEmpty(staleHosts)) {
            Collection<URI> staleHostURIs = Collections2.transform(staleHosts, CommonTransformerFunctions.FCTN_STRING_TO_URI);
            _log.info(String.format("Stale host references [%s] will be removed from Export Group %s", Joiner.on(',').join(staleHostURIs), exportGroup.getId()));
            exportGroup.removeHosts(new ArrayList<>(staleHostURIs));
        }
    }
    if (!ExportGroupType.Initiator.toString().equalsIgnoreCase(exportGroup.getType()) && CollectionUtils.isEmpty(exportGroup.getHosts()) && !exportGroup.checkInternalFlags(DataObject.Flag.INTERNAL_OBJECT)) {
        // COP-27689 - Even if all the export masks got cleared, the export Group still remains with initiators and volumes.
        // Clean up all the initiators, volumes and ports as there are no available export masks.
        _log.info("There are no hosts in the export Group {}-->{} after cleaning up stale hosts.", exportGroup.getId(), exportGroup.getLabel());
        resetExportGroup(exportGroup, dbClient);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 17 with Initiator

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

the class NetworkUtil method getNetworkToInitiators.

/**
 * Returns a Map of networkURI => [set of endpoints connected].
 *
 * @param dbClient
 * @param initiators
 * @return
 */
public static Map<URI, Set<String>> getNetworkToInitiators(DbClient dbClient, List<Initiator> initiators) {
    Map<URI, Set<String>> networkToEndPoints = new HashMap<URI, Set<String>>();
    for (Initiator initiator : initiators) {
        Set<NetworkLite> networkLites = getEndpointAllNetworksLite(initiator.getInitiatorPort(), dbClient);
        if (null == networkLites || networkLites.isEmpty()) {
            _log.info(String.format("getNetworkToInitiators(%s) -- Initiator is not associated with any network", initiator.getInitiatorPort()));
        } else {
            for (NetworkLite networkLite : networkLites) {
                URI networkUri = networkLite.getId();
                _log.info(String.format("Adding initiator, network (%s, %s) to map", initiator.getInitiatorPort(), networkLite.getLabel()));
                Set<String> endPoints = networkToEndPoints.get(networkUri);
                if (null == endPoints) {
                    endPoints = new HashSet<String>();
                }
                endPoints.add(initiator.getInitiatorPort());
                networkToEndPoints.put(networkUri, endPoints);
            }
        }
    }
    return networkToEndPoints;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Initiator(com.emc.storageos.db.client.model.Initiator) URI(java.net.URI)

Example 18 with Initiator

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

the class VPlexUtil method getBackendPortInitiators.

/**
 * Returns a set of all VPLEX backend ports as their related
 * Initiator URIs for a given VPLEX storage system.
 *
 * @param vplexUri - URI of the VPLEX system to find initiators for
 * @param dbClient - database client instance
 * @return a Set of Initiator URIs
 */
public static Set<URI> getBackendPortInitiators(URI vplexUri, DbClient dbClient) {
    _log.info("finding backend port initiators for VPLEX: " + vplexUri);
    Set<URI> initiators = new HashSet<>();
    List<StoragePort> ports = ConnectivityUtil.getStoragePortsForSystem(dbClient, vplexUri);
    for (StoragePort port : ports) {
        if (StoragePort.PortType.backend.name().equals(port.getPortType())) {
            Initiator init = ExportUtils.getInitiator(port.getPortNetworkId(), dbClient);
            if (init != null) {
                _log.info("found initiator {} for wwpn {}", init.getId(), port.getPortNetworkId());
                initiators.add(init.getId());
            }
        }
    }
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) HashSet(java.util.HashSet)

Example 19 with Initiator

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

the class VPlexUtil method filterInitiatorsForVplex.

/**
 * Filter a list of initiators to contain only those with protocols
 * supported by the VPLEX.
 *
 * @param dbClient a database client instance
 * @param initiators list of initiators
 *
 * @return a filtered list of initiators containing
 *         only those with protocols supported by VPLEX
 */
public static List<URI> filterInitiatorsForVplex(DbClient dbClient, List<URI> initiators) {
    // filter initiators for FC protocol type only (CTRL-6326)
    List<URI> initsToRemove = new ArrayList<>();
    for (URI init : initiators) {
        Initiator initiator = dbClient.queryObject(Initiator.class, init);
        if ((null != initiator) && !HostInterface.Protocol.FC.toString().equals(initiator.getProtocol())) {
            initsToRemove.add(init);
        }
    }
    initiators.removeAll(initsToRemove);
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 20 with Initiator

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

the class VPlexUtil method makeHostInitiatorsMap.

/**
 * Given a list of initiator URIs, make a map of Host URI to a list of Initiators.
 *
 * @param initiators -- list of Initiator URIs
 * @return -- Map of Host URI to List<Initiator> (objects)
 */
public static Map<URI, List<Initiator>> makeHostInitiatorsMap(List<URI> initiators, DbClient dbClient) {
    // sort initiators in a host to initiator map
    Map<URI, List<Initiator>> hostInitiatorMap = new HashMap<>();
    if (!initiators.isEmpty()) {
        for (URI initiatorUri : initiators) {
            Initiator initiator = dbClient.queryObject(Initiator.class, initiatorUri);
            URI initiatorHostURI = VPlexUtil.getInitiatorHost(initiator);
            List<Initiator> initiatorSet = hostInitiatorMap.get(initiatorHostURI);
            if (initiatorSet == null) {
                hostInitiatorMap.put(initiatorHostURI, new ArrayList<Initiator>());
                initiatorSet = hostInitiatorMap.get(initiatorHostURI);
            }
            initiatorSet.add(initiator);
        }
    }
    _log.info("assembled map of hosts to initiators: " + hostInitiatorMap);
    return hostInitiatorMap;
}
Also used : HashMap(java.util.HashMap) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54