Exemple #1
0
  public List<Config> getCurrentConfigList() throws ConfigException {

    ConfigReader configReader = null;

    switch (agentConfig.getConfigInitTypeParam()) {
      case CONFIG_BY_EXPLICIT_PARAMS:
        configReader = getConfigViaExplicitParams();
        break;
      case CONFIG_BY_CORE_TYPE_VIA_GALAXY_OUTPUT:
        configReader = getConfigViaGalaxyAndCoreTypeConfig();
        break;
      case CONFIG_BY_DISCOVERY_VIA_GALAXY_OUTPUT:
        configReader = getConfigViaGalaxyAndDiscovery();
        break;
    }

    List<Config> configList = null;

    if (configReader != null) {
      configList = configReader.getConfigurations();
    }

    if (configList != null && configList.size() > 0) {
      return configList;
    } else {
      log.info("No monitoring configurations initialized");
      return null;
    }
  }
Exemple #2
0
  private ConfigReader getConfigViaExplicitParams() throws ConfigException {
    // This mode is primarily for testing
    //
    // Get config params from lists of local monitoring config filenames, host names, and config
    // paths...
    //  if the number of entries in one of the lists is less than the others, the last entry in the
    // shorter list will
    //  be replicated for each remaining config set.
    //  Thus if there is only one config file name, but 10 hostnames, then the same config file will
    // be applied to all 10 hosts, etc.
    //  (Note it's a bit inefficient therefore, as it will repeatedly open and close the same input
    // file)...
    //
    if (agentConfig.getExplicitConfigFiles().isEmpty()
        || agentConfig.getExplicitTypes().isEmpty()
        || agentConfig.getExplicitPaths().isEmpty()) {
      log.debug(
          "Could not configure via explicit params, must have non-null params for hostList, typeList and pathList");
      return null;
    }

    Iterator<String> configFileIter = agentConfig.getExplicitConfigFiles().iterator();
    Iterator<String> hostIter = agentConfig.getExplicitHosts().iterator();
    Iterator<String> pathIter = agentConfig.getExplicitPaths().iterator();
    Iterator<String> typeIter = agentConfig.getExplicitTypes().iterator();

    String configFile = null;
    String host = null;
    String path = null;
    String type = null;

    CompoundConfigReader configReader = new CompoundConfigReader();

    while (hostIter.hasNext() || typeIter.hasNext() || pathIter.hasNext()) {

      if (configFileIter.hasNext()) {
        configFile = configFileIter.next();
      }

      if (hostIter.hasNext()) {
        host = hostIter.next();
      }

      if (pathIter.hasNext()) {
        path = pathIter.next();
      }

      if (typeIter.hasNext()) {
        type = typeIter.next();
      }

      try {
        if (configFile != null) {
          log.info(
              "Adding initial configuration with config file '"
                  + configFile
                  + "', host '"
                  + host
                  + "', path '"
                  + path
                  + "', type '"
                  + type);
          Reader configFileReader = new FileReader(configFile);

          configReader.addConfigReader(
              new ConfigStreamReader(
                  configFileReader, host, path, type, guiceDefaultsForDataSources));
        } else {
          log.info(
              "Adding initial configuration with host '"
                  + host
                  + "', path '"
                  + path
                  + "', type '"
                  + type);
          List<InputStream> configResourceStreams =
              configFileUtils.getMonitoringTypeConfigStreamList(type, path, false);
          for (InputStream configResourceStream : configResourceStreams) {
            InputStreamReader configStreamReader = new InputStreamReader(configResourceStream);

            configReader.addConfigReader(
                new ConfigStreamReader(
                    configStreamReader, host, path, type, guiceDefaultsForDataSources));
          }
        }

        if (guiceDefaultsForDataSources.isJMXMonitoringProfilePollingEnabled()) {
          configReader.addConfigReader(
              new JMXMonitoringProfilePoller(host, path, type, guiceDefaultsForDataSources));
        }
      } catch (FileNotFoundException fnfEx) {
        log.warn("Could not open file %s: %s", configFile, fnfEx);
        throw new ConfigException("Could not open file " + configFile, fnfEx);
      }
    }

    return configReader;
  }