protected static String getVersion(String filepath)
{
Properties system;
String version="";
try {
system = PropertiesLoaderUtils.loadProperties(new ClassPathResource(filepath));
version=StringUtils.toString(system.getProperty("crawlNode.version"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.debug(e.toString());
}
return version;
}
protected static String buildCrawlParams() {
// TODO Auto-generated method stub
String result="";
LinkedHashMap<String, String> params=new LinkedHashMap<String, String>();
InetAddress inet;
try {
inet = InetAddress.getLocalHost();
String ip=StringUtils.toString(inet.getHostAddress());
params.put("ip", ip);
String hostname=inet.getHostName();
params.put("hostname", hostname);
logger.debug("ip:{}",ip);
logger.debug("hostname:{}",hostname);
logger.debug("version:{}",getVersion("conf/system.properties"));
ObjectMapper mapper=new ObjectMapper();
result=mapper.writeValueAsString(params);
} catch (Exception e) {
// TODO Auto-generated catch block
logger.warn("获取抓取机环境参数出现错误");
}
logger.info("final crawlParams:{}",result);
return result;
}