diff --git a/dev/Server/build.gradle b/dev/Server/build.gradle index c5b0a98..81c0419 100644 --- a/dev/Server/build.gradle +++ b/dev/Server/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.hours22' -version = '2.1-SNAPSHOT' +version = '2.3-SNAPSHOT' sourceCompatibility = '1.8' repositories { diff --git a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/CommonController.java b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/CommonController.java index ba4e2f9..078c2d6 100644 --- a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/CommonController.java +++ b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/CommonController.java @@ -61,7 +61,6 @@ public void GetIndex(HttpServletRequest req, HttpServletResponse response) throw "O pc 언제꺼 ??? db에 반영 됌.
" + "- observer pattern 적용 필요\r\n" + "- 비동기 처리 필요"); - System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : / <- GET method [Client Ip : "+ cic.getClientIp(req) +" ] at " + transFormat.format(new Date())); } @@ -69,7 +68,6 @@ public void GetIndex(HttpServletRequest req, HttpServletResponse response) throw @RequestMapping(value = "/testpage", method = RequestMethod.GET) public @ResponseBody String GetTestPage(HttpServletRequest request, HttpServletResponse response) throws IOException { dss.test(); - System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : /testpage <- GET method [Client Ip : " +cic.getClientIp(request)+" ] at " + transFormat.format(new Date())); return "Test Page"; @@ -77,7 +75,6 @@ public void GetIndex(HttpServletRequest req, HttpServletResponse response) throw @RequestMapping(value = "/pc/{id}", method = RequestMethod.GET) public @ResponseBody String GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException { - System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : /pc/"+ id +" <- GET method [Client Ip : "+ cic.getClientIp(req) + " ] at " + transFormat.format(new Date())); @@ -91,7 +88,6 @@ public void GetIndex(HttpServletRequest req, HttpServletResponse response) throw @RequestMapping(value = "/pc/{id}", method = RequestMethod.POST) public void PostPcInstanceData(HttpServletRequest request, HttpServletResponse response, @RequestBody Map map, @PathVariable String id) throws IOException { String json = ojm.writeValueAsString(map); - System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : "+ json +" <- POST method [Client : "+ cic.getClientIp(request) + " ] at "+transFormat.format(new Date())); diff --git a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/MobileController.java b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/MobileController.java index 199d661..49820c4 100644 --- a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/MobileController.java +++ b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/MobileController.java @@ -52,17 +52,14 @@ public class MobileController{ @Autowired ClientInfoController cic; - SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @RequestMapping(value = "/mobile/pc", method = RequestMethod.GET) public void GetPcData(HttpServletRequest request, HttpServletResponse response) throws IOException { - response.setContentType("application/json;charset=UTF-8"); // RedisLoad_JsonToObj(); // HttpResponse_ObjToJson(); System.out.println("--------------------------------------------------------------------------------------------"); - System.out.println("Input : /mobile/pc <- GET method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) ); lc.getConnection(); @@ -132,13 +129,11 @@ public String call() throws Exception { @RequestMapping(value = "/mobile/pc/{id}/data", method = RequestMethod.GET) public void GetPcRamCpuData(HttpServletRequest request, HttpServletResponse response, @PathVariable String id) throws IOException { - response.setContentType("application/json;charset=UTF-8"); // RedisLoad_JsonToObj(); // HttpResponse_ObjToJson(); lc.getConnection(); - System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : /mobile/pc/"+id+"/data <- GET method [Client Ip : "+ cic.getClientIp(request) +" ] at " + transFormat.format(new Date())); @@ -154,7 +149,6 @@ public void GetPcRamCpuData(HttpServletRequest request, HttpServletResponse resp @RequestMapping(value = "/mobile/pc/{id}/power/{endTime}", method = RequestMethod.POST) - public @ResponseBody Callable> PostPcPowerOff(HttpServletRequest request, HttpServletResponse response, @PathVariable String id, @PathVariable String endTime) throws IOException, InterruptedException, ParseException { response.setContentType("application/json;charset=UTF-8"); @@ -162,7 +156,6 @@ public void GetPcRamCpuData(HttpServletRequest request, HttpServletResponse resp System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : /pc/"+id+"/power/"+endTime+" <- POST method(언제꺼? v2.0) [Client Ip : " +cic.getClientIp(request)+" ] at "+transFormat.format(new Date())); System.out.println("현재 Thread ID : " + Thread.currentThread().getId()); - lc.getConnection(); String jsonStringForAndroid = lc.getConnectionHgetall(id); @@ -180,15 +173,17 @@ public void GetPcRamCpuData(HttpServletRequest request, HttpServletResponse resp String res = thread.getName(); if(res.equals("PCPowerOffExc-Return-"+id)) { thread.interrupt(); - System.out.println("******"+res+" 스레드를 종료시킵니다.******"); + System.out.println("******"+res+" 스레드를 종료시킵니다. [PowerReturn]******"); + } + if(res.equals("PCPowerOffMsg-Return-"+id)) { + thread.interrupt(); + System.out.println("******"+res+" 스레드를 종료시킵니다. [MessageReturn]******"); } } - Date now = new Date(); String form = endTime; SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - System.out.println("Mobile에서 PC종료시간을 새로 설정하였습니다. (변경된 methd)" + transFormat.format(now)); String [] seq = form.split("-"); form = seq[0] + "-" + seq[1] + "-" + seq[2] +" "+seq[3] +":"+seq[4]; @@ -196,15 +191,12 @@ public void GetPcRamCpuData(HttpServletRequest request, HttpServletResponse resp Map jsonObject = new HashMap(); jsonObject.put("id", id); - jsonObject.put("powerStatus", "OFF"); - jsonObject.put("endTime", endTime); String jsonString = ojm.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject); //lc.getConnectionHsetAllData(id, jsonObject); lc.getConnectionHset(id, jsonObject); - // response System.out.println("hget 디버깅 결과 : " + jsonString); @@ -264,9 +256,9 @@ public Map call() throws Exception { lc.getConnectionHset(id, jsonObjectExit); lc.getConnectionExit(); - return jsonObjectExit; - } - } - }; + return jsonObjectExit; + } + } + }; } } \ No newline at end of file diff --git a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/PcController.java b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/PcController.java index a7bab31..d0fb510 100644 --- a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/PcController.java +++ b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/controller/PcController.java @@ -35,7 +35,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.hours22.system_monitor_ver11.client.ClientInfoController; import com.hours22.system_monitor_ver11.client.ServerTimer; - import com.hours22.system_monitor_ver11.db.DataService; import com.hours22.system_monitor_ver11.db.LettuceController; @@ -63,13 +62,11 @@ public void PostPcData(HttpServletRequest request, HttpServletResponse response, System.out.println("--------------------------------------------------------------------------------------------"); System.out.println("Input : /pc/"+id+"/data <- POST method [Client Ip : " +cic.getClientIp(request)+"] at "+transFormat.format(new Date()) ); - lc.getConnection(); lc.getConnectionHset(id, map); lc.getConnectionExit(); System.out.println(map.toString()); - Set setOfThread = Thread.getAllStackTraces().keySet(); for(Thread thread : setOfThread){ System.out.println("Active Thread's [ Number : " +thread.getId()+" / Name : "+thread.getName()+" ] "); @@ -82,12 +79,11 @@ public void PostPcData(HttpServletRequest request, HttpServletResponse response, } } - response.getWriter().print("Success /pc/"+id+"/data <- POST method !!"); } + @RequestMapping(value = "/pc/{id}/power/{endTime}", method = RequestMethod.POST) - public @ResponseBody Callable> PostPcPowerOff(HttpServletRequest request, HttpServletResponse response, @PathVariable String id, @PathVariable String endTime) throws IOException, InterruptedException, ParseException { response.setContentType("application/json;charset=UTF-8"); @@ -106,8 +102,12 @@ public void PostPcData(HttpServletRequest request, HttpServletResponse response, String res = thread.getName(); if(res.equals("PCPowerOffExc-Return-"+id)) { thread.interrupt(); - System.out.println("******"+res+" 스레드를 종료시킵니다.******"); + System.out.println("******"+res+" 스레드를 종료시킵니다. [PowerReturn]******"); opt = 2; + }; + if(res.equals("PCPowerOffMsg-Return-"+id)) { + thread.interrupt(); + System.out.println("******"+res+" 스레드를 종료시킵니다. [MessageReturn]******"); } } @@ -117,7 +117,6 @@ public void PostPcData(HttpServletRequest request, HttpServletResponse response, ct.setName("PCPowerOffExc-"+id); System.out.println("현재 Thread [ ID : " + ct.getId()+ " / Name : "+ct.getName()+" ] "); - lc.getConnection(); String jsonStringForAndroid = lc.getConnectionHgetall(id); @@ -127,18 +126,30 @@ public void PostPcData(HttpServletRequest request, HttpServletResponse response, Date now = new Date(); - String form = endTime; - SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + + String eform = endTime; + String startTime = transFormat.format(now); + + char[] sfromArr = null; + sfromArr = startTime.toCharArray(); + for(int i=4; i<=13; i+=3) { + sfromArr[i] = '-'; + } + startTime = String.valueOf(sfromArr); + + //2020-05-15 11:34 + if(opt == 1) System.out.println(id+" PC가 켜졌습니다! (변경된 methd)" + transFormat.format(now)); else if(opt == 2) System.out.println(id+" PC의 종료시간이 변경되었습니다." + transFormat.format(now)); - - String [] seq = form.split("-"); - form = seq[0] + "-" + seq[1] + "-" + seq[2] +" "+seq[3] +":"+seq[4]; - System.out.println("종료예약 설정 [시간 : "+form+"]"); + String [] eseq = eform.split("-"); + eform = eseq[0] + "-" + eseq[1] + "-" + eseq[2] +" "+eseq[3] +":"+eseq[4]; + System.out.println("종료예약 설정 [시간 : "+eform+"]"); Map jsonObject = new HashMap(); + if(opt == 1) + jsonObject.put("startTime", startTime); jsonObject.put("id", id); jsonObject.put("powerStatus", "OFF"); jsonObject.put("endTime", endTime); @@ -150,7 +161,7 @@ else if(opt == 2) // response System.out.println("hget 디버깅 결과 : " + jsonString); - Date to = transFormat.parse(form); + Date to = transFormat.parse(eform); lc.getConnectionExit(); return new Callable>() { @@ -181,7 +192,7 @@ public Map call() throws Exception { //Thread.currentThread().interrupt(); Thread.sleep(2000); }catch(InterruptedException e){ - System.out.println(Thread.currentThread().getName() +" Thread가 중지되었습니다."); + System.out.println(Thread.currentThread().getName() +" Thread가 중지되었습니다.[Power]"); interrupted = true; break; } @@ -210,6 +221,7 @@ public Map call() throws Exception { } }; } + @RequestMapping(value = "/pc/{id}/message/{min}", method = RequestMethod.GET) public @ResponseBody Callable> GetWarningMsg(HttpServletRequest request, HttpServletResponse response, @PathVariable String id, @PathVariable String min) throws IOException, InterruptedException, ParseException { response.setContentType("application/json;charset=UTF-8"); @@ -238,7 +250,6 @@ public Map call() throws Exception { - String EndTime; lc.getConnection(); EndTime = lc.getConnectionHgetField(id, "endTime"); @@ -285,16 +296,16 @@ public Map call() throws Exception { long start, end, slept; boolean interrupted = false; - Date nnow = new Date(); + Date now = new Date(); - while(to.getTime() - nnow.getTime() > 0) { + while(goal.getTime() - now.getTime() > 0) { try{ // do stuff - nnow = new Date(); + now = new Date(); //Thread.currentThread().interrupt(); Thread.sleep(2000); }catch(InterruptedException e){ - System.out.println(Thread.currentThread().getName() +" Thread가 중지되었습니다."); + System.out.println(Thread.currentThread().getName() +" Thread가 중지되었습니다. [Msg]"); interrupted = true; break; } @@ -321,6 +332,5 @@ public Map call() throws Exception { } } }; - } } \ No newline at end of file diff --git a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/DataService.java b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/DataService.java index ae6c541..967ed8d 100644 --- a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/DataService.java +++ b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/DataService.java @@ -10,6 +10,8 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -72,11 +74,11 @@ public void test() { public Map GetAllPcDataRedis() throws JsonProcessingException { - // ϼ JSONObject (ü) + //���� �ϼ��� JSONObject ����(��ü) JSONObject jsonObject = new JSONObject(); - //person JSON Array + //person�� JSON������ ���� Array ���� JSONArray jsonArray = new JSONArray(); - //person Ѹ  JSONObject + //person�� �Ѹ� ������ �� JSONObject ���� JSONObject jsonInfo = new JSONObject(); int i = 0; @@ -93,10 +95,22 @@ public Map GetAllPcDataRedis() throws JsonProcessingException { String tkey = new String(cursor.next()); //String kvalue = ojm.writeValueAsString((PcData)valueOperations.get(tkey)); String kvalue = mc.getConnectionHgetall(tkey); - System.out.println("key data [" + ++i +"] = " + tkey +" "+ kvalue); // ȸ Key ̸ + System.out.println("key data [" + ++i +"번째] = " + tkey +" "+ kvalue); // ��ȸ�� Key�� �̸��� ��� System.out.println(); //arrList.put(Integer.toString(i), kvalue); - jsonArray.add(kvalue); + + // String -> JsonParser + JSONParser parser = new JSONParser(); + Object obj = null; + try { + obj = parser.parse(kvalue); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + JSONObject jsonTmpObj = (JSONObject) obj; + + jsonArray.add(jsonTmpObj); } } finally { jsonObject.put("pcs", jsonArray); diff --git a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/LettuceController.java b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/LettuceController.java index 3a58d06..246602e 100644 --- a/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/LettuceController.java +++ b/dev/Server/src/main/java/com/hours22/system_monitor_ver11/db/LettuceController.java @@ -190,7 +190,6 @@ public void getConnectionHset(String key, Map map) { // field : cpuData if(map.get("cpuData") != null) { syncCmd.hset(key, "cpuData", map.get("cpuData")); - System.out.println("hset "+key+ " cpuData -> true"); } else { System.out.println("hset "+key+ " cpuData -> false"); @@ -210,13 +209,11 @@ public void getConnectionHset(String key, Map map) { System.out.println("hset "+key+ " startTime -> true"); } else { System.out.println("hset "+key+ " startTime -> false"); - } // field : endTime if(map.get("endTime") != null) { syncCmd.hset(key, "endTime", map.get("endTime")); - System.out.println("hset "+key+ " endTime -> true"); } else { System.out.println("hset "+key+ " endTime -> false");