Index: web-module/src/main/java/egovframework/api/arms/devicelist/batch/DeviceListBatch.java =================================================================== diff -u -rd6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7 -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/batch/DeviceListBatch.java (.../DeviceListBatch.java) (revision d6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7) +++ web-module/src/main/java/egovframework/api/arms/devicelist/batch/DeviceListBatch.java (.../DeviceListBatch.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -1,11 +1,9 @@ package egovframework.api.arms.devicelist.batch; -import egovframework.com.cmm.service.EgovProperties; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.springframework.http.HttpEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; @@ -19,9 +17,12 @@ @Component public class DeviceListBatch { - @Scheduled(fixedDelay=60000*5, initialDelay =10000) - //@Scheduled(cron="0 0/5 * * * ?") - public void getInfoFromELK() throws Exception { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + //@Scheduled(fixedDelay=60000*5, initialDelay =10000) + //@Scheduled(cron="0/10 0 * * * ?") + //@Scheduled(fixedDelay=60000*1) + public void updateDeviceHost() { HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setReadTimeout(5000); // 읽기시간초과, ms factory.setConnectTimeout(3000); // 연결시간초과, ms @@ -35,61 +36,6 @@ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - String postdata = "{\n" + - " \"aggs\": {\n" + - " \"2\": {\n" + - " \"terms\": {\n" + - " \"field\": \"host.name.keyword\",\n" + - " \"order\": {\n" + - " \"_count\": \"desc\"\n" + - " },\n" + - " \"missing\": \"__missing__\",\n" + - " \"size\": 5\n" + - " }\n" + - " }\n" + - " },\n" + - " \"size\": 0,\n" + - " \"_source\": {\n" + - " \"excludes\": []\n" + - " },\n" + - " \"stored_fields\": [\n" + - " \"*\"\n" + - " ],\n" + - " \"script_fields\": {},\n" + - " \"docvalue_fields\": [\n" + - " {\n" + - " \"field\": \"@timestamp\",\n" + - " \"format\": \"date_time\"\n" + - " },\n" + - " {\n" + - " \"field\": \"system.process.cpu.start_time\",\n" + - " \"format\": \"date_time\"\n" + - " }\n" + - " ],\n" + - " \"query\": {\n" + - " \"bool\": {\n" + - " \"must\": [],\n" + - " \"filter\": [\n" + - " {\n" + - " \"match_all\": {}\n" + - " }\n" + - " ],\n" + - " \"should\": [],\n" + - " \"must_not\": []\n" + - " }\n" + - " }\n" + - "}"; - - HttpEntity request = new HttpEntity(postdata, headers); - - String allinoneBaseUrl = EgovProperties.getProperty("allinone.monitoring.baseurl"); - String allinoneMetricbeatPatternStr = EgovProperties.getProperty("allinone.monitoring.metricbeatindex"); - String returnResultStr = restTemplate.postForObject( allinoneBaseUrl + allinoneMetricbeatPatternStr + "/_search", request, String.class); - - JSONParser parser = new JSONParser(); - Object obj = parser.parse( returnResultStr ); - JSONObject resultJsonObj = (JSONObject) obj; - - System.out.println(resultJsonObj.toJSONString()); + restTemplate.getForEntity("http://localhost:28080/api/v1/devicelist/restController/{action}", String.class, "update"); } } Index: web-module/src/main/java/egovframework/api/arms/devicelist/controller/AdminDeviceListController.java =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/controller/AdminDeviceListController.java (.../AdminDeviceListController.java) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/src/main/java/egovframework/api/arms/devicelist/controller/AdminDeviceListController.java (.../AdminDeviceListController.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -112,4 +112,5 @@ modelAndView.addObject("result", "true"); return modelAndView; } + } \ No newline at end of file Index: web-module/src/main/java/egovframework/api/arms/devicelist/controller/AnonymousDeviceListController.java =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/controller/AnonymousDeviceListController.java (.../AnonymousDeviceListController.java) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/src/main/java/egovframework/api/arms/devicelist/controller/AnonymousDeviceListController.java (.../AnonymousDeviceListController.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -130,4 +130,22 @@ modelAndView.addObject("result", list); return modelAndView; } + + @ResponseBody + @RequestMapping(value = "/update.do", method = RequestMethod.GET) + public ModelAndView updateList(ModelMap model, + HttpServletRequest request) throws Exception { + + try { + Integer updateCount = deviceListService.updateDeviceListToJstree(); + logger.info("DeviceList update Count = " + updateCount); + } catch (Exception e) { + e.printStackTrace(); + } + + + ModelAndView modelAndView = new ModelAndView("jsonView"); + modelAndView.addObject("result", "done"); + return modelAndView; + } } Index: web-module/src/main/java/egovframework/api/arms/devicelist/controller/RestDeviceListController.java =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/controller/RestDeviceListController.java (.../RestDeviceListController.java) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/src/main/java/egovframework/api/arms/devicelist/controller/RestDeviceListController.java (.../RestDeviceListController.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -1,8 +1,11 @@ package egovframework.api.arms.devicelist.controller; +import egovframework.api.arms.devicelist.service.DeviceListService; import egovframework.com.ext.jstree.support.mvc.GenericAbstractController; +import egovframework.com.ext.jstree.support.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,11 +24,22 @@ private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @RequestMapping(value="/restController/{testStr}",method= RequestMethod.GET) - public ModelAndView getNode(@PathVariable(value ="testStr") String testStr, ModelMap model, + @Autowired + private DeviceListService deviceListService; + + @RequestMapping(value="/restController/{action}",method= RequestMethod.GET) + public ModelAndView getNode(@PathVariable(value ="action") String actionStr,ModelMap model, HttpServletRequest request) throws Exception { + + try { + Integer updateCount = deviceListService.updateDeviceListToJstree(); + logger.info("DeviceList update Count = " + updateCount); + } catch (Exception e) { + e.printStackTrace(); + } + ModelAndView modelAndView = new ModelAndView("jsonView"); - modelAndView.addObject("result", testStr); + modelAndView.addObject("result", "done"); return modelAndView; } } Index: web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListService.java =================================================================== diff -u -rd6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7 -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListService.java (.../DeviceListService.java) (revision d6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7) +++ web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListService.java (.../DeviceListService.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -3,7 +3,7 @@ import egovframework.api.arms.devicelist.vo.DeviceListDTO; import egovframework.com.ext.jstree.springHibernate.core.service.JsTreeHibernateService; -import java.util.HashSet; +import java.util.List; /** * Created by Administrator on 2020-11-08. @@ -15,8 +15,8 @@ //차집합을 통해 디비에 등록할 리스트를 추린다. //추려진 데이터를 jstree method api를 통해 업데이트 한다. - public HashSet getDeviceListsFromJstree () throws Exception; - public HashSet getDeviceListsFromELK () throws Exception; - public HashSet getDeviceListDifferrence (HashSet jstreeDeviceList, HashSet elkDeviceLists) throws Exception; - public Integer updateDeviceListToJstree (HashSet updateTargets) throws Exception; + public List getDeviceListsFromJstree () throws Exception; + public List getDeviceListsFromELK () throws Exception; + public List getDeviceListDifference (List jstreeDeviceList, List elkDeviceLists) throws Exception; + public Integer updateDeviceListToJstree () throws Exception; } Index: web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java =================================================================== diff -u -rd6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7 -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java (.../DeviceListServiceImpl.java) (revision d6cfabcdbf63cc4fa4a8d0a6e732d6f11f09edd7) +++ web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java (.../DeviceListServiceImpl.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -1,38 +1,211 @@ package egovframework.api.arms.devicelist.service; +import egovframework.api.arms.devicelist.batch.DeviceListBatch; import egovframework.api.arms.devicelist.vo.DeviceListDTO; +import egovframework.com.cmm.service.EgovProperties; import egovframework.com.ext.jstree.springHibernate.core.service.JsTreeHibernateServiceImpl; +import org.apache.commons.collections.CollectionUtils; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.hibernate.criterion.Order; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; -import java.util.HashSet; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; /** * Created by Administrator on 2020-11-08. */ -@Component +@Service("DeviceListService") public class DeviceListServiceImpl extends JsTreeHibernateServiceImpl implements DeviceListService{ private final Logger logger = LoggerFactory.getLogger(this.getClass()); + //database jstree method 를 활용하여 full list를 얻어온다. -> 디비에 등록된 host full list + //elasticsearch api 를 활용해서 full list 를 얻어온다. -> ELK에 등록된 host full list + //차집합을 통해 디비에 등록할 리스트를 추린다. + //추려진 데이터를 jstree method api를 통해 업데이트 한다. + + @Override - public HashSet getDeviceListsFromJstree() throws Exception { - return null; + public List getDeviceListsFromJstree() throws Exception { + + DeviceListDTO jsTreeHibernateDTO = new DeviceListDTO(); + jsTreeHibernateDTO.setOrder(Order.asc("c_id")); + List list = this.getChildNode(jsTreeHibernateDTO); + return list; } @Override - public HashSet getDeviceListsFromELK() throws Exception { - return null; + public List getDeviceListsFromELK() throws Exception { + + JSONArray jsonArrayInfoFromELK = this.getInfoFromELK(); + + ArrayList deviceListDTOs = new ArrayList(); + for (Object bucketJsonObj: jsonArrayInfoFromELK) { + JSONObject bucketJson = (JSONObject) bucketJsonObj; + logger.info(bucketJson.get("key").toString()); + + DeviceListDTO deviceListDTO = new DeviceListDTO(); + deviceListDTO.setC_title(bucketJson.get("key").toString()); + deviceListDTO.setC_monitor_device_hostname(bucketJson.get("key").toString()); + //포지션 잡아야 함 + deviceListDTOs.add(deviceListDTO); + } + + return deviceListDTOs; } @Override - public HashSet getDeviceListDifferrence(HashSet jstreeDeviceList, HashSet elkDeviceLists) throws Exception { - return null; + public List getDeviceListDifference(List jstreeDeviceList, List elkDeviceLists) throws Exception { + + ArrayList jstreeDeviceStringList = new ArrayList(); + for (DeviceListDTO deviceListDTO: jstreeDeviceList) { + logger.info("DB List from jstree = " + deviceListDTO.getC_monitor_device_hostname()); + jstreeDeviceStringList.add(deviceListDTO.getC_monitor_device_hostname()); + } + + ArrayList differences = new ArrayList(); + ArrayList elkDeviceStringList = new ArrayList(); + for (DeviceListDTO deviceListDTO : elkDeviceLists) { + logger.info("ELK List from API = " + deviceListDTO.getC_monitor_device_hostname()); + elkDeviceStringList.add(deviceListDTO.getC_monitor_device_hostname()); + + if ( jstreeDeviceStringList.contains(deviceListDTO.getC_monitor_device_hostname())){ + logger.info("contained check" + deviceListDTO.getC_monitor_device_hostname()); + }else { + differences.add(deviceListDTO.getC_monitor_device_hostname()); + } + } + + ArrayList targetList = new ArrayList(); + for (String insertTargetDeviceHost : differences) { + logger.info("difference check =" + insertTargetDeviceHost); + + DeviceListDTO deviceListDTO = new DeviceListDTO(); + deviceListDTO.setC_title(insertTargetDeviceHost); + deviceListDTO.setC_monitor_device_hostname(insertTargetDeviceHost); + deviceListDTO.setC_parentid(new Long(2)); + deviceListDTO.setRef(new Long(2)); + deviceListDTO.setC_type("default"); + + targetList.add(deviceListDTO); + } + + return targetList; } @Override - public Integer updateDeviceListToJstree(HashSet updateTargets) throws Exception { - return null; + @Transactional(rollbackFor = { Exception.class }, propagation = Propagation.REQUIRED) + public Integer updateDeviceListToJstree() throws Exception { + + //database jstree method 를 활용하여 full list를 얻어온다. -> 디비에 등록된 host full list + List deviceListsFromJstree = getDeviceListsFromJstree(); + + //elasticsearch api 를 활용해서 full list 를 얻어온다. -> ELK에 등록된 host full list + List deviceListsFromELK = getDeviceListsFromELK(); + + //차집합을 통해 디비에 등록할 리스트를 추린다. + List differenceUpdateSet = getDeviceListDifference(deviceListsFromJstree, deviceListsFromELK); + + for (DeviceListDTO deviceListDTO: differenceUpdateSet) { + this.addNode(deviceListDTO); + } + + return differenceUpdateSet.size(); } + + public JSONArray getInfoFromELK() throws Exception { + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); + factory.setReadTimeout(5000); // 읽기시간초과, ms + factory.setConnectTimeout(3000); // 연결시간초과, ms + HttpClient httpClient = HttpClientBuilder.create() + .setMaxConnTotal(100) // connection pool 적용 + .setMaxConnPerRoute(5) // connection pool 적용 + .build(); + factory.setHttpClient(httpClient); // 동기실행에 사용될 HttpClient 세팅 + RestTemplate restTemplate = new RestTemplate(factory); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + String postdata = "{\n" + + " \"aggs\": {\n" + + " \"2\": {\n" + + " \"terms\": {\n" + + " \"field\": \"host.name.keyword\",\n" + + " \"order\": {\n" + + " \"_count\": \"desc\"\n" + + " },\n" + + " \"missing\": \"__missing__\",\n" + + " \"size\": 5\n" + + " }\n" + + " }\n" + + " },\n" + + " \"size\": 0,\n" + + " \"_source\": {\n" + + " \"excludes\": []\n" + + " },\n" + + " \"stored_fields\": [\n" + + " \"*\"\n" + + " ],\n" + + " \"script_fields\": {},\n" + + " \"docvalue_fields\": [\n" + + " {\n" + + " \"field\": \"@timestamp\",\n" + + " \"format\": \"date_time\"\n" + + " },\n" + + " {\n" + + " \"field\": \"system.process.cpu.start_time\",\n" + + " \"format\": \"date_time\"\n" + + " }\n" + + " ],\n" + + " \"query\": {\n" + + " \"bool\": {\n" + + " \"must\": [],\n" + + " \"filter\": [\n" + + " {\n" + + " \"match_all\": {}\n" + + " }\n" + + " ],\n" + + " \"should\": [],\n" + + " \"must_not\": []\n" + + " }\n" + + " }\n" + + "}"; + + HttpEntity request = new HttpEntity(postdata, headers); + + String allinoneBaseUrl = EgovProperties.getProperty("allinone.monitoring.baseurl"); + String allinoneMetricbeatPatternStr = EgovProperties.getProperty("allinone.monitoring.metricbeatindex"); + String returnResultStr = restTemplate.postForObject( allinoneBaseUrl + allinoneMetricbeatPatternStr + "/_search", request, String.class); + + JSONParser jsonParser = new JSONParser(); + Object jsonObj = jsonParser.parse( returnResultStr ); + JSONObject resultJsonObj = (JSONObject) jsonObj; + + JSONObject filtedJsonObj = (JSONObject) jsonParser.parse( resultJsonObj.get("aggregations").toString() ); + JSONObject hostJsonObj = (JSONObject) jsonParser.parse( filtedJsonObj.get("2").toString() ); + JSONArray bucketJsonObjs = (JSONArray) jsonParser.parse( hostJsonObj.get("buckets").toString() ); + + logger.info(resultJsonObj.toJSONString()); + + return bucketJsonObjs; + } } Index: web-module/src/main/java/egovframework/api/arms/devicelist/vo/DeviceListDTO.java =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/main/java/egovframework/api/arms/devicelist/vo/DeviceListDTO.java (.../DeviceListDTO.java) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/src/main/java/egovframework/api/arms/devicelist/vo/DeviceListDTO.java (.../DeviceListDTO.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -3,20 +3,18 @@ /** * Created by Administrator on 2020-11-08. */ + import egovframework.com.ext.jstree.springHibernate.core.vo.JsTreeHibernateSearchDTO; -import org.hibernate.annotations.Cache; import org.hibernate.annotations.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import javax.persistence.*; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import java.io.Serializable; -import lombok.Getter; -import lombok.Setter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - @Entity @Table(name = "T_ARMS_MONITOR_DEVICELIST") @SelectBeforeUpdate(value = true) @@ -32,52 +30,41 @@ super(); } + //@Getter @Setter @Column(name = "c_monitor_name") - @Getter @Setter private String c_monitor_name; @Column(name = "c_monitor_update_date") - @Getter @Setter private String c_monitor_update_date; @Column(name = "c_monitor_update_beatname") - @Getter @Setter private String c_monitor_update_beatname; @Column(name = "c_monitor_device_hostname") - @Getter @Setter private String c_monitor_device_hostname; @Column(name = "c_monitor_device_ip") - @Getter @Setter private String c_monitor_device_ip; @Column(name = "c_monitor_url_filebeat") - @Getter @Setter private String c_monitor_url_filebeat; @Column(name = "c_monitor_url_topbeat") - @Getter @Setter private String c_monitor_url_topbeat; @Column(name = "c_monitor_url_metricbeat") - @Getter @Setter private String c_monitor_url_metricbeat; @Column(name = "c_monitor_url_packetbeat") - @Getter @Setter private String c_monitor_url_packetbeat; @Column(name = "c_monitor_url_heartbeat") - @Getter @Setter private String c_monitor_url_heartbeat; @Column(name = "c_monitor_url_apm") - @Getter @Setter private String c_monitor_url_apm; @Column(name = "c_monitor_url_scouter") - @Getter @Setter private String c_monitor_url_scouter; @Override @@ -86,4 +73,100 @@ //this.setC_link(((DeviceListDTO) paramInstance).getC_link()); } } + + public String getC_monitor_name() { + return c_monitor_name; + } + + public void setC_monitor_name(String c_monitor_name) { + this.c_monitor_name = c_monitor_name; + } + + public String getC_monitor_update_date() { + return c_monitor_update_date; + } + + public void setC_monitor_update_date(String c_monitor_update_date) { + this.c_monitor_update_date = c_monitor_update_date; + } + + public String getC_monitor_update_beatname() { + return c_monitor_update_beatname; + } + + public void setC_monitor_update_beatname(String c_monitor_update_beatname) { + this.c_monitor_update_beatname = c_monitor_update_beatname; + } + + public String getC_monitor_device_hostname() { + return c_monitor_device_hostname; + } + + public void setC_monitor_device_hostname(String c_monitor_device_hostname) { + this.c_monitor_device_hostname = c_monitor_device_hostname; + } + + public String getC_monitor_device_ip() { + return c_monitor_device_ip; + } + + public void setC_monitor_device_ip(String c_monitor_device_ip) { + this.c_monitor_device_ip = c_monitor_device_ip; + } + + public String getC_monitor_url_filebeat() { + return c_monitor_url_filebeat; + } + + public void setC_monitor_url_filebeat(String c_monitor_url_filebeat) { + this.c_monitor_url_filebeat = c_monitor_url_filebeat; + } + + public String getC_monitor_url_topbeat() { + return c_monitor_url_topbeat; + } + + public void setC_monitor_url_topbeat(String c_monitor_url_topbeat) { + this.c_monitor_url_topbeat = c_monitor_url_topbeat; + } + + public String getC_monitor_url_metricbeat() { + return c_monitor_url_metricbeat; + } + + public void setC_monitor_url_metricbeat(String c_monitor_url_metricbeat) { + this.c_monitor_url_metricbeat = c_monitor_url_metricbeat; + } + + public String getC_monitor_url_packetbeat() { + return c_monitor_url_packetbeat; + } + + public void setC_monitor_url_packetbeat(String c_monitor_url_packetbeat) { + this.c_monitor_url_packetbeat = c_monitor_url_packetbeat; + } + + public String getC_monitor_url_heartbeat() { + return c_monitor_url_heartbeat; + } + + public void setC_monitor_url_heartbeat(String c_monitor_url_heartbeat) { + this.c_monitor_url_heartbeat = c_monitor_url_heartbeat; + } + + public String getC_monitor_url_apm() { + return c_monitor_url_apm; + } + + public void setC_monitor_url_apm(String c_monitor_url_apm) { + this.c_monitor_url_apm = c_monitor_url_apm; + } + + public String getC_monitor_url_scouter() { + return c_monitor_url_scouter; + } + + public void setC_monitor_url_scouter(String c_monitor_url_scouter) { + this.c_monitor_url_scouter = c_monitor_url_scouter; + } } Index: web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java =================================================================== diff -u -r0fb44798806f6b84267d40c5eba7de3f0e481ca7 -r9fadf60d728e3c03ff2588003f7f93296f04862f --- web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java (.../Java8LambdaTest.java) (revision 0fb44798806f6b84267d40c5eba7de3f0e481ca7) +++ web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java (.../Java8LambdaTest.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) @@ -1,8 +1,16 @@ package egovframework.com.ext.jstree.support.util; +import egovframework.api.arms.devicelist.vo.DeviceListDTO; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -11,6 +19,7 @@ public class Java8LambdaTest { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); static List persons; @BeforeClass @@ -23,7 +32,6 @@ new Java8Lambda("David", 12)); } - @Test public void functionalJavaTest1() { System.out.println("=== RunnableTest ==="); @@ -176,4 +184,74 @@ System.out.println(filtered); } + + @Test + public void jsonObjectTest() throws ParseException { + String orgStr = "{\n" + + " \"took\": 3590,\n" + + " \"timed_out\": false,\n" + + " \"_shards\": {\n" + + " \"total\": 13,\n" + + " \"successful\": 13,\n" + + " \"skipped\": 0,\n" + + " \"failed\": 0\n" + + " },\n" + + " \"hits\": {\n" + + " \"total\": {\n" + + " \"value\": 10000,\n" + + " \"relation\": \"gte\"\n" + + " },\n" + + " \"max_score\": null,\n" + + " \"hits\": []\n" + + " },\n" + + " \"aggregations\": {\n" + + " \"2\": {\n" + + " \"doc_count_error_upper_bound\": 0,\n" + + " \"sum_other_doc_count\": 16619,\n" + + " \"buckets\": [\n" + + " {\n" + + " \"key\": \"jstree-backend-654b68476c-jrtpg\",\n" + + " \"doc_count\": 593514\n" + + " },\n" + + " {\n" + + " \"key\": \"jstree-backend-68ff5f655c-chckb\",\n" + + " \"doc_count\": 354578\n" + + " },\n" + + " {\n" + + " \"key\": \"5d6951d245a1\",\n" + + " \"doc_count\": 336206\n" + + " },\n" + + " {\n" + + " \"key\": \"jstree-backend-5b5746d7cc-9npd2\",\n" + + " \"doc_count\": 109625\n" + + " },\n" + + " {\n" + + " \"key\": \"1dc3be21a15d\",\n" + + " \"doc_count\": 7436\n" + + " }\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + JSONParser jsonParser = new JSONParser(); + Object jsonObj = jsonParser.parse( orgStr ); + JSONObject resultJsonObj = (JSONObject) jsonObj; + + JSONObject filtedJsonObj = (JSONObject) jsonParser.parse( resultJsonObj.get("aggregations").toString() ); + JSONObject hostJsonObj = (JSONObject) jsonParser.parse( filtedJsonObj.get("2").toString() ); + JSONArray bucketJsonObjs = (JSONArray) jsonParser.parse( hostJsonObj.get("buckets").toString() ); + + ArrayList deviceListDTOs = new ArrayList(); + for (Object bucketJsonObj: bucketJsonObjs) { + JSONObject bucketJson = (JSONObject) bucketJsonObj; + logger.info(bucketJson.get("key").toString()); + + DeviceListDTO deviceListDTO = new DeviceListDTO(); + deviceListDTO.setC_monitor_device_hostname(bucketJson.get("key").toString()); + deviceListDTOs.add(deviceListDTO); + } + + logger.info("list size = " + deviceListDTOs.size()); + + } }