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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations