use of com.ecwid.consul.v1.health.model.Check in project motan by weibocom.
the class ConsulRegistryService method getNodes.
@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
List<JSONObject> results = new ArrayList<JSONObject>();
List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
for (Check check : checks) {
String serviceId = check.getServiceId();
String[] strings = serviceId.split("-");
if (strings[1].equals(service)) {
Check.CheckStatus status = check.getStatus();
JSONObject node = new JSONObject();
if (nodeType.equals(status.toString())) {
node.put("host", strings[0]);
node.put("info", null);
results.add(node);
}
}
}
return results;
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ConsulAutoServiceRegistrationCustomizedPropsTests method contextLoads.
@Test
public void contextLoads() {
Response<Map<String, Service>> response = consul.getAgentServices();
Map<String, Service> services = response.getValue();
Service service = services.get("myTestService1-B");
assertThat("service was null", service, is(notNullValue()));
assertThat("service port is discovery port", service.getPort(), equalTo(4452));
assertThat("service id was wrong", "myTestService1-B", equalTo(service.getId()));
assertThat("service name was wrong", "myTestService-B", equalTo(service.getService()));
assertThat("property hostname was wrong", "myhost", equalTo(this.properties.getHostname()));
assertThat("property ipAddress was wrong", "10.0.0.1", equalTo(this.properties.getIpAddress()));
assertThat("service address was wrong", "myhost", equalTo(service.getAddress()));
Response<List<Check>> checkResponse = consul.getHealthChecksForService("myTestService-B", QueryParams.DEFAULT);
List<Check> checks = checkResponse.getValue();
assertThat("checks was wrong size", checks, hasSize(0));
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ConsulAutoRegistrationHealthCheckTlsSkipVerifyTests method contextLoads.
@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
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class TtlSchedulerRemoveTests method should_not_send_check_if_service_removed.
@Test
public void should_not_send_check_if_service_removed() throws InterruptedException {
// wait for Ttlscheduler to send a check to consul.
Thread.sleep(1000);
Check serviceCheck = getCheckForService("ttlSchedulerRemove");
assertThat("Service check is in wrong state", serviceCheck.getStatus(), equalTo(PASSING));
// Remove service from TtlScheduler and wait for TTL to expired.
ttlScheduler.remove("ttlSchedulerRemove-id");
Thread.sleep(2100);
serviceCheck = getCheckForService("ttlSchedulerRemove");
assertThat("Service check is in wrong state", serviceCheck.getStatus(), equalTo(CRITICAL));
}
use of com.ecwid.consul.v1.health.model.Check in project spring-cloud-consul by spring-cloud.
the class ConsulAutoRegistration method registration.
public static ConsulAutoRegistration registration(AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List<ConsulRegistrationCustomizer> registrationCustomizers, HeartbeatProperties heartbeatProperties) {
NewService service = new NewService();
String appName = getAppName(properties, context.getEnvironment());
service.setId(getInstanceId(properties, context));
if (!properties.isPreferAgentAddress()) {
service.setAddress(properties.getHostname());
}
service.setName(normalizeForDns(appName));
service.setTags(createTags(properties));
if (properties.getPort() != null) {
service.setPort(properties.getPort());
// we know the port and can set the check
setCheck(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
}
ConsulAutoRegistration registration = new ConsulAutoRegistration(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
customize(registrationCustomizers, registration);
return registration;
}
Aggregations