Java Code Examples for org.apache.commons.configuration.AbstractConfiguration#getBoolean()

The following examples show how to use org.apache.commons.configuration.AbstractConfiguration#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogConfigUtils.java    From singer with Apache License 2.0 5 votes vote down vote up
/**
 * Singer can restart itself if # of failures exceeds threshold, and in daily
 * cadence. The following is singer restart related configuration:
 *
 * singer.restart.onFailures=true singer.restart.numberOfFailuresAllowed=100
 * singer.restart.daily=true singer.restart.dailyRestartUtcTimeRangeBegin=02:30
 * singer.restart.dailyRestartUtcTimeRangeEnd=03:30
 */
private static SingerRestartConfig parseSingerRestartConfig(PropertiesConfiguration configHeader) throws ConfigurationException {
  SingerRestartConfig restartConfig = new SingerRestartConfig();
  AbstractConfiguration subsetConfig = new SubsetConfiguration(configHeader,
      SingerConfigDef.SINGER_RESTART_PREFIX);

  if (subsetConfig.containsKey(SingerConfigDef.ON_FAILURES)) {
    restartConfig.restartOnFailures = subsetConfig.getBoolean(SingerConfigDef.ON_FAILURES);
  }
  if (subsetConfig.containsKey(SingerConfigDef.NUMBER_OF_FAILURES_ALLOWED)) {
    restartConfig.numOfFailuesAllowed = subsetConfig
        .getInt(SingerConfigDef.NUMBER_OF_FAILURES_ALLOWED);
  }
  if (subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_FLAG)) {
    restartConfig.restartDaily = subsetConfig.getBoolean(SingerConfigDef.DAILY_RESTART_FLAG);
  }

  if (restartConfig.restartDaily) {
    if (!subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_TIME_BEGIN)
        || !subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_TIME_END)) {
      throw new ConfigurationException("Daily restart time range is not set correctly");
    }

    restartConfig.dailyRestartUtcTimeRangeBegin = subsetConfig
        .getString(SingerConfigDef.DAILY_RESTART_TIME_BEGIN);
    restartConfig.dailyRestartUtcTimeRangeEnd = subsetConfig
        .getString(SingerConfigDef.DAILY_RESTART_TIME_END);
    Date startTime = SingerUtils.convertToDate(restartConfig.dailyRestartUtcTimeRangeBegin);
    Date endTime = SingerUtils.convertToDate(restartConfig.dailyRestartUtcTimeRangeEnd);
    if (endTime.compareTo(startTime) <= 0) {
      throw new ConfigurationException("Daily restart end time is not later than start time");
    }
  }
  return restartConfig;
}
 
Example 2
Source File: JMSSenderWorker.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private void handleProtocolSpecificConditions(JMSException e, JmsOptions options) {
    AbstractConfiguration config = ConfigurationWrapper.getConfig();

    /*
     * This handles a special condition when using AMQP 1.0 with QPid JMS. As explained by Keith on
     * issue #141, "... this corresponds to the condition where the sending link is blocked awaiting credit.
     * When the peer is the Artemis Broker, this can correspond to a queue/disk full situation ..." as well
     * as serving as a work-around for some SUT issues like https://issues.apache.org/jira/browse/ARTEMIS-1898
     *
     * In the future, this behavior should be driven by the front end, so we still have the ability to mark as fail
     * situations when the clients or the SUTs failed to cleanup/terminate/shutdown correctly.
     *
     * The previous behavior can be changed by the option worker.protocol.amqp10.block.is.failure
     */
    boolean amqpBlockIsFailure = config.getBoolean("worker.protocol.amqp10.block.is.failure",
            false);

    if (amqpBlockIsFailure) {
        logger.error("JMS error while running the sender worker: {}", e.getMessage(), e);

        workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_FAILURE, e);
    }
    else {
        if (options.getProtocol() == JMSProtocol.AMQP && e.getCause() instanceof InterruptedException) {
            logger.warn("Ignoring JMS error while running the sender worker: {}", e.getMessage(), e);

            workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_SUCCESS, e);
        }
        else {
            logger.error("JMS error while running the sender worker: {}", e.getMessage(), e);

            workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_FAILURE, e);
        }
    }
}
 
Example 3
Source File: InterconnectInspector.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private void checkCleanupErrorPolicy(final JMSException e) throws JMSException {
    final AbstractConfiguration config = ConfigurationWrapper.getConfig();
    final boolean cleanupErrorsIsFailure = config.getBoolean("inspector.cleanup.error.is.failure", false);

    if (cleanupErrorsIsFailure) {
        throw e;
    }
}
 
Example 4
Source File: LogConfigUtils.java    From singer with Apache License 2.0 4 votes vote down vote up
public static SingerLogConfig parseLogConfig(String logName,
                                             AbstractConfiguration logConfiguration) throws ConfigurationException {
  logConfiguration.setThrowExceptionOnMissing(true);

  String local_dir = null;
  if (logConfiguration.containsKey("logDir")) {
    local_dir = logConfiguration.getString("logDir");
  } else if (logConfiguration.containsKey("local_dir")) {
    local_dir = logConfiguration.getString("local_dir");
  } else {
    throw new ConfigurationException("missing logDir/local_dir");
  }
  if (local_dir != null && local_dir.endsWith("/")) {
    local_dir = local_dir.substring(0, local_dir.length() - 1);
  }

  String logfile_regex;
  if (logConfiguration.containsKey("logStreamRegex")) {
    logfile_regex = logConfiguration.getString("logStreamRegex");
  } else if (logConfiguration.containsKey("logfile_regex")) {
    logfile_regex = logConfiguration.getString("logfile_regex");
  } else {
    throw new ConfigurationException("missing logStreamRegex/logfile_regex");
  }

  LogStreamProcessorConfig processorConfig = parseLogStreamProcessorConfig(
      new SubsetConfiguration(logConfiguration, "processor."));
  LogStreamReaderConfig readerConfig = parseLogStreamReaderConfig(
      new SubsetConfiguration(logConfiguration, "reader."));
  LogStreamWriterConfig writerConfig = parseLogStreamWriterConfig(
      new SubsetConfiguration(logConfiguration, "writer."));

  // initialize the optional fields
  logConfiguration.setThrowExceptionOnMissing(false);
  String logDecider = logConfiguration.getString("logDecider");
  SingerLogConfig config = new SingerLogConfig(logName, local_dir, logfile_regex, processorConfig,
      readerConfig, writerConfig);
  config.setLogDecider(logDecider);
  if (logConfiguration.containsKey("enableHeadersInjector")){
    boolean enableHeadersInjector = logConfiguration.getBoolean("enableHeadersInjector");
    config.setEnableHeadersInjector(enableHeadersInjector);
    if (enableHeadersInjector && logConfiguration.containsKey("headersInjectorClass")){
      config.setHeadersInjectorClass(logConfiguration.getString("headersInjectorClass"));
    }
  }

  FileNameMatchMode matchMode = FileNameMatchMode.PREFIX;
  String matchModeStr = logConfiguration.getString("logFileMatchMode");
  if (matchModeStr != null) {
    matchModeStr = matchModeStr.toLowerCase();
    if (matchModeStr.equals("exact")) {
      matchMode = FileNameMatchMode.EXACT;
    } else if (!matchModeStr.equals("prefix")) {
      throw new ConfigurationException("Invalid logFileNameMatchMode : " + matchModeStr);
    }
  }
  config.setFilenameMatchMode(matchMode);

  if (logConfiguration.containsKey(SingerConfigDef.LOG_RETENTION_SECONDS)) {
    config
        .setLogRetentionInSeconds(logConfiguration.getInt(SingerConfigDef.LOG_RETENTION_SECONDS));
  }

  if (logConfiguration.containsKey("enableLoggingAudit")){
    boolean enableLoggingAudit = logConfiguration.getBoolean("enableLoggingAudit");
    config.setEnableLoggingAudit(enableLoggingAudit);
    try {
      AuditConfig auditConfig = ConfigUtils.parseAuditConfig(new SubsetConfiguration(
          logConfiguration, "loggingaudit."));
      config.setAuditConfig(auditConfig);
    } catch(ConfigurationException e){
       LOG.error("TopicAuditConfig is not configured correctly for {}", logName, e);
       config.setEnableLoggingAudit(false);
    }
  }

  return config;
}
 
Example 5
Source File: LogConfigUtils.java    From singer with Apache License 2.0 4 votes vote down vote up
private static KafkaWriterConfig parseKafkaWriterConfig(AbstractConfiguration kafkaWriterConfiguration) throws ConfigurationException {
  kafkaWriterConfiguration.setThrowExceptionOnMissing(true);
  String topic;
  try {
    topic = kafkaWriterConfiguration.getString(SingerConfigDef.TOPIC);
  } catch (Exception x) {
    throw new ConfigurationException("KafkaWriter topic is required for Singer Configuration");
  }
  KafkaProducerConfig producerConfig = parseProducerConfig(
      new SubsetConfiguration(kafkaWriterConfiguration, SingerConfigDef.PRODUCER_CONFIG_PREFIX));

  String auditTopic = null;

  boolean auditingEnabled = false;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.AUDITING_ENABLED)) {
    auditingEnabled = kafkaWriterConfiguration.getBoolean(SingerConfigDef.AUDITING_ENABLED);

    if (auditingEnabled) {
      if (!kafkaWriterConfiguration.containsKey(SingerConfigDef.AUDIT_TOPIC)) {
        throw new ConfigurationException("Auditing enabled but missing audit topic");
      } else {
        auditTopic = kafkaWriterConfiguration.getString(SingerConfigDef.AUDIT_TOPIC);
      }
    }
  }

  boolean skipNoLeaderPartitions = false;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.SKIP_NO_LEADER_PARTITIONS)) {
    skipNoLeaderPartitions = kafkaWriterConfiguration
        .getBoolean(SingerConfigDef.SKIP_NO_LEADER_PARTITIONS);
  }

  int writeTimeoutInSeconds = 60;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.KAFKA_WRITE_TIMEOUT_IN_SECONDS)) {
    writeTimeoutInSeconds = kafkaWriterConfiguration
        .getInt(SingerConfigDef.KAFKA_WRITE_TIMEOUT_IN_SECONDS);
  }

  KafkaWriterConfig writerConfig = new KafkaWriterConfig(topic, producerConfig);
  writerConfig.setAuditTopic(auditTopic);
  writerConfig.setAuditingEnabled(auditingEnabled);
  writerConfig.setSkipNoLeaderPartitions(skipNoLeaderPartitions);
  writerConfig.setWriteTimeoutInSeconds(writeTimeoutInSeconds);
  return writerConfig;
}
 
Example 6
Source File: DummyAuthenticatorImpl.java    From mithqtt with Apache License 2.0 4 votes vote down vote up
@Override
public void init(AbstractConfiguration config) {
    this.allowDollar = config.getBoolean("allowDollar", true);
    this.deniedTopic = config.getString("deniedTopic", null);
}