Search in sources :

Example 31 with CommandRunner

use of org.glassfish.embeddable.CommandRunner 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/appscoped_db_with_resources_xml.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 {
        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 + "/appscoped_db_with_resources_xml/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");
        }
    }
}
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 32 with CommandRunner

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

the class CoffeeTest 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) IOException(java.io.IOException)

Example 33 with CommandRunner

use of org.glassfish.embeddable.CommandRunner 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 34 with CommandRunner

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

the class BasicbookstoreDnsPaasTest method CreateLbSharedService.

/* Creates LB as a shared service */
public void CreateLbSharedService(GlassFish glassfish) throws Exception {
    ServiceLocator habitat = Globals.getDefaultHabitat();
    org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
    ActionReport report = habitat.getService(ActionReport.class);
    String template = checkMode(glassfish);
    if (template.equalsIgnoreCase("Native")) {
        template = "LBNative";
    } else if (template.equalsIgnoreCase("kvm")) {
        template = "apachemodjk";
    } else {
        template = "otd-new";
    }
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("create-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("template", template);
    parameterMap.add("configuration", "http-port=50080:https-port=50081:ssl-enabled=true:health-check-interval=60:health-check-timeout=10");
    parameterMap.add("servicetype", "LB");
    parameterMap.add("DEFAULT", "hudson-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'hudson-shared-lb-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.embeddable.CommandRunner)

Example 35 with CommandRunner

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

the class BasicbookstoreDnsPaasTest method CreateDNSExternalService.

/*Create DNS external shared service*/
public void CreateDNSExternalService() {
    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("create-external-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "DNS");
    parameterMap.add("configuration", "domain-name=hudson.com:dns-ip=10.178.214.173:dns-private-key-file-loc=" + System.getenv("PAAS_TESTS_HOME") + "/basic-bookstore-dns/Kkey-glassfish.+157+05094.private");
    parameterMap.add("DEFAULT", "hudson-dns-external-services");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created external service 'hudson-dns-external-services' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.embeddable.CommandRunner)

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