Search in sources :

Example 1 with EtcdConfiguration

use of org.apache.camel.component.etcd.EtcdConfiguration in project camel by apache.

the class EtcdServiceDiscovery method getServices.

protected List<ServiceDefinition> getServices(Predicate<EtcdServiceDefinition> filter) {
    List<ServiceDefinition> servers = Collections.emptyList();
    if (isRunAllowed()) {
        try {
            final EtcdConfiguration conf = getConfiguration();
            final EtcdKeyGetRequest request = getClient().get(conf.getServicePath()).recursive();
            if (conf.hasTimeout()) {
                request.timeout(conf.getTimeout(), TimeUnit.SECONDS);
            }
            final EtcdKeysResponse response = request.send().get();
            if (Objects.nonNull(response.node) && !response.node.nodes.isEmpty()) {
                servers = response.node.nodes.stream().map(node -> node.value).filter(ObjectHelper::isNotEmpty).map(this::nodeFromString).filter(Objects::nonNull).filter(filter).sorted(EtcdServiceDefinition.COMPARATOR).collect(Collectors.toList());
            }
        } catch (Exception e) {
            throw new RuntimeCamelException(e);
        }
    }
    return servers;
}
Also used : EtcdKeysResponse(mousio.etcd4j.responses.EtcdKeysResponse) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Logger(org.slf4j.Logger) EtcdClient(mousio.etcd4j.EtcdClient) Predicate(java.util.function.Predicate) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) EtcdConfiguration(org.apache.camel.component.etcd.EtcdConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) DefaultServiceDiscovery(org.apache.camel.impl.cloud.DefaultServiceDiscovery) ObjectHelper(org.apache.camel.util.ObjectHelper) Collections(java.util.Collections) EtcdHelper(org.apache.camel.component.etcd.EtcdHelper) ObjectHelper(org.apache.camel.util.ObjectHelper) EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest) EtcdConfiguration(org.apache.camel.component.etcd.EtcdConfiguration) Objects(java.util.Objects) EtcdKeysResponse(mousio.etcd4j.responses.EtcdKeysResponse) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 EtcdClient (mousio.etcd4j.EtcdClient)1 EtcdKeyGetRequest (mousio.etcd4j.requests.EtcdKeyGetRequest)1 EtcdKeysResponse (mousio.etcd4j.responses.EtcdKeysResponse)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 ServiceDefinition (org.apache.camel.cloud.ServiceDefinition)1 EtcdConfiguration (org.apache.camel.component.etcd.EtcdConfiguration)1 EtcdHelper (org.apache.camel.component.etcd.EtcdHelper)1 DefaultServiceDiscovery (org.apache.camel.impl.cloud.DefaultServiceDiscovery)1 ObjectHelper (org.apache.camel.util.ObjectHelper)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1