/** * Retrieves the single service. * <p/> * GET /v1/catalog/service/{service} * * @return A {@link com.orbitz.consul.model.ConsulResponse} containing * {@link com.orbitz.consul.model.catalog.CatalogService} objects. */ public ConsulResponse<List<CatalogService>> getService(String service) { return getService(service, QueryOptions.BLANK); }
/** * Deregisters a service or node. * <p/> * PUT /v1/catalog/deregister * * @param deregistration A {@link CatalogDeregistration} */ public void deregister(CatalogDeregistration deregistration) { deregister(deregistration, QueryOptions.BLANK); }
/** * Retrieves a single node. * <p/> * GET /v1/catalog/node/{node} * * @return A list of matching {@link com.orbitz.consul.model.catalog.CatalogService} objects. */ public ConsulResponse<CatalogNode> getNode(String node) { return getNode(node, QueryOptions.BLANK); }
public static NodesCatalogCache newCache( final CatalogClient catalogClient, final QueryOptions queryOptions, final int watchSeconds) { final CallbackConsumer<Node> callbackConsumer = (index, callback) -> catalogClient.getNodes(watchParams(index, watchSeconds, queryOptions), callback); return new NodesCatalogCache(Node::getNode, callbackConsumer, catalogClient.getConfig().getCacheConfig(), catalogClient.getEventHandler()); }
public static ServiceCatalogCache newCache( final CatalogClient catalogClient, final String serviceName, final QueryOptions queryOptions, final int watchSeconds) { final CallbackConsumer<CatalogService> callbackConsumer = (index, callback) -> catalogClient.getService(serviceName, watchParams(index, watchSeconds, queryOptions), callback); CacheDescriptor cacheDescriptor = new CacheDescriptor("catalog.service", serviceName); return new ServiceCatalogCache(CatalogService::getServiceId, callbackConsumer, catalogClient.getConfig().getCacheConfig(), catalogClient.getEventHandler(), cacheDescriptor); }
/** * Retrieves all services for a given datacenter. * <p/> * GET /v1/catalog/services?dc={datacenter} * * @return A {@link com.orbitz.consul.model.ConsulResponse} containing a map of service name to list of tags. */ public ConsulResponse<Map<String, List<String>>> getServices() { return getServices(QueryOptions.BLANK); }
/** * Retrieves all nodes. * <p/> * GET /v1/catalog/nodes * * @return A {@link com.orbitz.consul.model.ConsulResponse} containing a list of * {@link com.orbitz.consul.model.health.Node} objects. */ public ConsulResponse<List<Node>> getNodes() { return getNodes(QueryOptions.BLANK); }
/** * Registers a service or node. * <p/> * PUT /v1/catalog/register * * @param registration A {@link CatalogRegistration} */ public void register(CatalogRegistration registration) { register(registration, QueryOptions.BLANK); }
/** * Asynchronously retrieves the services for a given datacenter. * <p/> * GET /v1/catalog/services?dc={datacenter} * * @param callback Callback implemented by callee to handle results. * @return A {@link com.orbitz.consul.model.ConsulResponse} containing a map of service name to list of tags. */ public void getServices(ConsulResponseCallback<Map<String, List<String>>> callback) { getServices(QueryOptions.BLANK, callback); }
@InvokeOnHeader(ConsulCatalogActions.LIST_NODES) protected void listNodes(Message message) throws Exception { processConsulResponse( message, getClient().getNodes( buildQueryOptions(message, getConfiguration()) ) ); }
@InvokeOnHeader(ConsulCatalogActions.REGISTER) protected void register(Message message) throws Exception { getClient().register(message.getMandatoryBody(CatalogRegistration.class)); setBodyAndResult(message, null); }
@Override public List<ServiceDefinition> getServices(String name) { List<CatalogService> services = client.get().catalogClient() .getService(name, queryOptions) .getResponse(); List<ServiceHealth> healths = client.get().healthClient() .getAllServiceInstances(name, queryOptions) .getResponse(); return services.stream() .map(service -> newService(name, service, healths)) .collect(Collectors.toList()); }
@Override public void run() { CatalogClient client = this.catalogClientInjector.getValue(); BigInteger index = null; while (true) { QueryOptions options = QueryOptions.BLANK; if (index != null) { options = ImmutableQueryOptions.builder() .wait("60s") .index(index) .build(); } ConsulResponse<Map<String, List<String>>> services = client.getServices(options); index = services.getIndex(); Map<String, List<String>> response = services.getResponse(); response.keySet().forEach(e -> { setupWatcher(e); }); try { Thread.sleep(1000); } catch (InterruptedException e) { break; } } }
@InvokeOnHeader(ConsulCatalogActions.LIST_SERVICES) protected void listServices(Message message) throws Exception { processConsulResponse( message, getClient().getNodes( buildQueryOptions(message, getConfiguration()) ) ); }
@InvokeOnHeader(ConsulCatalogActions.DEREGISTER) protected void deregister(Message message) throws Exception { getClient().deregister(message.getMandatoryBody(CatalogDeregistration.class)); setBodyAndResult(message, null); }
@InvokeOnHeader(ConsulCatalogActions.GET_NODE) protected void getNode(Message message) throws Exception { processConsulResponse( message, getClient().getNode( getMandatoryHeader(message, ConsulConstants.CONSUL_NODE, String.class), buildQueryOptions(message, getConfiguration()) ) ); } }
@InvokeOnHeader(ConsulCatalogActions.GET_SERVICE) protected void getService(Message message) throws Exception { processConsulResponse( message, getClient().getService( getMandatoryHeader(message, ConsulConstants.CONSUL_SERVICE, String.class), buildQueryOptions(message, getConfiguration()) ) ); }
ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken));
ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken));
ConsulResponse<List<CatalogService>> response = consulCatalogClient.getService("test-DoNothingRegistrator"); Assert.assertEquals(totalInstancesToTest,response.getResponse().size());