Search in sources :

Example 21 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project vertx-openshift-it by cescoffier.

the class ConfigurationIT method deployApp.

private static String deployApp(String name, String templatePath) throws IOException {
    String appName;
    List<? extends HasMetadata> entities = deploymentAssistant.deploy(name, new File(templatePath));
    Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
    if (first.isPresent()) {
        appName = first.get();
    } else {
        throw new IllegalStateException("Application deployment config not found");
    }
    Route route = deploymentAssistant.getRoute(appName);
    assertThat(route).isNotNull();
    return "http://" + route.getSpec().getHost();
}
Also used : BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) URISyntaxException(java.net.URISyntaxException) OC(io.vertx.it.openshift.utils.OC) JsonPath(io.restassured.path.json.JsonPath) Route(io.fabric8.openshift.api.model.Route) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Map(java.util.Map) RestAssured.get(io.restassured.RestAssured.get) Awaitility.await(org.awaitility.Awaitility.await) AfterClass(org.junit.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test) IOException(java.io.IOException) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) Ensure.ensureThat(io.vertx.it.openshift.utils.Ensure.ensureThat) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Optional(java.util.Optional) RestAssured(io.restassured.RestAssured) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) File(java.io.File) Route(io.fabric8.openshift.api.model.Route)

Example 22 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project vertx-openshift-it by cescoffier.

the class HealthCheckIT method getContainers.

private List<Container> getContainers() {
    DeploymentConfig dc = client.deploymentConfigs().withName(deploymentAssistant.applicationName()).get();
    ensureThat("the deployment config " + deploymentAssistant.applicationName() + " exists", () -> assertThat(dc).isNotNull());
    return dc.getSpec().getTemplate().getSpec().getContainers();
}
Also used : DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 23 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project vertx-openshift-it by cescoffier.

the class CircuitBreakerIT method deployApp.

/**
 * @param name
 * @param templatePath
 * @return the app route
 * @throws IOException
 */
private static String deployApp(String name, String templatePath) throws IOException {
    String appName = "";
    List<? extends HasMetadata> entities = OPENSHIFT.deploy(name, new File(templatePath));
    Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
    if (first.isPresent()) {
        appName = first.get();
    } else {
        throw new IllegalStateException("Application deployment config not found");
    }
    Route route = OPENSHIFT.client().routes().inNamespace(OPENSHIFT.project()).withName(appName).get();
    assertThat(route).isNotNull();
    return "http://" + route.getSpec().getHost();
}
Also used : CircuitBreakerState(io.vertx.circuitbreaker.CircuitBreakerState) Awaitility.await(org.awaitility.Awaitility.await) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) OpenShiftTestAssistant(io.vertx.it.openshift.utils.OpenShiftTestAssistant) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Route(io.fabric8.openshift.api.model.Route) Response(io.restassured.response.Response) Optional(java.util.Optional) JsonObject(io.vertx.core.json.JsonObject) RestAssured.get(io.restassured.RestAssured.get) RestAssured(io.restassured.RestAssured) Before(org.junit.Before) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) File(java.io.File) Route(io.fabric8.openshift.api.model.Route)

Example 24 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project vertx-openshift-it by cescoffier.

the class Deployment method deployIfNeeded.

public static String deployIfNeeded(KubernetesClient client, File input) {
    OpenShiftClient oc = oc(client);
    assertThat(input).isFile();
    try {
        byte[] bytes = Files.readBytes(input);
        try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes)) {
            DeploymentConfig deploymentConfig = oc.deploymentConfigs().load(bis).get();
            assertThat(deploymentConfig).isNotNull();
            if (oc.deploymentConfigs().withName(deploymentConfig.getMetadata().getName()).get() != null) {
                System.out.println("Skipping the creation of dc/" + deploymentConfig.getMetadata().getName());
                return deploymentConfig.getMetadata().getName();
            }
            oc.deploymentConfigs().create(deploymentConfig);
            OC.execute("deploy", deploymentConfig.getMetadata().getName(), "--latest", "-n", oc.getNamespace());
            return deploymentConfig.getMetadata().getName();
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to deploy deployment config " + input.getAbsolutePath(), e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 25 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project vertx-openshift-it by cescoffier.

the class Kube method setReplicasAndWait.

public static DeploymentConfig setReplicasAndWait(KubernetesClient client, String name, int number) {
    OpenShiftClient oc = oc(client);
    DeploymentConfig config = oc.deploymentConfigs().withName(name).get();
    if (config == null) {
        fail("Unable to find the deployment config " + name);
        return null;
    }
    if (config.getSpec().getReplicas() == number) {
        return config;
    }
    config = oc.deploymentConfigs().withName(name).edit().editSpec().withReplicas(number).endSpec().done();
    if (number == 0) {
        // Wait until no pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == 0);
    } else {
        // Wait until the right number of pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == number);
        // Wait for readiness
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).stream().filter(KubernetesHelper::isPodReady).count() == number);
    }
    return config;
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Aggregations

DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)30 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)10 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 Test (org.junit.Test)9 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)8 Service (io.fabric8.kubernetes.api.model.Service)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)7 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)7 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)6 ImageStream (io.fabric8.openshift.api.model.ImageStream)6 IOException (java.io.IOException)6 Controller (io.fabric8.kubernetes.api.Controller)5 Pod (io.fabric8.kubernetes.api.model.Pod)5 DeploymentSpec (io.fabric8.kubernetes.api.model.extensions.DeploymentSpec)5 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)4 ReplicaSetSpec (io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec)4 Route (io.fabric8.openshift.api.model.Route)4