use of org.glassfish.api.ActionReport in project Payara by payara.
the class SharedAndExternalServiceTest method testSharedAndExternalService.
private void testSharedAndExternalService() {
System.out.println("$$$$$$$$$$$$$ TEST SHARED AND EXTERNAL SERVICES $$$$$$$$$$$$$$$");
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("stop-shared-service", report);
ParameterMap parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-shared-lb-service");
invocation.parameters(parameterMap).execute();
System.out.print("Expected Failure message: " + report.getMessage());
Assert.assertTrue(report.hasFailures());
// Try deleting a shared service, referenced by the app. Should 'FAIL'
report = habitat.getService(ActionReport.class);
invocation = commandRunner.getCommandInvocation("delete-shared-service", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-shared-lb-service");
invocation.parameters(parameterMap).execute();
System.out.print("Expected Failure message: " + report.getMessage());
Assert.assertTrue(report.hasFailures());
// Try deleting a external service, referenced by the app. Should 'FAIL'
invocation = commandRunner.getCommandInvocation("delete-external-service", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-external-db-service");
invocation.parameters(parameterMap).execute();
System.out.println("Expected Failure message: " + report.getMessage());
Assert.assertTrue(report.hasFailures());
invocation = commandRunner.getCommandInvocation("stop-shared-service", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-shared-lb-service");
invocation.parameters(parameterMap).execute();
Assert.assertTrue(report.hasFailures());
System.out.print("Expected failure MSG: " + report.getMessage());
// List the services and check the status of both the services - it should be 'RUNNING'
invocation = commandRunner.getCommandInvocation("list-services", report);
parameterMap = new ParameterMap();
parameterMap.add("scope", "shared");
parameterMap.add("output", "service-name,state");
invocation.parameters(parameterMap).execute();
boolean sharedServiceStarted = false;
List<Map<String, String>> list = (List<Map<String, String>>) report.getExtraProperties().get("list");
for (Map<String, String> map : list) {
sharedServiceStarted = false;
String state = map.get("STATE");
if ("RUNNING".equalsIgnoreCase(state)) {
sharedServiceStarted = true;
} else {
break;
}
}
// check if the shared services are started.
Assert.assertTrue(sharedServiceStarted);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class SharedAndExternalServiceTest method deleteSharedAndExternalService.
private void deleteSharedAndExternalService() {
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("delete-shared-service", report);
ParameterMap parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-shared-lb-service");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
invocation = commandRunner.getCommandInvocation("delete-external-service", report);
parameterMap = new ParameterMap();
parameterMap.add("DEFAULT", "my-external-db-service");
invocation.parameters(parameterMap).execute();
Assert.assertFalse(report.hasFailures());
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class RollbackTransaction method execute.
/**
* Executes the command
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
transactionMgr.forceRollback(txnId);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setMessage(localStrings.getString("rollback.transaction.failed"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class UpdateNodeCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
Node node = nodes.getNode(name);
if (node == null) {
// node doesn't exist
String msg = Strings.get("noSuchNode", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// validate installdir if passed and running on localhost
if (StringUtils.ok(nodehost)) {
if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
TokenResolver resolver = null;
// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
// like the install directory or node directory.
if (node.nodeInUse()) {
String badparam = null;
String configNodedir = node.getNodeDir();
String configInstalldir = node.getInstallDir();
if (!allowableChange(nodedir, configNodedir)) {
badparam = "nodedir";
}
if (!allowableChange(installdir, configInstalldir)) {
badparam = "installdir";
}
if (StringUtils.ok(badparam)) {
String msg = Strings.get("noUpdate.nodeInUse", name, badparam);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
try {
updateNodeElement(name);
} catch (TransactionFailure e) {
logger.warning("failed.to.update.node " + name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class UpdateNodeConfigCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
StringBuilder msg = new StringBuilder();
Node node = null;
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
logger = context.getLogger();
// Make sure Node is valid
node = nodes.getNode(name);
if (node == null) {
String m = Strings.get("noSuchNode", name);
logger.warning(m);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(m);
return;
}
if (node.isDefaultLocalNode()) {
String m = Strings.get("update.node.config.defaultnode", name);
logger.warning(m);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(m);
return;
}
// After updating the config node it needs to have a host
if (!StringUtils.ok(nodehost) && !StringUtils.ok(node.getNodeHost())) {
String m = Strings.get("update.node.config.missing.attribute", node.getName(), NodeUtils.PARAM_NODEHOST);
logger.warning(m);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(m);
return;
}
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
if (installdir != null) {
map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
}
if (nodehost != null) {
map.add(NodeUtils.PARAM_NODEHOST, nodehost);
}
if (nodedir != null) {
map.add(NodeUtils.PARAM_NODEDIR, nodedir);
}
map.add(NodeUtils.PARAM_TYPE, "CONFIG");
if (map.size() > 1) {
CommandInvocation ci = cr.getCommandInvocation("_update-node", report, context.getSubject());
ci.parameters(map);
ci.execute();
if (StringUtils.ok(report.getMessage())) {
if (msg.length() > 0) {
msg.append(NL);
}
msg.append(report.getMessage());
}
report.setMessage(msg.toString());
}
}
Aggregations