@Test public void verifyClasspathProvidedConfig() throws IOException { StreamflowEnvironment.setStreamflowHome(tempFolder.getRoot().getAbsolutePath()); StreamflowEnvironment.initialize(); String yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); StreamflowConfig classpathConfig = mapper.readValue(yamlConfig, StreamflowConfig.class); StreamflowConfig loadedConfig = ConfigLoader.getConfig(); assertEquals("Classpath streamflow config should match ConfigLoader streamflow config", classpathConfig, loadedConfig); }
public static StreamflowConfig getConfig() { String yamlConfig = null; File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); return new StreamflowConfig(); } } }
ConfigLoader { public static StreamflowConfig getConfig() { String yamlConfig = null; File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); return new StreamflowConfig(); } } } }
ConfigLoader { public static StreamflowConfig getConfig() { String yamlConfig = null; File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); return new StreamflowConfig(); } } }  }
ConfigLoader { public static StreamflowConfig getConfig() { String yamlConfig = null; File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); return new StreamflowConfig(); } } }  static StreamflowConfig getConfig(); }
ConfigLoader { public static StreamflowConfig getConfig() { String yamlConfig = null; File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString(Thread.currentThread().getContextClassLoader(). getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); return new StreamflowConfig(); } } }  static StreamflowConfig getConfig(); static Logger LOG; }