Search in sources :

Example 16 with LifecycleException

use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project wildfly-swarm by wildfly-swarm.

the class WildFlySwarmContainer method deploy.

@Override
public synchronized ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    StartupTimeout startupTimeout = this.testClass.getAnnotation(StartupTimeout.class);
    if (startupTimeout != null) {
        setTimeout(startupTimeout.value());
    }
    this.delegateContainer = new UberjarSimpleContainer(this.containerContext.get(), this.deploymentContext.get(), this.testClass);
    try {
        this.delegateContainer.setJavaVmArguments(this.getJavaVmArguments()).requestedMavenArtifacts(this.requestedMavenArtifacts).start(archive);
        // start wants to connect to the remote container, which isn't up until now, so
        // we override start above and call it here instead
        super.start();
        ProtocolMetaData metaData = new ProtocolMetaData();
        metaData.addContext(createDeploymentContext(archive.getId()));
        return metaData;
    } catch (Throwable e) {
        if (e instanceof LifecycleException) {
            e = e.getCause();
        }
        throw new DeploymentException(e.getMessage(), e);
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) StartupTimeout(org.wildfly.swarm.arquillian.StartupTimeout)

Example 17 with LifecycleException

use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project keycloak by keycloak.

the class InfinispanServerDeployableContainer method start.

@Override
public void start() throws LifecycleException {
    List<String> commands = new ArrayList<>();
    commands.add("./server.sh");
    if (configuration.getServerConfig() != null) {
        commands.add("-c");
        commands.add(configuration.getServerConfig());
    }
    if (configuration.getPortOffset() != null && configuration.getPortOffset() > 0) {
        commands.add("-o");
        commands.add(configuration.getPortOffset().toString());
    }
    commands.add(String.format("-Dcom.sun.management.jmxremote.port=%s", configuration.getManagementPort()));
    commands.add("-Dcom.sun.management.jmxremote.authenticate=false");
    commands.add("-Dcom.sun.management.jmxremote.ssl=false");
    ProcessBuilder pb = new ProcessBuilder(commands);
    pb = pb.directory(new File(configuration.getInfinispanHome(), "/bin")).inheritIO().redirectErrorStream(true);
    pb.environment().put("LAUNCH_ISPN_IN_BACKGROUND", "false");
    pb.environment().put("ISPN_PIDFILE", pidFile.getAbsolutePath());
    if (configuration.getJavaVmArguments() != null) {
        pb.environment().put("JAVA_OPTS", configuration.getJavaVmArguments());
    }
    String javaHome = configuration.getJavaHome();
    if (javaHome != null && !javaHome.isEmpty()) {
        pb.environment().put("JAVA_HOME", javaHome);
    }
    try {
        log.info("Starting Infinispan server");
        log.infof("  Home directory: %s", configuration.getInfinispanHome());
        log.infof("  Commands: %s", commands);
        log.infof("  Environment: %s", pb.environment());
        infinispanServerProcess = pb.start();
        trustAllCertificates();
        long startTimeMillis = System.currentTimeMillis();
        long startupTimeoutMillis = 30 * 1000;
        URL consoleURL = new URL(String.format("%s://localhost:%s/console/", CACHE_SERVER_AUTH ? "https" : "http", 11222 + configuration.getPortOffset()));
        while (true) {
            Thread.sleep(1000);
            if (System.currentTimeMillis() > startTimeMillis + startupTimeoutMillis) {
                stop();
                throw new LifecycleException("Infinispan server startup timed out.");
            }
            HttpURLConnection connection = (HttpURLConnection) consoleURL.openConnection();
            connection.setReadTimeout(1000);
            connection.setConnectTimeout(1000);
            try {
                connection.connect();
                if (connection.getResponseCode() == 200) {
                    break;
                }
                connection.disconnect();
            } catch (ConnectException ex) {
            // ignoring
            }
        }
        log.info("Infinispan server started.");
    } catch (IOException ex) {
        throw new LifecycleException("Unable to start Infinispan server.", ex);
    } catch (InterruptedException ex) {
        log.error("Infinispan server startup process interupted.", ex);
        stop();
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) HttpURLConnection(java.net.HttpURLConnection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL) ConnectException(java.net.ConnectException)

Example 18 with LifecycleException

use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project keycloak by keycloak.

the class CustomFuseContainer method start.

@Override
public void start() throws LifecycleException {
    // Try to connect to an already running server
    MBeanServerConnection mbeanServer = null;
    try {
        mbeanServer = getMBeanServerConnection(500, TimeUnit.MILLISECONDS);
    } catch (TimeoutException ignore) {
    }
    if (mbeanServer != null && !config.isAllowConnectingToRunningServer()) {
        throw new LifecycleException("The server is already running! Managed containers does not support connecting to running server instances due to the " + "possible harmful effect of connecting to the wrong server. Please stop server before running or change to another type of container.\n" + "To disable this check and allow Arquillian to connect to a running server, set allowConnectingToRunningServer to true in the container configuration");
    }
    // Start the Karaf process
    if (mbeanServer == null) {
        String karafHome = config.getKarafHome();
        if (karafHome == null)
            throw new IllegalStateException("karafHome cannot be null");
        File karafHomeDir = new File(karafHome).getAbsoluteFile();
        if (!karafHomeDir.isDirectory())
            throw new IllegalStateException("Not a valid Karaf home dir: " + karafHomeDir);
        String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
        log.infof("Using java: %s", java);
        List<String> cmd = new ArrayList<>();
        cmd.add(java);
        // JavaVM args
        String javaArgs = config.getJavaVmArguments();
        if (!javaArgs.contains("-Xmx")) {
            javaArgs = KarafManagedContainerConfiguration.DEFAULT_JAVAVM_ARGUMENTS + " " + javaArgs;
        }
        cmd.addAll(Arrays.asList(javaArgs.split("\\s")));
        // Karaf properties
        cmd.add("-Dkaraf.home=" + karafHomeDir);
        cmd.add("-Dkaraf.base=" + karafHomeDir);
        cmd.add("-Dkaraf.etc=" + karafHomeDir + "/etc");
        cmd.add("-Dkaraf.data=" + karafHomeDir + "/data");
        cmd.add("-Dkaraf.instances=" + karafHomeDir + "/instances");
        cmd.add("-Dkaraf.restart.jvm.supported=true");
        cmd.add("-Dkaraf.startLocalConsole=false");
        cmd.add("-Dkaraf.startRemoteShell=true");
        // Java properties
        cmd.add("-Djava.io.tmpdir=" + new File(karafHomeDir, "data/tmp"));
        cmd.add("-Djava.util.logging.config.file=" + new File(karafHomeDir, "etc/java.util.logging.properties"));
        cmd.add("-Djava.endorsed.dirs=" + new File(karafHomeDir, "lib/endorsed"));
        // Classpath
        StringBuilder classPath = new StringBuilder();
        boolean fuse7 = new File(karafHomeDir, "lib/boot/").exists();
        if (fuse7) {
            log.info("Adding karaf4 libraries to classpath.");
            String[] libDirs = { "lib/boot/", "lib/ext/" };
            for (String libDir : libDirs) {
                File karafLibBootDir = new File(karafHomeDir, libDir);
                String[] libs = karafLibBootDir.list((File dir, String name) -> name.endsWith(".jar"));
                for (String lib : libs) {
                    String separator = classPath.length() > 0 ? File.pathSeparator : "";
                    classPath.append(separator).append(new File(karafLibBootDir, lib));
                }
            }
        } else {
            // fuse6
            log.info("Adding karaf3 libraries to classpath.");
            File karafLibDir = new File(karafHomeDir, "lib");
            String[] libs = karafLibDir.list((File dir, String name) -> name.startsWith("karaf"));
            for (String lib : libs) {
                String separator = classPath.length() > 0 ? File.pathSeparator : "";
                classPath.append(separator).append(new File(karafHomeDir, "lib/" + lib));
            }
        }
        cmd.add("-classpath");
        cmd.add(classPath.toString());
        // Main class
        cmd.add("org.apache.karaf.main.Main");
        // Output the startup command
        StringBuffer cmdstr = new StringBuffer();
        for (String tok : cmd) {
            cmdstr.append(tok).append(" ");
        }
        log.debugv("Starting Karaf with: {0}", cmdstr);
        try {
            ProcessBuilder processBuilder = new ProcessBuilder(cmd);
            processBuilder.directory(karafHomeDir);
            processBuilder.redirectErrorStream(true);
            process = processBuilder.start();
            new Thread(new ConsoleConsumer()).start();
        } catch (IOException ex) {
            throw new LifecycleException("Cannot start managed Karaf container", ex);
        }
        // Get the MBeanServerConnection
        try {
            log.debug("Geting the MBeanServerConnection");
            mbeanServer = getMBeanServerConnection(120, TimeUnit.SECONDS);
        } catch (TimeoutException ex) {
            destroyKarafProcess();
            throw new LifecycleException("Cannot obtain MBean server connection", ex);
        }
    }
    mbeanServerInstance.set(mbeanServer);
    try {
        // Get the FrameworkMBean
        ObjectName oname = ObjectNameFactory.create("osgi.core:type=framework,*");
        frameworkMBean = getMBeanProxy(mbeanServer, oname, FrameworkMBean.class, 30, TimeUnit.SECONDS);
        // Get the BundleStateMBean
        oname = ObjectNameFactory.create("osgi.core:type=bundleState,*");
        bundleStateMBean = getMBeanProxy(mbeanServer, oname, BundleStateMBean.class, 30, TimeUnit.SECONDS);
        // Get the BundleStateMBean
        oname = ObjectNameFactory.create("osgi.core:type=serviceState,*");
        serviceStateMBean = getMBeanProxy(mbeanServer, oname, ServiceStateMBean.class, 30, TimeUnit.SECONDS);
        // Install the arquillian bundle to become active
        installArquillianBundle();
        // Await the arquillian bundle to become active
        awaitArquillianBundleActive(30, TimeUnit.SECONDS);
        // Await the beginning start level
        Integer beginningStartLevel = config.getKarafBeginningStartLevel();
        if (beginningStartLevel != null)
            awaitBeginningStartLevel(beginningStartLevel, 30, TimeUnit.SECONDS);
        // Await bootsrap complete services
        awaitBootstrapCompleteServices();
    } catch (RuntimeException rte) {
        destroyKarafProcess();
        throw rte;
    } catch (IOException | InterruptedException | TimeoutException | LifecycleException ex) {
        destroyKarafProcess();
        throw new LifecycleException("Cannot start Karaf container", ex);
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) ServiceStateMBean(org.osgi.jmx.framework.ServiceStateMBean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FrameworkMBean(org.osgi.jmx.framework.FrameworkMBean) ObjectName(javax.management.ObjectName) BundleStateMBean(org.osgi.jmx.framework.BundleStateMBean) File(java.io.File) MBeanServerConnection(javax.management.MBeanServerConnection) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)18 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)10 IOException (java.io.IOException)9 NamingException (javax.naming.NamingException)5 File (java.io.File)4 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ConnectException (java.net.ConnectException)2 HttpURLConnection (java.net.HttpURLConnection)2 Socket (java.net.Socket)2 RemoteServer (org.apache.openejb.config.RemoteServer)2 GlassFishException (org.glassfish.embeddable.GlassFishException)2 CloseableProcess (fish.payara.arquillian.container.payara.process.CloseableProcess)1 ConsoleReader (fish.payara.arquillian.container.payara.process.ConsoleReader)1 FabricController (io.fabric8.testkit.FabricController)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInputStream (java.io.ObjectInputStream)1