Search in sources :

Example 56 with Client

use of io.fabric8.kubernetes.client.Client 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 57 with Client

use of io.fabric8.kubernetes.client.Client 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 58 with Client

use of io.fabric8.kubernetes.client.Client 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 59 with Client

use of io.fabric8.kubernetes.client.Client 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 60 with Client

use of io.fabric8.kubernetes.client.Client in project vertx-openshift-it by cescoffier.

the class Http2IT method testGRPC.

@Test
public void testGRPC() throws Exception {
    Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
    String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
    System.out.println("Host: " + host);
    System.out.println("Port: " + 443);
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
    AtomicReference<String> result = new AtomicReference<>();
    System.out.println("Sending request...");
    stub.sayHello(request, asyncResponse -> {
        System.out.println("Got result");
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
            result.set(asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
    await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
    assertThat(result.get()).contains("Hello OpenShift");
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ManagedChannel(io.grpc.ManagedChannel) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) Assertions(io.fabric8.kubernetes.assertions.Assertions) TimeUnit(java.util.concurrent.TimeUnit) Kube.securedUrlForRoute(io.vertx.it.openshift.utils.Kube.securedUrlForRoute) HttpVersion(io.vertx.core.http.HttpVersion) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Matchers.is(org.hamcrest.Matchers.is) HttpClientOptions(io.vertx.core.http.HttpClientOptions) org.junit(org.junit) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)42 Test (org.junit.Test)34 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)29 Service (io.fabric8.kubernetes.api.model.Service)24 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)23 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)20 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 Pod (io.fabric8.kubernetes.api.model.Pod)14 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 URL (java.net.URL)8 Map (java.util.Map)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 DockerClient (io.fabric8.docker.client.DockerClient)6 MalformedURLException (java.net.MalformedURLException)6 Session (io.fabric8.arquillian.kubernetes.Session)5