Refine search
@SuppressWarnings("unchecked") @Override public Map<String, DataSourceConfiguration> load(final String data) { Map<String, YamlDataSourceConfiguration> result = (Map) new Yaml().load(data); Preconditions.checkState(null != result && !result.isEmpty(), "No available data sources to load for orchestration."); return Maps.transformValues(result, new Function<YamlDataSourceConfiguration, DataSourceConfiguration>() { @Override public DataSourceConfiguration apply(final YamlDataSourceConfiguration input) { DataSourceConfiguration result = new DataSourceConfiguration(input.getDataSourceClassName()); result.getProperties().putAll(input.getProperties()); return result; } }); } }
public static void LoadYaml(String confPath) { Yaml yaml = new Yaml(); try { InputStream stream = new FileInputStream(confPath); conf = (Map) yaml.load(stream); if (conf == null || conf.isEmpty() == true) { throw new RuntimeException("Failed to read config file"); } } catch (FileNotFoundException e) { System.out.println("No such file " + confPath); throw new RuntimeException("No config file"); } catch (Exception e1) { e1.printStackTrace(); throw new RuntimeException("Failed to read config file"); } return; }
private static Map LoadYaml(String confPath) { Map ret = null; Yaml yaml = new Yaml(); try { InputStream stream = new FileInputStream(confPath); ret = (Map) yaml.load(stream); if (ret == null || ret.isEmpty() == true) { throw new RuntimeException("Failed to read config file"); } } catch (FileNotFoundException e) { System.out.println("No such file " + confPath); throw new RuntimeException("No config file"); } catch (Exception e1) { e1.printStackTrace(); throw new RuntimeException("Failed to read config file"); } return ret; }
public static Map loadDefinedConf(String confFile) { File file = new File(confFile); if (!file.exists()) { return LoadConf.findAndReadYaml(confFile, true, false); } Yaml yaml = new Yaml(); Map ret; try { ret = (Map) yaml.load(new FileReader(file)); } catch (FileNotFoundException e) { ret = null; } if (ret == null) ret = new HashMap(); return new HashMap(ret); }
private static Map loadYaml(String confPath) { Map ret = new HashMap<>(); Yaml yaml = new Yaml(); InputStream stream = null; try { stream = new FileInputStream(confPath); ret = (Map) yaml.load(stream); if (ret == null || ret.isEmpty()) { return null; } } catch (FileNotFoundException e) { throw new RuntimeException("No config file"); } catch (Exception e1) { throw new RuntimeException("Failed to read config file"); } finally { if (stream != null) { try { stream.close(); } catch (Exception e) { e.printStackTrace(); } } } return ret; }
private static <T> T parseObject(String rawConfig) { Constructor constructor = new Constructor(ConfiguratorConfig.class); TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class); itemDescription.addPropertyParameters("items", ConfigItem.class); constructor.addTypeDescription(itemDescription); Yaml yaml = new Yaml(constructor); return yaml.load(rawConfig); }
public List<UrlGroup> getUrlGroups() throws IOException { ClassPathResource resource = new ClassPathResource("performance-url-groups.yml"); Yaml yaml = new Yaml(); List<Map<String,Object>> load = (List<Map<String, Object>>) yaml.load(resource.getInputStream()); return load.stream().map(map -> UrlGroup.from(map)).collect(Collectors.toList()); }
private static <T> T parseObject(String rawConfig) { Constructor constructor = new Constructor(ConfiguratorConfig.class); TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class); itemDescription.addPropertyParameters("items", ConfigItem.class); constructor.addTypeDescription(itemDescription); Yaml yaml = new Yaml(constructor); return yaml.load(rawConfig); }
public static void main(String[] args) throws Exception { if (args.length != 1) { throw new IllegalArgumentException("YAML file required"); } Yaml yaml = new Yaml(new UaaConfigConstructor()); BufferedReader br = new BufferedReader(new FileReader(args[0])); UaaConfiguration config = (UaaConfiguration) yaml.load(br); ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<UaaConfiguration>> errors = validator.validate(config); System.out.println(errors); } }
public void updateAutoBootstrap(String yamlFile, boolean autobootstrap) throws IOException { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); @SuppressWarnings("rawtypes") Map map = yaml.load(new FileInputStream(yamlFile)); // Dont bootstrap in restore mode map.put("auto_bootstrap", autobootstrap); if (logger.isInfoEnabled()) { logger.info("Updating yaml: " + yaml.dump(map)); } yaml.dump(map, new FileWriter(yamlFile)); }
/** * Parse the TopologyLoadConf from a file in YAML format. * @param file the file to read from * @return the parsed conf * @throws IOException if there is an issue reading the file. */ public static TopologyLoadConf fromConf(File file) throws IOException { Yaml yaml = new Yaml(new SafeConstructor()); Map<String, Object> yamlConf = (Map<String, Object>)yaml.load(new FileReader(file)); return TopologyLoadConf.fromConf(yamlConf); }
public static ConditionRouterRule parse(String rawRule) { Constructor constructor = new Constructor(ConditionRouterRule.class); Yaml yaml = new Yaml(constructor); ConditionRouterRule rule = yaml.load(rawRule); rule.setRawRule(rawRule); if (CollectionUtils.isEmpty(rule.getConditions())) { rule.setValid(false); } return rule; }
public static ConditionRouterRule parse(String rawRule) { Constructor constructor = new Constructor(ConditionRouterRule.class); Yaml yaml = new Yaml(constructor); ConditionRouterRule rule = yaml.load(rawRule); rule.setRawRule(rawRule); if (CollectionUtils.isEmpty(rule.getConditions())) { rule.setValid(false); } return rule; }
private Map<String,?> readKubeConfig() { String kubeConfig = System.getenv("KUBECONFIG"); Reader reader = kubeConfig == null ? getFileReaderFromDir(new File(getHomeDir(),".kube/config")) : getFileReaderFromDir(new File(kubeConfig)); if (reader != null) { Yaml ret = new Yaml(); return (Map<String, ?>) ret.load(reader); } return null; }
@Override @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { Assert.state(yaml != null, "Yaml document should not be null"); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); try { logger.trace("Yaml document is\n" + yaml); configuration = (T) (new Yaml(constructor)).load(yaml); Set<ConstraintViolation<T>> errors = validator.validate(configuration); if (!errors.isEmpty()) { logger.error("YAML configuration failed validation"); for (ConstraintViolation<?> error : errors) { logger.error(error.getPropertyPath() + ": " + error.getMessage()); } if (exceptionIfInvalid) { @SuppressWarnings("rawtypes") ConstraintViolationException summary = new ConstraintViolationException((Set) errors); throw summary; } } } catch (YAMLException e) { if (exceptionIfInvalid) { throw e; } } }