Search in sources :

Example 1 with LifecycleException

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

the class PayaraServerControl method executeAdminCommand.

private void executeAdminCommand(String description, String command, List<String> args, ProcessOutputConsumer consumer) throws LifecycleException {
    final List<String> cmd = buildCommand(command, args);
    if (config.isOutputToConsole()) {
        System.out.println(description + " using command: " + cmd.toString());
    }
    int result;
    try (CloseableProcess process = new CloseableProcess(new ProcessBuilder(cmd).redirectErrorStream(true).start());
        ConsoleReader consoleReader = new ConsoleReader(process, consumer)) {
        new Thread(consoleReader).start();
        result = process.waitFor();
    } catch (IOException | InterruptedException e) {
        logger.log(SEVERE, description + (e instanceof IOException ? " failed." : " interrupted."), e);
        throw new LifecycleException("Unable to execute " + cmd.toString(), e);
    }
    if (result != 0) {
        throw new LifecycleException("Unable to execute " + cmd.toString());
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) ConsoleReader(fish.payara.arquillian.container.payara.process.ConsoleReader) CloseableProcess(fish.payara.arquillian.container.payara.process.CloseableProcess) IOException(java.io.IOException)

Example 2 with LifecycleException

use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project fabric8 by jboss-fuse.

the class Fabric8Container method start.

@Override
public void start() throws LifecycleException {
    // lets kill any containers that are running before we start
    FabricAssertions.killJavaAndDockerProcesses();
    fabricControllerManager = createFabricControllerManager();
    Fabric8ContainerConfiguration config = configuration.get();
    config.configure(fabricControllerManager);
    try {
        FabricController fabricController = FabricAssertions.assertFabricCreate(fabricControllerManager);
        controller.set(fabricController);
    } catch (Exception e) {
        throw new LifecycleException("Failed to create fabric: " + e, e);
    }
    System.out.println("Created a controller " + controller.get());
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) FabricController(io.fabric8.testkit.FabricController) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 3 with LifecycleException

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

the class DaemonDeployableContainerBase method start.

@Override
public void start() throws LifecycleException {
    // Open up remote resources
    try {
        final long startTime = System.currentTimeMillis();
        final int secondsToWait = this.timeout;
        // 10 seconds from now
        final long acceptableTime = startTime + 1000 * secondsToWait;
        Socket socket = null;
        while (true) {
            try {
                // TODO Security Action
                socket = new Socket(remoteAddress.getHostString(), remoteAddress.getPort());
                if (log.isLoggable(Level.FINEST)) {
                    log.finest("Got connection to " + remoteAddress.toString());
                }
                break;
            } catch (final ConnectException ce) {
                if (log.isLoggable(Level.FINEST)) {
                    log.finest("No connection yet available to remote process");
                }
                final long currentTime = System.currentTimeMillis();
                // Time expired?
                if (currentTime > acceptableTime) {
                    throw new LifecycleException("Could not connect to the server at " + remoteAddress.getHostString() + ":" + remoteAddress.getPort() + " in the allotted " + secondsToWait + "s", ce);
                }
                // Sleep and try again
                try {
                    Thread.sleep(200);
                } catch (final InterruptedException e) {
                    Thread.interrupted();
                    throw new RuntimeException("No one should be interrupting us while we're waiting to connect", e);
                }
            }
        }
        assert socket != null : "Socket should have been connected";
        this.socket = socket;
        final OutputStream socketOutstream = socket.getOutputStream();
        this.socketOutstream = socketOutstream;
        final PrintWriter writer = new PrintWriter(new OutputStreamWriter(socketOutstream, WireProtocol.CHARSET), true);
        this.writer = writer;
        final InputStream socketInstream = socket.getInputStream();
        this.socketInstream = socketInstream;
        final BufferedReader reader = new BufferedReader(new InputStreamReader(socketInstream));
        this.reader = reader;
        final StringBuilder builder = new StringBuilder();
        builder.append(WireProtocol.COMMAND_CHECK_DEPLOYMENT);
        builder.append(WireProtocol.COMMAND_EOF_DELIMITER);
        final String checkCommand = builder.toString();
        // Request
        writer.write(checkCommand);
        writer.flush();
        Throwable error = null;
        try {
            final ObjectInputStream response = new ObjectInputStream(socketInstream);
            error = (Throwable) response.readObject();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        if (error != null) {
            throw new LifecycleException(error.getMessage(), error);
        }
    } catch (final IOException ioe) {
        this.closeRemoteResources();
        throw new LifecycleException("Could not open connection to remote process", ioe);
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) InputStreamReader(java.io.InputStreamReader) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) Socket(java.net.Socket) ConnectException(java.net.ConnectException) PrintWriter(java.io.PrintWriter) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with LifecycleException

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

the class TomEEWebappContainer method downloadTomcat.

protected void downloadTomcat(final File catalinaDirectory, final String tomcatVersion, final String defaultTempDir) throws LifecycleException {
    String source = null;
    try {
        int v = Integer.parseInt(tomcatVersion.substring(0, tomcatVersion.indexOf('.')));
        source = "http://archive.apache.org/dist/tomcat/tomcat-" + v + "/v" + v + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
    } catch (final Exception e) {
    // no-op
    }
    if (source == null) {
        throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
    }
    final File zipFile = Setup.downloadFile("org.apache.tomcat:tomcat:" + tomcatVersion + ":zip", source, defaultTempDir);
    Zips.unzip(zipFile, catalinaDirectory);
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) File(java.io.File) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) IOException(java.io.IOException)

Example 5 with LifecycleException

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

the class PayaraContainer method stop.

@Override
public void stop() throws LifecycleException {
    try {
        unbindCommandRunner();
        glassfish.stop();
    } catch (Exception e) {
        throw new LifecycleException("Could not stop GlassFish Embedded", e);
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) NamingException(javax.naming.NamingException) GlassFishException(org.glassfish.embeddable.GlassFishException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Aggregations

LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)14 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)8 IOException (java.io.IOException)6 NamingException (javax.naming.NamingException)5 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)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 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 ConnectException (java.net.ConnectException)1 URL (java.net.URL)1