Search in sources :

Example 51 with CommandResult

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

the class ExtSharedServiceEnableDisableTest 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/ext-shared-service-enable-disable-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    // Obtaining the IP address of the DAS
    String ip_address = "127.0.0.1";
    try {
        Enumeration netint_enum = NetworkInterface.getNetworkInterfaces();
        for (Iterator it = Collections.list(netint_enum).iterator(); it.hasNext(); ) {
            NetworkInterface netint = (NetworkInterface) it.next();
            if (netint.getName().equals("virbr0")) {
                Enumeration inetAddresses = netint.getInetAddresses();
                if (inetAddresses.hasMoreElements()) {
                    InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
                    ip_address = inetAddress.toString();
                    ip_address = ip_address.substring(1, ip_address.length());
                    break;
                }
            }
        }
    } catch (SocketException socketException) {
        socketException.printStackTrace();
    }
    Deployer deployer = null;
    String appName = null;
    try {
        {
            // start-database
            ServiceLocator habitat = Globals.getDefaultHabitat();
            ServerContext serverContext = habitat.getService(ServerContext.class);
            String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbhome", serverContext.getInstallRoot().getAbsolutePath() + File.separator + "databases", "--dbhost", ip_address };
            ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
            try {
                startDatabase.execute();
            } catch (ExecException e) {
                e.printStackTrace();
            }
        }
        // Create the shared & external services first, as these services will be referenced by the application
        createSharedAndExternalServices(ip_address);
        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-ext-shared-service-enable-disable-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 + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
        testSharedAndExternalService();
        // 4. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-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 + "]");
            deleteSharedAndExternalService();
            {
                // stop-database
                ServiceLocator habitat = Globals.getDefaultHabitat();
                ServerContext serverContext = habitat.getService(ServerContext.class);
                String[] stopDbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbhost", ip_address };
                ProcessExecutor stopDatabase = new ProcessExecutor(stopDbArgs);
                try {
                    stopDatabase.execute();
                } catch (ExecException e) {
                    e.printStackTrace();
                }
            }
            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) ExecException(com.sun.enterprise.util.ExecException) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) ExecException(com.sun.enterprise.util.ExecException) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServerContext(org.glassfish.internal.api.ServerContext) GlassFish(org.glassfish.embeddable.GlassFish) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 52 with CommandResult

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

the class BookStoreTest 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/bookstore2.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // Create Java EE shared service.
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=JavaEE", "--configuration", "min.clustersize=2:max.clustersize=4", "--servicetype", "JavaEE", "JavaEE_Shared_Service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        // 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() + "]");
        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-bookstore 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 + "/bookstore2/BookStoreServlet", "Please wait while accessing the bookstore database.....");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore2/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://" + instanceIP + ":" + HTTP_PORT + "/bookstore2/BookStoreServlet", "Advanced guide for developing PaaS components");
    // 4. Undeploy the Bookstore application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            CommandResult deleteResult = commandRunner.run("delete-shared-service", "JavaEE_Shared_Service");
            System.out.println("\ndelete-shared-service command output [" + deleteResult.getOutput() + "]");
            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)

Example 53 with CommandResult

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

the class MQSharedServiceTest 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.
    // TODO :: use mvn apis to get the
    File archive = new File("/tmp/ejb30-hello-mdb-ear.ear");
    // 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();
        System.out.println("Deployer: " + deployer);
        System.out.println("archive: " + archive);
        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 mq-shared-service-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        System.out.println("HTTP_PORT : " + HTTP_PORT);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/web/mdbtest", "filterMessage=nulltestattribute=null, initParams:");
    // 4. Undeploy the MQ 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 54 with CommandResult

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

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

the class RunAdminCommandsServlet method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    PrintWriter out = httpServletResponse.getWriter();
    out.println("Inside RunAdminCommandsServlet...");
    out.println("CommandRunner = " + cr);
    if (cr != null) {
        CommandResult result = cr.run("create-jdbc-connection-pool", "--datasourceclassname=org.apache.derby.jdbc.ClientDataSource", "--restype=javax.sql.XADataSource", "--property=portNumber=1527:password=APP:user=APP:serverName=localhost:databaseName=sun-appserv-samples:connectionAttributes=create\\=true", "sample_derby_pool");
        out.println("Ran create-jdbc-connection-pool command. Output = [ " + result.getOutput() + "]");
        result = cr.run("version");
        out.println("Ran version command. Output = [" + result.getOutput() + "]");
    }
    out.flush();
    out.close();
}
Also used : PrintWriter(java.io.PrintWriter) CommandResult(org.glassfish.embeddable.CommandResult)

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