use of org.glassfish.api.admin.ParameterMap 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.admin.ParameterMap 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.admin.ParameterMap in project Payara by payara.
the class RestartDeploymentGroupCommand method doRolling.
private void doRolling(AdminCommandContext context) {
List<Server> servers = domain.getServersInTarget(deploymentGroup);
StringBuilder output = new StringBuilder();
Logger logger = context.getLogger();
for (Server server : servers) {
ParameterMap instanceParameterMap = new ParameterMap();
// Set the instance name as the operand for the commnd
instanceParameterMap.set("DEFAULT", server.getName());
ActionReport instanceReport = runner.getActionReport("plain");
instanceReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("stop-instance", instanceReport, context.getSubject());
invocation.parameters(instanceParameterMap);
String msg = "stop-instance" + " " + server.getName();
logger.info(msg);
if (verbose) {
output.append(msg).append(NL);
}
invocation.execute();
logger.info(invocation.report().getMessage());
if (verbose) {
output.append(invocation.report().getMessage()).append(NL);
}
instanceParameterMap = new ParameterMap();
// Set the instance name as the operand for the commnd
instanceParameterMap.set("DEFAULT", server.getName());
instanceReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
invocation = runner.getCommandInvocation("start-instance", instanceReport, context.getSubject());
invocation.parameters(instanceParameterMap);
msg = "start-instance" + " " + server.getName();
logger.info(msg);
if (verbose) {
output.append(msg).append(NL);
}
invocation.execute();
logger.info(invocation.report().getMessage());
if (verbose) {
output.append(invocation.report().getMessage()).append(NL);
}
try {
long delayVal = Long.valueOf(delay);
if (delayVal > 0) {
Thread.currentThread().sleep(delayVal);
}
} catch (InterruptedException e) {
}
}
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class StopDeploymentGroupCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
logger.info(Strings.get("stop.dg", deploymentGroup));
// Require that we be a DAS
if (!env.isDas()) {
String msg = Strings.get("cluster.command.notDas");
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
ClusterCommandHelper clusterHelper = new ClusterCommandHelper(domain, runner);
ParameterMap map = null;
if (kill) {
map = new ParameterMap();
map.add("kill", "true");
}
try {
// Run start-instance against each instance in the cluster
String commandName = "stop-instance";
clusterHelper.runCommand(commandName, map, deploymentGroup, context, verbose);
} catch (CommandException e) {
String msg = e.getLocalizedMessage();
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
}
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class InstanceInfo method pingInstance.
// TODO what about security????
private Future<InstanceCommandResult> pingInstance() {
try {
ActionReport aReport = report.addSubActionsReport();
InstanceCommandResult aResult = new InstanceCommandResult();
ParameterMap map = new ParameterMap();
map.set("type", "terse");
InstanceCommandExecutor ice = new InstanceCommandExecutor(habitat, "__locations", FailurePolicy.Error, FailurePolicy.Error, svr, host, port, logger, map, aReport, aResult);
return stateService.submitJob(svr, ice, aResult);
/*
String ret = rac.executeCommand(map).trim();
if (ret == null || (!ret.endsWith("/" + name)))
return -1;
running = true;
String uptimeStr = rac.getAttributes().get("Uptime_value");
return Long.parseLong(uptimeStr);
*/
} catch (CommandException ex) {
running = false;
return null;
}
}
Aggregations