use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class AppServerStartup method shutdown.
// TODO(Sahoo): Revisit this method after discussing with Jerome.
private void shutdown() {
CommandRunner runner = commandRunnerProvider.get();
if (runner != null) {
final ParameterMap params = new ParameterMap();
// By default we don't want to shutdown forcefully, as that will cause the VM to exit and that's not
// a very good behavior for a code known to be embedded in other processes.
final boolean noForcedShutdown = Boolean.parseBoolean(context.getArguments().getProperty(com.sun.enterprise.glassfish.bootstrap.Constants.NO_FORCED_SHUTDOWN, "true"));
if (noForcedShutdown) {
params.set("force", "false");
}
final InternalSystemAdministrator kernelIdentity = locator.getService(InternalSystemAdministrator.class);
if (env.isDas()) {
runner.getCommandInvocation("stop-domain", new DoNothingActionReporter(), kernelIdentity.getSubject()).parameters(params).execute();
} else {
runner.getCommandInvocation("_stop-instance", new DoNothingActionReporter(), kernelIdentity.getSubject()).parameters(params).execute();
}
}
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class InserverCommandRunnerHelper method runCommand.
public ActionReport runCommand(final String command, final ParameterMap parameters, final ActionReport report, final Subject subject) {
try {
final AdminCommand adminCommand = commandRunner.getCommand(command, report, logger);
if (adminCommand == null) {
// maybe commandRunner already reported the failure?
if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE)
return report;
String message = adminStrings.getLocalString("adapter.command.notfound", "Command {0} not found", command);
// cound't find command, not a big deal
logger.log(Level.FINE, message);
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return report;
}
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(command, report, subject);
inv.parameters(parameters).execute();
} catch (Throwable t) {
/*
* Must put the error information into the report
* for the client to see it.
*/
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(t);
report.setMessage(t.getLocalizedMessage());
report.setActionDescription("Last-chance exception handler");
}
return report;
}
use of org.glassfish.api.admin.CommandRunner in project Payara by payara.
the class DeployRemoteArchiveCommand method execute.
@Override
public void execute(AdminCommandContext context) {
CommandRunner commandRunner = serviceLocator.getService(CommandRunner.class);
ActionReport actionReport = context.getActionReport();
// Initialise to null so we can do a null check later
File fileToDeploy = null;
// Should treat uppercase letters as equivalent to lowercase
// in schema names (section 3.1 of the RFC 2396)
String lowerPath = path.toLowerCase();
// Assume only Http or Https connections are direct URIs
if (lowerPath.startsWith("http://") || lowerPath.startsWith("https://")) {
try {
URI pathURI = new URI(path);
// Download the file to temp, and return a File object to pass to the deploy command
fileToDeploy = URIUtils.convertToFile(pathURI);
// Get file name from URI
String fileName = new File(pathURI.getPath()).getName();
// If a name hasn't been provided, get it from the file name
if (name == null) {
name = JavaArchiveUtils.removeJavaArchiveExtension(fileName, true);
}
// If a context root hasn't been provided, get it from the file name
if (contextroot == null) {
contextroot = "/" + JavaArchiveUtils.removeJavaArchiveExtension(fileName, true);
}
} catch (IOException | URISyntaxException ex) {
logger.log(Level.SEVERE, ex.getMessage());
actionReport.setMessage("Exception converting URI to File: " + path);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
} else {
try {
// If the path String doesn't start with Http or Https, then assume it's a GAV coordinate
logger.log(Level.FINE, "Path does not appear to be a URI, will attempt to read as GAV coordinate");
// Get the URI for the given GAV coordinate
Entry<String, URI> artefactEntry = GAVConvertor.getArtefactMapEntry(path, additionalRepositories);
// Download the file to temp, and return a File object to pass to the deploy command
fileToDeploy = URIUtils.convertToFile(artefactEntry.getValue());
// If a name hasn't been provided, get it from the artefact URI
if (name == null) {
String fileName = new File(artefactEntry.getValue().getPath()).getName();
name = JavaArchiveUtils.removeJavaArchiveExtension(fileName, true);
}
// If a context root hasn't been provided, get it from the artefact name
if (contextroot == null) {
contextroot = "/" + artefactEntry.getKey();
}
} catch (IOException | URISyntaxException ex) {
logger.log(Level.SEVERE, ex.getMessage());
actionReport.setMessage("Exception converting GAV to File: " + path);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
// Only continue if we actually have a file to deploy
if (fileToDeploy != null) {
ActionReport subReport = actionReport.addSubActionsReport();
CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("deploy", subReport, context.getSubject());
ParameterMap parameters = createAndPopulateParameterMap(fileToDeploy);
commandInvocation.parameters(parameters);
commandInvocation.execute();
} else {
actionReport.setMessage("Provided path does not appear to be a valid URI or GAV coordinate: " + path + "\nSee the server log for more details");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of org.glassfish.api.admin.CommandRunner 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.get(AsadminRecorderService.class);
if (asadminRecorderService != null && asadminRecorderService.isEnabled()) {
asadminRecorderService.recordAsadminCommand(commandName, parameters);
}
AdminAuditService auditService = Globals.getDefaultHabitat().getService(AdminAuditService.class);
if (auditService != null && auditService.isEnabled()) {
auditService.recordAsadminCommand(commandName, parameters, subject);
}
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 in project Payara by payara.
the class PayaraServerNameGenerator method getNodeNames.
private static List<String> getNodeNames(ActionReport report, AdminCommandContext context, CommandRunner commandRunner) {
List<String> nodeNames = new ArrayList<>();
CommandRunner.CommandInvocation listNodesCommand = commandRunner.getCommandInvocation("list-nodes", report, context.getSubject());
listNodesCommand.execute();
Properties extraProperties = listNodesCommand.report().getExtraProperties();
if (extraProperties != null) {
nodeNames.addAll((List<String>) extraProperties.get("nodeNames"));
}
return nodeNames;
}
Aggregations