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");
}
}
}
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;
}
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";
}
}
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());
}
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());
}
Aggregations