Search in sources :

Example 1 with NewService

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);
        }
    }
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with NewService

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
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with NewService

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;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 4 with NewService

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);
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 5 with NewService

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;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Aggregations

NewService (com.ecwid.consul.v1.agent.model.NewService)14 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