Search in sources :

Example 1 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class CommandResource method executeCommand.

private Response executeCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, boolean supportsMultiparResult, String xIndentHeader, String modelETag, Cookie jSessionId) throws WebApplicationException {
    // Scope support
    if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
        RestLogging.restLogger.log(Level.FINEST, "executeCommand(): ", commandName);
    }
    // Check command model
    CommandModel model = getCommandModel(commandName);
    checkCommandModelETag(model, modelETag);
    // Execute it
    boolean notifyOption = false;
    if (params != null) {
        notifyOption = params.containsKey("notify");
    }
    // new RestActionReporter(); //Must use PropsFileActionReporter because some commands react diferently on it :-(
    ActionReporter ar = new PropsFileActionReporter();
    final RestPayloadImpl.Outbound outbound = new RestPayloadImpl.Outbound(false);
    final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), ar, getSubject(), notifyOption);
    if (inbound != null) {
        commandInvocation.inbound(inbound);
    }
    commandInvocation.outbound(outbound).parameters(params).execute();
    ar = (ActionReporter) commandInvocation.report();
    fixActionReporterSpecialCases(ar);
    ActionReport.ExitCode exitCode = ar.getActionExitCode();
    int status = HttpURLConnection.HTTP_OK;
    /*200 - ok*/
    if (exitCode == ActionReport.ExitCode.FAILURE) {
        status = HttpURLConnection.HTTP_INTERNAL_ERROR;
    }
    ResponseBuilder rb = Response.status(status);
    if (xIndentHeader != null) {
        rb.header("X-Indent", xIndentHeader);
    }
    if (supportsMultiparResult && outbound.size() > 0) {
        ParamsWithPayload pwp = new ParamsWithPayload(outbound, ar);
        rb.entity(pwp);
    } else {
        rb.type(MediaType.APPLICATION_JSON_TYPE);
        rb.entity(ar);
    }
    if (isSingleInstanceCommand(model)) {
        rb.cookie(getJSessionCookie(jSessionId));
    }
    return rb.build();
}
Also used : PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) ActionReport(org.glassfish.api.ActionReport) ActionReporter(com.sun.enterprise.admin.report.ActionReporter) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) ParamsWithPayload(com.sun.enterprise.admin.remote.ParamsWithPayload) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RestPayloadImpl(com.sun.enterprise.admin.remote.RestPayloadImpl)

Example 2 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class ActionReportResultHtmlProvider method processReport.

protected String processReport(ActionReporter ar) {
    StringBuilder result = new StringBuilder();
    String des = ar.getActionDescription();
    // check for no description, make it blank
    if (des == null) {
        des = "";
    }
    final String message = ResourceUtil.encodeString((ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
    if (message != null) {
        result.append("<h2>").append(des).append(" output:</h2><h3>").append("<pre>").append(message).append("</pre>").append(HEADING_END);
    }
    if (ar.getActionExitCode() != ExitCode.SUCCESS) {
        result.append("<h3>Exit Code: ").append(ar.getActionExitCode().toString()).append(HEADING_END);
    }
    Properties properties = ar.getTopMessagePart().getProps();
    if (!properties.isEmpty()) {
        result.append(processProperties(properties));
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        if ((extraProperties.size() == 1) && (extraProperties.get("methods") != null)) {
        // do not show only methods metadata in html, not really needed
        } else {
            result.append(getExtraProperties(extraProperties));
        }
    }
    List<ActionReport.MessagePart> children = ar.getTopMessagePart().getChildren();
    if (!children.isEmpty()) {
        result.append(processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if (!subReports.isEmpty()) {
        result.append(processSubReports(subReports));
    }
    return result.toString();
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.admin.report.ActionReporter) Properties(java.util.Properties)

Example 3 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class ActionReportXmlProvider method processReport.

protected XmlObject processReport(ActionReporter ar) {
    XmlMap result = new XmlMap("map");
    result.put("message", (ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
    result.put("command", ar.getActionDescription());
    result.put("exit_code", ar.getActionExitCode().toString());
    Properties properties = ar.getTopMessagePart().getProps();
    if ((properties != null) && (!properties.isEmpty())) {
        result.put("properties", new XmlMap("properties", properties));
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        result.put("extraProperties", getExtraProperties(result, extraProperties));
    }
    List<MessagePart> children = ar.getTopMessagePart().getChildren();
    if ((children != null) && (!children.isEmpty())) {
        result.put("children", processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if ((subReports != null) && (!subReports.isEmpty())) {
        result.put("subReports", processSubReports(subReports));
    }
    return result;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) XmlMap(org.glassfish.admin.rest.utils.xml.XmlMap) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.admin.report.ActionReporter)

Example 4 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class PlainTextActionReporterTest method aggregateTest.

@Test
public void aggregateTest() {
    ActionReporter successfulRoot = new PlainTextActionReporter();
    assert successfulRoot.hasSuccesses();
    assert !successfulRoot.hasFailures();
    assert !successfulRoot.hasWarnings();
    ActionReport failedChild = successfulRoot.addSubActionsReport();
    failedChild.setActionExitCode(ActionReport.ExitCode.FAILURE);
    assert successfulRoot.hasSuccesses();
    assert successfulRoot.hasFailures();
    assert !successfulRoot.hasWarnings();
    assert !failedChild.hasSuccesses();
    assert !failedChild.hasWarnings();
    assert failedChild.hasFailures();
    ActionReport warningChild = failedChild.addSubActionsReport();
    warningChild.setActionExitCode(ActionReport.ExitCode.WARNING);
    assert successfulRoot.hasSuccesses();
    assert successfulRoot.hasFailures();
    assert successfulRoot.hasWarnings();
    assert !failedChild.hasSuccesses();
    assert failedChild.hasWarnings();
    assert failedChild.hasFailures();
    assert warningChild.hasWarnings();
    assert !warningChild.hasSuccesses();
    ActionReport successfulChild = warningChild.addSubActionsReport();
    assert failedChild.hasSuccesses();
    assert warningChild.hasSuccesses();
    assert !warningChild.hasFailures();
    StringBuilder sb = new StringBuilder();
    successfulRoot.setMessage("sr");
    successfulRoot.getCombinedMessages(successfulRoot, sb);
    assertEquals("sr", sb.toString());
    warningChild.setMessage("wc");
    sb = new StringBuilder();
    successfulRoot.getCombinedMessages(successfulRoot, sb);
    assertEquals("sr\nwc", sb.toString());
    failedChild.setMessage("fc");
    sb = new StringBuilder();
    successfulRoot.getCombinedMessages(successfulRoot, sb);
    assertEquals("sr\nfc\nwc", sb.toString());
}
Also used : ActionReporter(com.sun.enterprise.admin.report.ActionReporter) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) Test(org.junit.Test)

Example 5 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class GetTokensCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReporter report = (ActionReporter) context.getActionReport();
    PropertyResolver resolver = new PropertyResolver(domain, target);
    String sep = "";
    String eol = System.getProperty("line.separator");
    StringBuilder output = new StringBuilder();
    Map<String, String> values = new TreeMap<String, String>();
    Properties properties = new Properties();
    properties.put("tokens", values);
    for (String token : tokens) {
        String value = resolver.getPropertyValue(token);
        if ((value == null) && (checkSystemProperties)) {
            value = System.getProperty(token);
        }
        output.append(sep).append(token).append(" = ").append(value);
        sep = eol;
        values.put(token, value);
    }
    report.setMessage(output.toString());
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    report.setExtraProperties(properties);
}
Also used : ActionReporter(com.sun.enterprise.admin.report.ActionReporter) PropertyResolver(org.glassfish.config.support.PropertyResolver) TreeMap(java.util.TreeMap) Properties(java.util.Properties)

Aggregations

ActionReporter (com.sun.enterprise.admin.report.ActionReporter)9 Properties (java.util.Properties)3 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)3 PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ActionReport (org.glassfish.api.ActionReport)2 MessagePart (org.glassfish.api.ActionReport.MessagePart)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 RestPayloadImpl (com.sun.enterprise.admin.remote.RestPayloadImpl)1 PropsFileActionReporter (com.sun.enterprise.admin.report.PropsFileActionReporter)1 CachedCommandModel (com.sun.enterprise.admin.util.CachedCommandModel)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Server (com.sun.enterprise.config.serverbeans.Server)1 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)1 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)1 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)1 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)1 TreeMap (java.util.TreeMap)1 JsonObject (javax.json.JsonObject)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1