Search in sources :

Example 46 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CommandExecutorImpl method executeCommand.

/**
 * Runs a command from somewhere OTHER THAN an already-running,
 * previously-authorized command.
 * <p>
 * If a command is already running then it should have a valid Subject and
 * that Subject must be used in running a nested command.  This
 * method uses the internal system admin identity to authorize the command to be run and
 * this should never be done if a user has authenticated to the system
 * and is running a separate, already-authorized command.  This method
 * is, therefore, used from some embedded functionality.
 *
 * @param command
 * @param args
 * @return
 * @throws CommandException
 */
/* package */
ActionReport executeCommand(String command, String... args) throws CommandException {
    ParameterMap commandParams = getParameters(command, args);
    final ActionReport actionReport = createActionReport();
    org.glassfish.api.admin.CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(command, actionReport, embeddedSystemAdministrator.getSubject(), false);
    inv.parameters(commandParams).execute();
    return actionReport;
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 47 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CommandExecutorImpl method getParameters.

ParameterMap getParameters(String command, String[] args) throws CommandException {
    CommandModel commandModel = commandRunner.getModel(command, logger);
    if (commandModel == null) {
        throw new CommandException("Command lookup failed for command " + command);
    }
    // Filter out the global options.
    // We are interested only in --passwordfile option. No other options are relevant when GlassFish is running in embedded mode.
    Parser parser = new Parser(args, 0, ProgramOptions.getValidOptions(), true);
    ParameterMap globalOptions = parser.getOptions();
    List<String> operands = parser.getOperands();
    String[] argv = operands.toArray(new String[operands.size()]);
    parser = new Parser(argv, 0, commandModel.getParameters(), false);
    ParameterMap options = parser.getOptions();
    operands = parser.getOperands();
    options.set("DEFAULT", operands);
    // if command has a "terse" option, set it in options
    if (commandModel.getModelFor("terse") != null)
        options.set("terse", Boolean.toString(terse));
    // Read the passwords from the password file and set it in command options.
    if (globalOptions.size() > 0) {
        String pwfile = globalOptions.getOne(ProgramOptions.PASSWORDFILE);
        if (pwfile != null && pwfile.length() > 0) {
            Map<String, String> passwords = CLIUtil.readPasswordFileOptions(pwfile, false);
            for (CommandModel.ParamModel opt : commandModel.getParameters()) {
                if (opt.getParam().password()) {
                    String pwdname = opt.getName();
                    String pwd = passwords.get(pwdname);
                    if (pwd != null) {
                        options.set(pwdname, pwd);
                    }
                }
            }
        }
    }
    return options;
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) CommandModel(org.glassfish.api.admin.CommandModel) CommandException(org.glassfish.api.admin.CommandException) Parser(com.sun.enterprise.admin.cli.Parser)

Example 48 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class JsonParameterMapProvider method readFrom.

@Override
public ParameterMap readFrom(Class<ParameterMap> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream in) throws IOException {
    JsonObject obj;
    try {
        JsonParser parser = Json.createParser(in);
        if (parser.hasNext()) {
            parser.next();
            obj = parser.getObject();
        } else {
            obj = JsonValue.EMPTY_JSON_OBJECT;
        }
        ParameterMap map = new ParameterMap();
        for (String k : obj.keySet()) {
            Object value = obj.get(k);
            if (value instanceof JsonArray) {
                JsonArray array = (JsonArray) value;
                for (int i = 0; i < array.size(); i++) {
                    map.add(k, "" + array.get(i));
                }
            } else {
                map.add(k, "" + value);
            }
        }
        return map;
    } catch (Exception ex) {
        Logger.getLogger("org.glassfish.admin.rest").log(Level.SEVERE, null, ex);
        ParameterMap map = new ParameterMap();
        map.add("error", "Entity Parsing Error: " + ex.getMessage());
        return map;
    }
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject) ParameterMap(org.glassfish.api.admin.ParameterMap) JsonObject(javax.json.JsonObject) IOException(java.io.IOException) JsonParser(javax.json.stream.JsonParser)

Example 49 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class TemplateCommandGetResource method prepareParameters.

private ParameterMap prepareParameters() {
    ParameterMap data = new ParameterMap();
    processCommandParams(data);
    addQueryString(uriInfo.getQueryParameters(), data);
    purgeEmptyEntries(data);
    adjustParameters(data);
    return data;
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 50 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class SetDomainConfigResource method setDomainConfig.

@POST
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public Response setDomainConfig(HashMap<String, String> data) {
    final Iterator<Entry<String, String>> iterator = data.entrySet().iterator();
    if (iterator.hasNext()) {
        ParameterMap fixed = new ParameterMap();
        Map.Entry entry = iterator.next();
        fixed.add("DEFAULT", entry.getKey() + "=" + entry.getValue());
        return super.executeCommandLegacyFormat(fixed);
    }
    // i18n
    throw new RuntimeException("You must supply exactly one configuration option.");
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) ParameterMap(org.glassfish.api.admin.ParameterMap) HashMap(java.util.HashMap) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

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