Search in sources :

Example 36 with Template

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

the class MqttIT method initialize.

@BeforeClass
public static void initialize() throws IOException {
    File template = new File("target/classes/META-INF/fabric8/openshift.yml");
    ensureThat(String.format("template file %s can be deployed", template), () -> deploymentAssistant.deploy("mqtt-broker", template));
    ensureThat("the mqtt server is up and running", () -> await("Waiting for the mqtt server to be ready..").atMost(5, TimeUnit.MINUTES).untilAsserted(() -> {
        Service service = client.services().withName("mqtt-secured-service").get();
        assertThat(service).isNotNull();
        assertThat(client.deploymentConfigs().withName("vertx-mqtt-it").isReady()).isTrue();
    }));
    mqttRoute = securedUrlForRoute(client.routes().withName("mqtt-secured-route").get()).getHost();
    /* on OSO, the only way to test the insecure MQTT client connecting to server running in OpenShift
    is through port forwarding. */
    String pod = OC.executeWithQuotes(false, "get", "po", "--selector", "app=vertx-mqtt-it", "-o", "jsonpath='{.items[0].metadata.name}'").replace("'", "");
    p1 = Runtime.getRuntime().exec("oc port-forward " + pod + " :1883");
    BufferedReader reader = new BufferedReader(new InputStreamReader(p1.getInputStream()));
    Pattern pattern = Pattern.compile(".*:(\\d+)");
    Matcher matcher = pattern.matcher(reader.readLine());
    String podString = "";
    while (matcher.find()) {
        podString = matcher.group(1);
    }
    port = Integer.parseInt(podString);
    vertx = Vertx.vertx();
    mqttSecuredClient = clientSetup(MqttClient.create(vertx, mqttClientOptions));
    mqttInsecureClient = clientSetup(MqttClient.create(vertx));
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) Service(io.fabric8.kubernetes.api.model.Service) File(java.io.File)

Example 37 with Template

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

the class ServiceDiscoveryIT method initialize.

@BeforeClass
public static void initialize() throws IOException {
    initializeServiceAccount();
    deploymentAssistant.deploy("database", new File("src/test/resources/templates/database.yml"));
    deploymentAssistant.awaitPodReadinessOrFail(pod -> "my-database".equals(pod.getMetadata().getLabels().get("app")));
    SortedMap<String, File> dependencies = new TreeMap<>();
    dependencies.put("A-Endpoints", new File("../some-http-services/target/classes/META-INF/fabric8/openshift.yml"));
    dependencies.put("B-Gateway", new File("../discovery-gateway/target/classes/META-INF/fabric8/openshift.yml"));
    dependencies.forEach((name, template) -> ensureThat(String.format("template file %s can be deployed", template), () -> deploymentAssistant.deploy(name, template)));
    ensureThat("the gateway is up and running", () -> await().atMost(5, TimeUnit.MINUTES).catchUncaughtExceptions().untilAsserted(() -> {
        Service service = client.services().withName("discovery-gateway").get();
        assertThat(service).isNotNull();
        route = client.routes().withName("discovery-gateway").get();
        assertThat(route).isNotNull();
        get(urlForRoute(route, "/health")).then().statusCode(200);
    }));
    someServiceHelper = new OpenShiftHelper(client, "some-http-services");
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) File(java.io.File) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) BeforeClass(org.junit.BeforeClass)

Example 38 with Template

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

the class MapsIT method initialize.

@BeforeClass
public static void initialize() throws IOException {
    initializeServiceAccount();
    SortedMap<String, File> dependencies = new TreeMap<>();
    dependencies.put("A-Maps", new File("../" + APPLICATION_NAME + "/target/classes/META-INF/fabric8/openshift.yml"));
    dependencies.forEach((name, template) -> Ensure.ensureThat(String.format("template file %s can be deployed", template), () -> deploymentAssistant.deploy(name, template)));
    Ensure.ensureThat("The maps app is up and running", () -> await().atMost(5, TimeUnit.MINUTES).catchUncaughtExceptions().untilAsserted(() -> {
        Service service = client.services().withName(APPLICATION_NAME).get();
        Assertions.assertThat(service).isNotNull();
        route = client.routes().withName(APPLICATION_NAME).get();
        Assertions.assertThat(route).isNotNull();
        get(Kube.urlForRoute(route, "/health")).then().statusCode(200);
    }));
    clusterMapsHelper = new OpenShiftHelper(client, APPLICATION_NAME);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) TreeMap(java.util.TreeMap) File(java.io.File) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) BeforeClass(org.junit.BeforeClass)

Example 39 with Template

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

the class WebSessionIT method initialize.

@BeforeClass
public static void initialize() throws IOException {
    initializeServiceAccount();
    SortedMap<String, File> dependencies = new TreeMap<>();
    dependencies.put("A-WebSession", new File("../" + APPLICATION_NAME + "/target/classes/META-INF/fabric8/openshift.yml"));
    dependencies.forEach((name, template) -> Ensure.ensureThat(String.format("template file %s can be deployed", template), () -> deploymentAssistant.deploy(name, template)));
    Ensure.ensureThat("The web-session app is up and running", () -> await().atMost(5, TimeUnit.MINUTES).catchUncaughtExceptions().untilAsserted(() -> {
        Service service = client.services().withName(APPLICATION_NAME).get();
        Assertions.assertThat(service).isNotNull();
        route = client.routes().withName(APPLICATION_NAME).get();
        Assertions.assertThat(route).isNotNull();
        get(Kube.urlForRoute(route, "/health")).then().statusCode(200);
    }));
    clusterWebSessionHelper = new OpenShiftHelper(client, APPLICATION_NAME);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) TreeMap(java.util.TreeMap) File(java.io.File) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) BeforeClass(org.junit.BeforeClass)

Example 40 with Template

use of io.fabric8.openshift.api.model.Template in project logging-log4j2 by apache.

the class KubernetesLookup method initialize.

private boolean initialize() {
    if (kubernetesInfo == null || (isSpringIncluded && !kubernetesInfo.isSpringActive)) {
        initLock.lock();
        try {
            boolean isSpringActive = isSpringActive();
            if (kubernetesInfo == null || (!kubernetesInfo.isSpringActive && isSpringActive)) {
                KubernetesInfo info = new KubernetesInfo();
                KubernetesClient client = null;
                info.isSpringActive = isSpringActive;
                if (pod == null) {
                    client = new KubernetesClientBuilder().createClient();
                    if (client != null) {
                        pod = getCurrentPod(System.getenv(HOSTNAME), client);
                        info.masterUrl = client.getMasterUrl();
                        if (pod != null) {
                            info.namespace = pod.getMetadata().getNamespace();
                            namespace = client.namespaces().withName(info.namespace).get();
                        }
                    } else {
                        LOGGER.warn("Kubernetes is not available for access");
                    }
                } else {
                    info.masterUrl = masterUrl;
                }
                if (pod != null) {
                    if (namespace != null) {
                        info.namespaceId = namespace.getMetadata().getUid();
                        info.namespaceAnnotations = namespace.getMetadata().getAnnotations();
                        info.namespaceLabels = namespace.getMetadata().getLabels();
                    }
                    info.app = pod.getMetadata().getLabels().get("app");
                    info.hostName = pod.getSpec().getNodeName();
                    info.annotations = pod.getMetadata().getAnnotations();
                    final String app = info.app != null ? info.app : "";
                    info.podTemplateHash = pod.getMetadata().getLabels().get("pod-template-hash");
                    info.accountName = pod.getSpec().getServiceAccountName();
                    info.clusterName = pod.getMetadata().getClusterName();
                    info.hostIp = pod.getStatus().getHostIP();
                    info.labels = pod.getMetadata().getLabels();
                    info.podId = pod.getMetadata().getUid();
                    info.podIp = pod.getStatus().getPodIP();
                    info.podName = pod.getMetadata().getName();
                    ContainerStatus containerStatus = null;
                    List<ContainerStatus> statuses = pod.getStatus().getContainerStatuses();
                    if (statuses.size() == 1) {
                        containerStatus = statuses.get(0);
                    } else if (statuses.size() > 1) {
                        String containerId = ContainerUtil.getContainerId();
                        if (containerId != null) {
                            containerStatus = statuses.stream().filter(cs -> cs.getContainerID().contains(containerId)).findFirst().orElse(null);
                        }
                    }
                    final String containerName;
                    if (containerStatus != null) {
                        info.containerId = containerStatus.getContainerID();
                        info.imageId = containerStatus.getImageID();
                        containerName = containerStatus.getName();
                    } else {
                        containerName = null;
                    }
                    Container container = null;
                    List<Container> containers = pod.getSpec().getContainers();
                    if (containers.size() == 1) {
                        container = containers.get(0);
                    } else if (containers.size() > 1 && containerName != null) {
                        container = containers.stream().filter(c -> c.getName().equals(containerName)).findFirst().orElse(null);
                    }
                    if (container != null) {
                        info.containerName = container.getName();
                        info.imageName = container.getImage();
                    }
                    kubernetesInfo = info;
                }
            }
        } finally {
            initLock.unlock();
        }
    }
    return kubernetesInfo != null;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Container(io.fabric8.kubernetes.api.model.Container)

Aggregations

Template (io.fabric8.openshift.api.model.Template)32 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)24 IOException (java.io.IOException)20 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)16 HashMap (java.util.HashMap)15 Test (org.junit.Test)15 File (java.io.File)14 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)12 Service (io.fabric8.kubernetes.api.model.Service)11 Parameter (io.fabric8.openshift.api.model.Parameter)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Container (io.fabric8.kubernetes.api.model.Container)8 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)8 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)8 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)8 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)7 OpenShiftHelper (io.vertx.it.openshift.utils.OpenShiftHelper)7