use of io.fabric8.kubernetes.api.model.PodTemplateSpec in project camel by apache.
the class KubernetesReplicationControllersProducerTest method createScaleAndDeleteReplicationController.
@Test
public void createScaleAndDeleteReplicationController() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
Exchange ex = template.request("direct:createReplicationController", 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, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
rcSpec.setReplicas(1);
PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
rcSpec.setTemplate(t);
Map<String, String> selectorMap = new HashMap<String, String>();
selectorMap.put("server", "nginx");
rcSpec.setSelector(selectorMap);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
}
});
ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
assertEquals(rc.getMetadata().getName(), "test");
ex = template.request("direct:scaleReplicationController", 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, "test");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_REPLICAS, 2);
}
});
Thread.sleep(10000);
Integer replicas = ex.getOut().getBody(Integer.class);
assertTrue(replicas == 2);
ex = template.request("direct:deleteReplicationController", 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, "test");
}
});
boolean rcDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(rcDeleted);
}
use of io.fabric8.kubernetes.api.model.PodTemplateSpec in project camel by apache.
the class KubernetesReplicationControllersProducerTest method createAndDeleteReplicationController.
@Test
public void createAndDeleteReplicationController() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
Exchange ex = template.request("direct:createReplicationController", 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, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
rcSpec.setReplicas(2);
PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
rcSpec.setTemplate(t);
Map<String, String> selectorMap = new HashMap<String, String>();
selectorMap.put("server", "nginx");
rcSpec.setSelector(selectorMap);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
}
});
ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
assertEquals(rc.getMetadata().getName(), "test");
ex = template.request("direct:deleteReplicationController", 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, "test");
}
});
boolean rcDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(rcDeleted);
}
use of io.fabric8.kubernetes.api.model.PodTemplateSpec in project camel by apache.
the class KubernetesReplicationControllersConsumerTest method createAndDeleteReplicationController.
@Test
public void createAndDeleteReplicationController() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED", "MODIFIED", "MODIFIED", "MODIFIED");
Exchange ex = template.request("direct:createReplicationController", 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, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
rcSpec.setReplicas(2);
PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
rcSpec.setTemplate(t);
Map<String, String> selectorMap = new HashMap<String, String>();
selectorMap.put("server", "nginx");
rcSpec.setSelector(selectorMap);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
}
});
ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
assertEquals(rc.getMetadata().getName(), "test");
ex = template.request("direct:deleteReplicationController", 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, "test");
}
});
boolean rcDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(rcDeleted);
Thread.sleep(3000);
mockResultEndpoint.assertIsSatisfied();
}
Aggregations