Search in sources :

Example 1 with EndpointPort

use of io.fabric8.kubernetes.api.model.EndpointPort 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;
}
Also used : Endpoints(io.fabric8.kubernetes.api.model.Endpoints) EndpointSubset(io.fabric8.kubernetes.api.model.EndpointSubset) EndpointPort(io.fabric8.kubernetes.api.model.EndpointPort) ArrayList(java.util.ArrayList) DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition)

Example 2 with EndpointPort

use of io.fabric8.kubernetes.api.model.EndpointPort 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)

Aggregations

DefaultServiceDefinition (org.apache.camel.impl.cloud.DefaultServiceDefinition)2 EndpointAddress (io.fabric8.kubernetes.api.model.EndpointAddress)1 EndpointPort (io.fabric8.kubernetes.api.model.EndpointPort)1 EndpointSubset (io.fabric8.kubernetes.api.model.EndpointSubset)1 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)1 ArrayList (java.util.ArrayList)1 ServiceDefinition (org.apache.camel.cloud.ServiceDefinition)1