Java Code Examples for com.ecwid.consul.v1.agent.model.NewService#Check

The following examples show how to use com.ecwid.consul.v1.agent.model.NewService#Check . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsulRegistry.java    From dubbo3 with Apache License 2.0 7 votes vote down vote up
@Override
protected void doRegister(URL url) {
    NewService dubboService = new NewService();
    dubboService.setTags(Arrays.asList("dubbo"));
    dubboService.setAddress(url.toFullString());
    dubboService.setPort(url.getPort());
    dubboService.setId(convertConsulSerivceId(url));
    dubboService.setName(url.getServiceInterface());
    //set health checker
    String dubboHTTPCheckURL = System.getProperty("DUBBO_HTTP_CHECK_URL");
    if (dubboHTTPCheckURL == null) {
        dubboHTTPCheckURL = System.getenv("DUBBO_HTTP_CHECK_URL");
    }
    if (dubboHTTPCheckURL != null) {
        NewService.Check check = new NewService.Check();
        check.setHttp(dubboHTTPCheckURL);
        check.setInterval("15s");
        check.setTimeout("3s");
        dubboService.setCheck(check);
    }
    consulClient.agentServiceRegister(dubboService);
}
 
Example 2
Source File: ConsulAutoServiceRegistrationCustomizedDiscoveryPortTests.java    From spring-cloud-consul with Apache License 2.0 7 votes vote down vote up
@Test
public void contextLoads() {
	NewService service = this.registration.getService();
	assertThat(service).as("service was null").isNotNull();
	assertThat(service.getPort()).as("service port is 0").isGreaterThan(0);

	NewService.Check check = service.getCheck();
	assertThat(check).as("check was null").isNotNull();

	String httpCheck = String.format("%s://%s:%s%s", this.properties.getScheme(),
			this.properties.getHostname(), this.properties.getPort(),
			this.properties.getHealthCheckPath());
	assertThat(check.getHttp()).as("http check was wrong").isEqualTo(httpCheck);

	// unable to call consul api to get health check details
}
 
Example 3
Source File: ConsulNamingService.java    From brpc-java with Apache License 2.0 6 votes vote down vote up
private NewService getConsulNewService(RegisterInfo registerInfo) {
    NewService newService = new NewService();
    newService.setName(registerInfo.getServiceId());
    newService.setId(generateInstanceId(registerInfo));
    newService.setAddress(registerInfo.getHost());
    newService.setPort(registerInfo.getPort());
    newService.setTags(Arrays.asList(ConsulConstants.CONSUL_SERVICE_TAG));

    NewService.Check check = new NewService.Check();
    check.setTtl(this.consulInterval + "s");
    check.setDeregisterCriticalServiceAfter("3m");
    newService.setCheck(check);

    return newService;
}
 
Example 4
Source File: ConsulService.java    From saluki with Apache License 2.0 6 votes vote down vote up
public NewService getNewService() {
    NewService consulService = new NewService();
    consulService.setName(this.name);
    consulService.setId(this.id);
    consulService.setAddress(this.address);
    consulService.setPort(this.port);
    consulService.setTags(unmodifiableList(new ArrayList<>(this.tags)));
    NewService.Check check = new NewService.Check();
    check.setTtl(this.interval + "s");
    check.setDeregisterCriticalServiceAfter("3m");
    consulService.setCheck(check);
    return consulService;
}
 
Example 5
Source File: ConsulRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private NewService createServiceDef(URL url, long ttl) {
	NewService newService = new NewService();
	newService.setId(toCategoryPath(url));
	newService.setName(url.getServiceInterface());
	newService.setAddress(URL.encode(url.toFullString()));
	newService.setPort(url.getPort());
	String version = makeVersionTag(url);
	newService.setTags(Collections.singletonList(version));
	int ttlInSeconds = (int) ttl / 1000;
	NewService.Check check = new NewService.Check();
	check.setTtl(ttlInSeconds + "s");
	newService.setCheck(check);
	return newService;
}
 
Example 6
Source File: ConsulAutoRegistration.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
public static NewService.Check createCheck(Integer port,
		HeartbeatProperties ttlConfig, ConsulDiscoveryProperties properties) {
	NewService.Check check = new NewService.Check();
	if (StringUtils.hasText(properties.getHealthCheckCriticalTimeout())) {
		check.setDeregisterCriticalServiceAfter(
				properties.getHealthCheckCriticalTimeout());
	}
	if (ttlConfig.isEnabled()) {
		// FIXME 3.0.0
		// https://github.com/spring-cloud/spring-cloud-consul/issues/614
		check.setTtl(ttlConfig.getTtl().getSeconds() + "s");
		return check;
	}

	Assert.notNull(port, "createCheck port must not be null");
	Assert.isTrue(port > 0, "createCheck port must be greater than 0");

	if (properties.getHealthCheckUrl() != null) {
		check.setHttp(properties.getHealthCheckUrl());
	}
	else {
		check.setHttp(String.format("%s://%s:%s%s", properties.getScheme(),
				properties.getHostname(), port, properties.getHealthCheckPath()));
	}
	check.setHeader(properties.getHealthCheckHeaders());
	check.setInterval(properties.getHealthCheckInterval());
	check.setTimeout(properties.getHealthCheckTimeout());
	check.setTlsSkipVerify(properties.getHealthCheckTlsSkipVerify());
	return check;
}
 
Example 7
Source File: ConsulAutoRegistrationIncludeHostnameInInstanceIdTests.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Test
public void contextLoads() {
	NewService service = this.registration.getService();
	assertThat(service).as("service was null").isNotNull();

	NewService.Check check = service.getCheck();
	assertThat(service.getId()).as("id is null").isNotNull();
	assertThat(service.getId()).as("id no include hostname").contains("testhostname");
	assertThat(service.getId()).as("service id was wrong")
			.isEqualTo(this.registration.getInstanceId());

}
 
Example 8
Source File: ConsulAutoRegistrationHealthCheckHeadersTests.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Test
public void contextLoads() {
	NewService service = this.registration.getService();
	assertThat(service).as("service was null").isNotNull();

	NewService.Check check = service.getCheck();
	assertThat(check).as("check was null").isNotNull();
	assertThat(check.getHeader()).as("header is null").isNotNull();
	assertThat(check.getHeader()).as("header is empty").isNotEmpty();
	assertThat(check.getHeader().get("X-Config-Token").get(0))
			.as("expected header value not found").isEqualTo("ACCESSTOKEN");

	// unable to call consul api to get health check details
}
 
Example 9
Source File: ConsulAutoRegistrationHealthCheckTlsSkipVerifyTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void contextLoads() {
	NewService service = this.registration.getService();
	assertThat(service).as("service was null").isNotNull();

	NewService.Check check = service.getCheck();
	assertThat(check).as("check was null").isNotNull();
	assertThat(check.getTlsSkipVerify()).as("tls_skip_verify was wrong")
			.isEqualTo(Boolean.TRUE);

	// unable to call consul api to get health check details
}
 
Example 10
Source File: ConsulServiceRegistryCheckTtlTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
private ConsulRegistration createHttpRegistration() {
	NewService service = this.registration.getService();
	NewService.Check httpCheck = new NewService.Check();
	httpCheck.setHttp(
			String.format("%s://%s:%s%s", this.discoveryProperties.getScheme(),
					this.discoveryProperties.getHostname(), this.randomServerPort,
					this.discoveryProperties.getHealthCheckPath()));
	httpCheck.setInterval(this.discoveryProperties.getHealthCheckInterval());
	NewService httpService = new NewService();
	httpService.setId(service.getId() + "-http");
	httpService.setName(service.getName() + "-http");
	httpService.setCheck(httpCheck);
	return new ConsulRegistration(httpService, this.discoveryProperties);
}
 
Example 11
Source File: ConsulAutoServiceRegistrationManagementCustomizerTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void contextLoads() {
	ConsulAutoRegistration managementRegistration = this.autoRegistration
			.managementRegistration();
	List<NewService.Check> checks = managementRegistration.getService().getChecks();
	List<String> ttls = checks.stream().map(NewService.Check::getTtl)
			.collect(Collectors.toList());
	assertThat(ttls.contains("39s"))
			.as("Management registration not customized with 'foo' customizer")
			.isTrue();
	assertThat(ttls.contains("36s"))
			.as("Management registration not customized with 'bar' customizer")
			.isTrue();
}
 
Example 12
Source File: ConsulAutoServiceRegistrationManagementCustomizerTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
private void addCheck(ConsulRegistration managementRegistration, String ttl) {
	NewService managementService = managementRegistration.getService();
	NewService.Check check = new NewService.Check();
	check.setTtl(ttl);
	List<NewService.Check> checks = managementService.getChecks() != null
			? new ArrayList<>(managementService.getChecks()) : new ArrayList<>();
	checks.add(check);
	managementRegistration.getService().setChecks(checks);
}