Search in sources :

Example 1 with ConsulClient

use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.

the class ConsulUtils method createClient.

public static ConsulClient createClient(String apiAddress, int apiPort, TlsConfiguration tlsConfiguration) throws Exception {
    HttpClient httpClient = createHttpClient(tlsConfiguration.getClientCert(), tlsConfiguration.getClientKey(), tlsConfiguration.getServerCert());
    ConsulRawClient rawClient = new ConsulRawClient("https://" + apiAddress + ':' + apiPort, httpClient);
    Field agentAddress = ReflectionUtils.findField(ConsulRawClient.class, "agentAddress");
    ReflectionUtils.makeAccessible(agentAddress);
    ReflectionUtils.setField(agentAddress, rawClient, "https://" + apiAddress + ':' + apiPort + "/consul");
    return new ConsulClient(rawClient);
}
Also used : Field(java.lang.reflect.Field) ConsulClient(com.ecwid.consul.v1.ConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) HttpClient(org.apache.http.client.HttpClient)

Example 2 with ConsulClient

use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.

the class ConsulKeyValueService method deleteAlert.

public void deleteAlert(Cluster cluster, PrometheusAlert alert) {
    Ambari ambari = cluster.getAmbari();
    try {
        TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
        ConsulClient consulClient = ConsulUtils.createClient(ambari.getHost(), cluster.getPort(), tlsConfig);
        String alertKey = getKeyNameForAlert(alert);
        consulClient.deleteKVValue(alertKey);
        LOGGER.info("Alert has been removed from Consul KV store with name: '{}' on host: '{}'.", alertKey, ambari.getHost());
    } catch (Exception e) {
        LOGGER.warn("Alert could not be deleted from Consul KV store:", e);
    }
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 3 with ConsulClient

use of com.ecwid.consul.v1.ConsulClient in project spring-cloud-consul by spring-cloud.

the class ConsulPropertySourceLocatorAppNameCustomizedTests method setup.

@Before
public void setup() {
    this.properties = new ConsulProperties();
    this.client = new ConsulClient(properties.getHost(), properties.getPort());
    this.client.deleteKVValues(PREFIX);
    this.client.setKVValue(KEY1, VALUE1);
    this.client.setKVValue(KEY2, VALUE2);
    this.context = new SpringApplicationBuilder(Config.class).web(false).run("--spring.application.name=testConsulPropertySourceLocatorAppNameCustomized", "--spring.cloud.consul.config.name=" + CONFIG_NAME, "--spring.cloud.consul.config.prefix=" + ROOT);
    this.client = context.getBean(ConsulClient.class);
    this.properties = context.getBean(ConsulProperties.class);
    this.environment = context.getEnvironment();
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConsulProperties(org.springframework.cloud.consul.ConsulProperties) Before(org.junit.Before)

Example 4 with ConsulClient

use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.

the class ConsulServiceCheckerTask method checkStatus.

@Override
public boolean checkStatus(ConsulContext consulContext) {
    String serviceName = consulContext.getTargets().get(0);
    ConsulClient client = consulContext.getConsulClient();
    LOGGER.info("Checking consul service registration of '{}'", serviceName);
    List<CatalogService> service = ConsulUtils.getService(Collections.singletonList(client), serviceName);
    if (service.isEmpty()) {
        LOGGER.info("Consul service '{}' is not registered yet", serviceName);
        return false;
    } else {
        LOGGER.info("Consul service '{}' found on '{}'", serviceName, service.get(0).getNode());
        return true;
    }
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) CatalogService(com.ecwid.consul.v1.catalog.model.CatalogService)

Example 5 with ConsulClient

use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.

the class ConsulHostServiceTypeCheckerTaskTest method checkStatusForConnectionError.

@Test
@SuppressWarnings("unchecked")
public void checkStatusForConnectionError() {
    ConsulRawClient raw1 = mock(ConsulRawClient.class);
    ConsulClient client1 = new ConsulClient(raw1);
    when(raw1.makeGetRequest(SERVICE_ENDPOINT + AMBARI_SERVICE, null, QueryParams.DEFAULT)).thenThrow(TransportException.class);
    boolean result = task.checkStatus(new ConsulContext(stack, client1, Collections.singletonList(AMBARI_SERVICE)));
    assertFalse(result);
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) Test(org.junit.Test)

Aggregations

ConsulClient (com.ecwid.consul.v1.ConsulClient)17 Before (org.junit.Before)5 ConsulProperties (org.springframework.cloud.consul.ConsulProperties)5 Test (org.junit.Test)4 ConsulRawClient (com.ecwid.consul.v1.ConsulRawClient)3 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)3 QueryParams (com.ecwid.consul.v1.QueryParams)2 Response (com.ecwid.consul.v1.Response)2 GetValue (com.ecwid.consul.v1.kv.model.GetValue)2 Ambari (com.sequenceiq.periscope.domain.Ambari)2 TlsConfiguration (com.sequenceiq.periscope.model.TlsConfiguration)2 List (java.util.List)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RawResponse (com.ecwid.consul.transport.RawResponse)1 NewService (com.ecwid.consul.v1.agent.model.NewService)1 CatalogService (com.ecwid.consul.v1.catalog.model.CatalogService)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 PluginFailureException (com.sequenceiq.cloudbreak.service.cluster.PluginFailureException)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 Field (java.lang.reflect.Field)1