Search in sources :

Example 31 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.

the class ConfigMaps method createConfigMapAnnotations.

private static Map<String, String> createConfigMapAnnotations(Session session, String status) {
    Map<String, String> annotations = new HashMap<>();
    File dir = Util.getProjectBaseDir(session);
    String gitUrl = Util.findGitUrl(session, dir);
    annotations.put(Annotations.Tests.SESSION_ID, session.getId());
    annotations.put(Annotations.Tests.TEST_SESSION_STATUS, status);
    if (Strings.isNotBlank(gitUrl)) {
        annotations.put(Annotations.Builds.GIT_URL, gitUrl);
    }
    // lets see if there's a maven generated set of pom properties
    File pomProperties = new File(dir, "target/maven-archiver/pom.properties");
    if (pomProperties.isFile()) {
        try {
            Properties properties = new Properties();
            properties.load(new FileInputStream(pomProperties));
            Map<String, String> map = PropertiesHelper.toMap(properties);
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                if (Strings.isNotBlank(key) && Strings.isNotBlank(value)) {
                    annotations.put(Annotations.Project.PREFIX + key, value);
                }
            }
        } catch (IOException e) {
            session.getLogger().warn("Failed to load " + pomProperties + " file to annotate the namespace: " + e);
        }
    }
    return annotations;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 32 with Session

use of io.fabric8.arquillian.kubernetes.Session in project strimzi by strimzi.

the class ControllerIT method setup.

@Before
public void setup(TestContext context) throws Exception {
    LOGGER.info("Setting up test");
    Runtime.getRuntime().addShutdownHook(kafkaHook);
    kafkaCluster = new KafkaCluster();
    kafkaCluster.addBrokers(1);
    kafkaCluster.deleteDataPriorToStartup(true);
    kafkaCluster.deleteDataUponShutdown(true);
    kafkaCluster.usingDirectory(Files.createTempDirectory("controller-integration-test").toFile());
    kafkaCluster.startup();
    kubeClient = new DefaultKubernetesClient().inNamespace(NAMESPACE);
    LOGGER.info("Using namespace {}", NAMESPACE);
    Map<String, String> m = new HashMap();
    m.put(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.brokerList());
    m.put(Config.ZOOKEEPER_CONNECT.key, "localhost:" + zkPort(kafkaCluster));
    m.put(Config.NAMESPACE.key, NAMESPACE);
    session = new Session(kubeClient, new Config(m));
    Async async = context.async();
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            deploymentId = ar.result();
            adminClient = session.adminClient;
            topicsConfigWatcher = session.topicConfigsWatcher;
            topicWatcher = session.topicWatcher;
            topicsWatcher = session.topicsWatcher;
            async.complete();
        } else {
            context.fail("Failed to deploy session");
        }
    });
    async.await();
    waitFor(context, () -> this.topicsWatcher.started(), timeout, "Topics watcher not started");
    waitFor(context, () -> this.topicsConfigWatcher.started(), timeout, "Topic configs watcher not started");
    waitFor(context, () -> this.topicWatcher.started(), timeout, "Topic watcher not started");
    // We can't delete events, so record the events which exist at the start of the test
    // and then waitForEvents() can ignore those
    preExistingEvents = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems().stream().map(evt -> evt.getMetadata().getUid()).collect(Collectors.toSet());
    LOGGER.info("Finished setting up test");
}
Also used : KafkaCluster(io.debezium.kafka.KafkaCluster) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Before(org.junit.Before)

Example 33 with Session

use of io.fabric8.arquillian.kubernetes.Session in project strimzi by strimzi.

the class Main method deploy.

private void deploy(Config config) {
    DefaultKubernetesClient kubeClient = new DefaultKubernetesClient();
    Vertx vertx = Vertx.vertx();
    Session session = new Session(kubeClient, config);
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            LOGGER.info("Session deployed");
        } else {
            LOGGER.error("Error deploying Session", ar.cause());
        }
    });
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Vertx(io.vertx.core.Vertx)

Example 34 with Session

use of io.fabric8.arquillian.kubernetes.Session 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 35 with Session

use of io.fabric8.arquillian.kubernetes.Session in project vertx-openshift-it by cescoffier.

the class WebSessionIT method testClusteredWebSession.

@Test
public void testClusteredWebSession() throws Exception {
    HttpClient httpClient = vertx.createHttpClient();
    AtomicReference<Map.Entry<String, String>> cookie = new AtomicReference<>();
    int loops = 30;
    for (int i = 0; i < loops; i++) {
        String key = getKey(i);
        String value = getValue(i);
        URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
        CountDownLatch latch = new CountDownLatch(1);
        HttpClientRequest request = httpClient.putAbs(url.toString());
        Optional.ofNullable(cookie.get()).ifPresent(c -> request.headers().add("cookie", c.getKey() + "=" + c.getValue()));
        request.handler(resp -> {
            resp.cookies().stream().map(c -> c.split("=", 2)).map(split -> new SimpleImmutableEntry<>(split[0], split[1].split(";")[0])).filter(entry -> "vertx-web.session".equals(entry.getKey())).forEach(cookie::set);
            latch.countDown();
        }).exceptionHandler(t -> {
            t.printStackTrace();
            latch.countDown();
        }).end(value);
        latch.await(1, TimeUnit.MINUTES);
        // Give some time to the replication operation
        TimeUnit.SECONDS.sleep(1);
    }
    scaleTo(2);
    // Give some time to the rebalancing process
    TimeUnit.SECONDS.sleep(10);
    assertNotNull("No session cookie", cookie.get());
    for (int i = 0; i < loops; i++) {
        String key = getKey(i);
        String value = getValue(i);
        URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
        given().cookie(cookie.get().getKey(), cookie.get().getValue()).when().get(url).then().assertThat().statusCode(200).body(equalTo(value));
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) OC(io.vertx.it.openshift.utils.OC) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Route(io.fabric8.openshift.api.model.Route) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Ensure(io.vertx.it.openshift.utils.Ensure) After(org.junit.After) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Service(io.fabric8.kubernetes.api.model.Service) Before(org.junit.Before) Vertx(io.vertx.core.Vertx) Kube(io.vertx.it.openshift.utils.Kube) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) TreeMap(java.util.TreeMap) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) RestAssured(io.restassured.RestAssured) Assert(org.junit.Assert) Awaitility(org.awaitility.Awaitility) SortedMap(java.util.SortedMap) HttpClient(io.vertx.core.http.HttpClient) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)14 Session (io.fabric8.arquillian.kubernetes.Session)8 FabricException (io.fabric8.api.FabricException)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)7 Test (org.junit.Test)6 Session (com.jcraft.jsch.Session)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 File (java.io.File)5 Logger (io.fabric8.arquillian.kubernetes.log.Logger)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 Service (io.fabric8.kubernetes.api.model.Service)4 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 ArrayList (java.util.ArrayList)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 FabricAuthenticationException (io.fabric8.api.FabricAuthenticationException)3 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)3 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)3 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)3 MultiException (io.fabric8.utils.MultiException)3 HashMap (java.util.HashMap)3