use of org.glassfish.embeddable.CommandRunner in project Payara by payara.
the class PayaraContainer method executeCommand.
private String executeCommand(String command, String... parameterList) throws Throwable {
CommandRunner runner = glassfish.getCommandRunner();
CommandResult result = runner.run(command, parameterList);
String output = null;
switch(result.getExitStatus()) {
case FAILURE:
case WARNING:
throw result.getFailureCause();
case SUCCESS:
output = result.getOutput();
log.info("command " + command + " parameters" + parameterList + " result: " + output);
break;
}
return output;
}
use of org.glassfish.embeddable.CommandRunner in project Payara by payara.
the class BasicbookstoreDnsPaasTest method deleteSharedLbandDNSexternalSerivce.
/*Delete shared LB service*/
private void deleteSharedLbandDNSexternalSerivce() {
ServiceLocator habitat = Globals.getDefaultHabitat();
org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
ActionReport report = habitat.getService(ActionReport.class);
// Try stopping a shared service, referenced by the app. Should 'FAIL'
org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
ParameterMap parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "hudson-shared-lb-service");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
invocation = commandRunner.getCommandInvocation("delete-external-service", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "hudson-dns-external-services");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
}
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/basic_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 {
// 2.1. Create the shared DB service
CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database", "--configuration", "database.name=foobar", "--servicetype", "Database", "coffee-service");
System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
// 2.2. List services to check for the shared service
CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared", "--output", "service-name, state");
System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
// 2.3. 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 + "/basic_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");
// 4.1. Delete Shared DB Service.
CommandResult deleteResult = commandRunner.run("delete-shared-service", "coffee-service");
System.out.println("\ndelete-shared-service command output [" + deleteResult.getOutput() + "]");
}
}
}
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 BasicDBPaaSTest 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") + // TODO :: use mvn apis
"/target/basic_db_paas_sample.war");
// to 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";
/**
* Look for a table entry by name SYSFILES in the output to ensure
* DB is provisioned
*/
String instanceIP = getLBIPAddress(glassfish);
get("http://" + instanceIP + ":" + HTTP_PORT + "/basic_db_paas_sample/BasicDBPaaSServlet", "SYSFILES");
// 4. Undeploy the PaaS-DB application using 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");
}
}
}
}
Aggregations