Search in sources :

Example 6 with Result

use of io.fabric8.insight.metrics.model.Result 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 7 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesPodsProducerTest method getPodTest.

@Test
public void getPodTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:getPod", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_NAME, "elasticsearch-7015o");
        }
    });
    Pod result = ex.getOut().getBody(Pod.class);
    assertNull(result);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 8 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesReplicationControllersProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<ReplicationController> result = template.requestBody("direct:list", "", List.class);
    boolean fabric8Exists = false;
    Iterator<ReplicationController> it = result.iterator();
    while (it.hasNext()) {
        ReplicationController rc = it.next();
        if ("fabric8".equalsIgnoreCase(rc.getMetadata().getName())) {
            fabric8Exists = true;
        }
    }
    assertTrue(fabric8Exists);
}
Also used : ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Test(org.junit.Test)

Example 9 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesReplicationControllersProducerTest method listByLabelsTest.

@Test
public void listByLabelsTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:listByLabels", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("component", "elasticsearch");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
        }
    });
    List<ReplicationController> result = ex.getOut().getBody(List.class);
    boolean rcExists = false;
    Iterator<ReplicationController> it = result.iterator();
    while (it.hasNext()) {
        ReplicationController rc = it.next();
        if ("elasticsearch".equalsIgnoreCase(rc.getMetadata().getName())) {
            rcExists = true;
        }
    }
    assertFalse(rcExists);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Result

use of io.fabric8.insight.metrics.model.Result in project camel by apache.

the class KubernetesReplicationControllersProducerTest method getReplicationControllerTest.

@Test
public void getReplicationControllerTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:getReplicationController", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "elasticsearch");
        }
    });
    ReplicationController result = ex.getOut().getBody(ReplicationController.class);
    assertNull(result);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10