use of com.ecwid.consul.v1.agent.model.NewService in project spring-cloud-consul by spring-cloud.
the class ConsulServiceRegistryTests method contextLoads.
@Test
public void contextLoads() {
assertThat(autoRegistration).as("autoRegistration created erroneously").isNull();
String serviceId = "myNonAutoRegisteredService";
NewService service = new NewService();
service.setAddress("localhost");
service.setId("myNonAutoRegisteredService-A1");
service.setName(serviceId);
service.setPort(port);
service.setTags(Collections.singletonList("mytag"));
ConsulRegistration registration = new ConsulRegistration(service, this.properties);
Throwable t = null;
try {
serviceRegistry.register(registration);
assertHasInstance(serviceId);
assertStatus(registration, "UP");
// only works if query-passing = true
serviceRegistry.setStatus(registration, "OUT_OF_SERVICE");
assertEmptyInstances(serviceId);
assertStatus(registration, "OUT_OF_SERVICE");
serviceRegistry.setStatus(registration, "UP");
assertHasInstance(serviceId);
} catch (RuntimeException e) {
throw e;
} finally {
serviceRegistry.deregister(registration);
if (t == null) {
// just deregister, test already failed
assertEmptyInstances(serviceId);
}
}
}
use of com.ecwid.consul.v1.agent.model.NewService 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.agent.model.NewService 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;
}
use of com.ecwid.consul.v1.agent.model.NewService in project spring-cloud-consul by spring-cloud.
the class ConsulAutoRegistration method managementRegistration.
public static ConsulAutoRegistration managementRegistration(AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, HeartbeatProperties heartbeatProperties) {
NewService management = new NewService();
management.setId(getManagementServiceId(properties, context));
management.setAddress(properties.getHostname());
management.setName(getManagementServiceName(properties, context.getEnvironment()));
management.setPort(getManagementPort(properties, context));
management.setTags(properties.getManagementTags());
if (properties.isRegisterHealthCheck()) {
management.setCheck(createCheck(getManagementPort(properties, context), heartbeatProperties, properties));
}
return new ConsulAutoRegistration(management, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
}
use of com.ecwid.consul.v1.agent.model.NewService in project dubbo by alibaba.
the class ConsulRegistry method buildService.
private NewService buildService(URL url) {
NewService service = new NewService();
service.setAddress(url.getHost());
service.setPort(url.getPort());
service.setId(buildId(url));
service.setName(url.getServiceInterface());
service.setCheck(buildCheck(url));
service.setTags(buildTags(url));
service.setMeta(Collections.singletonMap(URL_META_KEY, url.toFullString()));
return service;
}
Aggregations