Search in sources :

Example 1 with PersistentVolume

use of io.fabric8.kubernetes.api.model.PersistentVolume 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());
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) Map(java.util.Map) PersistentVolumeList(io.fabric8.kubernetes.api.model.PersistentVolumeList)

Example 2 with PersistentVolume

use of io.fabric8.kubernetes.api.model.PersistentVolume in project camel by apache.

the class KubernetesPersistentVolumesProducer method doGetPersistentVolume.

protected void doGetPersistentVolume(Exchange exchange, String operation) throws Exception {
    PersistentVolume pv = null;
    String pvName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_NAME, String.class);
    if (ObjectHelper.isEmpty(pvName)) {
        LOG.error("Get a specific Persistent Volume require specify a Persistent Volume name");
        throw new IllegalArgumentException("Get a specific Persistent Volume require specify a Persistent Volume name");
    }
    pv = getEndpoint().getKubernetesClient().persistentVolumes().withName(pvName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pv);
}
Also used : DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume)

Example 3 with PersistentVolume

use of io.fabric8.kubernetes.api.model.PersistentVolume in project camel by apache.

the class KubernetesPersistentVolumesClaimsProducerTest 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_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
        }
    });
    List<PersistentVolume> result = ex.getOut().getBody(List.class);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with PersistentVolume

use of io.fabric8.kubernetes.api.model.PersistentVolume in project camel by apache.

the class KubernetesPersistentVolumesProducerTest 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_PERSISTENT_VOLUMES_LABELS, labels);
        }
    });
    List<PersistentVolume> result = ex.getOut().getBody(List.class);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

PersistentVolume (io.fabric8.kubernetes.api.model.PersistentVolume)4 Map (java.util.Map)3 DoneablePersistentVolume (io.fabric8.kubernetes.api.model.DoneablePersistentVolume)2 HashMap (java.util.HashMap)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 Test (org.junit.Test)2 PersistentVolumeList (io.fabric8.kubernetes.api.model.PersistentVolumeList)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1