Search in sources :

Example 11 with NewService

use of com.ecwid.consul.v1.agent.model.NewService in project spring-cloud-consul by spring-cloud.

the class ConsulAutoRegistration method lifecycleRegistration.

// TODO: do I need this here, or should I just copy what I need back into lifecycle?
@Deprecated
public static ConsulAutoRegistration lifecycleRegistration(Integer port, String instanceId, AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List<ConsulRegistrationCustomizer> registrationCustomizers, HeartbeatProperties heartbeatProperties) {
    NewService service = new NewService();
    String appName = getAppName(properties, context.getEnvironment());
    service.setId(instanceId);
    if (!properties.isPreferAgentAddress()) {
        service.setAddress(properties.getHostname());
    }
    service.setName(normalizeForDns(appName));
    service.setTags(createTags(properties));
    // If an alternate external port is specified, register using it instead
    if (properties.getPort() != null) {
        service.setPort(properties.getPort());
    } else {
        service.setPort(port);
    }
    Assert.notNull(service.getPort(), "service.port may not be null");
    setCheck(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
    ConsulAutoRegistration registration = new ConsulAutoRegistration(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
    customize(registrationCustomizers, registration);
    return registration;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 12 with NewService

use of com.ecwid.consul.v1.agent.model.NewService in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationCustomizedDiscoveryPortTests method contextLoads.

@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", properties.getScheme(), properties.getHostname(), properties.getPort(), properties.getHealthCheckPath());
    assertThat(check.getHttp()).as("http check was wrong").isEqualTo(httpCheck);
// unable to call consul api to get health check details
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

NewService (com.ecwid.consul.v1.agent.model.NewService)11 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ConsulClient (com.ecwid.consul.v1.ConsulClient)1 QueryParams (com.ecwid.consul.v1.QueryParams)1 HealthService (com.ecwid.consul.v1.health.model.HealthService)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InetUtils (org.springframework.cloud.commons.util.InetUtils)1 InetUtilsProperties (org.springframework.cloud.commons.util.InetUtilsProperties)1