use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class FlushInstancesConnectionPool method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Resources resources = domain.getResources();
String scope = "";
if (moduleName != null) {
if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
report.setMessage("Modulename is not that of a valid module: " + moduleName);
report.setActionExitCode(ActionReport.ExitCode.WARNING);
return;
}
Application application = applications.getApplication(applicationName);
Module module = application.getModule(moduleName);
resources = module.getResources();
scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
} else if (applicationName != null) {
if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
report.setMessage("ApplicationName is not that of a valid module: " + applicationName);
report.setActionExitCode(ActionReport.ExitCode.WARNING);
return;
}
Application application = applications.getApplication(applicationName);
resources = application.getResources();
scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
}
if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
report.setMessage("Connection Pool is not valid");
report.setActionExitCode(ActionReport.ExitCode.WARNING);
return;
}
List<Future> instanceFlushes = new ArrayList<>();
for (Server server : domain.getServers().getServer()) {
instanceFlushes.add(executor.submit(new Runnable() {
@Override
public void run() {
ActionReport subReport = report.addSubActionsReport();
try {
if (!server.isRunning()) {
// skip servers that are stopped
return;
}
String host = server.getAdminHost();
int port = server.getAdminPort();
ParameterMap map = new ParameterMap();
map.add("poolName", poolName);
if (applicationName != null) {
map.add("appname", applicationName);
}
if (moduleName != null) {
map.add("modulename", moduleName);
}
if (server.isDas()) {
CommandRunner runner = habitat.getService(CommandRunner.class);
CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("_flush-connection-pool", subReport, context.getSubject());
invocation.parameters(map);
invocation.execute();
} else {
RemoteRestAdminCommand rac = new ServerRemoteRestAdminCommand(habitat, "_flush-connection-pool", host, port, false, "admin", null, LOGGER);
rac.executeCommand(map);
ActionReport result = rac.getActionReport();
subReport.setActionExitCode(result.getActionExitCode());
subReport.setMessage(result.getMessage());
}
} catch (CommandException ex) {
subReport.failure(Logger.getLogger("CONNECTORS-ADMIN"), ex.getLocalizedMessage(), ex);
subReport.appendMessage(server.getName());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}));
}
for (Future future : instanceFlushes) {
try {
future.get();
} catch (InterruptedException | ExecutionException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
}
if (report.hasFailures()) {
report.setActionExitCode(ActionReport.ExitCode.WARNING);
}
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class SetJMXMonitoringConfiguration method enableOnTarget.
/**
* @param actionReport
* @param context
* @param enabled
*/
private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
CommandRunner runner = serviceLocator.getService(CommandRunner.class);
ActionReport subReport = context.getActionReport().addSubActionsReport();
CommandRunner.CommandInvocation invocation;
if (target.equals("server-config")) {
invocation = runner.getCommandInvocation("__enable-jmx-monitoring-service-on-das", subReport, context.getSubject());
} else {
invocation = runner.getCommandInvocation("__enable-jmx-monitoring-service-on-instance", subReport, context.getSubject());
}
// Build the parameters
ParameterMap params = new ParameterMap();
enabled = Boolean.valueOf(jmxMonitoringConfig.getEnabled());
params.add("enabled", enabled.toString());
params.add("target", target);
invocation.parameters(params);
invocation.execute();
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class CreateDockerContainerCommand method unregisterInstance.
/**
* Lifecycle helper method that attempts to remove an instance registry if we failed to create the corresponding
* Docker container
*
* @param adminCommandContext
* @param actionReport
*/
private void unregisterInstance(AdminCommandContext adminCommandContext, ActionReport actionReport) {
if (commandRunner != null) {
actionReport.appendMessage("\n\nWill attempt to unregister instance...");
ActionReport subActionReport = actionReport.addSubActionsReport();
CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("_unregister-instance", subActionReport, adminCommandContext.getSubject());
ParameterMap commandParameters = new ParameterMap();
commandParameters.add("DEFAULT", instanceName);
commandInvocation.parameters(commandParameters);
commandInvocation.execute();
// give a more useful message
if (subActionReport.getActionExitCode() == SUCCESS) {
actionReport.appendMessage("\nSuccessfully unregistered instance");
} else {
actionReport.appendMessage("\nFailed to unregister instance, user intervention will be required");
}
}
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class SetMonitoringConfiguration method enableOnTarget.
/**
* @param actionReport
* @param context
* @param enabled
*/
private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
CommandRunner runner = serviceLocator.getService(CommandRunner.class);
ActionReport subReport = context.getActionReport().addSubActionsReport();
CommandRunner.CommandInvocation invocation;
if (target.equals("server-config")) {
invocation = runner.getCommandInvocation("__enable-monitoring-service-on-das", subReport, context.getSubject());
} else {
invocation = runner.getCommandInvocation("__enable-monitoring-service-on-instance", subReport, context.getSubject());
}
// Build the parameters
ParameterMap params = new ParameterMap();
enabled = Boolean.valueOf(monitoringConfig.getEnabled());
params.add("enabled", enabled.toString());
params.add("target", target);
invocation.parameters(params);
invocation.execute();
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class SetNotificationConfiguration method enableNotificationConfigureOnTarget.
private void enableNotificationConfigureOnTarget(ActionReport actionReport, AdminCommandContext context) {
CommandRunner runner = serviceLocator.getService(CommandRunner.class);
ActionReport subReport = context.getActionReport().addSubActionsReport();
inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject());
ParameterMap params = new ParameterMap();
params.add("enabled", enabled.toString());
params.add("target", target);
params.add("dynamic", dynamic.toString());
inv.parameters(params);
inv.execute();
// swallow the offline warning as it is not a problem
if (subReport.hasWarnings()) {
subReport.setMessage("");
}
}
Aggregations