Search in sources :

Example 31 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class VerifierMain method main.

public static void main(String[] args) throws GlassFishException, IOException {
    VerifierFrameworkContext verifierFrameworkContext = new Initializer(args).getVerificationContext();
    // Since in gui mode, we don't get a chance to clean up, we need to install a shutdown hook
    addShutdownHook();
    gfr = GlassFishRuntime.bootstrap();
    GlassFishProperties gfp = new GlassFishProperties();
    gfp.setProperty(StartupContext.TIME_ZERO_NAME, (new Long(System.currentTimeMillis())).toString());
    final String VERIFIER_MODULE = "org.glassfish.verifier";
    gfp.setProperty(StartupContext.STARTUP_MODULE_NAME, VERIFIER_MODULE);
    // gfp.setConfigFileURI("file:/tmp/domain.xml");
    GlassFish gf = gfr.newGlassFish(gfp);
    gf.start();
    int failedCount = -1;
    Verifier verifier = gf.getService(Verifier.class);
    if (verifierFrameworkContext.isUsingGui()) {
        MainFrame mf = new MainFrame(verifierFrameworkContext.getJarFileName(), true, verifier);
        mf.setSize(800, 600);
        mf.setVisible(true);
    } else {
        LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
        try {
            verifier.init(verifierFrameworkContext);
            verifier.verify();
        } catch (Exception e) {
            LogRecord logRecord = new LogRecord(Level.SEVERE, smh.getLocalString(verifier.getClass().getName() + // NOI18N
            ".verifyFailed", // NOI18N
            "Could not verify successfully."));
            logRecord.setThrown(e);
            verifierFrameworkContext.getResultManager().log(logRecord);
        }
        verifier.generateReports();
        failedCount = verifierFrameworkContext.getResultManager().getFailedCount() + verifierFrameworkContext.getResultManager().getErrorCount();
        System.exit(failedCount);
    }
}
Also used : LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) LogRecord(java.util.logging.LogRecord) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) MainFrame(com.sun.enterprise.tools.verifier.gui.MainFrame) GlassFishException(org.glassfish.embeddable.GlassFishException) IOException(java.io.IOException)

Example 32 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class MultipleSPETest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS-bookstore application. Deployment should fail
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-spe-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNull(appName);
    } catch (Exception e) {
        System.out.println("$$$$$$$$$$$$$$$$Exception$$$$$$");
    } finally {
        // 3. Register one of the plugins as the default S.P.E
        ServiceLocator habitat = Globals.getDefaultHabitat();
        org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        ActionReport report = habitat.getService(ActionReport.class);
        org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("register-service-provisioning-engine", report);
        ParameterMap parameterMap = new ParameterMap();
        parameterMap.add("type", "Database");
        parameterMap.add("defaultservice", "true");
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Registered a default SPE :" + !report.hasFailures());
        // 4. Deploy the application. Deployment should succeed.
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        // 5. Access the app to make sure PaaS-basic-shared-service-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic-spe-test/list", "Here is a list of animals in the zoo.");
        // Retrieve the  port number used by the connection pool
        invocation = commandRunner.getCommandInvocation("get", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "server.resources.jdbc-connection-pool.jdbc/__multiple_spe_paas_sample.property.PortNumber");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                if (commandResult.getOutput().contains("Nothing to list.")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
        commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        invocation = commandRunner.getCommandInvocation("unregister-service-provisioning-engine", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Unregistered the default SPE :" + !report.hasFailures());
    }
}
Also used : PrintStream(java.io.PrintStream) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) PaaSDeploymentException(org.glassfish.paas.orchestrator.PaaSDeploymentException) IOException(java.io.IOException) Exception(java.lang.Exception) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 33 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class BasicPaaSServiceMetadataTest method bootstrap.

private GlassFish bootstrap() throws Exception {
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    return glassfish;
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 34 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project solr-document-store by DBCDK.

the class Payara method getInstance.

static Payara getInstance(String port) throws GlassFishException {
    if (glassfish == null) {
        payaraPort = Integer.parseInt(port);
        BootstrapProperties bootstrap = new BootstrapProperties();
        GlassFishRuntime runtime = GlassFishRuntime.bootstrap(bootstrap);
        GlassFishProperties glassfishProperties = new GlassFishProperties();
        glassfishProperties.setPort("http-listener", payaraPort);
        glassfish = runtime.newGlassFish(glassfishProperties);
        glassfish.start();
        runner = glassfish.getCommandRunner();
        runner.setTerse(true);
    }
    return new Payara();
}
Also used : BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 35 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class EJBContainerProviderImpl method createContainer.

private Locations createContainer(Map<?, ?> properties, Locations l) throws EJBException {
    synchronized (lock) {
        // if (container == null || !container.isOpen()) {
        try {
            if (runtime != null) {
                // dispose of the old one
                runtime.shutdown();
            }
            BootstrapProperties bootstrapProperties = new BootstrapProperties();
            // Propagate non EJB embeddable container properties into GlassFishProperties
            Properties newProps = new Properties();
            if (properties != null) {
                copyUserProperties(properties, newProps);
            }
            // Disable weaving if it is not spesified
            if (newProps.getProperty(WEAVING) == null) {
                newProps.setProperty(WEAVING, "false");
            }
            GlassFishProperties glassFishProperties = new GlassFishProperties(newProps);
            if (Boolean.getBoolean(KEEP_TEMPORARY_FILES)) {
                // set autodelete to false.
                glassFishProperties.setProperty("org.glassfish.embeddable.autoDelete", "false");
                // make sure the domain.xml is written back.
                glassFishProperties.setConfigFileReadOnly(false);
            }
            if (l.installed_root != null && l.instance_root != null) {
                // Real install
                _logger.info("[EJBContainerProviderImpl] Using installation location " + l.installed_root.getCanonicalPath());
                bootstrapProperties.setInstallRoot(l.installed_root.getCanonicalPath());
            }
            if (l.instance_root != null && l.reuse_instance_location) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("[EJBContainerProviderImpl] Reusing instance location at: " + l.instance_root);
                }
                _logger.info("[EJBContainerProviderImpl] Using instance location: " + l.instance_root.getCanonicalPath());
                glassFishProperties.setInstanceRoot(l.instance_root.getCanonicalPath());
            } else if (l.domain_file != null) {
                _logger.info("[EJBContainerProviderImpl] Using config file location: " + l.domain_file.toURI().toString());
                glassFishProperties.setConfigFileURI(l.domain_file.toURI().toString());
            }
            addWebContainerIfRequested(properties, glassFishProperties);
            runtime = GlassFishRuntime.bootstrap(bootstrapProperties);
            _logger.info("[EJBContainerProviderImpl] Using runtime class: " + runtime.getClass());
            GlassFish server = runtime.newGlassFish(glassFishProperties);
            if (l.instance_root != null && !l.reuse_instance_location) {
                // XXX Start the server to get the services
                server.start();
                EmbeddedSecurity es = server.getService(EmbeddedSecurity.class);
                ServiceLocator habitat = server.getService(ServiceLocator.class);
                server.stop();
                // If we are running from an existing install, copy over security files to the temp instance
                if (es != null) {
                    es.copyConfigFiles(habitat, l.instance_root, l.domain_file);
                }
            }
            // server is started in EJBContainerImpl constructor
            container = new EJBContainerImpl(server);
            validateInstanceDirectory();
            archiveFactory = server.getService(ArchiveFactory.class);
            Sniffer sniffer = server.getService(Sniffer.class, "Ejb");
            ejbAnnotations = sniffer.getAnnotationTypes();
        } catch (Exception e) {
            try {
                if (container != null) {
                    container.stop();
                }
            } catch (Exception e0) {
                _logger.log(Level.SEVERE, e0.getMessage(), e0);
            }
            container = null;
            throw new EJBException(e);
        }
    // }
    }
    return l;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) EmbeddedSecurity(com.sun.enterprise.security.EmbeddedSecurity) Sniffer(org.glassfish.api.container.Sniffer) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) EJBException(javax.ejb.EJBException) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) IOException(java.io.IOException) EJBException(javax.ejb.EJBException)

Aggregations

GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)35 GlassFish (org.glassfish.embeddable.GlassFish)30 File (java.io.File)24 PrintStream (java.io.PrintStream)21 Deployer (org.glassfish.embeddable.Deployer)21 Test (org.junit.Test)21 CommandRunner (org.glassfish.embeddable.CommandRunner)18 CommandResult (org.glassfish.embeddable.CommandResult)17 JarFile (java.util.jar.JarFile)13 IOException (java.io.IOException)6 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)6 GlassFishException (org.glassfish.embeddable.GlassFishException)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 URI (java.net.URI)3 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 GlassFishRuntime (org.glassfish.embeddable.GlassFishRuntime)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1