/**
   * Get the network that has the endpoint
   *
   * @param endpoint the formatted and validated endpoint
   * @param dbClient an instance if DbClient
   * @param excludedNetworks do not get network with nativeId in the list
   * @return a reference to the network that contains the endpoint. Null if the network is not
   *     found.
   */
  public static NetworkLite getEndpointNetworkLite(
      String endpoint, DbClient dbClient, Set<String> excludedNetworks) {
    _log.debug("Finding networklite for endpoint {}", endpoint);
    URIQueryResultList networkList = new URIQueryResultList();
    Iterator<URI> iterator;
    URI networkUri = null;
    NetworkLite network;
    dbClient.queryByConstraint(
        AlternateIdConstraint.Factory.getEndpointNetworkConstraint(endpoint), networkList);
    iterator = networkList.iterator();
    while (iterator.hasNext()) {
      networkUri = iterator.next();
      network = getNetworkLite(networkUri, dbClient);

      // vsan id is in the excluded list, skip it
      if (excludedNetworks != null && excludedNetworks.contains(network.getNativeId())) {
        continue;
      }

      if (network != null && network.getInactive() == false) {
        _log.info(
            String.format(
                "endpoint %s in network %s (%s)", endpoint, network.getLabel(), network.getId()));
        return network;
      } else {
        _log.info(
            "networklite {} for endpoint {} was deleted or is inactive", networkUri, endpoint);
      }
    }
    _log.info("networklite could not be found for endpoint {}", endpoint);
    return null;
  }
  /**
   * 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;
  }