Search in sources :

Example 16 with DeploymentException

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

the class ManagedSEDeployableContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    LOGGER.info("Deploying " + archive.getName());
    // First of all clear the list of previously materialized deployments - otherwise the class path would grow indefinitely
    materializedFiles.clear();
    // Create a new classpath
    classpathDependencies.clear();
    if (ClassPath.isRepresentedBy(archive)) {
        for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) {
            Asset asset = child.getAsset();
            if (asset instanceof ArchiveAsset) {
                Archive<?> assetArchive = ((ArchiveAsset) asset).getArchive();
                if (ClassPathDirectory.isRepresentedBy(assetArchive)) {
                    materializeDirectory(assetArchive);
                } else {
                    materializeArchive(assetArchive);
                }
            }
        }
    } else {
        materializeArchive(archive);
    }
    Properties systemProperties = getSystemProperties(archive);
    readJarFilesFromDirectory();
    addTestResourcesDirectory(systemProperties);
    List<String> processCommand = buildProcessCommand(systemProperties);
    logExecutedCommand(processCommand);
    // Launch the process
    final ProcessBuilder processBuilder = new ProcessBuilder(processCommand);
    String path = systemProperties.getProperty("container.user.dir");
    if (path != null) {
        processBuilder.directory(new File(path));
    }
    processBuilder.environment().put("JAVA_HOME", new File(System.getProperty(SYSPROP_KEY_JAVA_HOME)).getAbsolutePath());
    processBuilder.redirectErrorStream(true);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    try {
        process = processBuilder.start();
    } catch (final IOException e) {
        throw new DeploymentException("Could not start process", e);
    }
    int finalWaitTime = debugModeEnabled ? (3 * waitTime) : waitTime;
    // Wait for socket connection
    if (!isServerStarted(host, port, finalWaitTime)) {
        throw new DeploymentException("Child JVM process failed to start within " + finalWaitTime + " seconds.");
    }
    if (!isJMXTestRunnerMBeanRegistered(host, port, finalWaitTime)) {
        throw new DeploymentException("JMXTestRunnerMBean not registered within " + finalWaitTime + " seconds.");
    }
    ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    protocolMetaData.addContext(new JMXContext(host, port));
    return protocolMetaData;
}
Also used : Node(org.jboss.shrinkwrap.api.Node) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) Properties(java.util.Properties) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File) JMXContext(org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext)

Example 17 with DeploymentException

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

the class ManagedSEDeployableContainer method materializeDirectory.

private void materializeDirectory(Archive<?> archive) throws DeploymentException {
    if (archive.getContent().isEmpty()) {
        // Do not materialize an empty directory
        return;
    }
    File entryDirectory = new File(TARGET.concat(File.separator).concat(archive.getName()));
    try {
        if (entryDirectory.exists()) {
            // Always delete previous content
            FileDeploymentUtils.deleteContent(entryDirectory.toPath());
        } else {
            if (!entryDirectory.mkdirs()) {
                throw new DeploymentException("Could not create class path directory: " + entryDirectory);
            }
        }
        for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) {
            Asset asset = child.getAsset();
            if (asset instanceof ClassAsset) {
                FileDeploymentUtils.materializeClass(entryDirectory, (ClassAsset) asset);
            } else if (asset == null) {
                FileDeploymentUtils.materializeSubdirectories(entryDirectory, child);
            }
        }
    } catch (IOException e) {
        throw new DeploymentException("Could not materialize class path directory: " + archive.getName(), e);
    }
    materializedFiles.add(entryDirectory);
}
Also used : ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Node(org.jboss.shrinkwrap.api.Node) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) IOException(java.io.IOException) File(java.io.File)

Example 18 with DeploymentException

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

the class ManagedSEDeployableContainer method isJMXTestRunnerMBeanRegistered.

private boolean isJMXTestRunnerMBeanRegistered(final String host, final int port, int waitTime) throws DeploymentException {
    // Taken from org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext
    final String jmxServiceUrl = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
    try (JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL(jmxServiceUrl), null)) {
        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        return new Await(waitTime, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                mbsc.getObjectInstance(new ObjectName(JMXTestRunnerMBean.OBJECT_NAME));
                LOGGER.fine("JMXTestRunnerMBean registered with the remote MBean server at: " + jmxServiceUrl);
                return true;
            }
        }).start();
    } catch (IOException e) {
        throw new DeploymentException("Could not verify JMXTestRunnerMBean registration", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) IOException(java.io.IOException) Await(org.apache.camel.itest.springboot.arquillian.container.util.Await) MBeanServerConnection(javax.management.MBeanServerConnection) Callable(java.util.concurrent.Callable) ObjectName(javax.management.ObjectName)

Example 19 with DeploymentException

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

the class CommonPayaraManager method deploy.

public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    if (archive == null) {
        throw new IllegalArgumentException("archive must not be null");
    }
    final String archiveName = archive.getName();
    final ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    try {
        InputStream deployment = archive.as(ZipExporter.class).exportAsInputStream();
        // Build up the POST form to send to Payara
        final FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new StreamDataBodyPart("id", deployment, archiveName));
        deploymentName = createDeploymentName(archiveName);
        addDeployFormFields(deploymentName, form);
        // Do Deploy the application on the remote Payara
        HTTPContext httpContext = payaraClient.doDeploy(deploymentName, form);
        protocolMetaData.addContext(httpContext);
    } catch (PayaraClientException e) {
        throw new DeploymentException("Could not deploy " + archiveName, e);
    }
    return protocolMetaData;
}
Also used : StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) InputStream(java.io.InputStream) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) PayaraClientException(fish.payara.arquillian.container.payara.clientutils.PayaraClientException)

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