/** * Sets or replaces all elements for {@link Check#getServiceTags() serviceTags} list. * @param elements An iterable of serviceTags elements * @return {@code this} builder for use in a chained invocation */ public final Builder serviceTags(Iterable<String> elements) { serviceTagsBuilder = ImmutableList.builder(); return addAllServiceTags(elements); }
/** * Registers a script Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param args Specifies command argument to run to update the status of the check. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, String args, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .args(Collections.singletonList(args)) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Builds a new {@link ImmutableCheck ImmutableCheck}. * @return An immutable instance of Check * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCheck build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableCheck.validate(new ImmutableCheck( id, name, notes, output, args, interval, ttl, http, tcp, grpc, grpcUseTls, serviceId, serviceTagsBuilder.build(), deregisterCriticalServiceAfter)); }
ImmutableCheck.Builder builder = ImmutableCheck.builder(); if (json.id != null) { builder.id(json.id); builder.name(json.name); builder.notes(json.notes); builder.output(json.output); builder.args(json.args); builder.interval(json.interval); builder.ttl(json.ttl); builder.http(json.http); builder.tcp(json.tcp); builder.grpc(json.grpc); builder.grpcUseTls(json.grpcUseTls); builder.serviceId(json.serviceId); builder.addAllServiceTags(json.serviceTags); builder.deregisterCriticalServiceAfter(json.deregisterCriticalServiceAfter);
id(instance.getId()); name(instance.getName()); Optional<String> notesOptional = instance.getNotes(); if (notesOptional.isPresent()) { notes(notesOptional); output(outputOptional); args(argsOptional); interval(intervalOptional); ttl(ttlOptional); http(httpOptional); tcp(tcpOptional); grpc(grpcOptional); grpcUseTls(grpcUseTlsOptional); serviceId(serviceIdOptional); addAllServiceTags(instance.getServiceTags()); Optional<String> deregisterCriticalServiceAfterOptional = instance.getDeregisterCriticalServiceAfter(); if (deregisterCriticalServiceAfterOptional.isPresent()) { deregisterCriticalServiceAfter(deregisterCriticalServiceAfterOptional);
/** * Registers a HTTP Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param http Health check URL. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, URL http, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .http(http.toExternalForm()) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Registers a script Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param args Health script for Consul to use. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, List<String> args, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .args(args) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Registers a TCP Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param tcp Health check TCP host and port. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, HostAndPort tcp, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .tcp(tcp.toString()) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Registers a Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param ttl Time to live for the Consul dead man's switch. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, long ttl, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .ttl(String.format("%ss", ttl)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Creates an immutable copy of a {@link Check} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Check instance */ public static ImmutableCheck copyOf(Check instance) { if (instance instanceof ImmutableCheck) { return (ImmutableCheck) instance; } return ImmutableCheck.builder() .from(instance) .build(); }
/** * Creates a builder for {@link ImmutableCheck ImmutableCheck}. * @return A new ImmutableCheck builder */ public static ImmutableCheck.Builder builder() { return new ImmutableCheck.Builder(); }