Search in sources :

Example 26 with CommandRunner

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

the class BasicSharedServiceTest method getLBIPAddress.

private String getLBIPAddress(GlassFish glassfish) {
    String lbIP = null;
    String IPAddressPattern = "IP-ADDRESS\\s*\n*(.*)\\s*\n(([01]?\\d*|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([0-9]?\\d\\d?|2[0-4]\\d|25[0-5]))";
    try {
        CommandRunner commandRunner = glassfish.getCommandRunner();
        String result = commandRunner.run("list-services", "--type", "LB", "--output", "IP-ADDRESS").getOutput().toString();
        if (result.contains("Nothing to list.")) {
            result = commandRunner.run("list-services", "--type", "JavaEE", "--output", "IP-ADDRESS").getOutput().toString();
            Pattern p = Pattern.compile(IPAddressPattern);
            Matcher m = p.matcher(result);
            if (m.find()) {
                lbIP = m.group(2);
            } else {
                lbIP = "localhost";
            }
        } else {
            Pattern p = Pattern.compile(IPAddressPattern);
            Matcher m = p.matcher(result);
            if (m.find()) {
                lbIP = m.group(2);
            } else {
                lbIP = "localhost";
            }
        }
    } catch (Exception e) {
        System.out.println("Regex has thrown an exception " + e.getMessage());
        return "localhost";
    }
    return lbIP;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CommandRunner(org.glassfish.embeddable.CommandRunner)

Example 27 with CommandRunner

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

the class BasicPaaSTest method getLBIPAddress.

private String getLBIPAddress(GlassFish glassfish) {
    String lbIP = null;
    String IPAddressPattern = "IP-ADDRESS\\s*\n*(.*)\\s*\n(([01]?\\d*|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([0-9]?\\d\\d?|2[0-4]\\d|25[0-5]))";
    try {
        CommandRunner commandRunner = glassfish.getCommandRunner();
        String result = commandRunner.run("list-services", "--type", "LB", "--output", "IP-ADDRESS").getOutput().toString();
        if (result.contains("Nothing to list.")) {
            result = commandRunner.run("list-services", "--type", "JavaEE", "--output", "IP-ADDRESS").getOutput().toString();
            Pattern p = Pattern.compile(IPAddressPattern);
            Matcher m = p.matcher(result);
            if (m.find()) {
                lbIP = m.group(2);
            } else {
                lbIP = "localhost";
            }
        } else {
            Pattern p = Pattern.compile(IPAddressPattern);
            Matcher m = p.matcher(result);
            if (m.find()) {
                lbIP = m.group(2);
            } else {
                lbIP = "localhost";
            }
        }
    } catch (Exception e) {
        System.out.println("Regex has thrown an exception " + e.getMessage());
        return "localhost";
    }
    return lbIP;
}
Also used : CommandRunner(org.glassfish.embeddable.CommandRunner)

Example 28 with CommandRunner

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

the class BasicPaaSTest 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/basic_paas_sample.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 + "/basic_paas_sample/BasicPaaSServlet", "Request headers from the request:");
    // 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)

Example 29 with CommandRunner

use of org.glassfish.embeddable.CommandRunner 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/bookstore.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-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 + "/bookstore/BookStoreServlet", "Please wait while accessing the bookstore database.....");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore/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 + "/bookstore/BookStoreServlet", "Advanced guide for developing PaaS components");
    // 4. Undeploy the Bookstore 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) 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 30 with CommandRunner

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

the class UberMain method run.

public void run() throws Exception {
    // handle Ctrt-C.
    addShutdownHook();
    GlassFishProperties gfProps = new GlassFishProperties();
    gfProps.setProperty("org.glassfish.embeddable.autoDelete", System.getProperty("org.glassfish.embeddable.autoDelete", "true"));
    gf = GlassFishRuntime.bootstrap().newGlassFish(gfProps);
    gf.start();
    CommandRunner cr = gf.getCommandRunner();
    while (true) {
        System.out.print("\n\nGlassFish $ ");
        String str = null;
        try {
            str = new BufferedReader(new InputStreamReader(System.in)).readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (str != null && str.trim().length() != 0) {
            if ("exit".equalsIgnoreCase(str) || "quit".equalsIgnoreCase(str)) {
                break;
            }
            String[] split = str.split(" ");
            String command = split[0].trim();
            String[] commandParams = null;
            if (split.length > 1) {
                commandParams = new String[split.length - 1];
                for (int i = 1; i < split.length; i++) {
                    commandParams[i - 1] = split[i].trim();
                }
            }
            try {
                CommandResult result = commandParams == null ? cr.run(command) : cr.run(command, commandParams);
                System.out.println("\n" + result.getOutput());
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
        }
    }
    try {
        gf.stop();
        gf.dispose();
    } catch (Exception ex) {
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) CommandResult(org.glassfish.embeddable.CommandResult)

Aggregations

CommandRunner (org.glassfish.embeddable.CommandRunner)60 CommandResult (org.glassfish.embeddable.CommandResult)26 File (java.io.File)22 Deployer (org.glassfish.embeddable.Deployer)22 GlassFish (org.glassfish.embeddable.GlassFish)18 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)18 Test (org.junit.Test)18 Matcher (java.util.regex.Matcher)17 Pattern (java.util.regex.Pattern)17 PrintStream (java.io.PrintStream)16 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)16 ActionReport (org.glassfish.api.ActionReport)15 ParameterMap (org.glassfish.api.admin.ParameterMap)15 IOException (java.io.IOException)12 JarFile (java.util.jar.JarFile)9 List (java.util.List)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)3 ExecException (com.sun.enterprise.util.ExecException)2 Exception (java.lang.Exception)2