Search in sources :

Example 46 with CommandResult

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

the class BasicbookstoreDnsPaasTest method checkMode.

/* Check the mode of test execution */
public String checkMode(GlassFish glassfish) throws Exception {
    ArrayList params = new ArrayList();
    CommandResult result = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    params.clear();
    params.add("--virtualization");
    params.add("Native");
    result = commandRunner.run("list-templates", (String[]) params.toArray(new String[params.size()]));
    if (result.getOutput().contains("Native")) {
        return "Native";
    }
    params.clear();
    params.add("--virtualization");
    params.add("kvm");
    result = commandRunner.run("list-templates", (String[]) params.toArray(new String[params.size()]));
    if (result.getOutput().contains("apachemodjk")) {
        return "kvm";
    } else {
        return "ovm";
    }
}
Also used : ArrayList(java.util.ArrayList) CommandRunner(org.glassfish.embeddable.CommandRunner) CommandResult(org.glassfish.embeddable.CommandResult)

Example 47 with CommandResult

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

the class BasicbookstoreDnsPaasTest method runTests.

private void runTests(GlassFish glassfish) throws Exception {
    // 2. Deploy the PaaS application.
    File basicArchive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to
    "/basic_paas_sample.war");
    File bookArchive = new File(System.getProperty("basedir") + "/bookstore.war");
    Assert.assertTrue(basicArchive.exists());
    Assert.assertTrue(bookArchive.exists());
    Deployer deployer = null;
    String firstappName = null;
    String secondappName = null;
    BaseTest firstBaseTest = new BaseTest(glassfish);
    BaseTest secondBaseTest = new BaseTest(glassfish);
    try {
        CreateDNSExternalService();
        CreateLbSharedService(glassfish);
        firstappName = firstBaseTest.deploy(basicArchive, "basic_paas_sample", null);
        System.err.println("Deployed [" + firstappName + "]");
        Assert.assertNotNull(firstappName);
        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.
        firstappName = firstappName.replaceAll("_", "-");
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        get("http://" + firstappName + ".hudson.com:" + HTTP_PORT + "/BasicPaaSServlet", "Request headers from the request:");
        secondappName = secondBaseTest.deploy(bookArchive, "bookstore", null);
        System.err.println("Deployed [" + secondappName + "]");
        Assert.assertNotNull(secondappName);
        secondappName = secondappName.replaceAll("_", "-");
        get("http://" + secondappName + ".hudson.com:" + HTTP_PORT + "/BookStoreServlet", "Please wait while accessing the bookstore database.....");
        get("http://" + secondappName + ".hudson.com:" + HTTP_PORT + "/BookStoreServlet?title=Advanced+guide+for+developing+PaaS+components&authors=Shalini+M&price=100%24", "Here are the list of books available in our store:");
        get("http://" + secondappName + ".hudson.com:" + HTTP_PORT + "/BookStoreServlet", "Advanced guide for developing PaaS components");
        get("http://" + firstappName + ".hudson.com:" + HTTP_PORT + "/BasicPaaSServlet", "Request headers from the request:");
        if (secondappName != null) {
            secondBaseTest.undeploy();
            System.err.println("Undeployed [" + secondappName + "]");
        }
        get("http://" + firstappName + ".hudson.com:" + HTTP_PORT + "/BasicPaaSServlet", "Request headers from the request:");
    // 4. Undeploy the PaaS application . TODO :: use cloud-undeploy??
    } finally {
        if (firstappName != null) {
            firstappName = firstappName.replaceAll("-", "_");
            firstBaseTest.undeploy();
            System.err.println("Undeployed [" + firstappName + "]");
            deleteSharedLbandDNSexternalSerivce();
            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) BaseTest(org.glassfish.tests.paas.basetest.BaseTest) CommandRunner(org.glassfish.embeddable.CommandRunner) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult)

Example 48 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/basic_db_teardown_sql.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    List dbConnectionDetails = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2.1. Create the shared DB service
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database", "--configuration", "database.name=foobar", "--servicetype", "Database", "coffee-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        // 2.2. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared", "--output", "service-name, state");
        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 + "/basic_db_teardown_sql/CoffeeServlet", "Coffee ID");
        dbConnectionDetails = getDbConnectionDetails("http://" + instanceIP + ":" + HTTP_PORT + "/basic_db_teardown_sql/DbConnectionDetailsServlet");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            testTearDownSql(dbConnectionDetails);
            System.out.println("Destroying the resources created");
            // 4.1. Delete Shared DB Service.
            CommandResult deleteResult = commandRunner.run("delete-shared-service", "coffee-service");
            System.out.println("\ndelete-shared-service command output [" + deleteResult.getOutput() + "]");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) List(java.util.List) 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 49 with CommandResult

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

the class BasicJPAPaaSTest 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-jpa.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.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-jpa 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-jpa/list", "Here is a list of animals in the zoo.");
    // 4. Undeploy the Zoo catalogue 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 varify whether undeploy succeeded");
            }
        }
    }
}
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) IOException(java.io.IOException) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Example 50 with CommandResult

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

the class BasicServiceDiscoveryPaaSTest 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 apis
    "/target/basic_sd_paas_sample.war");
    // 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";
        testGetServiceMetadata(archive);
        testGenerateGFDeploymentPlan(archive);
    // 4. Undeploy the PaaS-DB application using 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 : 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)

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