use of java.util.Map in project camel by apache.
the class KubernetesPersistentVolumesProducer method doListPersistentVolumesByLabels.
protected void doListPersistentVolumesByLabels(Exchange exchange, String operation) throws Exception {
PersistentVolumeList pvList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS, Map.class);
NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> pvs;
pvs = getEndpoint().getKubernetesClient().persistentVolumes();
for (Map.Entry<String, String> entry : labels.entrySet()) {
pvs.withLabel(entry.getKey(), entry.getValue());
}
pvList = pvs.list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(pvList.getItems());
}
use of java.util.Map in project camel by apache.
the class KubernetesPodsProducer method doListPodsByLabel.
protected void doListPodsByLabel(Exchange exchange, String operation) {
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
if (ObjectHelper.isEmpty(labels)) {
LOG.error("Get pods by labels require specify a labels set");
throw new IllegalArgumentException("Get pods by labels require specify a labels set");
}
MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = getEndpoint().getKubernetesClient().pods();
for (Map.Entry<String, String> entry : labels.entrySet()) {
pods.withLabel(entry.getKey(), entry.getValue());
}
PodList podList = pods.list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(podList.getItems());
}
use of java.util.Map in project camel by apache.
the class KubernetesConfigMapsProducer method doListConfigMapsByLabels.
protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception {
ConfigMapList configMapsList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps();
for (Map.Entry<String, String> entry : labels.entrySet()) {
configMaps.withLabel(entry.getKey(), entry.getValue());
}
configMapsList = configMaps.list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(configMapsList.getItems());
}
use of java.util.Map 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 java.util.Map 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);
}
Aggregations