Search in sources :

Example 16 with Processor

use of io.fabric8.watcher.Processor in project camel by apache.

the class KubernetesConfigMapsProducerTest method getConfigMapTest.

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

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

Example 17 with Processor

use of io.fabric8.watcher.Processor in project camel by apache.

the class KubernetesNamespacesProducerTest method getNamespace.

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

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

Example 18 with Processor

use of io.fabric8.watcher.Processor in project fabric8 by jboss-fuse.

the class FileWatcher method unscan.

private void unscan(final Path file) throws IOException {
    if (isMatchesFile(file)) {
        Processor processor = getProcessor();
        if (processor != null) {
            processor.onRemove(file);
        }
        lastModified = System.currentTimeMillis();
    } else {
        // lets find all the files that now no longer exist
        List<Path> files = new ArrayList<Path>(processedMap.keySet());
        for (Path path : files) {
            if (!Files.exists(path)) {
                LOGGER.debug("File has been deleted: " + path);
                processedMap.remove(path);
                if (isMatchesFile(path)) {
                    Processor processor = getProcessor();
                    if (processor != null) {
                        processor.onRemove(path);
                    }
                    fireListeners(path, ENTRY_DELETE);
                    lastModified = System.currentTimeMillis();
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Processor(io.fabric8.watcher.Processor) ArrayList(java.util.ArrayList)

Example 19 with Processor

use of io.fabric8.watcher.Processor in project fabric8 by jboss-fuse.

the class FileWatcherMapping method init.

public void init() throws IOException {
    if (camelContext == null) {
        throw new IllegalArgumentException("CamelContext must be configured on " + this);
    }
    mapper = new DozerBeanMapper();
    setFileMatchPattern("glob:META-INF/services/dozer/*.xml");
    setProcessor(new Processor() {

        public void process(Path path) {
            addOrUpdateMapping(path);
        }

        public void onRemove(Path path) {
            removeMapping(path);
        }
    });
    super.init();
    LOG.info("Watching directory " + getRoot() + " for Dozer XML Mapping file changes");
}
Also used : Path(java.nio.file.Path) Processor(io.fabric8.watcher.Processor) DozerBeanMapper(org.dozer.DozerBeanMapper)

Example 20 with Processor

use of io.fabric8.watcher.Processor in project camel by apache.

the class KubernetesNodesConsumerTest method createAndDeletePod.

@Test
public void createAndDeletePod() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    mockResultEndpoint.expectedMessageCount(1);
    mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "MODIFIED");
    Exchange ex = template.request("direct:createPod", 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, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
            PodSpec podSpec = new PodSpec();
            podSpec.setHostname("localhost");
            Container cont = new Container();
            cont.setImage("docker.io/jboss/wildfly:latest");
            cont.setName("pippo");
            List<ContainerPort> containerPort = new ArrayList<ContainerPort>();
            ContainerPort port = new ContainerPort();
            port.setHostIP("0.0.0.0");
            port.setHostPort(8080);
            port.setContainerPort(8080);
            containerPort.add(port);
            cont.setPorts(containerPort);
            List<Container> list = new ArrayList<Container>();
            list.add(cont);
            podSpec.setContainers(list);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_POD_SPEC, podSpec);
        }
    });
    ex = template.request("direct:deletePod", 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, "test");
        }
    });
    boolean podDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(podDeleted);
    Thread.sleep(3000);
    mockResultEndpoint.assertIsSatisfied();
}
Also used : Processor(org.apache.camel.Processor) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Exchange(org.apache.camel.Exchange) Container(io.fabric8.kubernetes.api.model.Container) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)33 Processor (org.apache.camel.Processor)33 Test (org.junit.Test)33 HashMap (java.util.HashMap)27 Map (java.util.Map)27 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)5 Namespace (io.fabric8.kubernetes.api.model.Namespace)4 Service (io.fabric8.kubernetes.api.model.Service)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Container (io.fabric8.kubernetes.api.model.Container)3 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)3 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)3 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)3 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)3 Secret (io.fabric8.kubernetes.api.model.Secret)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2