All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.singularity.runner.base.config.SingularityConfigurationLoader Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package com.hubspot.singularity.runner.base.config;

import java.io.BufferedReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.util.Properties;

import com.google.common.base.Optional;
import com.google.common.base.Throwables;

public abstract class SingularityConfigurationLoader {

  private final String propertyFile;
  private final Optional defaultLogFileName;

  public SingularityConfigurationLoader(String propertyFile, Optional defaultLogFileName) {
    this.propertyFile = propertyFile;
    this.defaultLogFileName = defaultLogFileName;
  }

  public void bindPropertiesFile(Properties properties) {
    try (BufferedReader br = Files.newBufferedReader(Paths.get(propertyFile), Charset.defaultCharset())) {
      properties.load(br);
    } catch (NoSuchFileException nsfe) {
    } catch (Throwable t) {
      throw Throwables.propagate(t);
    }
  }

  public void bindAllDefaults(Properties properties) {
    if (defaultLogFileName.isPresent()) {
      properties.put(SingularityRunnerBaseConfigurationLoader.ROOT_LOG_FILENAME, defaultLogFileName.get());
    }

    bindDefaults(properties);
  }

  protected abstract void bindDefaults(Properties properties);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy