gets supervisor workers by host or supervisor id, note that id priors to host.

@param host host
@param id   supervisor id
@return supervisor workers
183733
private SupervisorWorkers getSupervisorWorkersByHostOrId(String host, String id) throws TException {
        long start = System.nanoTime();

        if (StringUtils.isBlank(id) && StringUtils.isBlank(host)) {
            throw new TException("Must specify host or supervisor id!");
        }

        try {
            StormClusterState stormClusterState = data.getStormClusterState();

            // all supervisors
            Map<String, SupervisorInfo> supervisorInfos = Cluster.get_all_SupervisorInfo(stormClusterState, null);
            SupervisorInfo supervisorInfo = null;
            String ip;
            if (!StringUtils.isBlank(id)) {
                supervisorInfo = supervisorInfos.get(id);
                host = supervisorInfo.getHostName();
                ip = NetWorkUtils.host2Ip(host);
            } else {
                ip = NetWorkUtils.host2Ip(host);
                for (Entry<String, SupervisorInfo> entry : supervisorInfos.entrySet()) {
                    SupervisorInfo info = entry.getValue();
                    if (info.getHostName().equals(host) || info.getHostName().equals(ip)) {
                        id = entry.getKey();
                        supervisorInfo = info;
                        break;
                    }
                }
            }
            if (supervisorInfo == null) {
                throw new TException("unknown supervisor id:" + id);
            }

            Map<String, Assignment> assignments = Cluster.get_all_assignment(stormClusterState, null);
            Map<Integer, WorkerSummary> portWorkerSummaries = new TreeMap<>();
            int usedSlotNumber = 0;
            Map<String, Map<Integer, String>> topologyTaskToComponent = new HashMap<>();

            Map<String, MetricInfo> metricInfoMap = new HashMap<>();
            for (Entry<String, Assignment> entry : assignments.entrySet()) {
                String topologyId = entry.getKey();
                Assignment assignment = entry.getValue();

                Set<ResourceWorkerSlot> workers = assignment.getWorkers();
                for (ResourceWorkerSlot worker : workers) {
                    if (!id.equals(worker.getNodeId())) {
                        continue;
                    }
                    usedSlotNumber++;

                    Integer port = worker.getPort();
                    WorkerSummary workerSummary = portWorkerSummaries.get(port);
                    if (workerSummary == null) {
                        workerSummary = new WorkerSummary();
                        workerSummary.set_port(port);
                        workerSummary.set_topology(topologyId);
                        workerSummary.set_tasks(new ArrayList<TaskComponent>());

                        portWorkerSummaries.put(port, workerSummary);
                    }

                    Map<Integer, String> taskToComponent = topologyTaskToComponent.get(topologyId);
                    if (taskToComponent == null) {
                        taskToComponent = Cluster.get_all_task_component(stormClusterState, topologyId, null);
                        topologyTaskToComponent.put(topologyId, taskToComponent);
                    }

                    int earliest = TimeUtils.current_time_secs();
                    for (Integer taskId : worker.getTasks()) {
                        TaskComponent taskComponent = new TaskComponent();
                        taskComponent.set_component(taskToComponent.get(taskId));
                        taskComponent.set_taskId(taskId);
                        Integer startTime = assignment.getTaskStartTimeSecs().get(taskId);
                        if (startTime != null && startTime < earliest) {
                            earliest = startTime;
                        }

                        workerSummary.add_to_tasks(taskComponent);
                    }

                    workerSummary.set_uptime(TimeUtils.time_delta(earliest));

                    String workerSlotName = getWorkerSlotName(ip, port);
                    List<MetricInfo> workerMetricInfoList = this.data.getMetricCache().getMetricData(topologyId, MetaType.WORKER);
                    if (workerMetricInfoList.size() > 0) {
                        MetricInfo workerMetricInfo = workerMetricInfoList.get(0);
                        // remove metrics that don't belong to current worker
                        for (Iterator<String> itr = workerMetricInfo.get_metrics().keySet().iterator();
                             itr.hasNext(); ) {
                            String metricName = itr.next();
                            if (!metricName.contains(ip)) {
                                itr.remove();
                            }
                        }
                        metricInfoMap.put(workerSlotName, workerMetricInfo);
                    }
                }
            }

            List<WorkerSummary> workerList = new ArrayList<>();
            workerList.addAll(portWorkerSummaries.values());

            Map<String, Integer> supervisorToUsedSlotNum = new HashMap<>();
            supervisorToUsedSlotNum.put(id, usedSlotNumber);
            SupervisorSummary supervisorSummary = NimbusUtils.mkSupervisorSummary(supervisorInfo, id, supervisorToUsedSlotNum);

            return new SupervisorWorkers(supervisorSummary, workerList, metricInfoMap);
        } catch (TException e) {
            LOG.info("Failed to get ClusterSummary ", e);
            throw e;
        } catch (Exception e) {
            LOG.info("Failed to get ClusterSummary ", e);
            throw new TException(e);
        } finally {
            long end = System.nanoTime();
            SimpleJStormMetric.updateNimbusHistogram("getSupervisorWorkers", (end - start) / TimeUtils.NS_PER_US);
        }

    }
1027098
public static Map<String, SupervisorInfo> get_all_SupervisorInfo(
            StormClusterState stormClusterState, RunnableCallback callback) throws Exception {
        Map<String, SupervisorInfo> rtn = new TreeMap<>();
        // get /ZK/supervisors
        List<String> supervisorIds = stormClusterState.supervisors(callback);
        // ignore any supervisors in blacklist
        List<String> blacklist = stormClusterState.get_blacklist();

        if (supervisorIds != null) {
            for (Iterator<String> iter = supervisorIds.iterator(); iter.hasNext(); ) {
                String supervisorId = iter.next();
                // get /supervisors/supervisorid
                SupervisorInfo supervisorInfo = stormClusterState.supervisor_info(supervisorId);
                if (supervisorInfo == null) {
                    LOG.warn("Failed to get SupervisorInfo of " + supervisorId);
                } else if (blacklist.contains(supervisorInfo.getHostName())) {
                    LOG.warn(" hostname:" + supervisorInfo.getHostName() + " is in blacklist");
                } else {
                    rtn.put(supervisorId, supervisorInfo);
                }
            }
        } else {
            LOG.info("No alive supervisor");
        }

        return rtn;
    }
860341
@Override
    @Synchronized
    public void takeLeadership(CuratorFramework client) throws Exception {
        log.info("Obtained leadership to monitor the Host to Segment Container Mapping");

        //Attempt a rebalance whenever leadership is obtained to ensure no host events are missed.
        hostsChange.release();

        //Start cluster monitor.
        pravegaServiceCluster = new ClusterZKImpl(client, ClusterType.HOST);

        //Add listener to track host changes on the monitored pravega cluster.
        pravegaServiceCluster.addListener((type, host) -> {
            switch (type) {
                case HOST_ADDED:
                case HOST_REMOVED:
                    //We don't keep track of the hosts and we always query for the entire set from the cluster
                    //when changes occur. This is to avoid any inconsistencies if we miss any notifications.
                    log.info("Received event: {} for host: {}. Wake up leader for rebalancing", type, host);
                    hostsChange.release();
                    break;
                case ERROR:
                    //This event should be due to ZK connection errors and would have been received by the monitor too,
                    //hence not handling it explicitly here.
                    log.info("Received error event when monitoring the pravega host cluster, ignoring...");
                    break;
            }
        });

        //Keep looping here as long as possible to stay as the leader and exclusively monitor the pravega cluster.
        while (true) {
            try {
                if (suspended.get()) {
                    log.info("Monitor is suspended, waiting for notification to resume");
                    suspendMonitor.acquire();
                    log.info("Resuming monitor");
                }

                hostsChange.acquire();
                log.info("Received rebalance event");

                // Wait here until rebalance can be performed.
                waitForRebalance();

                // Clear all events that has been received until this point since this will be included in the current
                // rebalance operation.
                hostsChange.drainPermits();
                triggerRebalance();
            } catch (InterruptedException e) {
                log.warn("Leadership interrupted, releasing monitor thread");

                //Stop watching the pravega cluster.
                pravegaServiceCluster.close();
                throw e;
            } catch (Exception e) {
                //We will not release leadership if in suspended mode.
                if (!suspended.get()) {
                    log.warn("Failed to perform rebalancing, relinquishing leadership");

                    //Stop watching the pravega cluster.
                    pravegaServiceCluster.close();
                    throw e;
                }
            }
        }
    }
1359614
def _get_ids_from_hostname(self, hostname):
        """"""
        results = self.list_hardware(hostname=hostname, mask="id")
        return [result['id'] for result in results]
779529
public RedisClusterNode getPartition(String host, int port) {

        for (RedisClusterNode partition : nodeReadView) {

            RedisURI uri = partition.getUri();

            if (matches(uri, host, port)) {
                return partition;
            }

            for (RedisURI redisURI : partition.getAliases()) {

                if (matches(redisURI, host, port)) {
                    return partition;
                }
            }
        }

        return null;
    }
348686
public Set<Integer> getAvailablePorts(SupervisorDetails supervisor) {
        Set<Integer> usedPorts = this.getUsedPorts(supervisor);

        Set<Integer> ret = new HashSet<>();
        ret.addAll(getAssignablePorts(supervisor));
        ret.removeAll(usedPorts);

        return ret;
    }
318453
protected Proxy getProxy(final Settings settings, final String serverId, final String host) {
		if (settings == null)
			return null;
		List<Proxy> proxies = settings.getProxies();
		if (proxies == null || proxies.isEmpty())
			return null;

		// search id match first
		if ( serverId != null && !serverId.isEmpty() ) {
			for (Proxy proxy : proxies) {
				if ( proxy.isActive() ) {
					final String proxyId = proxy.getId();
					if ( proxyId != null && !proxyId.isEmpty() ) {
						if ( proxyId.equalsIgnoreCase(serverId) ) {
							if ( ( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) ) ) {
								if ( matchNonProxy( proxy, host ) )
									return null;
								else
									return proxy;
							}
						}
					}
				}
			}
		}

		// search active proxy
		for (Proxy proxy : proxies)
			if ( proxy.isActive() &&
					( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) )
					)
			{
				if ( matchNonProxy( proxy, host ) )
					return null;
				else
					return proxy;
			}

		return null;
	}
440357
public static Collection<InetAddress> getAllByName(String host, boolean allowIPv6) {
       Enumeration<NetworkInterface> networkInterfaces = cloneInterfaces(ResolutionUtils.networkInterfaces);
       List<String> resolvedAddresses = resolveDeviceAddress(host, networkInterfaces, allowIPv6);
       List<InetAddress> resolvedDeviceURIs = new ArrayList<>();
       List<InetAddress> resolvedHosts = resolvedDeviceURIs;
       for (String resolvedAddress : resolvedAddresses) {
           try {
               resolvedHosts.addAll(asList(InetAddress.getAllByName(resolvedAddress)));
           } catch (UnknownHostException e) {
               e.printStackTrace();
           }
       }
       return resolvedHosts;
   }
1171421
@Override
	public List<Identity> getApprovers(AuthzTrans trans, String user) throws OrganizationException {
		Identity orgIdentity = getIdentity(trans, user);
		List<Identity> orgIdentitys = new ArrayList<Identity>();
		if(orgIdentity!=null) {
			String supervisorID = orgIdentity.responsibleTo();
			if (supervisorID.indexOf('@') < 0) {
			    supervisorID += getDomain();
			}
			Identity supervisor = getIdentity(trans, supervisorID);
			orgIdentitys.add(supervisor);
		}
		return orgIdentitys;	
	}
410250
private static Set<Integer> getPartitionIdsForHosts(AbstractTopology topology, Set<Integer> hostIds) {
        Set<Integer> partitionIds = new HashSet<>();
        for (int hostId : hostIds) {
            partitionIds.addAll(topology.getPartitionIdList(hostId));
        }
        return partitionIds;
    }
122620
public static String getParentId(String digest, String host) throws IOException {
        DockerClient dockerClient = null;
        try {
            dockerClient = getDockerClient(host);
            return dockerClient.inspectImageCmd(digest).exec().getParent();
        } finally {
            closeQuietly(dockerClient);
        }
    }
980743
public static Registry getRegistry(String host, int port)
   throws RemoteException
   {
	return LocateRegistry.getRegistry(host, port);
   }
1116816
public static String queryIp(String host) {
		InetAddress[] addresses;
		try {
			addresses = InetAddress.getAllByName(host);
		}
		catch (UnknownHostException e) {
			return null;
		}
		// System.out.println("len:" + addresses.length);
		if (addresses.length == 1) {
			return addresses[0].getHostAddress();
		}
		else {
			// 多IP时，随机返回一个
			int random = new Random().nextInt(addresses.length);
			return addresses[random].getHostAddress();
		}
	}
584111
public java.util.List<String> getHostIds() {
        if (hostIds == null) {
            hostIds = new com.amazonaws.internal.SdkInternalList<String>();
        }
        return hostIds;
    }
41252
public synchronized List<alluxio.grpc.JobCommand> pollAllPendingCommands(long workerId) {
    if (!mWorkerIdToPendingCommands.containsKey(workerId)) {
      return Lists.newArrayList();
    }
    List<JobCommand> commands =
        Lists.newArrayList(mWorkerIdToPendingCommands.get(workerId));
    mWorkerIdToPendingCommands.get(workerId).clear();
    return commands;
  }
1270511
private Path getHost( String id, long version ) {
        Path ret = root;
        for( String part : id.split( "-" ) ) {
            ret = ret.resolve( part );
        }

        return ret.resolve( "" + version );
    }
1174373
public static InetAddress getIPHostAddress(String host) {
        InetAddress result = null;
        Matcher matcher = IPV4_QUADS.matcher(host);
        if (matcher == null || !matcher.matches()) {
            return result;
        }
        try {
            // Doing an Inet.getByAddress() avoids a lookup.
            result = InetAddress.getByAddress(host,
                    new byte[] {
                    (byte)(new Integer(matcher.group(1)).intValue()),
                    (byte)(new Integer(matcher.group(2)).intValue()),
                    (byte)(new Integer(matcher.group(3)).intValue()),
                    (byte)(new Integer(matcher.group(4)).intValue())});
        } catch (NumberFormatException e) {
            logger.warning(e.getMessage());
        } catch (UnknownHostException e) {
            logger.warning(e.getMessage());
        }
        return result;
    }