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);
}
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);
}
}
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();
}
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;
}
}
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);
}
Aggregations