Example #1
0
  public static List<ConfigValues> getConfigValues(ConfigSchema schema, ConfigResponse config) {
    List<ConfigValues> values = new ArrayList<ConfigValues>();

    if (schema == null) {
      return values;
    }

    List options = schema.getOptions();
    int size = options.size();

    for (int i = 0; i < size; i++) {
      ConfigOption option = (ConfigOption) options.get(i);
      String value = config.getValue(option.getName(), true);

      if (option instanceof StringConfigOption) {
        StringConfigOption strOption = (StringConfigOption) option;

        if (strOption.isHidden()) {
          continue; // Ignore
        }
      } else if (option instanceof BooleanConfigOption) {
        if (value == null) {
          value = String.valueOf(false);
        }
      }

      values.add(new ConfigValues(option.getName(), value));
    }

    return values;
  }
Example #2
0
  /**
   * Extracts request parameters corresponding to the {@link ConfigOption} formal argument.
   *
   * <p><b>Note:</b> Multiple values corresponding to a single parameter would be concatenated to a
   * whitespace delimited string.<br>
   * <b>Note:</b> Boolean request parameters missing from the request would be considered as
   * provided with a <code>false</code> value.
   *
   * @param configOption Request parameter metadata.
   * @param prefix Request parameter name prefix.
   * @param request {@link HttpServletRequest} instance.
   * @return
   */
  public static final String getRequestConfigOption(
      final ConfigOption configOption, final String prefix, final HttpServletRequest request) {
    String value = null;

    final String reqParamName = prefix + configOption.getName();
    String[] arrRequestParams = request.getParameterValues(reqParamName);
    if (arrRequestParams == null) {
      // if the
      if (configOption instanceof BooleanConfigOption) {
        value = Boolean.FALSE.toString();
      } else {
        return null;
      } // EO else if the configuration was not of a boolean nature.

    } else if (arrRequestParams.length > 1) {
      value = "";
      for (int regExps = 0; regExps < arrRequestParams.length; regExps++) {
        value += arrRequestParams[regExps] + " ";
      } // EO while there are more values
    } // EO else if option had more than one value
    else {
      value = arrRequestParams[0];
    } // EO else if there was a single value

    return value;
  } // EOM
  private ServerResource createTcRuntimeServerResource(
      String catalinaHome, String catalinaBase, String[] processArgs, MxProcess process)
      throws PluginException {

    String query = PROC_JAVA + ",Args.*.eq=-D" + getProcHomeProperty() + "=" + catalinaBase;

    // Create the server resource
    ServerResource server = newServerResource(catalinaBase);
    server.setDescription(getServerDescription(server.getInstallPath()));
    adjustClassPath(catalinaBase);

    ConfigResponse config = new ConfigResponse();
    ConfigSchema schema =
        getConfigSchema(getTypeInfo().getName(), ProductPlugin.CFGTYPE_IDX_PRODUCT);

    if (schema != null) {
      ConfigOption option = schema.getOption(PROP_PROCESS_QUERY);

      if (option != null) {
        // Configure process.query
        config.setValue(option.getName(), query);
      }
    }

    if (process.getURL() != null) {
      config.setValue(mxUtil.getJmxUrlProperty(), process.getURL());
    } else {
      String[] args = process.getArgs();
      for (int j = 0; j < args.length; j++) {
        if (configureListenerMxURL(config, catalinaBase)) {
          break;
        } else if (configureMxURL(config, args[j])) {
          break;
        } else if (configureLocalMxURL(config, args[j], query)) {
          // continue as .port might come later
        }
      }
    }

    storeProcessUserAndGroup(process, config);

    config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_BASE, catalinaBase);
    config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_HOME, catalinaHome);

    // default anything not auto-configured
    config.setValue("jmx.password", getJMXPassword(catalinaBase));
    setProductConfig(server, config, process.getPid());
    discoverServerConfig(server, process.getPid());

    server.setMeasurementConfig();
    // must set control config now so user doesn't have to enter config
    // properties prior to executing control actions
    server.setControlConfig();
    server.setName(
        getPlatformName()
            + " "
            + getServerName("tc Runtime")
            + " "
            + getBaseDirectoryName(catalinaBase));

    ConfigResponse controlConfig = new ConfigResponse();

    String controlProgram = determineControlProgram(catalinaHome, catalinaBase);
    controlConfig.setValue(ServerControlPlugin.PROP_PROGRAM, controlProgram);
    server.setControlConfig(controlConfig);
    return server;
  }