Search in sources :

Example 21 with Session

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

the class Util method waitUntilWeCanDestroyNamespace.

protected static void waitUntilWeCanDestroyNamespace(Session session) {
    final Logger log = session.getLogger();
    String confirmDestroy = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_CONFIRM_ENABLED, "false");
    if (Objects.equal(confirmDestroy, "true")) {
        showErrorsBeforePause(session);
        System.out.println();
        System.out.println("Waiting to destroy the namespace.");
        System.out.println("Please type: [Q] to terminate the namespace.");
        while (true) {
            try {
                int ch = System.in.read();
                if (ch < 0 || ch == 'Q') {
                    System.out.println("\nStopping...");
                    break;
                } else {
                    System.out.println("Found character: " + Character.toString((char) ch));
                }
            } catch (IOException e) {
                log.warn("Failed to read from input. " + e);
                break;
            }
        }
    } else {
        String timeoutText = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_TIMEOUT, "0");
        Long timeout = null;
        if (Strings.isNotBlank(timeoutText)) {
            try {
                timeout = Long.parseLong(timeoutText);
            } catch (NumberFormatException e) {
                log.warn("Failed to parse timeout value '" + timeoutText + "' for $Constants.NAMESPACE_CLEANUP_TIMEOUT. " + e);
            }
        }
        if (timeout != null && timeout > 0L) {
            showErrorsBeforePause(session);
            System.out.println();
            System.out.println("Sleeping for " + timeout + " seconds until destroying the namespace");
            try {
                Thread.sleep(timeout * 1000);
            } catch (InterruptedException e) {
                log.info("Interupted sleeping to GC the namespace: " + e);
            }
        }
    }
    System.out.println("Now destroying the Fabric8 Arquillian test case namespace");
}
Also used : IOException(java.io.IOException) Logger(io.fabric8.arquillian.kubernetes.log.Logger)

Example 22 with Session

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

the class DependencyResolverTest method testResolutionOfPomWithNoDeps.

@Test
public void testResolutionOfPomWithNoDeps() throws IOException {
    Session session = new Session("test-session", "test-session-123", new AnsiLogger());
    DependencyResolver resolver = new DependencyResolver(DependencyResolver.class.getResource("/test-pom.xml").getFile(), true);
    Assert.assertTrue(resolver.resolve(session).isEmpty());
}
Also used : AnsiLogger(io.fabric8.arquillian.kubernetes.log.AnsiLogger) Session(io.fabric8.arquillian.kubernetes.Session) DependencyResolver(io.fabric8.arquillian.kubernetes.DependencyResolver) Test(org.junit.Test)

Example 23 with Session

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

the class SessionListener method generateSecrets.

private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
    Set<Secret> secrets = new HashSet<>();
    Map<String, String> annotations = meta.getAnnotations();
    if (annotations != null && !annotations.isEmpty()) {
        for (Map.Entry<String, String> entry : annotations.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (SecretKeys.isSecretKey(key)) {
                SecretKeys keyType = SecretKeys.fromValue(key);
                for (String name : Secrets.getNames(value)) {
                    Map<String, String> data = new HashMap<>();
                    Secret secret = null;
                    try {
                        secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
                    } catch (Exception e) {
                    // ignore - probably doesn't exist
                    }
                    if (secret == null) {
                        for (String c : Secrets.getContents(value, name)) {
                            data.put(c, keyType.generate());
                        }
                        secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
                        secrets.add(secret);
                    }
                }
            }
        }
    }
    return secrets;
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) SecretKeys(io.fabric8.arquillian.utils.SecretKeys) MultiException(io.fabric8.utils.MultiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 24 with Session

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

the class SuiteListener method start.

public void start(@Observes(precedence = 100) BeforeSuite event, Configuration configuration, Logger logger) {
    session = new Session(configuration.getSessionId(), configuration.getNamespace(), logger);
    session.init();
    sessionProducer.set(session);
    controlEvent.fire(new Start(session));
}
Also used : Start(io.fabric8.arquillian.kubernetes.event.Start)

Example 25 with Session

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

the class SuiteListener method stop.

public void stop(@Observes(precedence = -100) AfterSuite event, Logger logger) {
    controlEvent.fire(new Stop(session));
    session.destroy();
}
Also used : Stop(io.fabric8.arquillian.kubernetes.event.Stop)

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