use of org.glassfish.api.admin.AdminCommand in project Payara by payara.
the class RuntimeRootImpl method restartDomain.
public void restartDomain() {
final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
final AdminCommandContext ctx = new AdminCommandContextImpl(AMXLoggerInfo.getLogger(), new PlainTextActionReporter());
final AdminCommand cmd = new RestartDomainCommand(registry);
cmd.execute(ctx);
}
use of org.glassfish.api.admin.AdminCommand in project Payara by payara.
the class ListCommandDescriptorsCommand method execute.
@Override
public void execute(AdminCommandContext context) {
setAdminCommands();
sort();
for (AdminCommand cmd : adminCmds) {
cliCmds.add(reflect(cmd));
}
ActionReport report = context.getActionReport();
StringBuilder sb = new StringBuilder();
sb.append("ALL COMMANDS: ").append(EOL);
for (CLICommand cli : cliCmds) {
sb.append(cli.toString()).append(EOL);
}
report.setMessage(sb.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.admin.AdminCommand 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.AdminCommand in project Payara by payara.
the class AdminAdapter method doCommand.
private ActionReport doCommand(String requestURI, Request req, ActionReport report, Payload.Outbound outboundPayload, Subject subject) throws ProcessHttpCommandRequestException {
if (!requestURI.startsWith(getContextRoot())) {
String msg = adminStrings.getLocalString("adapter.panic", "Wrong request landed in AdminAdapter {0}", requestURI);
report.setMessage(msg);
LogHelper.getDefaultLogger().info(msg);
return report;
}
// wbn handle no command and no slash-suffix
String command = "";
if (requestURI.length() > getContextRoot().length() + 1) {
command = requestURI.substring(getContextRoot().length() + 1);
}
String scope = getScope(command);
command = getCommandAfterScope(command);
String qs = req.getQueryString();
final ParameterMap parameters = extractParameters(qs);
String passwordOptions = req.getHeader("X-passwords");
if (passwordOptions != null) {
decodePasswords(parameters, passwordOptions);
}
try {
// If the upload option is present and false, this needs converting to a path
String uploadValue = parameters.getOne("upload");
if ("false".equalsIgnoreCase(uploadValue)) {
Buffer contentBuffer = req.getInputBuffer().getBuffer();
int capacity = contentBuffer.capacity();
byte[] path = new byte[capacity];
for (int i = 0; i < capacity; i++) {
path[i] = contentBuffer.get(i);
}
// path as passed in
parameters.add("path", new String(path));
// remove to prevent exception as this is not a param in the command class
parameters.remove("upload");
}
Payload.Inbound inboundPayload = PayloadImpl.Inbound.newInstance(req.getContentType(), req.getInputStream());
if (aalogger.isLoggable(Level.FINE)) {
aalogger.log(Level.FINE, "***** AdminAdapter {0} *****", req.getMethod());
}
// or not the upload flag is set.
if ("true".equalsIgnoreCase(uploadValue)) {
// This is a file that needs to be extracted
File extractLocation = new File(domain.getApplicationRoot() + File.separator + "upload-" + inboundPayload.hashCode() + File.separator);
if (!extractLocation.mkdirs()) {
aalogger.log(Level.WARNING, strings.getLocalString("payload.mkdirsFailed", "Attempt to create directories for {0} failed; no further information is available. Continuing.", extractLocation.getAbsolutePath()));
}
PayloadFilesManager.Perm permFileManager = new PayloadFilesManager.Perm(extractLocation, null, aalogger);
permFileManager.processParts(inboundPayload);
parameters.add("path", extractLocation.toString());
parameters.remove("upload");
}
AdminCommand adminCommand = commandRunner.getCommand(scope, command, report, aalogger);
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
aalogger.log(Level.FINE, message);
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return report;
}
// Validate admin command eTag
String modelETag = req.getHeader(RemoteRestAdminCommand.COMMAND_MODEL_MATCH_HEADER);
if (modelETag != null && !commandRunner.validateCommandModelETag(adminCommand, modelETag)) {
String message = adminStrings.getLocalString("commandmodel.etag.invalid", "Cached command model for command {0} is invalid.", command);
aalogger.log(Level.FINE, message);
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new ProcessHttpCommandRequestException(report, HttpStatus.PRECONDITION_FAILED_412);
}
// Execute
if (validatePrivacy(adminCommand)) {
// if (adminCommand.getClass().getAnnotation(Visibility.class).privacy().equals(visibility.privacy())) {
// todo : needs to be changed, we should reuse adminCommand
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(scope, command, report, subject, parameters.containsKey("notify"));
inv.parameters(parameters).inbound(inboundPayload).outbound(outboundPayload).execute();
try {
// note it has become extraordinarily difficult to change the reporter!
CommandRunnerImpl.ExecutionContext inv2 = (CommandRunnerImpl.ExecutionContext) inv;
report = inv2.report();
} catch (Exception e) {
}
} else {
report.failure(aalogger, adminStrings.getLocalString("adapter.wrongprivacy", "Command {0} does not have {1} visibility", command, privacyClass.getSimpleName().toLowerCase(Locale.ENGLISH)), null);
return report;
}
} catch (ProcessHttpCommandRequestException reqEx) {
throw reqEx;
} 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 AdminAdapter exception handler");
}
return report;
}
use of org.glassfish.api.admin.AdminCommand in project Payara by payara.
the class CommandResourceMetaData method getRestRedirectPointToBean.
@SuppressWarnings("unchecked")
public static List<CommandResourceMetaData> getRestRedirectPointToBean(String beanName) {
synchronized (restRedirects) {
if (restRedirects.isEmpty()) {
final ServiceLocator habitat = Globals.getDefaultHabitat();
processConfigBeans(habitat);
List<ActiveDescriptor<?>> iter = habitat.getDescriptors(BuilderHelper.createContractFilter(AdminCommand.class.getName()));
for (ActiveDescriptor<?> ad : iter) {
if (!(ad.getQualifiers().contains(RestEndpoints.class.getName()))) {
continue;
}
if (!ad.isReified()) {
try {
habitat.reifyDescriptor(ad);
} catch (MultiException me) {
// If we can't see the command, forget it
continue;
}
}
final Class<? extends AdminCommand> clazz = (Class<? extends AdminCommand>) ad.getImplementationClass();
RestEndpoints endpoints = clazz.getAnnotation(RestEndpoints.class);
if (endpoints != null) {
RestEndpoint[] list = endpoints.value();
if ((list != null) && (list.length > 0)) {
for (RestEndpoint endpoint : list) {
Service service = clazz.getAnnotation(Service.class);
String configBean = endpoint.configBean().getSimpleName();
CommandResourceMetaData metaData = new CommandResourceMetaData();
metaData.command = service.name();
metaData.httpMethod = endpoint.opType().name();
metaData.resourcePath = endpoint.path().isEmpty() ? service.name() : endpoint.path();
metaData.displayName = endpoint.description().isEmpty() ? metaData.resourcePath : endpoint.description();
metaData.commandParams = new ParameterMetaData[endpoint.params().length];
int index = 0;
for (RestParam param : endpoint.params()) {
ParameterMetaData currentParam = new ParameterMetaData();
metaData.commandParams[index] = currentParam;
currentParam.name = param.name();
currentParam.value = param.value();
index++;
}
addCommandMetaData(configBean, metaData);
}
}
}
}
}
}
return restRedirects.get(beanName);
}
Aggregations