Search in sources :

Example 31 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class JmxServiceUrlsResource method getJmxServiceUrl.

@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult getJmxServiceUrl() {
    try {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL[] urls = (JMXServiceURL[]) mBeanServer.getAttribute(getBootAMXMBeanObjectName(), "JMXServiceURLs");
        List<String> jmxUrls = new ArrayList<String>();
        for (JMXServiceURL url : urls) {
            jmxUrls.add(url.getURLPath());
        }
        RestActionReporter ar = new RestActionReporter();
        ar.setActionDescription("Get JMX Service URLs");
        ar.setSuccess();
        ar.getExtraProperties().put("jmxServiceUrls", jmxUrls);
        return new ActionReportResult(ar);
    } catch (final JMException e) {
        throw new RuntimeException(e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 32 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class SystemPropertiesCliResource method deleteProperty.

protected Response deleteProperty(String parent, String propName) {
    ParameterMap pm = new ParameterMap();
    pm.add("DEFAULT", propName);
    pm.add("target", (parent == null) ? getParent(uriInfo) : parent);
    RestActionReporter actionReport = ResourceUtil.runCommand("delete-system-property", pm, getSubject());
    ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
    ActionReportResult results = new ActionReportResult(commandName, actionReport, new OptionsResult());
    int status = HttpURLConnection.HTTP_OK;
    /*200 - ok*/
    if (exitCode == ActionReport.ExitCode.FAILURE) {
        status = HttpURLConnection.HTTP_INTERNAL_ERROR;
    }
    return Response.status(status).entity(results).build();
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 33 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class ResourceUtil method runCommandWithSse.

public static EventOutput runCommandWithSse(final String commandName, final ParameterMap parameters, final Subject subject, final SseCommandHelper.ActionReportProcessor processor) {
    CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
    final RestActionReporter ar = new RestActionReporter();
    final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject).parameters(parameters);
    return SseCommandHelper.invokeAsync(commandInvocation, new SseCommandHelper.ActionReportProcessor() {

        @Override
        public ActionReport process(ActionReport report, EventOutput ec) {
            addCommandLog(ar, commandName, parameters);
            if (processor != null) {
                return processor.process(report, ec);
            }
            return ar;
        }
    });
}
Also used : EventOutput(org.glassfish.jersey.media.sse.EventOutput) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 34 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class ResourceUtil method getActionReportResult.

public static ActionReportResult getActionReportResult(ActionReport.ExitCode status, String message, HttpHeaders requestHeaders, UriInfo uriInfo) {
    RestActionReporter ar = new RestActionReporter();
    ar.setActionExitCode(status);
    return getActionReportResult(ar, message, requestHeaders, uriInfo);
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter)

Example 35 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class Util method getCurrentValues.

public static Map<String, String> getCurrentValues(String basePath, ServiceLocator habitat, Subject subject) {
    Map<String, String> values = new HashMap<String, String>();
    final String path = (basePath.endsWith(".")) ? basePath.substring(0, basePath.length() - 1) : basePath;
    RestActionReporter gr = ResourceUtil.runCommand("get", new ParameterMap() {

        {
            add("DEFAULT", path);
        }
    }, subject);
    MessagePart top = gr.getTopMessagePart();
    for (MessagePart child : top.getChildren()) {
        String message = child.getMessage();
        if (message.contains("=")) {
            String[] parts = message.split("=");
            values.put(parts[0], (parts.length > 1) ? parts[1] : "");
        }
    }
    return values;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) HashMap(java.util.HashMap) MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap)

Aggregations

RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)44 ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)23 OptionsResult (org.glassfish.admin.rest.results.OptionsResult)13 ActionReport (org.glassfish.api.ActionReport)12 Produces (javax.ws.rs.Produces)9 WebApplicationException (javax.ws.rs.WebApplicationException)8 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 GET (javax.ws.rs.GET)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Consumes (javax.ws.rs.Consumes)5 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)5 MessagePart (org.glassfish.api.ActionReport.MessagePart)5 ParameterMap (org.glassfish.api.admin.ParameterMap)5 CommandRunner (org.glassfish.api.admin.CommandRunner)4 Test (org.testng.annotations.Test)4 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)3 List (java.util.List)3 MultiException (org.glassfish.hk2.api.MultiException)3