Search in sources :

Example 1 with GlassFish

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

the class Util method startGlassFish.

public static synchronized GlassFish startGlassFish(String serverID, String installRoot, String instanceRoot, String configFileURI, boolean configFileReadOnly, int httpPort) throws GlassFishException {
    GlassFish glassfish = gfMap.get(serverID);
    if (glassfish != null) {
        return glassfish;
    }
    if (glassfishRuntime == null) {
        BootstrapProperties bootstrapProperties = new BootstrapProperties();
        if (installRoot != null) {
            bootstrapProperties.setInstallRoot(installRoot);
        }
        glassfishRuntime = GlassFishRuntime.bootstrap(bootstrapProperties);
    }
    GlassFishProperties glassfishProperties = new GlassFishProperties();
    if (instanceRoot != null) {
        glassfishProperties.setInstanceRoot(instanceRoot);
    }
    if (configFileURI != null) {
        glassfishProperties.setConfigFileURI(configFileURI);
        glassfishProperties.setConfigFileReadOnly(configFileReadOnly);
    }
    if (instanceRoot == null && configFileURI == null) {
        // only set port if embedded domain.xml is used
        if (httpPort != -1) {
            glassfishProperties.setPort("http-listener", httpPort);
        }
    }
    glassfish = glassfishRuntime.newGlassFish(glassfishProperties);
    glassfish.start();
    gfMap.put(serverID, glassfish);
    System.out.println("Started GlassFish [" + serverID + "]");
    return glassfish;
}
Also used : BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 2 with GlassFish

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

the class Util method disposeGlassFish.

public static synchronized void disposeGlassFish(String serverID) throws GlassFishException {
    GlassFish glassfish = gfMap.remove(serverID);
    if (glassfish != null) {
        glassfish.dispose();
        System.out.println("Stopped GlassFish [" + serverID + "]");
    }
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish)

Example 3 with GlassFish

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

the class ScaleServicePaaSTest method test.

@Test
public void test() throws Exception {
    // Bootstrap GlassFish DAS in embedded mode.
    GlassFish glassfish = bootstrap();
    // Deploy the PaaS app and verify it.
    runTests(glassfish);
    // Re-deploy the PaaS app and verify it.
    String testScenarios = System.getProperty("test.scenarios");
    if (testScenarios == null || "all".contains(testScenarios.toLowerCase())) {
        runTests(glassfish);
    }
    // 5. Stop the GlassFish DAS
    glassfish.dispose();
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) Test(org.junit.Test)

Example 4 with GlassFish

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

the class ScaleServicePaaSTest 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 5 with GlassFish

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

the class CustomDBNameTest 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 application.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn
    "/target/custom_db_name_paas_sample.war");
    // apis to get
    // the 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.assertNotNull(appName);
        CommandRunner commandRunner = glassfish.getCommandRunner();
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS 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 + "/custom_db_name_paas_sample/CustomDBNameServlet", "Customer ID");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.out.println("Destroying the resources created");
            System.err.println("Undeployed [" + appName + "]");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) 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) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Aggregations

GlassFish (org.glassfish.embeddable.GlassFish)44 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)29 Test (org.junit.Test)27 Deployer (org.glassfish.embeddable.Deployer)24 File (java.io.File)23 PrintStream (java.io.PrintStream)21 CommandRunner (org.glassfish.embeddable.CommandRunner)18 CommandResult (org.glassfish.embeddable.CommandResult)17 JarFile (java.util.jar.JarFile)12 GlassFishException (org.glassfish.embeddable.GlassFishException)6 IOException (java.io.IOException)4 URI (java.net.URI)4 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)2 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1