use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccessUpdateExisting.
/**
* Test of execute method, creating a new when there is already one.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccessUpdateExisting() {
assertTrue(parameters.size() == 0);
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
// Create another profiler, see if it overrides the existing one
parameters.set("DEFAULT", "testProfilerNew");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the resource was created
boolean isCreated = false;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfilerNew")) {
// assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
// assertEquals("nativelibrarypath", profiler.getNativeLibraryPath());
isCreated = true;
logger.fine("Profiler element testProfilerNew is created.");
}
assertTrue(isCreated);
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class CreateProfilerTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
// Delete the created profiler
ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {
public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
if (param.getProfiler() != null) {
param.setProfiler(null);
}
return null;
}
}, javaConfig);
parameters = new ParameterMap();
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class SystemPropertiesCliResource method get.
@GET
public ActionReportResult get() {
domain = locatorBridge.getRemoteLocator().getService(Domain.class);
ParameterMap data = new ParameterMap();
processCommandParams(data);
addQueryString(uriInfo.getQueryParameters(), data);
adjustParameters(data);
Map<String, Map<String, String>> properties = new TreeMap<String, Map<String, String>>();
RestActionReporter actionReport = new RestActionReporter();
getSystemProperties(properties, getEntity(), false);
actionReport.getExtraProperties().put("systemProperties", new ArrayList(properties.values()));
if (properties.isEmpty()) {
// i18n
actionReport.getTopMessagePart().setMessage("Nothing to list.");
}
ActionReportResult results = new ActionReportResult(commandName, actionReport, new OptionsResult());
return results;
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class AdminAdapter method extractParameters.
/**
* extract parameters from URI and save it in ParameterMap obj
*
* @params requestString string URI to extract
*
* @returns ParameterMap
*/
ParameterMap extractParameters(final String requestString) {
// extract parameters...
final ParameterMap parameters = new ParameterMap();
StringTokenizer stoken = new StringTokenizer(requestString == null ? "" : requestString, QUERY_STRING_SEPARATOR);
while (stoken.hasMoreTokens()) {
String token = stoken.nextToken();
if (token.indexOf("=") == -1)
continue;
String paramName = token.substring(0, token.indexOf("="));
String value = token.substring(token.indexOf("=") + 1);
try {
value = URLDecoder.decode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
aalogger.log(Level.WARNING, KernelLoggerInfo.cantDecodeParameter, new Object[] { paramName, value });
}
parameters.add(paramName, value);
}
// Dump parameters...
if (aalogger.isLoggable(Level.FINER)) {
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String v : entry.getValue()) aalogger.log(Level.FINER, "Key {0} = {1}", new Object[] { entry.getKey(), v });
}
}
return parameters;
}
use of org.glassfish.api.admin.ParameterMap 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 {
Payload.Inbound inboundPayload = PayloadImpl.Inbound.newInstance(req.getContentType(), req.getInputStream());
if (aalogger.isLoggable(Level.FINE)) {
aalogger.log(Level.FINE, "***** AdminAdapter {0} *****", req.getMethod());
}
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;
}
Aggregations