checkConfig.getString("path")); Registration.RegCheck check = Registration.RegCheck.http(http, checkConfig.getDuration("interval", TimeUnit.SECONDS), checkConfig.getDuration("timeout", TimeUnit.SECONDS));
: "/") + healthCheckPath; final Registration.RegCheck serviceRegCheck = Registration.RegCheck.http( heathCheckPath, healthCheckIntervalSec);
Optional<List<String>> argsOptional = instance.getArgs(); if (argsOptional.isPresent()) { args(argsOptional); Optional<String> intervalOptional = instance.getInterval(); if (intervalOptional.isPresent()) { interval(intervalOptional); Optional<String> ttlOptional = instance.getTtl(); if (ttlOptional.isPresent()) { ttl(ttlOptional); Optional<String> httpOptional = instance.getHttp(); if (httpOptional.isPresent()) { http(httpOptional); Optional<String> tcpOptional = instance.getTcp(); if (tcpOptional.isPresent()) { tcp(tcpOptional); Optional<String> grpcOptional = instance.getGrpc(); if (grpcOptional.isPresent()) { grpc(grpcOptional); Optional<Boolean> grpcUseTlsOptional = instance.getGrpcUseTls(); if (grpcUseTlsOptional.isPresent()) { grpcUseTls(grpcUseTlsOptional); Optional<String> timeoutOptional = instance.getTimeout();
checkConfig.getString("path")); Registration.RegCheck check = Registration.RegCheck.http(http, checkConfig.getDuration("interval", TimeUnit.SECONDS), checkConfig.getDuration("timeout", TimeUnit.SECONDS));
.address(getMicroservice().getHostname()) .port(getMicroservice().getInstanceSettings().getGrpcPort()) .check(Registration.RegCheck.ttl(30L)).tags(tags).meta(Collections.singletonMap("version", getMicroservice().getVersion().getVersionIdentifier())) .build();
@Override public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try{ /** * Deal with health check script */ String rawScript = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT); if (rawScript != null && !rawScript.trim().isEmpty()) { Long healthCheckScriptIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT_INTERVAL_SECONDS)); String healthCheckScript = rawScript.replaceAll(HEALTH_SCRIPT_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(HEALTH_SCRIPT_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); regCheck = Registration.RegCheck.args(Arrays.asList(healthCheckScript.split(" ")), healthCheckScriptIntervalSeconds); } }catch(Exception e){ logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e); } return regCheck; }
@Override public RegCheck buildRegistrationCheck( Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try{ /** * Deal with health check http */ String healthCheckHttp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP); if (healthCheckHttp != null && !healthCheckHttp.trim().isEmpty()) { healthCheckHttp = healthCheckHttp.replaceAll(HTTP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(HTTP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); Long healthCheckHttpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP_INTERVAL_SECONDS)); regCheck = Registration.RegCheck.http(healthCheckHttp, healthCheckHttpIntervalSeconds); } }catch(Exception e){ logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e); } return regCheck; }
@Override public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try { /** * Deal with health check tcp */ String healthCheckTcp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP); if (healthCheckTcp != null && !healthCheckTcp.trim().isEmpty()) { healthCheckTcp = healthCheckTcp.replaceAll(TCP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(TCP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); Long healthCheckTcpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP_INTERVAL_SECONDS)); regCheck = Registration.RegCheck.tcp(healthCheckTcp, healthCheckTcpIntervalSeconds); } } catch(Exception e) { logger.severe("Unexpected error occured trying to build TCP health check : " + e.getMessage(), e); } return regCheck; }
@Override public RegCheck buildRegistrationCheck( Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try{ /** * Deal with health check http */ String healthCheckHttp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP); if (healthCheckHttp != null && !healthCheckHttp.trim().isEmpty()) { healthCheckHttp = healthCheckHttp.replaceAll(HTTP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(HTTP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); Long healthCheckHttpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP_INTERVAL_SECONDS)); regCheck = Registration.RegCheck.http(healthCheckHttp, healthCheckHttpIntervalSeconds); } }catch(Exception e){ logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e); } return regCheck; }
@Override public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try { /** * Deal with health check tcp */ String healthCheckTcp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP); if (healthCheckTcp != null && !healthCheckTcp.trim().isEmpty()) { healthCheckTcp = healthCheckTcp.replaceAll(TCP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(TCP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); Long healthCheckTcpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP_INTERVAL_SECONDS)); regCheck = Registration.RegCheck.tcp(healthCheckTcp, healthCheckTcpIntervalSeconds); } } catch(Exception e) { logger.severe("Unexpected error occured trying to build TCP health check : " + e.getMessage(), e); } return regCheck; }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, String args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(Collections.singletonList(args), interval); register(port, check, name, id, tags, meta); }
public void advertise(Registration registration) { if (this.advertisements.contains(registration)) { return; } AgentClient client = this.agentClientInjector.getValue(); com.orbitz.consul.model.agent.Registration consulReg = ImmutableRegistration.builder() .address(registration.getAddress()) .port(registration.getPort()) .id(serviceId(registration)) .name(registration.getName()) .addTags(registration.getTags().toArray(new String[]{})) .check(com.orbitz.consul.model.agent.Registration.RegCheck.ttl(3L)) .build(); client.register(consulReg); this.advertisements.add(registration); }
/** * Registers the client as a service with Consul with a TCP based check * * @param port The public facing port of the service to register with Consul. * @param tcp Health check TCP host and port. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, HostAndPort tcp, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.tcp(tcp.toString(), interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, List<String> args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(args, interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with an http based check * * @param port The public facing port of the service to register with Consul. * @param http Health check URL. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, URL http, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.http(http.toExternalForm(), interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with a ttl check. * * @param port The public facing port of the service to register with Consul. * @param ttl Time to live in seconds for the Consul dead man's switch. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, long ttl, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.ttl(ttl); register(port, check, name, id, tags, meta); }
public void register(String name, int port) { log.info("Will register " + name + " with port " + port); AgentClient agentClient = client.agentClient(); Registration service = ImmutableRegistration.builder().id(name).name(name).port(port) .check(Registration.RegCheck.http("http://localhost:" + port + Constants.HEALTH_CONTEXT, 60, 5)).build(); agentClient.register(service); }
@Value.Check protected void validate() { checkState(getHttp().isPresent() || getTtl().isPresent() || getArgs().isPresent() || getTcp().isPresent() || getGrpc().isPresent(), "Check must specify either http, tcp, ttl, grpc or args"); if (getHttp().isPresent() || getArgs().isPresent() || getTcp().isPresent() || getGrpc().isPresent()) { checkState(getInterval().isPresent(), "Interval must be set if check type is http, tcp, grpc or args"); } }