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)));
}
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()));
}
}
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);
}
}
Aggregations