Index: web-module/src/main/java/egovframework/api/arms/dashboardlist/controller/AnonymousDashboardListController.java =================================================================== diff -u --- web-module/src/main/java/egovframework/api/arms/dashboardlist/controller/AnonymousDashboardListController.java (revision 0) +++ web-module/src/main/java/egovframework/api/arms/dashboardlist/controller/AnonymousDashboardListController.java (revision 7e5f33fc3b9c0eb9445dfdb6a14c69d7b0cd746f) @@ -0,0 +1,53 @@ +package egovframework.api.arms.dashboardlist.controller; + +import egovframework.api.arms.dashboardlist.service.DashboardListService; +import egovframework.com.cmm.annotation.IncludedInfo; +import egovframework.com.ext.jstree.support.mvc.GenericAbstractController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; + +/** + * Created by Administrator on 2021-01-10. + */ +@Controller +@RequestMapping(value = {"/api/dashboardlist"}) +public class AnonymousDashboardListController extends GenericAbstractController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private DashboardListService dashboardListService; + + @IncludedInfo(name = "ARMS Dashboard list API", listUrl = "/api/dashboardlist/getJsTreeView.do", order = 7777, gid = 7313) + @RequestMapping("/getJsTreeView.do") + public String getDashboardList() { + return "egovframework/api/dashboardlist/JsTreeView"; + } + + @ResponseBody + @RequestMapping(value = "/update.do", method = RequestMethod.GET) + public ModelAndView updateList(ModelMap model, + HttpServletRequest request) throws Exception { + + try { + Integer updateCount = dashboardListService.updateDashboardToGrafana(); + logger.info("DashboardList 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/dashboardlist/service/DashboardListService.java =================================================================== diff -u --- web-module/src/main/java/egovframework/api/arms/dashboardlist/service/DashboardListService.java (revision 0) +++ web-module/src/main/java/egovframework/api/arms/dashboardlist/service/DashboardListService.java (revision 7e5f33fc3b9c0eb9445dfdb6a14c69d7b0cd746f) @@ -0,0 +1,11 @@ +package egovframework.api.arms.dashboardlist.service; + +import egovframework.com.ext.jstree.springHibernate.core.service.JsTreeHibernateService; + +/** + * Created by Administrator on 2021-01-10. + */ +public interface DashboardListService extends JsTreeHibernateService { + + public Integer updateDashboardToGrafana() throws Exception; +} Index: web-module/src/main/java/egovframework/api/arms/dashboardlist/service/DashboardListServiceImpl.java =================================================================== diff -u --- web-module/src/main/java/egovframework/api/arms/dashboardlist/service/DashboardListServiceImpl.java (revision 0) +++ web-module/src/main/java/egovframework/api/arms/dashboardlist/service/DashboardListServiceImpl.java (revision 7e5f33fc3b9c0eb9445dfdb6a14c69d7b0cd746f) @@ -0,0 +1,64 @@ +package egovframework.api.arms.dashboardlist.service; + +import egovframework.api.arms.dashboardlist.batch.DashboardListConst; +import egovframework.com.cmm.service.EgovProperties; +import egovframework.com.ext.jstree.springHibernate.core.service.JsTreeHibernateServiceImpl; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import java.util.Base64; + +/** + * Created by Administrator on 2021-01-10. + */ +public class DashboardListServiceImpl extends JsTreeHibernateServiceImpl implements DashboardListService { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + @Override + public Integer updateDashboardToGrafana() 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 = createHttpHeaders("admin","qwe123"); + headers.setContentType(MediaType.APPLICATION_JSON); + + String postdata = DashboardListConst.DASHBOARD_TEMPLATE; + + HttpEntity request = new HttpEntity(postdata, headers); + + String influxdbUrl = EgovProperties.getProperty("allinone.monitoring.influxdb.url"); + String influxdbBaseUrl = influxdbUrl + "/api/dashboards/db"; + String returnResultStr = restTemplate.postForObject( influxdbBaseUrl, request, String.class); + + + return null; + } + + private HttpHeaders createHttpHeaders(String user, String password) + { + String notEncoded = user + ":" + password; + String encodedAuth = Base64.getEncoder().encodeToString(notEncoded.getBytes()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Authorization", "Basic " + encodedAuth); + return headers; + } +}