use of io.fabric8.kubernetes.api.model.ReplicationController 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.ReplicationController 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);
}
use of io.fabric8.kubernetes.api.model.ReplicationController 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);
}
use of io.fabric8.kubernetes.api.model.ReplicationController 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);
}
use of io.fabric8.kubernetes.api.model.ReplicationController 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);
}
Aggregations