Search in sources :

Example 1 with PluginFailureException

use of com.sequenceiq.cloudbreak.service.cluster.PluginFailureException 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();
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) PluginFailureException(com.sequenceiq.cloudbreak.service.cluster.PluginFailureException) HashSet(java.util.HashSet)

Aggregations

ConsulClient (com.ecwid.consul.v1.ConsulClient)1 PluginFailureException (com.sequenceiq.cloudbreak.service.cluster.PluginFailureException)1 HashSet (java.util.HashSet)1