use of org.glassfish.embeddable.CommandRunner in project Payara by payara.
the class HelloWorldTest method runTests.
private void runTests(GlassFish glassfish) throws Exception {
// 2. Deploy the PaaS application.
File archive = new File(System.getProperty("basedir") + "/target/helloworld.war");
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";
List<String> ips = getLBIPAddress(glassfish);
for (String ip : ips) {
get("http://" + ip + ":" + HTTP_PORT + "/helloworld/hi.jsp", "PaaS says Hello World!");
}
// 4. Undeploy the PaaS 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 verify whether undeploy succeeded");
}
}
}
}
use of org.glassfish.embeddable.CommandRunner in project Payara by payara.
the class HelloWorldTest method getLBIPAddress.
private List<String> getLBIPAddress(GlassFish glassfish) {
List<String> lbIPs = new ArrayList<String>();
String IPAddressPattern = "(([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", "LOAD_BALANCER", "--output", "IP-ADDRESS").getOutput().toString();
if (result.contains("Nothing to list.")) {
result = commandRunner.run("list-services", "--type", "JavaEE", "--output", "IP-ADDRESS").getOutput().toString();
System.out.println("#####" + result);
Pattern p = Pattern.compile(IPAddressPattern);
Matcher m = p.matcher(result);
while (m.find()) {
lbIPs.add(m.group(1));
}
System.out.println("LB IPs = " + lbIPs.toString());
} else {
Pattern p = Pattern.compile(IPAddressPattern);
Matcher m = p.matcher(result);
while (m.find()) {
lbIPs.add(m.group(1));
}
System.out.println("LB IPs = " + lbIPs.toString());
}
} catch (Exception e) {
System.out.println("Regex has thrown an exception " + e.getMessage());
lbIPs.add("localhost");
}
return lbIPs;
}
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/external_db_service_test.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 {
// 2.1. Generate and run Derby VM
CommandResult createDerbyVMResult = commandRunner.run("create-derby-vm", "--servicecharacteristics", "service-type=Database");
System.out.println("\ncreate-derby-vm command output [ " + createDerbyVMResult.getOutput() + "]");
String derbyIP = (createDerbyVMResult.getOutput().split("\n"))[1];
System.out.println("Derby IP = " + derbyIP);
// 2.2. Create the shared DB service
CommandResult createExternalServiceResult = commandRunner.run("create-external-service", "--configuration", "ip-address=" + derbyIP + ":databasename=foo:connectionAttributes=;'create=true':port=1527:user=APP:password=APP:host=" + derbyIP + ":classname=org.apache.derby.jdbc.ClientXADataSource:resourcetype=javax.sql.XADataSource", "--servicetype", "Database", "coffee-service");
System.out.println("\ncreate-external-service command output [ " + createExternalServiceResult.getOutput() + "]");
// 2.3. List services to check for the shared service
CommandResult listSharedServicesResult = commandRunner.run("list-services");
System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
// 2.4. 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 + "/external_db_service_test/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");
// 4.1. Delete External DB Service.
CommandResult deleteResult = commandRunner.run("delete-external-service", "coffee-service");
System.out.println("\ndelete-external-service command output [" + deleteResult.getOutput() + "]");
// 4.2. Delete generated derby VM
CommandResult deleteDerbyVMResult = commandRunner.run("delete-derby-vm");
System.out.println("\ndelete-derby-vm command output [ " + deleteDerbyVMResult.getOutput() + "]");
}
}
}
use of org.glassfish.embeddable.CommandRunner in project Payara by payara.
the class BookStoreTest 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 EmployeeTest 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;
}
Aggregations