Search in sources :

Example 1 with DefaultServiceHealth

use of org.apache.camel.impl.cloud.DefaultServiceHealth 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)

Aggregations

HashMap (java.util.HashMap)1 DefaultServiceDefinition (org.apache.camel.impl.cloud.DefaultServiceDefinition)1 DefaultServiceHealth (org.apache.camel.impl.cloud.DefaultServiceHealth)1