Search in sources :

Example 16 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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 17 with RestActionReporter

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

the class SystemPropertiesCliResource method saveProperties.

protected Response saveProperties(String parent, HashMap<String, String> data) {
    String propertiesString = convertPropertyMapToString(data);
    data = new HashMap<String, String>();
    data.put("DEFAULT", propertiesString);
    data.put("target", (parent == null) ? getParent(uriInfo) : parent);
    RestActionReporter actionReport = ResourceUtil.runCommand("create-system-properties", data, 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) ActionReport(org.glassfish.api.ActionReport) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 18 with RestActionReporter

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

the class ResourceUtil method runCommand.

/**
 * Executes the specified __asadmin command.
 * @param commandName
 * @param parameters
 * @param subject
 * @param managedJob
 * @return
 */
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob) {
    AsadminRecorderService asadminRecorderService = Globals.getDefaultHabitat().getService(AsadminRecorderService.class);
    if (asadminRecorderService.isEnabled()) {
        asadminRecorderService.recordAsadminCommand(commandName, parameters);
    }
    CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
    RestActionReporter ar = new RestActionReporter();
    final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject);
    if (managedJob) {
        commandInvocation.managedJob();
    }
    commandInvocation.parameters(parameters).execute();
    addCommandLog(ar, commandName, parameters);
    return ar;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) AsadminRecorderService(fish.payara.asadmin.recorder.AsadminRecorderService) CommandRunner(org.glassfish.api.admin.CommandRunner) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 19 with RestActionReporter

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

the class CollectionLeafResource method buildActionReportResult.

protected ActionReportResult buildActionReportResult() {
    RestActionReporter ar = new RestActionReporter();
    final String typeKey = upperCaseFirstLetter((decode(getName())));
    ar.setActionDescription(typeKey);
    ar.getExtraProperties().put("leafList", getEntity());
    OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
    Map<String, MethodMetaData> mmd = getMethodMetaData();
    optionsResult.putMethodMetaData("GET", mmd.get("GET"));
    optionsResult.putMethodMetaData("POST", mmd.get("POST"));
    ResourceUtil.addMethodMetaData(ar, mmd);
    return new ActionReportResult(ar, optionsResult);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 20 with RestActionReporter

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

the class CollectionLeafResource method runCommand.

private Response runCommand(String commandName, Map<String, String> data, String successMsgKey, String successMsg, String operationForbiddenMsgKey, String operationForbiddenMsg) {
    try {
        if (data.containsKey("error")) {
            String errorMessage = localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax.");
            return Response.status(400).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo)).build();
        }
        ResourceUtil.purgeEmptyEntries(data);
        ResourceUtil.adjustParameters(data);
        String attributeName = data.get("DEFAULT");
        if (null != commandName) {
            RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, getSubject());
            ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
            if (exitCode != ActionReport.ExitCode.FAILURE) {
                String successMessage = localStrings.getLocalString(successMsgKey, successMsg, new Object[] { attributeName });
                return Response.ok(ResourceUtil.getActionReportResult(actionReport, successMessage, requestHeaders, uriInfo)).build();
            }
            String errorMessage = getErrorMessage(data, actionReport);
            return Response.status(400).entity(ResourceUtil.getActionReportResult(actionReport, errorMessage, requestHeaders, uriInfo)).build();
        }
        String message = localStrings.getLocalString(operationForbiddenMsgKey, operationForbiddenMsg, new Object[] { uriInfo.getAbsolutePath() });
        return Response.status(403).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, message, requestHeaders, uriInfo)).build();
    } catch (Exception e) {
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) WebApplicationException(javax.ws.rs.WebApplicationException) ActionReport(org.glassfish.api.ActionReport) WebApplicationException(javax.ws.rs.WebApplicationException)

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