use of org.apache.camel.cloud.ServiceDefinition in project camel by apache.
the class KubernetesClientServiceDiscovery method getServices.
@Override
public List<ServiceDefinition> getServices(String name) {
LOG.debug("Discovering endpoints from namespace: {} with name: {}", getNamespace(), name);
Endpoints endpoints = client.endpoints().inNamespace(getNamespace()).withName(name).get();
List<ServiceDefinition> result = new ArrayList<>();
if (endpoints != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}", endpoints.getSubsets().size(), getNamespace(), name, getPortName());
}
for (EndpointSubset subset : endpoints.getSubsets()) {
if (subset.getPorts().size() == 1) {
addServers(name, result, subset.getPorts().get(FIRST), subset);
} else {
final List<EndpointPort> ports = subset.getPorts();
final int portSize = ports.size();
EndpointPort port;
for (int p = 0; p < portSize; p++) {
port = ports.get(p);
if (ObjectHelper.isEmpty(getPortName()) || getPortName().endsWith(port.getName())) {
addServers(name, result, port, subset);
}
}
}
}
}
return result;
}
use of org.apache.camel.cloud.ServiceDefinition 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;
}
use of org.apache.camel.cloud.ServiceDefinition in project camel by apache.
the class ConsulServiceDiscoveryTest method testServiceDiscovery.
// *************************************************************************
// Test
// *************************************************************************
@Test
public void testServiceDiscovery() throws Exception {
ConsulConfiguration configuration = new ConsulConfiguration(null);
ServiceDiscovery discovery = new ConsulServiceDiscovery(configuration);
List<ServiceDefinition> services = discovery.getServices("my-service");
assertNotNull(services);
assertEquals(3, services.size());
for (ServiceDefinition service : services) {
assertFalse(service.getMetadata().isEmpty());
assertTrue(service.getMetadata().containsKey("service_name"));
assertTrue(service.getMetadata().containsKey("service_id"));
assertTrue(service.getMetadata().containsKey("a-tag"));
assertTrue(service.getMetadata().containsKey("key1"));
assertTrue(service.getMetadata().containsKey("key2"));
}
}
Aggregations