Search in sources :

Example 1 with DefaultServiceDefinition

use of org.apache.camel.impl.cloud.DefaultServiceDefinition in project camel by apache.

the class ConsulServiceDiscovery method newService.

private ServiceDefinition newService(String serviceName, CatalogService service, List<ServiceHealth> serviceHealthList) {
    Map<String, String> meta = new HashMap<>();
    ObjectHelper.ifNotEmpty(service.getServiceId(), val -> meta.put("service_id", val));
    ObjectHelper.ifNotEmpty(service.getNode(), val -> meta.put("node", val));
    ObjectHelper.ifNotEmpty(service.getServiceName(), val -> meta.put("service_name", val));
    List<String> tags = service.getServiceTags();
    if (tags != null) {
        for (String tag : service.getServiceTags()) {
            String[] items = tag.split("=");
            if (items.length == 1) {
                meta.put(items[0], items[0]);
            } else if (items.length == 2) {
                meta.put(items[0], items[1]);
            }
        }
    }
    return new DefaultServiceDefinition(serviceName, service.getServiceAddress(), service.getServicePort(), meta, new DefaultServiceHealth(serviceHealthList.stream().allMatch(this::isHealthy)));
}
Also used : HashMap(java.util.HashMap) DefaultServiceHealth(org.apache.camel.impl.cloud.DefaultServiceHealth) DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition)

Example 2 with DefaultServiceDefinition

use of org.apache.camel.impl.cloud.DefaultServiceDefinition in project camel by apache.

the class KubernetesClientServiceDiscovery method addServers.

protected void addServers(String name, List<ServiceDefinition> servers, EndpointPort port, EndpointSubset subset) {
    final List<EndpointAddress> addresses = subset.getAddresses();
    final int size = addresses.size();
    for (int i = 0; i < size; i++) {
        servers.add(new DefaultServiceDefinition(name, addresses.get(i).getIp(), port.getPort()));
    }
}
Also used : DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition) EndpointAddress(io.fabric8.kubernetes.api.model.EndpointAddress)

Example 3 with DefaultServiceDefinition

use of org.apache.camel.impl.cloud.DefaultServiceDefinition in project camel by apache.

the class KubernetesEnvServiceDiscovery method getServices.

@Override
public List<ServiceDefinition> getServices(String name) {
    try {
        final CamelContext ctx = getCamelContext();
        final String host = ctx.resolvePropertyPlaceholders("{{service.host:" + name + "}}");
        final String num = ctx.resolvePropertyPlaceholders("{{service.port:" + name + "}}");
        final int port = ctx.getTypeConverter().tryConvertTo(int.class, num);
        return Collections.singletonList(new DefaultServiceDefinition(name, host, port));
    } catch (Exception e) {
        throw new RuntimeCamelException(e);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Aggregations

DefaultServiceDefinition (org.apache.camel.impl.cloud.DefaultServiceDefinition)3 EndpointAddress (io.fabric8.kubernetes.api.model.EndpointAddress)1 HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 DefaultServiceHealth (org.apache.camel.impl.cloud.DefaultServiceHealth)1