Search in sources :

Example 96 with Result

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

the class KubernetesNodesProducerTest 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 {
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("kubernetes.io/hostname", "172.28.128.4");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NODES_LABELS, labels);
        }
    });
    List<Node> result = ex.getOut().getBody(List.class);
    Node node = result.get(0);
    assertTrue(node.getStatus().getCapacity().get("pods").getAmount().equals("110"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Node(io.fabric8.kubernetes.api.model.Node) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 97 with Result

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

the class KubernetesPersistentVolumesClaimsProducerTest 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_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
        }
    });
    List<PersistentVolume> result = ex.getOut().getBody(List.class);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 98 with Result

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

the class KubernetesPersistentVolumesClaimsProducerTest method createListAndDeletePersistentVolumeClaim.

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

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
            PersistentVolumeClaimSpec pvcSpec = new PersistentVolumeClaimSpec();
            ResourceRequirements rr = new ResourceRequirements();
            Map<String, Quantity> mp = new HashMap<String, Quantity>();
            mp.put("storage", new Quantity("100"));
            rr.setLimits(mp);
            Map<String, Quantity> req = new HashMap<String, Quantity>();
            req.put("storage", new Quantity("100"));
            rr.setRequests(req);
            pvcSpec.setResources(rr);
            pvcSpec.setVolumeName("vol001");
            List<String> access = new ArrayList<String>();
            access.add("ReadWriteOnce");
            pvcSpec.setAccessModes(access);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC, pvcSpec);
        }
    });
    PersistentVolumeClaim pvc = ex.getOut().getBody(PersistentVolumeClaim.class);
    assertEquals(pvc.getMetadata().getName(), "test");
    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("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
        }
    });
    List<PersistentVolumeClaim> result = ex.getOut().getBody(List.class);
    boolean pvcExists = false;
    Iterator<PersistentVolumeClaim> it = result.iterator();
    while (it.hasNext()) {
        PersistentVolumeClaim pvcLocal = it.next();
        if ("test".equalsIgnoreCase(pvcLocal.getMetadata().getName())) {
            pvcExists = true;
        }
    }
    assertTrue(pvcExists);
    ex = template.request("direct:delete", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, "test");
        }
    });
    boolean pvcDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(pvcDeleted);
}
Also used : Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) Exchange(org.apache.camel.Exchange) PersistentVolumeClaimSpec(io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec) ArrayList(java.util.ArrayList) List(java.util.List) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 99 with Result

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

the class KubernetesPersistentVolumesProducerTest 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_PERSISTENT_VOLUMES_LABELS, labels);
        }
    });
    List<PersistentVolume> result = ex.getOut().getBody(List.class);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 100 with Result

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

the class KubernetesPodsProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<Pod> result = template.requestBody("direct:list", "", List.class);
    boolean defaultExists = false;
    Iterator<Pod> it = result.iterator();
    while (it.hasNext()) {
        Pod pod = it.next();
        if ((pod.getMetadata().getName()).contains("fabric8")) {
            defaultExists = true;
        }
    }
    assertTrue(defaultExists);
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) 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