init
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.eactive.eai.rms.bap.common.base;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
import com.eactive.eai.rms.common.base.BaseService;
|
||||
import com.eactive.eai.rms.onl.common.service.AgentUtilService;
|
||||
|
||||
public class BapBaseService extends BaseService{
|
||||
|
||||
/** The agentUtil service. */
|
||||
@Autowired
|
||||
@Qualifier("bapAgentUtilService")
|
||||
public AgentUtilService agentUtilService;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.eactive.eai.rms.bap.common.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.eactive.eai.agent.command.Command;
|
||||
import com.eactive.eai.rms.bap.manage.comm.server.BapServerService;
|
||||
import com.eactive.eai.rms.onl.common.service.AgentUtilService;
|
||||
|
||||
/**
|
||||
* 1. 기능 : 등록된 EAI Server 에 Command를 broadcast
|
||||
* 2. 처리 개요 : 등록된 EAI Server 에 Command를 broadcast
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @see 관련 기능을 참조
|
||||
* @since
|
||||
*
|
||||
*/
|
||||
|
||||
@Service("bapAgentUtilService")
|
||||
public class BapAgentUtilServiceImpl implements AgentUtilService {
|
||||
private final Logger logger = Logger.getLogger(getClass());
|
||||
final static String SERVLET_URL = "/BAPWeb/WebAgent";
|
||||
|
||||
private static int DEFAULT_CONNECT_TIME_OUT = 300; // 0 값을 입력하면 디폴트 값이 쓰이는 듯.
|
||||
|
||||
/**
|
||||
* eaiServerInfoService 를 대체한다.
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("bapServerService")
|
||||
private BapServerService bapServerService;
|
||||
|
||||
/**
|
||||
* 1. 기능 : AgentUtil 기본 생성자
|
||||
* 2. 처리 개요 :
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @exception
|
||||
**/
|
||||
public BapAgentUtilServiceImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Active-Standby 형태 일때 ip , port는 같고 인스턴스및 host가 다를경우 때문에 getEaiServerIpPortForActiveStandby 를 사용
|
||||
* 메모리 동기화시 한곳만 동기화 하면되고 데이터는 2개의 row가 존재함
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private HashMap<String, String> getAllSvrUrl(String instanceName) throws Exception {
|
||||
|
||||
HashMap<String, String> resultMap = new HashMap<String, String>();
|
||||
|
||||
//HashMap<String, Object> map = bapServerService.getEaiServerIpPortForActiveStandby();
|
||||
List<Map<String, Object>> list = bapServerService.getEaiServerIpPort();
|
||||
if (list != null) {
|
||||
for (int inx = 0; inx < list.size(); inx++) {
|
||||
Map<String, Object> map = list.get(inx);
|
||||
if ( instanceName == null || map.get("EAISVRINSTNM").toString().equals(instanceName)) {
|
||||
String svrIp = (String) map.get("EAISVRIP");
|
||||
String svrPort = (String) map.get("EAISVRLSNPORT");
|
||||
StringBuffer urlBuf = new StringBuffer();
|
||||
urlBuf.append("http://");
|
||||
urlBuf.append(svrIp + ":" + svrPort);
|
||||
urlBuf.append(SERVLET_URL);
|
||||
|
||||
resultMap.put( (String) map.get("EAISVRINSTNM"), urlBuf.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public HashMap<String, Object> broadcast(String serviceKey, Command command) throws Exception {
|
||||
return broadcast(command);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> broadcast(Command command) throws Exception {
|
||||
return broadcast(command, null);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> broadcast(Command command, String instanceName) throws Exception {
|
||||
|
||||
URLConnection urlCon;
|
||||
HashMap<String, String> servers = getAllSvrUrl(instanceName);
|
||||
|
||||
HashMap<String, Object> returnValue = new HashMap<String, Object>();
|
||||
|
||||
if (servers != null) {
|
||||
Iterator<String> it = servers.keySet().iterator();
|
||||
String svrName = "";
|
||||
String url = "";
|
||||
Object response = "";
|
||||
|
||||
while (it.hasNext()) {
|
||||
svrName = it.next();
|
||||
url = servers.get(svrName);
|
||||
|
||||
urlCon = getURLConnection(url);
|
||||
|
||||
if( logger.isDebugEnabled() ) {
|
||||
logger.debug("메모리동기화:cmd=" + command.getClass().getSimpleName() + " ,url=" + url);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if(urlCon != null){ //취약점소스 수정 2020.08.27
|
||||
response = sendCommand(urlCon, command);
|
||||
}
|
||||
|
||||
returnValue.put(svrName, response);
|
||||
} catch (Exception e) {
|
||||
logger.error("AgentUtil] broadcast Excpetion - " + url
|
||||
+ e.getMessage());
|
||||
returnValue.put(svrName, e.getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.error("AgentUtil] broadcast Error. - url is null");
|
||||
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : 해당 URLConnection으로 command 전송 처리 결과를 반환
|
||||
* 2. 처리 개요 : 해당 URLConnection으로 command 전송하고 처리 결과를 반환
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param urlCon 연결할 URLConnection
|
||||
* @param command 전송할 Command
|
||||
* @return String 처리된 결과
|
||||
* @exception Exception
|
||||
**/
|
||||
private Object sendCommand(URLConnection urlCon, Command command)
|
||||
throws Exception {
|
||||
ObjectOutputStream oos = null;
|
||||
ObjectInputStream ois = null;
|
||||
Object response = "";
|
||||
|
||||
// 2009.05.22 서버가 다운되어 있는 경우 응답시간이 너무 길어서 timeout 값을 지정함.
|
||||
// 2009.07.09 타임아웃 값을 3000 -> 100 으로 조정함.
|
||||
urlCon.setConnectTimeout(DEFAULT_CONNECT_TIME_OUT);
|
||||
|
||||
try {
|
||||
oos = new ObjectOutputStream(urlCon.getOutputStream());
|
||||
oos.writeObject(command);
|
||||
oos.flush();
|
||||
if( logger.isDebugEnabled() ) {
|
||||
logger.debug("AgentUtil] SendCommand - "
|
||||
+ urlCon.getURL().toString());
|
||||
}
|
||||
|
||||
ois = new ObjectInputStream(urlCon.getInputStream());
|
||||
response = ois.readObject();
|
||||
|
||||
} catch (ConnectException e) {
|
||||
logger.error("AgentUtil] sendCommand ConnectException. - "
|
||||
+ urlCon.getURL() + " can't Connect" + e.getMessage());
|
||||
throw e;
|
||||
} catch (IOException e2) {
|
||||
//e2.printStackTrace();
|
||||
logger.error("AgentUtil] sendCommand IOException. - "
|
||||
+ urlCon.getURL() + " error=" + e2.getMessage());
|
||||
throw e2;
|
||||
} catch (Exception e) {
|
||||
logger.error("AgentUtil] sendCommand Exception. - "
|
||||
+ urlCon.getURL() + e.getMessage());
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
if (oos != null) {
|
||||
oos.close();
|
||||
}
|
||||
if (ois != null) {
|
||||
ois.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
oos = null;
|
||||
logger.error("AgentUtil] sendCommand Error. - "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : 지정된 url의 URLConnection 생성
|
||||
* 2. 처리 개요 : 지정된 url의 URLConnection 생성
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param url URLConnection을 생성을 위한 url
|
||||
* @return URLConnection 생성된 URLConnection
|
||||
* @exception
|
||||
**/
|
||||
private URLConnection getURLConnection(String url) {
|
||||
URL u = null;
|
||||
try {
|
||||
u = new URL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
logger.error( e );
|
||||
}
|
||||
|
||||
HttpURLConnection conn = null;
|
||||
|
||||
try {
|
||||
conn = (HttpURLConnection) u.openConnection();
|
||||
} catch (ConnectException ce) {
|
||||
logger.error( ce );
|
||||
} catch (IOException ie) {
|
||||
logger.error( ie );
|
||||
} catch (Exception e) {
|
||||
logger.error( e );
|
||||
}
|
||||
|
||||
if (conn != null) {
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
} else {
|
||||
logger.error("AgentUtil] getURLConnection Error. - " + url
|
||||
+ " 의 HttpURLConnection 을 생성할 수 없습니다.");
|
||||
}
|
||||
|
||||
try {
|
||||
if (conn != null) {
|
||||
conn.setRequestMethod("POST");
|
||||
}
|
||||
} catch (ProtocolException pe) {
|
||||
logger.error("AgentUtil] getURLConnection ProtocolException. - "
|
||||
+ pe.getMessage());
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.setRequestProperty("Content-type", "application/octet-stream");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.eactive.eai.rms.bap.common.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;
|
||||
|
||||
@Repository("bapLogTableDao")
|
||||
public class BapLogTableDao extends SqlMapClientTemplateDao {
|
||||
|
||||
final Logger logger = Logger.getLogger(BapLogTableDao.class);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public long [] clearLogTable(HashMap<String, String> paramMap, int keyLevel) {
|
||||
|
||||
long [] cnt = new long[3];
|
||||
|
||||
cnt[0] = 0;
|
||||
cnt[1] = 0;
|
||||
cnt[2] = 0;
|
||||
|
||||
for (int inx = 0; inx < power( 16, keyLevel); inx++) {
|
||||
paramMap.put("uuid", toHex(inx,keyLevel));
|
||||
cnt[0] += this.template.update("BapLogDelete.clearStage", paramMap);
|
||||
cnt[1] += this.template.update("BapLogDelete.clearNoFileStage", paramMap);
|
||||
cnt[2] += this.template.update("BapLogDelete.clearNoFileMaster", paramMap);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
private int power( int x, int y ){
|
||||
if ( y == 1 )
|
||||
return x;
|
||||
return x * power( x, y -1);
|
||||
}
|
||||
|
||||
private String toHex( int val, int len){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String sval = Integer.toHexString(val);
|
||||
for ( int inx = 0; inx < len - sval.length(); inx++){
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(sval);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.eactive.eai.rms.bap.common.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.eactive.eai.common.util.DatetimeUtil;
|
||||
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
|
||||
import com.eactive.eai.rms.common.datasource.DataSourceType;
|
||||
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
|
||||
|
||||
|
||||
|
||||
public class BapLogTableDeleteJob implements Job {
|
||||
/**
|
||||
* Logger for this class
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(BapLogTableDeleteJob.class);
|
||||
|
||||
private transient BapLogTableDeleteService bapLogTableDeleteService;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
JobKey jobKey = context.getJobDetail().getKey();
|
||||
String data ="";
|
||||
for(String key : context.getJobDetail().getJobDataMap().getKeys()){
|
||||
data =data + key +"="+context.getJobDetail().getJobDataMap().getString(key) + ",";
|
||||
}
|
||||
logger.error("excute TestJob "+jobKey + "data ("+data+")");
|
||||
|
||||
ApplicationContext appContext = null;
|
||||
try {
|
||||
appContext = (ApplicationContext)context.getScheduler().getContext().get("applicationContext");
|
||||
} catch (SchedulerException e) {
|
||||
logger.error("applicationContext get module error",e);
|
||||
return ;
|
||||
}
|
||||
bapLogTableDeleteService = (BapLogTableDeleteService)appContext.getBean("bapLogTableDeleteService");
|
||||
|
||||
logger.info("START BAP_EMPTY_LOG_TABLE_SCHEDULER...");
|
||||
|
||||
int keyLevel = 2;
|
||||
int nofileStart = 7;
|
||||
int nofileEnd = 3;
|
||||
int stageStart = 37;
|
||||
int stageEnd = 30;
|
||||
|
||||
try{
|
||||
keyLevel = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("key.level"));
|
||||
}catch ( Exception e) {
|
||||
logger.error("keyLevel error",e);
|
||||
}
|
||||
try{
|
||||
nofileStart = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("nofile.start"));
|
||||
}catch ( Exception e) {
|
||||
logger.error("nofileStart error",e);
|
||||
}
|
||||
try{
|
||||
nofileEnd = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("nofile.end"));
|
||||
}catch ( Exception e) {
|
||||
logger.error("nofileEnd error",e);
|
||||
}
|
||||
try{
|
||||
stageStart = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("stage.start"));
|
||||
}catch ( Exception e) {
|
||||
logger.error("stageStart error",e);
|
||||
}
|
||||
try{
|
||||
stageEnd = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("stage.end"));
|
||||
}catch ( Exception e) {
|
||||
logger.error("stageEnd error",e);
|
||||
}
|
||||
|
||||
// DataSourceType dataType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.ISG);
|
||||
DataSourceType dataType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.BAP);
|
||||
|
||||
DataSourceContextHolder.setDataSourceType(dataType);
|
||||
HashMap<String, String> paramMap = new HashMap<String, String>();
|
||||
paramMap.put("nofileStart", DatetimeUtil.getDate(-1 * nofileStart)+"0000");
|
||||
paramMap.put("nofileEnd", DatetimeUtil.getDate(-1 * nofileEnd)+"9999");
|
||||
paramMap.put("stageStart", DatetimeUtil.getDate(-1 * stageStart)+"0000");
|
||||
paramMap.put("stageEnd", DatetimeUtil.getDate(-1 * stageEnd)+"9999");
|
||||
|
||||
try{
|
||||
long [] cnt = bapLogTableDeleteService.clearLogTable(paramMap, keyLevel );
|
||||
logger.info("[BAP_EMPTY_LOG_TABLE_SCHEDULER]스테이지 로그 삭제 건수:" + cnt[0]);
|
||||
logger.info("[BAP_EMPTY_LOG_TABLE_SCHEDULER]파일없는 스테이지 로그 삭제 건수:" + cnt[1]);
|
||||
logger.info("[BAP_EMPTY_LOG_TABLE_SCHEDULER]파일없는 마스터 로그 삭제 건수:" + cnt[2]);
|
||||
}catch ( Exception e){
|
||||
logger.error("...BAP_EMPTY_LOG_TABLE_SCHEDULER error="+e.getMessage(),e);
|
||||
}
|
||||
logger.info("...BAP_EMPTY_LOG_TABLE_SCHEDULER END");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.eactive.eai.rms.bap.common.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service("bapLogTableDeleteService")
|
||||
public class BapLogTableDeleteService {
|
||||
|
||||
/**
|
||||
* Logger for this class
|
||||
*/
|
||||
|
||||
@Autowired
|
||||
@Qualifier("bapLogTableDao")
|
||||
private BapLogTableDao bapLogTableDao;
|
||||
|
||||
public long [] clearLogTable(HashMap<String, String> paramMap, int keyLevel) {
|
||||
return bapLogTableDao.clearLogTable(paramMap, keyLevel);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user