server push 관련 소스 추가

main
이범준 4 months ago
parent ac801651da
commit f559039441

@ -48,4 +48,39 @@ public interface TrsmrcvDao {
*
*/
public String getJusoDownLink(Map<String,String> map);
/**
* command 퀀
*
*/
public String getCommandSeq(String str);
/**
* command insert
*
*/
public int insertCommand(Map<String,String> map);
/**
* command select
*
*/
public Map<String,String> selectCommandById(String commandSeq);
/**
* command select
*
*/
public Map<String,String> selectCommand(Map<String,String> map);
/**
* command update
*
*/
public int updateCommand(Map<String,String> map);
public int insertSendMail(Map<String, String> mailInMap);
public Map<String,String> selectSendMail(String commandSeq);
}

@ -136,4 +136,98 @@
SELECT FUN_JUSO_DOWN_URL(#{year},#{month}) FROM DUAL
</select>
<select id="getCommandSeq" parameterType="string" resultType="string">
SELECT SEQ_COMMAND.NEXTVAL FROM DUAL
</select>
<insert id="insertCommand" parameterType="map">
INSERT
INTO TB_CFS_COMMAND (
COMMAND_SEQ
, COMMAND
, SYS_NAME
, STAT_CD
, CREATER
, CREATE_DATE
)
VALUES (
#{commandSeq}
, #{command}
, #{sysName}
, '0'
, 'admin'
, SYSDATE
)
</insert>
<select id="selectCommandById" parameterType="string" resultType="map">
SELECT COMMAND_SEQ
, COMMAND
, SYS_NAME
, STAT_CD
FROM TB_CFS_COMMAND
WHERE COMMAND_SEQ = #{commandSeq}
</select>
<select id="selectCommand" parameterType="map" resultType="map">
SELECT COMMAND_SEQ
, COMMAND
, SYS_NAME
, STAT_CD
FROM (
SELECT COMMAND_SEQ
, COMMAND
, SYS_NAME
, STAT_CD
FROM TB_CFS_COMMAND
WHERE SYS_NAME = #{sysName}
AND STAT_CD = #{statCd}
ORDER BY TO_NUMBER(COMMAND_SEQ)
) WHERE ROWNUM = 1
</select>
<update id="updateCommand" parameterType="map">
UPDATE TB_CFS_COMMAND (
SET STAT_CD = #{statCd}
, UPDATER = 'admin'
, UPDATE_DATE = SYSDATE
WHERE COMMAND_SEQ = #{commandSeq}
</update>
<insert id="insertSendMail" parameterType="map">
INSERT
INTO TB_CFS_SEND_MAIL (
SEND_MAIL_SEQ
, COMMAND_SEQ
, HPUP
, MAIL_PROPS
, MAIL_FROM
, MAIL_TO
, MAIL_SUBJECT
, MAIL_TEXT
)
VALUES (
SEQ_SEND_MAIL.NEXTVAL
, #{commandSeq}
, #{hpup}
, #{mailProps}
, #{from}
, #{to}
, #{subject}
, #{text}
)
</insert>
<select id="selectSendMail" parameterType="string" resultType="map">
SELECT SEND_MAIL_SEQ
, COMMAND_SEQ
, HPUP
, MAIL_PROPS
, MAIL_FROM
, MAIL_TO
, MAIL_SUBJECT
, MAIL_TEXT
FROM TB_CFS_SEND_MAIL
WHERE COMMAND_SEQ = #{commandSeq}
</select>
</mapper>

@ -1,5 +1,8 @@
package cfs.trsmrcv.web;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -14,10 +17,12 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cfs.common.util.Result;
import cfs.common.util.ResultSmartPlatform;
import cfs.trsmrcv.dao.TrsmrcvDao;
import cfs.trsmrcv.service.CommCollectServerService;
@Controller
@ -25,6 +30,9 @@ public class CommHealthCheckController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@Resource(name = "trsmrcvDao")
private TrsmrcvDao trsmrcvDao;
@Resource(name="commCollectServerService")
private CommCollectServerService commCollectServerService;
@ -81,4 +89,45 @@ public class CommHealthCheckController {
return result.getResult();
}
@RequestMapping(value="/rest/getCommand", method=RequestMethod.POST)
public @ResponseBody Map<String, Object> getCommand(@RequestParam String sysName){
Map result = new HashMap();
if(sysName==null || sysName.equals("")){
result.put("res", "OK");
return result;
}
Map<String, String> commandSelMap = new HashMap<String,String>();
commandSelMap.put("sysName", sysName);
commandSelMap.put("statCd", "0");
Map<String, String> commandOutMap = trsmrcvDao.selectCommand(commandSelMap);
if(commandOutMap==null || commandOutMap.isEmpty()){
result.put("res", "OK");
return result;
}
String commandSeq = commandOutMap.get("COMMAND_SEQ").toString();
String commandType = commandOutMap.get("COMMAND").toString();
result.put("commandType",commandType);
if(commandType.equals("sendMail")){
Map<String, String> sendMailInfo = trsmrcvDao.selectSendMail(commandSeq);
if(sendMailInfo == null || sendMailInfo.isEmpty()){
result.put("res", "OK");
return result;
}
result.put("commandDetail", sendMailInfo);
}
Map<String, String> commandUpdMap = new HashMap<String,String>();
commandUpdMap.put("commandSeq", commandSeq);
commandUpdMap.put("statCd", "1");
trsmrcvDao.updateCommand(commandUpdMap);
result.put("res", "OK");
return result;
}
}

@ -22,6 +22,7 @@ import org.json.simple.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@ -113,4 +114,150 @@ public class TestController {
result.put("res", "OK");
return result;
}
@RequestMapping(value="/rest/test/noting.do", method=RequestMethod.POST)
public @ResponseBody Map<String, Object> noting(@RequestBody Map<String,Object> reqMap) throws Exception {
Map result = new HashMap();
String commandSeq = trsmrcvDao.getCommandSeq("");
Map<String, String> commandInMap = new HashMap<String,String>();
commandInMap.put("commandSeq", commandSeq);
commandInMap.put("sysName", "monitoring");
commandInMap.put("command", "nothing");
trsmrcvDao.insertCommand(commandInMap);
this.touchAndWait("monitoring", commandSeq);
result.put("res", "OK");
return result;
}
@RequestMapping(value="/rest/test/sendMail.do", method=RequestMethod.POST)
public @ResponseBody Map<String, Object> sendMail(@RequestBody Map<String,Object> reqMap) throws Exception {
Map result = new HashMap();
String SEND_MAIL_MANAGER = "monitoring";
String commandSeq = trsmrcvDao.getCommandSeq("");
Map<String, String> commandInMap = new HashMap<String,String>();
commandInMap.put("commandSeq", commandSeq);
commandInMap.put("sysName", SEND_MAIL_MANAGER);
commandInMap.put("command", "sendMail");
trsmrcvDao.insertCommand(commandInMap);
List<String> hpup = (List<String>) reqMap.get("hpup");
List<String> mailProps = (List<String>) reqMap.get("mailProps");
String from = reqMap.get("from").toString();
List<String> to = (List<String>) reqMap.get("to");
String subject = reqMap.get("subject").toString();
String text = reqMap.get("text").toString();
Map<String,String> mailInMap = new HashMap<String,String>();
mailInMap.put("commandSeq", commandSeq);
mailInMap.put("hpup", String.join(",", hpup));
mailInMap.put("mailProps", String.join(",", mailProps));
mailInMap.put("from", from);
mailInMap.put("to", String.join(",", to));
mailInMap.put("subject", subject);
mailInMap.put("text", text);
trsmrcvDao.insertSendMail(mailInMap);
this.touchAndWait(SEND_MAIL_MANAGER, commandSeq);
result.put("res", "OK");
return result;
}
private Map<String,Object> touchAndWait(String touchSys, String commandSeq) throws Exception {
Map<String,Object> commandResult = new HashMap<String,Object>();
this.shellCmd("/gpta/source-app/cfs/relay/ssh_ssh_touch.sh " + touchSys);
int FIRST_SLEEP = 2000;
Thread.sleep(FIRST_SLEEP);
int WAITING_CNT = 20;
int WAITING_SLEEP = 1000;
boolean commandComplate = false;
for(int i=0; i < WAITING_CNT; i++){
Map<String, String> commandOutMap = trsmrcvDao.selectCommandById(commandSeq);
if(commandOutMap.get("STAT_CD").equals("2")){
commandComplate = true;
//TODO if need result
//commandResult.put
}
if(commandComplate){
break;
}
Thread.sleep(WAITING_SLEEP);
}
return commandResult;
}
private boolean shellCmd(String cmd) {
Process process = null;
Runtime runtime = Runtime.getRuntime();
StringBuffer successOutput = new StringBuffer();
StringBuffer errorOutput = new StringBuffer();
BufferedReader successBufferReader = null;
BufferedReader errorBufferReader = null;
String msg = null;
boolean result = false;
logger.info("shellCmd - 1");
List<String> cmdList = new ArrayList<String>();
cmdList.add("/bin/sh");
cmdList.add("-c");
cmdList.add(cmd);
String[] array = cmdList.toArray(new String[cmdList.size()]);
try {
process = runtime.exec(array);
successBufferReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
while ((msg = successBufferReader.readLine()) != null) {
successOutput.append(msg + System.getProperty("line.separator"));
}
errorBufferReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
while ((msg = errorBufferReader.readLine()) != null) {
errorOutput.append(msg + System.getProperty("line.separator"));
}
process.waitFor();
if (process.exitValue() == 0) {
result = true;
} else {
logger.info("abnormal finish error : " + successOutput.toString());
}
if (errorOutput.toString().length() > 0) {
logger.info("error : " + errorOutput.toString());
}
} catch (IOException e) {
logger.info(e.getMessage());
} catch (InterruptedException e) {
logger.info(e.getMessage());
} finally {
try {
process.destroy();
if (successBufferReader != null) successBufferReader.close();
if (errorBufferReader != null) errorBufferReader.close();
} catch (IOException e1) {
logger.info(e1.getMessage());
}
}
return result;
}
}

Loading…
Cancel
Save