Search in sources :

Example 6 with DeploymentException

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

the class TomEEContainer method undeploy.

@Override
public void undeploy(final Archive<?> archive) throws DeploymentException {
    final String archiveName = archive.getName();
    if (configuration.isSingleDeploymentByArchiveName(archiveName)) {
        return;
    }
    final DeployedApp deployed = moduleIds.remove(archiveName);
    try {
        if (deployed == null) {
            LOGGER.warning(archiveName + " was not deployed");
            return;
        }
        doUndeploy(deployed);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to undeploy " + archiveName, e);
    } finally {
        if (deployed != null && !configuration.isSingleDumpByArchiveName()) {
            LOGGER.info("cleaning " + deployed.file.getAbsolutePath());
            // "i" folder
            Files.delete(deployed.file);
            final File pathFile = new File(deployed.path);
            if (!deployed.path.equals(deployed.file.getAbsolutePath()) && pathFile.exists()) {
                LOGGER.info("cleaning " + pathFile);
                Files.delete(pathFile);
            }
            final File parentFile = deployed.file.getParentFile();
            final File[] parentChildren = parentFile.listFiles();
            if (parentChildren == null || parentChildren.length == 0) {
                Files.delete(deployed.file.getParentFile());
            }
        }
    }
}
Also used : DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) File(java.io.File) NamingException(javax.naming.NamingException) UndeployException(org.apache.openejb.UndeployException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 7 with DeploymentException

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

the class EmbeddedTomEEContainer method undeploy.

@Override
public void undeploy(final Archive<?> archive) throws DeploymentException {
    final String name = archive.getName();
    stopCdiContexts(name);
    if (configuration.isSingleDeploymentByArchiveName(name)) {
        return;
    }
    try {
        this.container.undeploy(name);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to undeploy", e);
    } finally {
        this.classLoader.get().unregister(archive.getName());
        final File file = ARCHIVES.remove(archive);
        if (!configuration.isSingleDumpByArchiveName()) {
            final File folder = new File(file.getParentFile(), file.getName().substring(0, file.getName().length() - 4));
            if (folder.exists()) {
                Files.delete(folder);
            }
            Files.delete(file);
            final File parentFile = file.getParentFile();
            final File[] parentChildren = parentFile.listFiles();
            if (parentChildren == null || parentChildren.length == 0) {
                Files.delete(file.getParentFile());
            }
        }
    }
}
Also used : DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) File(java.io.File) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 8 with DeploymentException

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

the class CommonPayaraManager method undeploy.

public void undeploy(Archive<?> archive) throws DeploymentException {
    if (archive == null) {
        throw new IllegalArgumentException("archive must not be null");
    }
    deploymentName = createDeploymentName(archive.getName());
    try {
        // Build up the POST form to send to Payara
        FormDataMultiPart form = new FormDataMultiPart();
        form.field("target", configuration.getTarget(), TEXT_PLAIN_TYPE);
        form.field("operation", DELETE_OPERATION, TEXT_PLAIN_TYPE);
        payaraClient.doUndeploy(deploymentName, form);
    } catch (PayaraClientException e) {
        throw new DeploymentException("Could not undeploy " + archive.getName(), e);
    }
}
Also used : FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) PayaraClientException(fish.payara.arquillian.container.payara.clientutils.PayaraClientException)

Example 9 with DeploymentException

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

the class PayaraContainer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    String deploymentName = createDeploymentName(archive.getName());
    try {
        glassfish.getDeployer().deploy(toURL(archive).toURI(), "--name", deploymentName);
    } catch (Exception e) {
        throw new DeploymentException("Could not deploy " + archive.getName(), e);
    }
    try {
        HTTPContext httpContext = new HTTPContext(ADDRESS, bindHttpPort);
        findServlets(httpContext, resolveWebArchiveNames(archive));
        return new ProtocolMetaData().addContext(httpContext);
    } catch (GlassFishException e) {
        throw new DeploymentException("Could not probe Payara embedded for environment", e);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) 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)

Example 10 with DeploymentException

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

the class PayaraMicroDeployableContainer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    if (archive == null) {
        throw new IllegalArgumentException("archive must not be null");
    }
    try {
        // The main directory from which we'll conduct our business
        Path arquillianMicroDir = Files.createTempDirectory("arquillian-payara-micro");
        // Create paths for the directories we'll be using
        Path deploymentDir = arquillianMicroDir.resolve("deployments/");
        // Create the directories
        deploymentDir.toFile().mkdir();
        // Create the path for the deployment archive (e.g. the application war or ear)
        File deploymentFile = deploymentDir.resolve(archive.getName()).toFile();
        // Create the deployment file itself
        archive.as(ZipExporter.class).exportTo(deploymentFile);
        // Create the list of commands to start Payara Micro
        List<String> cmd = new ArrayList<>(asList("java", "-jar", configuration.getMicroJarFile().getAbsolutePath(), "--deploy", deploymentFile.getAbsolutePath()));
        // Start at a random port so multiple instances won't run in to eachother all the time
        if (configuration.isRandomHttpPort()) {
            cmd.addAll(asList("--port", (8080 + new SecureRandom().nextInt(1000)) + ""));
        }
        // Add --autoBindHttp if it's enabled
        if (configuration.isAutoBindHttp()) {
            cmd.addAll(asList("--autoBindHttp", "--autoBindRange", "1000"));
        }
        // Disable clustering if it's not explicitly enabled
        if (!configuration.isClusterEnabled()) {
            cmd.add("--nocluster");
        }
        // Enable --showServletMappings if it's supported
        if (configuration.getMicroVersion().isMoreRecentThan(new PayaraVersion("5.181-SNAPSHOT"))) {
            cmd.add("--showServletMappings");
        }
        // Start Payara Micro in debug mode if it's been enabled
        if (configuration.isDebug()) {
            cmd.add(1, "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006");
        }
        // Add the extra cmd options to the Payara Micro instance
        if (configuration.getCmdOptions() != null) {
            int index = 1;
            // Split on non-escaped spaces
            for (String option : configuration.getCmdOptions().split("(?<!\\\\) ")) {
                // Unescape any path spaces before adding the string
                cmd.add(index, option.replace("\\ ", " "));
                index++;
            }
        }
        // Add the extra micro options to the Payara Micro instance
        if (configuration.getExtraMicroOptions() != null) {
            // Split on non-escaped spaces
            for (String option : configuration.getExtraMicroOptions().split("(?<!\\\\) ")) {
                // Unescape any path spaces before adding the string
                cmd.add(option.replace("\\ ", " "));
            }
        }
        logger.info("Starting Payara Micro using cmd: " + cmd);
        // Allow Ctrl-C to stop the test, then start Payara Micro
        registerShutdownHook();
        payaraMicroProcess = new ProcessBuilder(cmd).redirectErrorStream(true).start();
        // Create an executor for handling the log reading and writing
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
        // Create a consumer for reading Payara Micro output
        BufferingConsumer consumer = new BufferingConsumer(createProcessOutputConsumer());
        ConsoleReader logReader = new ConsoleReader(payaraMicroProcess, consumer);
        executor.execute(logReader);
        // Check at intervals if Payara Micro has finished starting up or failed to start.
        CountDownLatch payaraMicroStarted = new CountDownLatch(1);
        executor.scheduleAtFixedRate(() -> {
            log = consumer.getBuffer().toString();
            // Check for app deployed
            Matcher startupMatcher = instanceConfigPattern.matcher(log);
            if (startupMatcher.find()) {
                payaraMicroStarted.countDown();
            }
        }, 1500, 200, MILLISECONDS);
        int startupTimeoutInSeconds = configuration.isDebug() ? -1 : configuration.getStartupTimeoutInSeconds();
        boolean microStarted = false;
        // Wait for Payara Micro to start up, or time out after the specified timeout
        if (startupTimeoutInSeconds == -1) {
            payaraMicroStarted.await();
            microStarted = true;
        } else {
            microStarted = payaraMicroStarted.await(startupTimeoutInSeconds, SECONDS);
        }
        if (microStarted) {
            // Shutdown log reading executor
            executor.shutdownNow();
            // Create a matcher for the 'Instance Configured' message
            Matcher instanceConfigMatcher = instanceConfigPattern.matcher(log);
            if (instanceConfigMatcher.find()) {
                // Get the host and port that the application started on.
                String host = instanceConfigMatcher.group("host").trim();
                String[] ports = instanceConfigMatcher.group("ports").trim().split(" ");
                int firstPort = Integer.parseInt(ports[0].trim());
                logger.info("Payara Micro running on host: " + host + " port: " + firstPort);
                HTTPContext httpContext = new HTTPContext(host, firstPort);
                // If the instance config is in the new JSON format, parse the JSON object.
                if (instanceConfigMatcher.group("jsonFormat") != null) {
                    processDeploymentAsJson(log.substring(instanceConfigMatcher.start()), httpContext);
                } else {
                    // Otherwise, parse it the old way
                    processDeploymentOldMethod(log.substring(instanceConfigMatcher.start()), httpContext);
                }
                ProtocolMetaData protocolMetaData = new ProtocolMetaData();
                protocolMetaData.addContext(httpContext);
                return protocolMetaData;
            }
        }
    } catch (IOException e) {
        // Occurs when there was an error starting the Payara Micro thread or the ConsoleReader thread.
        logger.severe("Failed in creating a thread for Payara Micro.\n" + e.getMessage());
        Thread.currentThread().interrupt();
        return null;
    } catch (InterruptedException e) {
        // Occurs when the timeout is reached in waiting for Payara Micro to start
        logger.severe("Timeout reached waiting for Payara Micro to start.\n" + e.getMessage());
        Thread.currentThread().interrupt();
        return null;
    }
    throw new DeploymentException("No applications were found deployed to Payara Micro.");
}
Also used : Path(java.nio.file.Path) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConsoleReader(fish.payara.arquillian.container.payara.process.ConsoleReader) Matcher(java.util.regex.Matcher) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BufferingConsumer(fish.payara.arquillian.container.payara.process.BufferingConsumer) PayaraVersion(fish.payara.arquillian.container.payara.PayaraVersion) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File)

Aggregations

DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)19 File (java.io.File)10 IOException (java.io.IOException)10 LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)9 NamingException (javax.naming.NamingException)7 ProtocolMetaData (org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)7 HTTPContext (org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext)6 InputStream (java.io.InputStream)4 Node (org.jboss.shrinkwrap.api.Node)4 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 TestObserver (org.apache.openejb.arquillian.common.TestObserver)3 AppInfo (org.apache.openejb.assembler.classic.AppInfo)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)3 PayaraClientException (fish.payara.arquillian.container.payara.clientutils.PayaraClientException)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Properties (java.util.Properties)2 AppContext (org.apache.openejb.AppContext)2 NoSuchApplicationException (org.apache.openejb.NoSuchApplicationException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2