use of com.ecwid.consul.v1.ConsulClient in project spring-cloud-consul by spring-cloud.
the class ConsulPropertySourceLocatorTests 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=" + APP_NAME, "--spring.cloud.consul.config.prefix=" + ROOT, "spring.cloud.consul.config.watch.delay=10");
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 spring-cloud-consul by spring-cloud.
the class ConsulPropertySourceTests method setup.
@Before
public void setup() {
properties = new ConsulProperties();
prefix = "consulPropertySourceTests" + new Random().nextInt(Integer.MAX_VALUE);
client = new ConsulClient(properties.getHost(), properties.getPort());
}
use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.
the class ConsulHostServiceTypeCheckerTaskTest method checkStatusForOneNodeResponse.
@Test
@SuppressWarnings("unchecked")
public void checkStatusForOneNodeResponse() {
ConsulRawClient raw1 = mock(ConsulRawClient.class);
RawResponse rawResponse = new RawResponse(200, null, SERVICE_RESPONSE, null, null, null);
ConsulClient client1 = new ConsulClient(raw1);
when(raw1.makeGetRequest(SERVICE_ENDPOINT + AMBARI_SERVICE, null, QueryParams.DEFAULT)).thenReturn(rawResponse);
boolean result = task.checkStatus(new ConsulContext(stack, client1, Collections.singletonList(AMBARI_SERVICE)));
assertTrue(result);
}
use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.
the class ConsulKeyValueService method addAlert.
public PrometheusAlert addAlert(Cluster cluster, PrometheusAlert alert) {
Ambari ambari = cluster.getAmbari();
try {
if (RUNNING.equals(cluster.getState())) {
TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
ConsulClient consulClient = ConsulUtils.createClient(ambari.getHost(), cluster.getPort(), tlsConfig);
String alertKey = getKeyNameForAlert(alert);
consulClient.setKVValue(alertKey, alert.getAlertRule());
LOGGER.info("Alert has been added to Consul KV store with name: '{}' on host: '{}'.", alertKey, ambari.getHost());
}
} catch (Exception e) {
LOGGER.warn("Alert could not be added to Consul KV store:", e);
}
return alert;
}
use of com.ecwid.consul.v1.ConsulClient in project cloudbreak by hortonworks.
the class ConsulKVCheckerTask method checkStatus.
@Override
public boolean checkStatus(ConsulKVCheckerContext context) {
List<String> keys = context.getKeys();
String expectedValue = context.getExpectedValue();
String failValue = context.getFailValue();
ConsulClient client = context.getConsulClient();
LOGGER.info("Checking if keys in Consul's key-value store have the expected value '{}'", expectedValue);
Set<String> failedKeys = new HashSet<>();
int matchingKeys = 0;
int notFoundKeys = 0;
for (String key : keys) {
String value = ConsulUtils.getKVValue(Collections.singletonList(client), key, null);
if (value != null) {
if (value.equals(failValue)) {
failedKeys.add(key);
} else if (value.equals(expectedValue)) {
matchingKeys++;
}
} else {
notFoundKeys++;
}
}
LOGGER.info("Keys: [Total: {}, {}: {}, Not {}: {}, Not found: {}, {}: {}]", keys.size(), expectedValue, matchingKeys, expectedValue, keys.size() - matchingKeys - notFoundKeys - failedKeys.size(), notFoundKeys, failValue, failedKeys.size());
if (!failedKeys.isEmpty()) {
throw new PluginFailureException(String.format("Found failure signal at keys: %s", failedKeys));
}
return matchingKeys == keys.size();
}
Aggregations