Search in sources :

Example 6 with Build

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

the class KubernetesBuildsProducer method doGetBuild.

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

Example 7 with Build

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

the class KubernetesConfigMapsProducer method doCreateConfigMap.

protected void doCreateConfigMap(Exchange exchange, String operation) throws Exception {
    ConfigMap configMap = null;
    String cfMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    HashMap<String, String> configMapData = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, HashMap.class);
    if (ObjectHelper.isEmpty(cfMapName)) {
        LOG.error("Create a specific configMap require specify a configMap name");
        throw new IllegalArgumentException("Create a specific configMap require specify a configMap name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific configMap require specify a namespace name");
        throw new IllegalArgumentException("Create a specific configMap require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(configMapData)) {
        LOG.error("Create a specific configMap require specify a data map");
        throw new IllegalArgumentException("Create a specific configMap require specify a data map");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
    ConfigMap cfMapCreating = new ConfigMapBuilder().withNewMetadata().withName(cfMapName).withLabels(labels).endMetadata().withData(configMapData).build();
    configMap = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).create(cfMapCreating);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(configMap);
}
Also used : DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 8 with Build

use of io.fabric8.openshift.api.model.Build 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);
}
Also used : Processor(org.apache.camel.Processor) Exchange(org.apache.camel.Exchange) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HashMap(java.util.HashMap) Map(java.util.Map) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Test(org.junit.Test)

Example 9 with Build

use of io.fabric8.openshift.api.model.Build 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);
}
Also used : Exchange(org.apache.camel.Exchange) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Processor(org.apache.camel.Processor) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HashMap(java.util.HashMap) Map(java.util.Map) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Test(org.junit.Test)

Example 10 with Build

use of io.fabric8.openshift.api.model.Build in project curiostack by curioswitch.

the class DeployConfigMapTask method exec.

@TaskAction
public void exec() {
    ImmutableDeploymentExtension config = getProject().getExtensions().getByType(DeploymentExtension.class);
    final ImmutableDeploymentConfiguration deploymentConfig = config.getTypes().getByName(type);
    Map<String, RpcAcl> aclMap = deploymentConfig.rpcAcls().entrySet().stream().map(entry -> new SimpleImmutableEntry<>(entry.getKey(), ImmutableRpcAcl.builder().rate(entry.getValue()).build())).collect(toImmutableMap(Entry::getKey, Entry::getValue));
    final String serializedAcls;
    try {
        serializedAcls = OBJECT_MAPPER.writeValueAsString(aclMap);
    } catch (JsonProcessingException e) {
        throw new UncheckedIOException("Could not serialize acls.", e);
    }
    ConfigMap configMap = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("rpcacls").withNamespace(deploymentConfig.namespace()).build()).withData(ImmutableMap.of("rpcacls.json", serializedAcls)).build();
    KubernetesClient client = new DefaultKubernetesClient();
    client.resource(configMap).createOrReplace();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Style(org.immutables.value.Value.Style) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImmutableDeploymentExtension(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Immutable(org.immutables.value.Value.Immutable) ImmutableDeploymentConfiguration(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension.ImmutableDeploymentConfiguration) UncheckedIOException(org.gradle.api.UncheckedIOException) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) TaskAction(org.gradle.api.tasks.TaskAction) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImplementationVisibility(org.immutables.value.Value.Style.ImplementationVisibility) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Entry(java.util.Map.Entry) DefaultTask(org.gradle.api.DefaultTask) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuilderVisibility(org.immutables.value.Value.Style.BuilderVisibility) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) DeploymentExtension(org.curioswitch.gradle.plugins.curioserver.DeploymentExtension) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) UncheckedIOException(org.gradle.api.UncheckedIOException) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ImmutableDeploymentExtension(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ImmutableDeploymentConfiguration(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension.ImmutableDeploymentConfiguration) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Test (org.junit.Test)255 ArrayList (java.util.ArrayList)74 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)69 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)68 HashMap (java.util.HashMap)67 File (java.io.File)53 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)51 IOException (java.io.IOException)50 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)45 Pod (io.fabric8.kubernetes.api.model.Pod)38 Map (java.util.Map)35 Service (io.fabric8.kubernetes.api.model.Service)34 FabricService (io.fabric8.api.FabricService)33 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)30 Container (io.fabric8.api.Container)29 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)28 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)27 List (java.util.List)26 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)25 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)25