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