use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class DeleteInstanceCommand method execute.
@Override
public void execute(AdminCommandContext ctx) {
ActionReport report = ctx.getActionReport();
logger = ctx.getLogger();
String msg = "";
boolean fsfailure = false;
boolean configfailure = false;
// We are going to delete a server instance. Get the instance
instance = servers.getServer(instanceName);
if (instance == null) {
msg = Strings.get("start.instance.noSuchInstance", instanceName);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
instanceHost = instance.getAdminHost();
// make sure instance is not running.
if (instance.isRunning()) {
msg = Strings.get("instance.shutdown", instanceName);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// We attempt to delete the instance filesystem first by running
// _delete-instance-filesystem. We then remove the instance
// from the config no matter if we could delete the files or not.
// Get the name of the node from the instance's node-ref field
noderef = instance.getNodeRef();
if (!StringUtils.ok(noderef)) {
msg = Strings.get("missingNodeRef", instanceName);
fsfailure = true;
} else {
theNode = nodes.getNode(noderef);
if (theNode == null) {
msg = Strings.get("noSuchNode", noderef);
fsfailure = true;
}
}
if (!fsfailure) {
nodedir = theNode.getNodeDirAbsolute();
deleteInstanceFilesystem(ctx);
report = ctx.getActionReport();
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
fsfailure = true;
}
msg = report.getMessage();
}
// Now remove the instance from domain.xml.
CommandInvocation ci = cr.getCommandInvocation("_unregister-instance", report, ctx.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", instanceName);
ci.parameters(map);
ci.execute();
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS && report.getActionExitCode() != ActionReport.ExitCode.WARNING) {
// Failed to delete from domain.xml
configfailure = true;
if (fsfailure) {
// Failed to delete instance from fs too
msg = msg + NL + report.getMessage();
} else {
msg = report.getMessage();
}
}
// OK, try to give a helpful message depending on the failure
if (configfailure && fsfailure) {
msg = msg + NL + NL + Strings.get("delete.instance.failed", instanceName, instanceHost);
} else if (configfailure && !fsfailure) {
msg = msg + NL + NL + Strings.get("delete.instance.config.failed", instanceName, instanceHost);
} else if (!configfailure && fsfailure) {
report.setActionExitCode(ActionReport.ExitCode.WARNING);
// leave msg as is
}
if (configfailure) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
}
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class ResourceUtil method runCommand.
/**
* Executes the specified __asadmin command.
* @param commandName
* @param parameters
* @param subject
* @param managedJob
* @return
*/
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob) {
AsadminRecorderService asadminRecorderService = Globals.getDefaultHabitat().getService(AsadminRecorderService.class);
if (asadminRecorderService.isEnabled()) {
asadminRecorderService.recordAsadminCommand(commandName, parameters);
}
CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
RestActionReporter ar = new RestActionReporter();
final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject);
if (managedJob) {
commandInvocation.managedJob();
}
commandInvocation.parameters(parameters).execute();
addCommandLog(ar, commandName, parameters);
return ar;
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class CreateHTTPLoadBalancerCommand method createLBConfig.
private void createLBConfig(String config, final Subject subject) throws CommandException {
CommandInvocation ci = runner.getCommandInvocation("create-http-lb-config", report, subject);
ParameterMap map = new ParameterMap();
// map.add("target", target);
map.add("responsetimeout", responsetimeout);
map.add("httpsrouting", httpsrouting == null ? null : httpsrouting.toString());
map.add("reloadinterval", reloadinterval);
map.add("monitor", monitor == null ? null : monitor.toString());
map.add("routecookie", routecookie == null ? null : routecookie.toString());
map.add("name", config);
ci.parameters(map);
ci.execute();
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class SetRestMonitoringConfigurationCommand method createRequiredMessageSecurityProvider.
private void createRequiredMessageSecurityProvider(ActionReport subActionReport, Subject subject) {
CommandInvocation invocation = commandRunner.getCommandInvocation("create-message-security-provider", subActionReport, subject, false);
ParameterMap parameters = new ParameterMap();
parameters.add("classname", RestMonitoringAuthModule.class.getName());
parameters.add("isdefaultprovider", "false");
parameters.add("layer", "HttpServlet");
parameters.add("providertype", "server");
parameters.add("target", target);
parameters.add("requestauthsource", "sender");
parameters.add("DEFAULT", AUTH_MODULE_NAME);
invocation.parameters(parameters).execute();
}
use of org.glassfish.api.admin.CommandRunner.CommandInvocation in project Payara by payara.
the class SetRestMonitoringConfigurationCommand method defaultRestMonitoringUserExists.
private boolean defaultRestMonitoringUserExists(ActionReport subActionReport, Subject subject) {
boolean exists = false;
CommandInvocation invocation = commandRunner.getCommandInvocation("list-file-users", subActionReport, subject, false);
ParameterMap parameters = new ParameterMap();
parameters.add("authrealmname", "file");
invocation.parameters(parameters).execute();
for (MessagePart message : subActionReport.getTopMessagePart().getChildren()) {
if (message.getMessage().equals(DEFAULT_USER_NAME)) {
exists = true;
break;
}
}
return exists;
}
Aggregations