Search in sources :

Example 1 with EtcdKeyGetRequest

use of mousio.etcd4j.requests.EtcdKeyGetRequest in project camel by apache.

the class EtcdKeysProducer method processGet.

private void processGet(EtcdClient client, String path, Exchange exchange) throws Exception {
    EtcdKeyGetRequest request = client.get(path);
    setRequestTimeout(request, exchange);
    setRequestRecursive(request, exchange);
    try {
        exchange.getIn().setHeader(EtcdConstants.ETCD_NAMESPACE, getNamespace());
        exchange.getIn().setBody(request.send().get());
    } catch (TimeoutException e) {
        throw new ExchangeTimedOutException(exchange, configuration.getTimeout());
    }
}
Also used : EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with EtcdKeyGetRequest

use of mousio.etcd4j.requests.EtcdKeyGetRequest 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)

Example 3 with EtcdKeyGetRequest

use of mousio.etcd4j.requests.EtcdKeyGetRequest in project camel by apache.

the class EtcdWatchConsumer method watch.

private void watch() throws Exception {
    if (!isRunAllowed()) {
        return;
    }
    EtcdKeyGetRequest request = getClient().get(getPath()).waitForChange(index.get());
    if (configuration.isRecursive()) {
        request.recursive();
    }
    if (configuration.getTimeout() != null) {
        request.timeout(configuration.getTimeout(), TimeUnit.MILLISECONDS);
    }
    request.send().addListener(this);
}
Also used : EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest)

Example 4 with EtcdKeyGetRequest

use of mousio.etcd4j.requests.EtcdKeyGetRequest in project vertx-zero by silentbalanceyh.

the class EtcdData method readNode.

private EtcdKeysResponse.EtcdNode readNode(final String path, final Function<String, EtcdKeyGetRequest> executor) {
    return Fn.getJvm(null, () -> {
        final EtcdKeyGetRequest request = executor.apply(path);
        /**
         * Timeout *
         */
        if (-1 != this.timeout) {
            request.timeout(this.timeout, TimeUnit.SECONDS);
        }
        final EtcdResponsePromise<EtcdKeysResponse> promise = request.send();
        final EtcdKeysResponse response = promise.get();
        return response.getNode();
    }, path);
}
Also used : EtcdKeyGetRequest(mousio.etcd4j.requests.EtcdKeyGetRequest) EtcdKeysResponse(mousio.etcd4j.responses.EtcdKeysResponse)

Aggregations

EtcdKeyGetRequest (mousio.etcd4j.requests.EtcdKeyGetRequest)4 EtcdKeysResponse (mousio.etcd4j.responses.EtcdKeysResponse)2 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 TimeoutException (java.util.concurrent.TimeoutException)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 EtcdClient (mousio.etcd4j.EtcdClient)1 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)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