Search in sources :

Example 61 with ParameterMap

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());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 62 with ParameterMap

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();
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Example 63 with 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;
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) Domain(com.sun.enterprise.config.serverbeans.Domain) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap) TreeMap(java.util.TreeMap) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) GET(javax.ws.rs.GET)

Example 64 with ParameterMap

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParameterMap(org.glassfish.api.admin.ParameterMap) List(java.util.List) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 65 with ParameterMap

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;
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) LoginException(javax.security.auth.login.LoginException) RemoteAdminAccessException(org.glassfish.internal.api.RemoteAdminAccessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Payload(org.glassfish.api.admin.Payload) RemoteRestAdminCommand(com.sun.enterprise.admin.remote.RemoteRestAdminCommand) AdminCommand(org.glassfish.api.admin.AdminCommand) CommandRunner(org.glassfish.api.admin.CommandRunner)

Aggregations

ParameterMap (org.glassfish.api.admin.ParameterMap)149 ActionReport (org.glassfish.api.ActionReport)68 CommandRunner (org.glassfish.api.admin.CommandRunner)37 Test (org.junit.Test)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 Map (java.util.Map)20 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)19 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)18 List (java.util.List)16 ArrayList (java.util.ArrayList)15 CommandRunner (org.glassfish.embeddable.CommandRunner)15 IOException (java.io.IOException)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 Before (org.junit.Before)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 CommandException (org.glassfish.api.admin.CommandException)12 File (java.io.File)11 MessagePart (org.glassfish.api.ActionReport.MessagePart)11 Resource (com.sun.enterprise.config.serverbeans.Resource)10 Logger (java.util.logging.Logger)9