Search in sources :

Example 26 with Deployer

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

the class BasicSharedServiceTest 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.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-shared-service-test.war");
    // archive location.
    org.junit.Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        // Create the shared services first, as these services will be referenced by the application
        createSharedServices();
        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-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-shared-service-test/list", "Here is a list of animals in the zoo.");
        testSharedService();
        // 4. Access the app to make sure PaaS-basic-shared-service-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic-shared-service-test/list", "Here is a list of animals in the zoo.");
    // 5. Undeploy the Zoo catalogue application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            deleteSharedService();
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                System.out.println(commandResult.getOutput().toString());
                if (commandResult.getOutput().contains("Nothing to list")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) 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)

Example 27 with Deployer

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

the class ScatteredArchiveTest method test.

@Test
public void test() throws Exception {
    GlassFishProperties props = new GlassFishProperties();
    props.setPort("http-listener", 8080);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
    glassfish.start();
    // Test Scattered Web Archive
    ScatteredArchive sa = new ScatteredArchive("scatteredarchive", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
    sa.addClassPath(new File("target/classes"));
    sa.addClassPath(new File("src/main/resources"));
    URI warURI = sa.toURI();
    printContents(warURI);
    // Deploy archive
    Deployer deployer = glassfish.getDeployer();
    String appname = deployer.deploy(warURI);
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "scatteredarchive");
    // Now create a http listener and access the app.
    WebContainer webcontainer = glassfish.getService(WebContainer.class);
    HttpListener listener = new HttpListener();
    listener.setId("my-listener");
    listener.setPort(9090);
    webcontainer.addWebListener(listener);
    get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
    get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    deployer.undeploy(appname);
    // Test Scattered RA
    ScatteredArchive rar = new ScatteredArchive("scatteredra", ScatteredArchive.Type.RAR);
    rar.addClassPath(new File("target/classes"));
    rar.addMetadata(new File("src/main/config/ra.xml"));
    URI rarURI = rar.toURI();
    printContents(rarURI);
    appname = deployer.deploy(rarURI);
    System.out.println("Deployed RAR [" + appname + "]");
    Assert.assertEquals(appname, "scatteredra");
    // Test Scattered Enterprise Archive.
    ScatteredEnterpriseArchive ear = new ScatteredEnterpriseArchive("sear");
    ear.addArchive(warURI, "sa.war");
    ear.addArchive(rarURI);
    ear.addMetadata(new File("src/main/config/application.xml"));
    URI earURI = ear.toURI();
    printContents(earURI);
    appname = deployer.deploy(earURI);
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "sear");
    get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
    get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    glassfish.dispose();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) WebContainer(org.glassfish.embeddable.web.WebContainer) ScatteredEnterpriseArchive(org.glassfish.embeddable.archive.ScatteredEnterpriseArchive) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 28 with Deployer

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

the class RunAdminCommandsTest method test.

@Test
public void test() throws Exception {
    GlassFishProperties props = new GlassFishProperties();
    props.setPort("http-listener", 9090);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
    glassfish.start();
    // Bind the command runner in JNDI tree with your own mapped-name.
    CommandRunner cr = glassfish.getCommandRunner();
    new InitialContext().bind("org.glassfish.embeddable.CommandRunner", cr);
    // Deploy archive
    Deployer deployer = glassfish.getDeployer();
    String appname = deployer.deploy(new File("target/servlet_runs_admin_cmds.war"));
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "servlet_runs_admin_cmds");
    get("http://localhost:9090/servlet_runs_admin_cmds", "JDBC connection pool sample_derby_pool created successfully");
    deployer.undeploy(appname);
    glassfish.dispose();
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) CommandRunner(org.glassfish.embeddable.CommandRunner) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) InitialContext(javax.naming.InitialContext) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 29 with Deployer

use of org.glassfish.embeddable.Deployer 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 30 with Deployer

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

the class ScaleServicePaaSTest method runTests.

private void runTests(GlassFish glassfish) throws Exception {
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to
    "/target/scale_service.war");
    // 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 + "/scale_service/ScaleServicePaaSServlet", "Request headers from the request:");
        // test scale up. TODO :: make sure app is accessible from the scaled instance
        result = commandRunner.run("_scale-service", "--servicename=scaleservice", "--scalecount=1", "--appname=scale_service");
        System.out.println("Output of scale up service [ " + result.getOutput() + "]");
        result = commandRunner.run("list-services");
        System.out.println("Output of list-services after scaling up [ " + result.getOutput() + "]");
        String[] strings = result.getOutput().split("JavaEE");
        System.out.println("Number of Java EE services " + strings.length);
        Assert.assertEquals(4, strings.length);
        // test scale down. TODO :: make sure app is no longer accessible from the scaled down instance
        result = commandRunner.run("_scale-service", "--servicename=scaleservice", "--scalecount=-1", "--appname=scale_service");
        System.out.println("Output of scale down service [ " + result.getOutput() + "]");
        result = commandRunner.run("list-services");
        System.out.println("Output of list-services after scaling down [ " + result.getOutput() + "]");
        strings = result.getOutput().split("JavaEE");
        System.out.println("Number of Java EE services " + strings.length);
        Assert.assertEquals(3, strings.length);
    // 4. Undeploy the PaaS application . TODO :: use cloud-undeploy??
    } finally {
        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");
            }
        }
    }
}
Also used : File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult)

Aggregations

Deployer (org.glassfish.embeddable.Deployer)33 File (java.io.File)32 GlassFish (org.glassfish.embeddable.GlassFish)24 Test (org.junit.Test)24 CommandRunner (org.glassfish.embeddable.CommandRunner)22 CommandResult (org.glassfish.embeddable.CommandResult)21 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)21 PrintStream (java.io.PrintStream)16 JarFile (java.util.jar.JarFile)13 URI (java.net.URI)6 IOException (java.io.IOException)4 InitialContext (javax.naming.InitialContext)4 GlassFishException (org.glassfish.embeddable.GlassFishException)4 URL (java.net.URL)3 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 NamingException (javax.naming.NamingException)2 SampleEjb (org.glassfish.distributions.test.ejb.SampleEjb)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2