Search in sources :

Example 6 with CommandResult

use of org.glassfish.embeddable.CommandResult 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)

Example 7 with CommandResult

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

the class HelloWorldTest method runTests.

private void runTests(GlassFish glassfish) throws Exception {
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + "/target/helloworld.war");
    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";
        List<String> ips = getLBIPAddress(glassfish);
        for (String ip : ips) {
            get("http://" + ip + ":" + HTTP_PORT + "/helloworld/hi.jsp", "PaaS says Hello World!");
        }
    // 4. Undeploy the PaaS application.
    } 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 verify whether undeploy succeeded");
            }
        }
    }
}
Also used : File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult)

Example 8 with CommandResult

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

the class CoffeeTest 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") + "/target/external_db_service_test.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2.1. Generate and run Derby VM
        CommandResult createDerbyVMResult = commandRunner.run("create-derby-vm", "--servicecharacteristics", "service-type=Database");
        System.out.println("\ncreate-derby-vm command output [ " + createDerbyVMResult.getOutput() + "]");
        String derbyIP = (createDerbyVMResult.getOutput().split("\n"))[1];
        System.out.println("Derby IP = " + derbyIP);
        // 2.2. Create the shared DB service
        CommandResult createExternalServiceResult = commandRunner.run("create-external-service", "--configuration", "ip-address=" + derbyIP + ":databasename=foo:connectionAttributes=;'create=true':port=1527:user=APP:password=APP:host=" + derbyIP + ":classname=org.apache.derby.jdbc.ClientXADataSource:resourcetype=javax.sql.XADataSource", "--servicetype", "Database", "coffee-service");
        System.out.println("\ncreate-external-service command output [ " + createExternalServiceResult.getOutput() + "]");
        // 2.3. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        // 2.4. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        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 + "/external_db_service_test/CoffeeServlet", "Coffee ID");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            System.out.println("Destroying the resources created");
            // 4.1. Delete External DB Service.
            CommandResult deleteResult = commandRunner.run("delete-external-service", "coffee-service");
            System.out.println("\ndelete-external-service command output [" + deleteResult.getOutput() + "]");
            // 4.2. Delete generated derby VM
            CommandResult deleteDerbyVMResult = commandRunner.run("delete-derby-vm");
            System.out.println("\ndelete-derby-vm command output [ " + deleteDerbyVMResult.getOutput() + "]");
        }
    }
}
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)

Example 9 with CommandResult

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

the class EmployeeTest 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") + "/target/multiple_app_scoped_service_test.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        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 + "/multiple_app_scoped_service_test/EmployeeServlet", "Employee ID");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_app_scoped_service_test/EmployeeServlet", "Employee Salary");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            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)

Example 10 with CommandResult

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

the class EmployeeTest 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") + "/target/multiple_shared_db_service_test.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2.1. Create the shared DB services
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database", "--configuration", "database.name=hr_database:database.init.sql=/tmp/init.hr-service.sql", "--servicetype", "Database", "hr-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        CommandResult createSharedServiceResult1 = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database:product-vendor=MySQL", "--configuration", "database.name=salary_database:database.init.sql=/tmp/init.salary-service.sql", "--servicetype", "Database", "salary-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult1.getOutput() + "]");
        // 2.2. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        // 2.3. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        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 + "/multiple_shared_db_service_test/EmployeeServlet", "Employee ID");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_shared_db_service_test/EmployeeServlet", "Employee Salary");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            System.out.println("Destroying the resources created");
            // 4.1. Delete Shared DB Service.
            CommandResult deletehrResult = commandRunner.run("delete-shared-service", "hr-service");
            System.out.println("\ndelete-shared-service hr-service command output [" + deletehrResult.getOutput() + "]");
            CommandResult deletesalResult = commandRunner.run("delete-shared-service", "salary-service");
            System.out.println("\ndelete-shared-service salary-service command output [" + deletesalResult.getOutput() + "]");
        }
    }
}
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

CommandResult (org.glassfish.embeddable.CommandResult)85 Test (org.junit.Test)72 CommandRunner (org.glassfish.embeddable.CommandRunner)26 File (java.io.File)21 Deployer (org.glassfish.embeddable.Deployer)21 GlassFish (org.glassfish.embeddable.GlassFish)17 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)17 PrintStream (java.io.PrintStream)16 GarbageCollectorChecker (fish.payara.nucleus.healthcheck.configuration.GarbageCollectorChecker)12 HoggingThreadsChecker (fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker)10 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)10 JarFile (java.util.jar.JarFile)9 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)6 GarbageCollectorHealthCheck (fish.payara.nucleus.healthcheck.preliminary.GarbageCollectorHealthCheck)6 HoggingThreadsHealthCheck (fish.payara.nucleus.healthcheck.preliminary.HoggingThreadsHealthCheck)4 StuckThreadsHealthCheck (fish.payara.nucleus.healthcheck.stuck.StuckThreadsHealthCheck)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 ExecException (com.sun.enterprise.util.ExecException)1