Map<String, ServiceInstance<ModelEndpoint>> containerToEndpoint = new HashMap<>(); try { for(String name : serviceDiscovery.queryForNames()) { for(ServiceInstance<ModelEndpoint> endpoint: serviceDiscovery.queryForInstances(name)) { ModelEndpoint ep = endpoint.getPayload();
@Override public Collection<String> queryForServiceNames() { try { // TODO - possibly cache this return discovery.queryForNames(); } catch ( Exception e ) { log.error("Could not query for names", e); throw new RuntimeException(e); } }
@Override public List<String> queryForNames() { try { LOG.info(new JSONObject() {{ put("type", "queryZkForNames"); /*put("description", "这个查询动作不能过于频繁,否则会有性能问题");*/ }}); return serviceDiscovery.queryForNames(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<String> queryForNames() { try { LOG.info(new JSONObject() {{ put("type", "queryZkForNames"); /*put("description", "这个查询动作不能过于频繁,否则会有性能问题");*/ }}); return serviceDiscovery.queryForNames(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<String> queryForNames() { try { LOG.info(new JSONObject() {{ put("type", "queryZkForNames"); /*put("description", "这个查询动作不能过于频繁,否则会有性能问题");*/ }}); return serviceDiscovery.queryForNames(); } catch (Exception e) { throw new RuntimeException(e); } }
public void listInstances(ServiceDiscovery<MetaData> serviceDiscovery) throws Exception { // This shows how to query all the instances in service discovery try { Collection<String> serviceNames = serviceDiscovery.queryForNames(); for (String serviceName : serviceNames) { Collection<ServiceInstance<MetaData>> instances = serviceDiscovery.queryForInstances(serviceName); log.info("serviceName: " + serviceName); for (ServiceInstance<MetaData> instance : instances) { outputInstance(instance); } } } catch (Exception e) { /* * Something bad did happen, but carry on */ log.error(e.getMessage(), e); } }
@GET @Path("v1/service") @Produces(MediaType.APPLICATION_JSON) public Response getAllNames() { try { List<String> instances = Lists.newArrayList(context.getServiceDiscovery().queryForNames()); Collections.sort(instances); return Response.ok(new ServiceNames(instances)).build(); } catch ( Exception e ) { log.error("Trying to get service names", e); return Response.serverError().build(); } }
private Collection<String> getNamesToQuery() throws Exception { if (this.zookeeperDependencies == null) { if (log.isDebugEnabled()) { log.debug("Using direct name resolution instead of dependency based one"); } List<String> names = new ArrayList<>(); for (String name : getServiceDiscovery().queryForNames()) { names.add(sanitize(name)); } return names; } if (log.isDebugEnabled()) { log.debug("Using dependency based names to query"); } return this.zookeeperDependencies.getDependencyNames(); }
private void doWork() { try { for ( String name : discovery.queryForNames() ) { checkService(name); } } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); log.error("GC for service names", e); } }
private static void listInstances(ServiceDiscovery<InstanceDetails> serviceDiscovery) throws Exception { // This shows how to query all the instances in service discovery try { Collection<String> serviceNames = serviceDiscovery.queryForNames(); System.out.println(serviceNames.size() + " type(s)"); for (String serviceName : serviceNames) { Collection<ServiceInstance<InstanceDetails>> instances = serviceDiscovery.queryForInstances(serviceName); System.out.println(serviceName); for (ServiceInstance<InstanceDetails> instance : instances) { outputInstance(instance); } } } finally { CloseableUtils.closeQuietly(serviceDiscovery); } }
@Override public List<String> getServices() { List<String> services = null; if (getServiceDiscovery() == null) { log.warn("Service Discovery is not yet ready - returning empty list of services"); return Collections.emptyList(); } try { Collection<String> names = getServiceDiscovery().queryForNames(); if (names == null) { return Collections.emptyList(); } services = new ArrayList<>(names); } catch (KeeperException.NoNodeException e) { if (log.isDebugEnabled()) { log.debug("Error getting services from zookeeper. Possibly, no service has registered.", e); } // this means that nothing has registered as a service yes return Collections.emptyList(); } catch (Exception e) { rethrowRuntimeException(e); } return services; }
private static void listInstances(ServiceDiscovery<InstanceDetails> serviceDiscovery) throws Exception { // This shows how to query all the instances in service discovery try { Collection<String> serviceNames = serviceDiscovery.queryForNames(); System.out.println(serviceNames.size() + " type(s)"); for ( String serviceName : serviceNames ) { Collection<ServiceInstance<InstanceDetails>> instances = serviceDiscovery.queryForInstances(serviceName); System.out.println(serviceName); for ( ServiceInstance<InstanceDetails> instance : instances ) { outputInstance(instance); } } } finally { CloseableUtils.closeQuietly(serviceDiscovery); } }
public List<String> listServiceInstance() throws Exception { List<String> list = new ArrayList<String>(); ServiceDiscovery<MetaData> serviceDiscovery = ServiceUtil.getServiceDiscovery(curatorFramework, basePath); try { Collection<String> serviceNames = serviceDiscovery.queryForNames(); for (String serviceName : serviceNames) { Collection<ServiceInstance<MetaData>> instances = serviceDiscovery.queryForInstances(serviceName); log.info("serviceName: " + serviceName); for (ServiceInstance<MetaData> instance : instances) { list.add(instance.getPayload().getListenAddress() + ":" + instance.getPayload().getListenPort()); outputInstance(instance); } } } catch (Exception e) { /* * Something bad did happen, but carry on */ log.error(e.getMessage(), e); } Collections.sort(list); log.debug("listsize:" + list.size()); return list; }
@Override protected void doStop() throws Exception { if (serviceDiscovery != null) { try { if (configuration.isDeregisterServicesOnStop()) { for (String serviceName: serviceDiscovery.queryForNames()) { for (ServiceInstance<MetaData> serviceInstance: serviceDiscovery.queryForInstances(serviceName)) { if (serviceList.contains(serviceInstance.getId())) { serviceDiscovery.unregisterService(serviceInstance); // remove the serviceId to the list of known server serviceList.remove(serviceInstance.getId()); } } } } serviceDiscovery.close(); } catch (Exception e) { LOGGER.warn("Error closing Curator ServiceDiscovery", e); } } if (curator != null && managedInstance) { curator.close(); } }
private synchronized void compute(Future<Void> done) { List<ServiceInstance<JsonObject>> instances = new ArrayList<>(); try { Collection<String> names = discovery.queryForNames(); for (String name : names) { instances.addAll(discovery.queryForInstances(name));
private synchronized void compute(Future<Void> done) { List<ServiceInstance<JsonObject>> instances = new ArrayList<>(); try { Collection<String> names = discovery.queryForNames(); for (String name : names) { instances.addAll(discovery.queryForInstances(name));