use of org.apache.camel.component.kubernetes.KubernetesEndpoint in project wildfly-camel by wildfly-extras.
the class KubernetesIntegrationTest method testKubernetesProducer.
@Test
public void testKubernetesProducer() throws Exception {
String kubernetesProducerURI = String.format("kubernetes:%s?category=pods&operation=createPod", getKubernetesMaster());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to(kubernetesProducerURI);
}
});
ProducerTemplate template = camelctx.createProducerTemplate();
String podName = POD_NAME + "-producer";
camelctx.start();
KubernetesEndpoint kubernetesEndpoint = camelctx.getEndpoint(kubernetesProducerURI, KubernetesEndpoint.class);
String kubernetesNamespace = getNamespace(kubernetesEndpoint.getKubernetesClient());
try {
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
headers.put(KubernetesConstants.KUBERNETES_POD_SPEC, createPodSpec());
Pod pod = template.requestBodyAndHeaders("direct:start", null, headers, Pod.class);
Assert.assertNotNull("Expected pod to be not null", pod);
Assert.assertEquals("Pending", pod.getStatus().getPhase());
} finally {
// Clean up
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
template.requestBodyAndHeaders("kubernetes:" + getKubernetesMaster() + "?category=pods&operation=deletePod", null, headers);
camelctx.stop();
}
}
use of org.apache.camel.component.kubernetes.KubernetesEndpoint in project wildfly-camel by wildfly-extras.
the class KubernetesIntegrationTest method testKubernetesConsumer.
@Test
public void testKubernetesConsumer() throws Exception {
String kubernetesConsumerURI = String.format("kubernetes:%s?category=pods", getKubernetesMaster());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(kubernetesConsumerURI).to("mock:result");
}
});
MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
mockEndpoint.expectedMinimumMessageCount(1);
ProducerTemplate template = camelctx.createProducerTemplate();
String podName = POD_NAME + "-consumer";
camelctx.start();
KubernetesEndpoint kubernetesEndpoint = camelctx.getEndpoint(kubernetesConsumerURI, KubernetesEndpoint.class);
String kubernetesNamespace = getNamespace(kubernetesEndpoint.getKubernetesClient());
try {
// Create a pod so we can generate some watch events
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
headers.put(KubernetesConstants.KUBERNETES_POD_SPEC, createPodSpec());
template.requestBodyAndHeaders("kubernetes:" + getKubernetesMaster() + "?category=pods&operation=createPod", null, headers);
mockEndpoint.assertIsSatisfied();
} finally {
// Clean up
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
template.requestBodyAndHeaders("kubernetes:" + getKubernetesMaster() + "?category=pods&operation=deletePod", null, headers);
camelctx.stop();
}
}
Aggregations