use of org.glassfish.embeddable.CommandResult in project Payara by payara.
the class MultipleSPETest 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. Deployment should fail
File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
"/target/basic-spe-test.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.assertNull(appName);
} catch (Exception e) {
System.out.println("$$$$$$$$$$$$$$$$Exception$$$$$$");
} finally {
// 3. Register one of the plugins as the default S.P.E
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("register-service-provisioning-engine", report);
ParameterMap parameterMap = new ParameterMap();
parameterMap.add("type", "Database");
parameterMap.add("defaultservice", "true");
parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
System.out.println("Registered a default SPE :" + !report.hasFailures());
// 4. Deploy the application. Deployment should succeed.
appName = deployer.deploy(archive);
System.err.println("Deployed [" + appName + "]");
Assert.assertNotNull(appName);
// 5. Access the app to make sure PaaS-basic-shared-service-test 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-spe-test/list", "Here is a list of animals in the zoo.");
// Retrieve the port number used by the connection pool
invocation = commandRunner.getCommandInvocation("get", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "server.resources.jdbc-connection-pool.jdbc/__multiple_spe_paas_sample.property.PortNumber");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
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");
}
}
commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
invocation = commandRunner.getCommandInvocation("unregister-service-provisioning-engine", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
System.out.println("Unregistered the default SPE :" + !report.hasFailures());
}
}
use of org.glassfish.embeddable.CommandResult in project Payara by payara.
the class ScaleServicePaaSTest 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/scale_service.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 + "/scale_service/ScaleServicePaaSServlet", "Request headers from the request:");
// test scale up. TODO :: make sure app is accessible from the scaled instance
result = commandRunner.run("_scale-service", "--servicename=scaleservice", "--scalecount=1", "--appname=scale_service");
System.out.println("Output of scale up service [ " + result.getOutput() + "]");
result = commandRunner.run("list-services");
System.out.println("Output of list-services after scaling up [ " + result.getOutput() + "]");
String[] strings = result.getOutput().split("JavaEE");
System.out.println("Number of Java EE services " + strings.length);
Assert.assertEquals(4, strings.length);
// test scale down. TODO :: make sure app is no longer accessible from the scaled down instance
result = commandRunner.run("_scale-service", "--servicename=scaleservice", "--scalecount=-1", "--appname=scale_service");
System.out.println("Output of scale down service [ " + result.getOutput() + "]");
result = commandRunner.run("list-services");
System.out.println("Output of list-services after scaling down [ " + result.getOutput() + "]");
strings = result.getOutput().split("JavaEE");
System.out.println("Number of Java EE services " + strings.length);
Assert.assertEquals(3, strings.length);
// 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.CommandResult in project Payara by payara.
the class BasicPaaSServiceMetadataTest 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_sample2.war");
// get the archive
// location.
Assert.assertTrue(archive.exists());
Deployer deployer = glassfish.getDeployer();
String 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_sample2/BasicPaaSServlet", "Request headers from the request:");
// 4. Undeploy the PaaS application . TODO :: use cloud-undeploy??
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.CommandResult in project Payara by payara.
the class Util method runCommand.
public static void runCommand(String commandLine, String serverId) throws Exception {
GlassFish glassfish = gfMap.get(serverId);
if (glassfish == null) {
throw new Exception("Embedded GlassFish [" + serverId + "] not running");
}
if (commandLine == null) {
throw new Exception("Command can not be null");
}
String[] split = commandLine.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();
}
}
CommandRunner cr = glassfish.getCommandRunner();
CommandResult result = commandParams == null ? cr.run(command) : cr.run(command, commandParams);
System.out.println("Executed command [" + commandLine + "]. Output : \n" + result.getOutput());
}
use of org.glassfish.embeddable.CommandResult in project Payara by payara.
the class BootCommand method execute.
public boolean execute(CommandRunner runner) {
boolean result = true;
CommandResult asadminResult = runner.run(command, arguments);
if (asadminResult.getExitStatus().equals(ExitStatus.FAILURE)) {
LOGGER.log(WARNING, String.format("Boot Command %s failed %s ", command, asadminResult.getOutput()), asadminResult.getFailureCause());
result = false;
} else {
LOGGER.log(INFO, String.format("Boot Command %s returned with result %s : %s", command, asadminResult.getExitStatus(), asadminResult.getOutput()));
}
return result;
}
Aggregations