Search in sources :

Example 1 with PropsFileActionReporter

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

the class CommandResource method executeSseCommand.

private Response executeSseCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, String modelETag, Cookie jSessionId) throws WebApplicationException {
    // Scope support
    if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
        RestLogging.restLogger.log(Level.FINEST, "executeSseCommand(): ", commandName);
    }
    // Check command model
    CommandModel model = getCommandModel(commandName);
    checkCommandModelETag(model, modelETag);
    // Execute it
    boolean notifyOption = false;
    if (params != null) {
        notifyOption = params.containsKey("notify");
    }
    final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), new PropsFileActionReporter(), getSubject(), notifyOption);
    if (inbound != null) {
        commandInvocation.inbound(inbound);
    }
    commandInvocation.outbound(new RestPayloadImpl.Outbound(false)).managedJob().parameters(params);
    ResponseBuilder rb = Response.status(HttpURLConnection.HTTP_OK);
    if (isSingleInstanceCommand(model)) {
        rb.cookie(getJSessionCookie(jSessionId));
    }
    rb.entity(SseCommandHelper.invokeAsync(commandInvocation, null));
    return rb.build();
}
Also used : CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RestPayloadImpl(com.sun.enterprise.admin.remote.RestPayloadImpl)

Example 2 with PropsFileActionReporter

use of com.sun.enterprise.admin.report.PropsFileActionReporter 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 3 with PropsFileActionReporter

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

the class ListCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    /* Issue 5918 Used in ManifestManager to keep output sorted */
    try {
        PropsFileActionReporter reporter = (PropsFileActionReporter) report;
        reporter.useMainChildrenAttribute(true);
    } catch (ClassCastException e) {
    // ignore, this is not a manifest output
    }
    if (monitor) {
        listMonitorElements(context);
        return;
    }
    List<Map.Entry> matchingNodesSorted = sortNodesByDottedName(matchingNodes);
    for (Map.Entry<Dom, String> node : matchingNodesSorted) {
        ActionReport.MessagePart part = report.getTopMessagePart().addChild();
        part.setChildrenType("DottedName");
        if (parentNodes[0].name.isEmpty()) {
            part.setMessage(node.getValue());
        } else {
            part.setMessage(parentNodes[0].name + "." + node.getValue());
        }
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ActionReport(org.glassfish.api.ActionReport) PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with PropsFileActionReporter

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

the class CreateJndiResourceTest method setUp.

@Before
public void setUp() {
    habitat = getHabitat();
    resources = habitat.<Domain>getService(Domain.class).getResources();
    server = habitat.getService(Server.class);
    parameters = new ParameterMap();
    context = new AdminCommandContextImpl(LogDomains.getLogger(CreateJndiResourceTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr = habitat.getService(CommandRunner.class);
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) CommandRunner(org.glassfish.api.admin.CommandRunner) Before(org.junit.Before)

Example 5 with PropsFileActionReporter

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

the class ListJndiResourcesTest method testExecuteSuccessListNoResource.

/**
 * Test of execute method, of class ListJndiResource.
 * delete-jndi-resource resource
 * list-jndi-resources
 */
@Test
public void testExecuteSuccessListNoResource() {
    createJndiResource();
    parameters = new ParameterMap();
    org.glassfish.resources.admin.cli.ListJndiResources listCommand = habitat.getService(org.glassfish.resources.admin.cli.ListJndiResources.class);
    cr.getCommandInvocation("list-jndi-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<ActionReport.MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum + 1, list.size());
    // as we newly created a resource after test "setup".
    origNum = origNum + 1;
    deleteJndiResource();
    ParameterMap parameters = new ParameterMap();
    listCommand = habitat.getService(org.glassfish.resources.admin.cli.ListJndiResources.class);
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJndiResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr.getCommandInvocation("list-jndi-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    list = context.getActionReport().getTopMessagePart().getChildren();
    if ((origNum - 1) == 0) {
    // Nothing to list.
    } else {
        assertEquals(origNum - 1, list.size());
    }
    List<String> listStr = new ArrayList<String>();
    for (ActionReport.MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertFalse(listStr.contains("resource"));
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.admin.report.PropsFileActionReporter) ActionReport(org.glassfish.api.ActionReport) AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

PropsFileActionReporter (com.sun.enterprise.admin.report.PropsFileActionReporter)30 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)23 ParameterMap (org.glassfish.api.admin.ParameterMap)19 Before (org.junit.Before)14 CommandRunner (org.glassfish.api.admin.CommandRunner)13 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 Test (org.junit.Test)9 MessagePart (org.glassfish.api.ActionReport.MessagePart)7 ActionReport (org.glassfish.api.ActionReport)5 Domain (com.sun.enterprise.config.serverbeans.Domain)4 Resource (com.sun.enterprise.config.serverbeans.Resource)4 Resources (com.sun.enterprise.config.serverbeans.Resources)3 IiopService (org.glassfish.orb.admin.config.IiopService)3 RestPayloadImpl (com.sun.enterprise.admin.remote.RestPayloadImpl)2 CachedCommandModel (com.sun.enterprise.admin.util.CachedCommandModel)2 ArrayList (java.util.ArrayList)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Ignore (org.junit.Ignore)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 ActionReporter (com.sun.enterprise.admin.report.ActionReporter)1