Search in sources :

Example 1 with BuildConfig

use of io.fabric8.openshift.api.model.BuildConfig in project camel by apache.

the class KubernetesBuildConfigsProducer method doGetBuildConfig.

protected void doGetBuildConfig(Exchange exchange, String operation) throws Exception {
    BuildConfig buildConfig = null;
    String buildConfigName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIG_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(buildConfigName)) {
        LOG.error("Get a specific Build Config require specify a Build Config name");
        throw new IllegalArgumentException("Get a specific Build Config require specify a Build Config name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific Build Config require specify a namespace name");
        throw new IllegalArgumentException("Get a specific Build Config require specify a namespace name");
    }
    buildConfig = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName).withName(buildConfigName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildConfig);
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig)

Example 2 with BuildConfig

use of io.fabric8.openshift.api.model.BuildConfig in project camel by apache.

the class KubernetesBuildConfigsProducer method doListBuildConfigsByLabels.

protected void doListBuildConfigsByLabels(Exchange exchange, String operation) throws Exception {
    BuildConfigList buildConfigsList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    } else {
        MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildConfigsList.getItems());
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfigResource(io.fabric8.openshift.client.dsl.BuildConfigResource) Map(java.util.Map) BuildConfigList(io.fabric8.openshift.api.model.BuildConfigList)

Example 3 with BuildConfig

use of io.fabric8.openshift.api.model.BuildConfig in project camel by apache.

the class KubernetesBuildConfigsProducerTest 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_BUILD_CONFIGS_LABELS, labels);
        }
    });
    List<BuildConfig> result = ex.getOut().getBody(List.class);
    assertTrue(result.size() == 0);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

BuildConfig (io.fabric8.openshift.api.model.BuildConfig)3 DoneableBuildConfig (io.fabric8.openshift.api.model.DoneableBuildConfig)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 Map (java.util.Map)2 BuildConfigList (io.fabric8.openshift.api.model.BuildConfigList)1 BuildConfigResource (io.fabric8.openshift.client.dsl.BuildConfigResource)1 HashMap (java.util.HashMap)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 Test (org.junit.Test)1