org.ho.yaml.Yaml Java Examples

The following examples show how to use org.ho.yaml.Yaml. 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: TomcatConfigReadin.java    From bestconf with Apache License 2.0 5 votes vote down vote up
private static HashMap loadYamlToHashMap(String filePath) {
	HashMap hashmap = null; 
	File f = new File(filePath);
	try {
		hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
	return hashmap;
}
 
Example #2
Source File: JYAML.java    From learnjavabug with MIT License 4 votes vote down vote up
public static void main(String[] args) {
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A\n\n xx:threedr3am");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A\n xx:threedr3am\n");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A\n xx: threedr3am");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A\n xx: threedr3am\n");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A     \n xx:     threedr3am\n");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A {}");
  printAndMatch("--- !com.threedr3am.bug.feature.JYAML$A    {}");

  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A xx:threedr3am");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A xx:threedr3am\n");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A xx:   threedr3am\n");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     xx:threedr3am    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     xx:   threedr3am    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     xx:\"threedr3am\"    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     \"xx\":\"threedr3am\"    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     'xx':\"threedr3am\"    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     'xx':    \"threedr3am\"    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     'xx':'threedr3am'    ");
  printAndMatch("foo !com.threedr3am.bug.feature.JYAML$A     'xx':   'threedr3am'    ");

  Yaml yaml = new Yaml();
  printAndMatch(yaml.dump(new JYAML()));
  printAndMatch(yaml.dump(new A("threedr3am")));

  //todo JYAML不支持参数构造,因此,gadget只能靠setter触发
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A\n\n xx:threedr3am");
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A\n xx:threedr3am\n");
  yaml.load("---axaaxa !com.threedr3am.bug.feature.JYAML$A\n xx: threedr3am");
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A\n xx: threedr3am\n");
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A     \n xx:     threedr3am\n");
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A {}");
  yaml.load("--- !com.threedr3am.bug.feature.JYAML$A    {}");

  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A xx:threedr3am");
  yaml.load("xxxx !com.threedr3am.bug.feature.JYAML$A xx:threedr3am\n");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A xx:   threedr3am\n");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     xx:threedr3am    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     xx:   threedr3am    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     xx:\"threedr3am\"    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     \"xx\":\"threedr3am\"    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     'xx':\"threedr3am\"    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     'xx':    \"threedr3am\"    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     'xx':'threedr3am'    ");
  yaml.load("foo !com.threedr3am.bug.feature.JYAML$A     'xx':   'threedr3am'    ");

}
 
Example #3
Source File: ElasticSearchPlugin.java    From OpenFalcon-SuitAgent with Apache License 2.0 4 votes vote down vote up
/**
 * 插件监控的服务正常运行时的內建监控报告
 * 若有些特殊的监控值无法用配置文件进行配置监控,可利用此方法进行硬编码形式进行获取
 * 注:此方法只有在监控对象可用时,才会调用,并加入到监控值报告中,一并上传
 *
 * @param metricsValueInfo 当前的JMXMetricsValueInfo信息
 * @return
 */
@Override
public Collection<FalconReportObject> inbuiltReportObjectsForValid(JMXMetricsValueInfo metricsValueInfo) {
    // 指定配置中配置的监控值
    int pid = metricsValueInfo.getJmxConnectionInfo().getPid();
    Set<FalconReportObject> result = new HashSet<>();
    String configPath = pluginDir + File.separator + metricsConfFile;
    try {
        String selfNodeId = ElasticSearchConfig.getNodeId(pid);
        String selfNodeName = ElasticSearchConfig.getNodeName(pid);
        if(StringUtils.isEmpty(selfNodeId) || StringUtils.isEmpty(selfNodeName)){
            log.error("获取es:{} 的服务信息失败",metricsValueInfo.getJmxConnectionInfo().getName());
        }else{
            HashMap<String,Object> confMap = Yaml.loadType(new FileInputStream(configPath),HashMap.class);
            if(confMap != null){
                for (String key : confMap.keySet()) {
                    String urlSuffix = key.substring(0,key.lastIndexOf('.'));
                    String url = ElasticSearchConfig.getConnectionUrl(pid) + "/" + urlSuffix;
                    Map<String,String> config = (Map<String, String>) confMap.get(key);

                    String method = config.get("method");
                    String metrics = config.get("metrics");
                    String valuePath = config.get("valuePath").replace("{selfNodeId}",selfNodeId).replace("{selfNodeName}",selfNodeName);
                    String counterType = config.get("counterType");
                    String valueExpress = config.get("valueExpress");

                    String tag = config.get("tag");
                    if("get".equalsIgnoreCase(method)){
                        String responseText = HttpUtil.get(url).getResult();
                        JSONObject jsonObject = JSONObject.parseObject(responseText);
                        if(jsonObject != null){
                            String[] paths = valuePath.split("\\.");
                            for(int i=0;i<paths.length;i++){
                                if(i == paths.length -1){
                                    Object value = jsonObject.get(paths[i]);
                                    if(value instanceof JSONObject){
                                        log.error("elasticSearch http获取值异常,检查{}路径(valuePath)是否为叶子节点:{}",key,config.get("valuePath"));
                                    }else{
                                        //服务的标识后缀名
                                        String name = metricsValueInfo.getJmxConnectionInfo().getName();

                                        FalconReportObject falconReportObject = new FalconReportObject();
                                        MetricsCommon.setReportCommonValue(falconReportObject,step);
                                        falconReportObject.setTimestamp(metricsValueInfo.getTimestamp());
                                        falconReportObject.setMetric(MetricsCommon.getMetricsName(metrics));

                                        falconReportObject.setValue(String.valueOf(executeJsExpress(valueExpress,value)));

                                        falconReportObject.setCounterType(CounterType.valueOf(counterType));

                                        falconReportObject.appendTags(MetricsCommon.getTags(name,this,serverName(), MetricsType.HTTP_URL_CONF)).
                                                appendTags(tag);

                                        result.add(falconReportObject);
                                    }
                                }else{
                                    jsonObject = jsonObject.getJSONObject(paths[i]);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        log.error("elasticSearch监控值获取发生异常",e);
    }

    return result;
}
 
Example #4
Source File: JYAML.java    From marshalsec with MIT License 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
 */
@Override
public String marshal ( Object o ) throws Exception {
    return Yaml.dump(o);
}
 
Example #5
Source File: JYAML.java    From marshalsec with MIT License 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object)
 */
@Override
public Object unmarshal ( String data ) throws Exception {
    return Yaml.loadType(data, Object.class);
}