commit d63e4d0c7e2ab5efc0cace1314fd2e681eb70df6 Author: MonHun Date: Sun Feb 11 22:12:10 2024 +0900 win 0211 diff --git a/README.md b/README.md new file mode 100644 index 0000000..df001e6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +### Spring Boot Starter + Mybatis + Tibero 연동 +#### EAI데이터 수신 확인후 UEAI의 프로시져 콜 + + diff --git a/lib/ipworks-local-1.0.0.jar b/lib/ipworks-local-1.0.0.jar new file mode 100644 index 0000000..557d507 Binary files /dev/null and b/lib/ipworks-local-1.0.0.jar differ diff --git a/lib/state-spring-boot-starter-1.0.3.jar b/lib/state-spring-boot-starter-1.0.3.jar new file mode 100644 index 0000000..4f5a7df Binary files /dev/null and b/lib/state-spring-boot-starter-1.0.3.jar differ diff --git a/lib/tibero-jdbc-7.0.0.jar b/lib/tibero-jdbc-7.0.0.jar new file mode 100644 index 0000000..69b9029 Binary files /dev/null and b/lib/tibero-jdbc-7.0.0.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7b6d749 --- /dev/null +++ b/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.8 + + + kr.gmtc.gw + eyegw + 0.0.1-SNAPSHOT + EyeGW_EaiIf + Spring Boot Mybatis + Tibero + + + + local-repository + local-repository + file:${basedir}/lib + + + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.0 + + + + kr.gmt.so + state-spring-boot-starter + 1.0.3 + system + ${basedir}/lib/state-spring-boot-starter-1.0.3.jar + + + + com.tmax.tibero + tibero-jdbc + 7 + system + ${basedir}/lib/tibero-jdbc-7.0.0.jar + + + + ipworks.local + ipworks-local-1.0.0 + system + 1.0.0 + ${basedir}/lib/ipworks-local-1.0.0.jar + + + + + + + + EyeGW_EaiIf + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + diff --git a/src/main/java/kr/gmtc/gw/comp/thread/CustomThread.java b/src/main/java/kr/gmtc/gw/comp/thread/CustomThread.java new file mode 100644 index 0000000..66de385 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/comp/thread/CustomThread.java @@ -0,0 +1,116 @@ +package kr.gmtc.gw.comp.thread; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import kr.gmtc.gw.comp.thread.handler.CustomThreadOnTerminate; +import kr.gmtc.gw.comp.thread.handler.CustomThreadWork; + +public class CustomThread extends Thread{ + + /* 대기시간 없음 */ + public static final long NO_SLEEP = 0; + /* 1밀리 초 */ + public static final long SLEEP_MILLI_SEC = 1; + /* 1초 */ + public static final long SLEEP_SECOND = 1000; + /* 30초 */ + public static final long SLEEP_HALF_MINIUTE = 30000; + /* 1분 */ + public static final long SLEEP_MINIUTE = 60000; + + public final String controllClassName; + public final long repeatMiliSec; + public final CustomThreadWork definedWork; + public final CustomThreadOnTerminate definedTerminate; + public final Logger logger; + private boolean running; + + + + /** + * 인터럽트를 받을 시 스레드가 종료됨.
+ * {@link Thread#sleep(long)} 기반으로 재실행 간격을 설정하므로 정확한 실행시간을 보장하지 않음.
+ * 정확한 실행시간 보장이 필요 할 경우 sleep 간격을 짧게 설정하고 호출위치에서 시간확인
+ * 정상적인 종료는 {@link #gracefulStop()}으로 종료함 + * @param threadName 스레드 이름 + * @param controllClass 스레드 관리 클래스, 일반적으로 this 사용 + * @param repeatMiliSec Sleep 시간(밀리 초), 0이하의 경우 대기시간 없음 + * @param definedWork 반복할 작업 + * @param definedTerminate 스레드가 인터럽트에 의해 종료될 경우 할 작업 + * @param autoStart 생성즉시 실행 + */ + + public CustomThread(String threadName, Object controllClass, long repeatMiliSec, + CustomThreadWork definedWork, CustomThreadOnTerminate definedTerminate, boolean autoStart) { + + if (definedWork == null) { + throw new IllegalArgumentException("[CustomThread] - definedWork is null."); + } + + this.definedWork = definedWork; + this.definedTerminate = definedTerminate; + this.controllClassName = controllClass == null ? "" : controllClass.getClass().getSimpleName(); + this.repeatMiliSec = repeatMiliSec > 0 ? repeatMiliSec : 0; + this.logger = LoggerFactory.getLogger(CustomThread.class); + this.running = false; + + setName(threadName); + setDaemon(true); + if (autoStart) { + this.start(); + } + } + + + @Override + public void run() { + logger.info("[CustomThread-"+getName()+"] Started."); + while ( this.running && !this.isInterrupted()) { + try { + try { + this.definedWork.work(); + + } finally { + if (this.repeatMiliSec > 0) { + Thread.sleep(this.repeatMiliSec); + } + } + } catch(InterruptedException e) { // 인터럽트 수신시 종료 + logger.error("[CustomThread-"+getName()+"] Interrupted. "+ e.toString()); + Thread.currentThread().interrupt(); + break; + } catch(Exception e) { // 처리되지 않은 예외 로깅, 예외에 의한 무한루프에 주의 + logger.error("[CustomThread-"+getName()+"] " + e.toString() + ":" + e.getStackTrace()[0] ); + } + } + + if(this.definedTerminate != null) { + this.definedTerminate.onTerminate(); + } + + logger.error("[CustomThread-"+ getName()+"] Stoped."); + + } + + @Override + public String toString() { + + return "CustomThread [controllClass=" + this.controllClassName + ", threadName=" + getName() + + ", runnig=" + this.running + ", alive=" + isAlive()+ ", repeatMiliSec=" + this.repeatMiliSec + + ", definedTerminate=" + (this.definedTerminate == null ? "no" : "yes") + "]"; + } + + @Override + public synchronized void start() { + this.running = true; + super.start(); + } + + /** + * 스레드 정상종료, 진행중인 작업 완료 후 종료됨. + */ + public void gracefulStop() { + this.running = false; + } +} diff --git a/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadOnTerminate.java b/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadOnTerminate.java new file mode 100644 index 0000000..8f6930b --- /dev/null +++ b/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadOnTerminate.java @@ -0,0 +1,6 @@ +package kr.gmtc.gw.comp.thread.handler; + +@FunctionalInterface +public interface CustomThreadOnTerminate { + public void onTerminate(); +} diff --git a/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadWork.java b/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadWork.java new file mode 100644 index 0000000..4d3d156 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/comp/thread/handler/CustomThreadWork.java @@ -0,0 +1,6 @@ +package kr.gmtc.gw.comp.thread.handler; + +@FunctionalInterface +public interface CustomThreadWork { + public void work() throws Exception; +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/EyeGWApplication.java b/src/main/java/kr/gmtc/gw/eyegw/EyeGWApplication.java new file mode 100644 index 0000000..3c2be60 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/EyeGWApplication.java @@ -0,0 +1,13 @@ +package kr.gmtc.gw.eyegw; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EyeGWApplication { + + public static void main(String[] args) { + SpringApplication.run(EyeGWApplication.class, args); + } + +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB1.java b/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB1.java new file mode 100644 index 0000000..ec5457d --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB1.java @@ -0,0 +1,54 @@ +package kr.gmtc.gw.eyegw.config; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +@Configuration +@MapperScan(value = "kr.gmtc.gw.eyegw.db1", sqlSessionFactoryRef = "factory") +public class DataSourceConfigDB1 { + + @Primary + @Bean(name = "datasource") + @ConfigurationProperties(prefix = "database.db1.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean(name = "factory") + public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { + SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean(); + sqlSessionFactory.setDataSource(dataSource); + + Resource[] res = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/DB1/*.xml"); + sqlSessionFactory.setMapperLocations(res); + + return sqlSessionFactory.getObject(); + } + + @Primary + @Bean(name="SqlSessionTemplate") + public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) throws Exception{ + return new SqlSessionTemplate(sqlSessionFactory); + } + + @Primary + @Bean + public DataSourceTransactionManager ATransactionManager(DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + +} + diff --git a/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB2.java b/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB2.java new file mode 100644 index 0000000..187a686 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/config/DataSourceConfigDB2.java @@ -0,0 +1,50 @@ +package kr.gmtc.gw.eyegw.config; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +@Configuration +@MapperScan(value = "kr.gmtc.gw.eyegw.db2", sqlSessionFactoryRef = "factory2") +public class DataSourceConfigDB2 { + + @Bean(name = "datasource2") + @ConfigurationProperties(prefix = "database.db2.datasource") + public DataSource dataSource2() { + return DataSourceBuilder.create().build(); + } + + @Bean(name = "factory2") + public SqlSessionFactory sqlSessionFactory2(@Qualifier("datasource2") DataSource dataSource) throws Exception { + SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean(); + sqlSessionFactory.setDataSource(dataSource); + + Resource[] res = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/DB2/*.xml"); + sqlSessionFactory.setMapperLocations(res); + + return sqlSessionFactory.getObject(); + } + + @Bean(name="SqlSessionTemplate2") + public SqlSessionTemplate sqlSessionTemplate2(SqlSessionFactory sqlSessionFactory) throws Exception{ + return new SqlSessionTemplate(sqlSessionFactory); + } + + // DataSource 에서 Transaction 관리를 위한 Manager 클래스 등록 + @Bean + public DataSourceTransactionManager BTransactionManager(@Qualifier("datasource2") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } +} + diff --git a/src/main/java/kr/gmtc/gw/eyegw/config/ServiceConfig.java b/src/main/java/kr/gmtc/gw/eyegw/config/ServiceConfig.java new file mode 100644 index 0000000..cd5575d --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/config/ServiceConfig.java @@ -0,0 +1,23 @@ +package kr.gmtc.gw.eyegw.config; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Queue; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration("ServiceConfig") +public class ServiceConfig { + + @Bean(name = "statusReportQ") + public HashMap> statusReportQ(){ + return new LinkedHashMap>(); + } + + @Bean(name = "serviceRunnig") + public boolean serviceRunnig(){ + return false; + } + +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/controller/MainController.java b/src/main/java/kr/gmtc/gw/eyegw/controller/MainController.java new file mode 100644 index 0000000..c75bfee --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/controller/MainController.java @@ -0,0 +1,383 @@ +package kr.gmtc.gw.eyegw.controller; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +import javax.annotation.Resource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import kr.gmt.so.state.StateManager; +import kr.gmt.so.state.model.SystemState; +import kr.gmtc.gw.comp.thread.CustomThread; +import kr.gmtc.gw.eyegw.config.ServiceConfig; +import kr.gmtc.gw.eyegw.db1.EaiIfCheckService; +import kr.gmtc.gw.eyegw.db1.EaiProcService; + +@Component("controller") +public class MainController implements ApplicationListener { + + // 프레임 워크 구성요소 // + /** 서비스 설정, {@code application.properties} */ + @Resource(name = "ServiceConfig") + private ServiceConfig serviceConfig; + + // DB // + /** + * DB1 Connection
+ * application.yml에 db.db1.use가 true로 설정되어야 사용가능
+ * db.db1.use가 false일 경우 주석처리 (Bean 런타임 에러 발생) + * @see DB1Connection + */ +// @Resource(name = "DB1Connection") +// private DB1Connection db1Connection; + + private EaiIfCheckService eaiIfCheckService; + private EaiProcService eaiProcService; + + // DB // + + + + // 업무처리 // + /** 업무 처리 스레드 */ + private List listCustomThreads; + // private CustomThread callThread_ArtsArr; + // private CustomThread callThread_ArtsDep; + // private CustomThread callThread_AcdmArr; + // private CustomThread callThread_AcdmDep; + // private CustomThread callThread_Gam; + // private CustomThread callThread_Amos; + // private CustomThread callThread_Notam; + private CustomThread chkThreadStatus; + + @Value("${settings.interval.proc.call}") + private int procCallInterval; + + @Value("${settings.interval.chk.thread}") + private int chkThreadInterval; + + + DateTimeFormatter dfPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + + + private static final Logger logger = LoggerFactory.getLogger(MainController.class); + + @Autowired + private StateManager stateMgr; + + private boolean swBeforeStatus = true; + + /** 초기화 실패 시 프로그램 종료 */ +// private void systemError() { +// // logger.writeLevelLog("-- FAIL TO STARTUP --", LogLevelType.LOG_ERROR, "AllLog"); +// System.exit(1); +// } + + /** + * 수정 금지
+ * Spring Bean 객체 생성, logger 초기화 + */ + public MainController(EaiProcService eaiProcService, EaiIfCheckService eaiIfCheckService) { + + this.eaiProcService = eaiProcService; + this.eaiProcService = eaiProcService; + this.eaiIfCheckService = eaiIfCheckService; + + } + + /** + * 실행 (1순위)
+ * 프로그램 초기화 + */ + @Order(0) + @EventListener(ApplicationReadyEvent.class) + public void initialize() { + try { + + // 업무 스래드(프로시저 호출) + listCustomThreads = new ArrayList(); + + listCustomThreads.add(new CustomThread("callThread_ArtsArr", this, procCallInterval, this::callThread_ArtsArr, null, false)); + listCustomThreads.add(new CustomThread("callThread_ArtsDep", this, procCallInterval, this::callThread_ArtsDep, null, false)); + listCustomThreads.add(new CustomThread("callThread_AcdmArr", this, procCallInterval, this::callThread_AcdmArr, null, false)); + listCustomThreads.add(new CustomThread("callThread_AcdmDep", this, procCallInterval, this::callThread_AcdmDep, null, false)); + listCustomThreads.add(new CustomThread("callThread_Gam", this, procCallInterval, this::callThread_Gam, null, false)); + listCustomThreads.add(new CustomThread("callThread_Amos", this, procCallInterval, this::callThread_Amos, null, false)); + listCustomThreads.add(new CustomThread("callThread_Notam", this, procCallInterval, this::callThread_Notam, null, false)); + + // 이중화 체크 및 업무스래드 체크 + chkThreadStatus = new CustomThread("chkThreadStatus", this, procCallInterval, this::chkThreadStatus, null, false); + + } catch (Exception e) { + logger.error("MainContoller-Thread create fail"); + System.exit(1); + } + } + + /** + * 실행 (2순위)
+ * 프로그램 실행 + */ + @Order(1) + @EventListener(ApplicationReadyEvent.class) + public void start() { + try { + + logger.info("MainContoller-Thread start"); + + for(CustomThread ct : listCustomThreads ){ + ct.start(); + } + + chkThreadStatus.start(); + + stateMgr.updateState(); + + } catch (Exception e) { + logger.error("MainContoller-Thread start fail"); + System.exit(1); + } + } + + + /** 종료 처리 */ + public void stop() { + + for(CustomThread ct : listCustomThreads ){ + ct.gracefulStop(); + } + + chkThreadStatus.gracefulStop(); + + } + + + private void chkThreadStatus(){ + + stateMgr.updateState(); + + boolean running = true; + boolean swNewStatus = stateMgr.isActive(); + + // 이중화 Active / Standby 상태 변경 체크 + if(swBeforeStatus != swNewStatus){ + + if(swNewStatus){ + for(CustomThread ct : listCustomThreads ) ct.start(); + }else{ + for(CustomThread ct : listCustomThreads ) ct.gracefulStop(); + } + + } + + // 해당 프로그램이 Active일때 Thread Interrupt 유무 체크 + if(swNewStatus){ + + for(CustomThread ct : listCustomThreads ){ + if(ct.isInterrupted()){ + running = false; + break; + } + } + + if(running){ + stateMgr.updateState(SystemState.Normal); + }else{ + stateMgr.updateState(SystemState.Error); + } + } + + swBeforeStatus = stateMgr.isActive(); + + // logger.info("swBeforeStatus : " + swBeforeStatus); + + } + + + + /** 종료 이벤트 (강제종료시 수행 안됨) */ + public void onApplicationEvent(ContextClosedEvent event) { + + stateMgr.updateState(SystemState.Stop); + for(CustomThread ct : listCustomThreads ) ct.gracefulStop(); + chkThreadStatus.gracefulStop(); + + logger.info("====================== SYSTEM STOPED ======================"); + } + + + /** + * 업무 로직
+ * 자동으로 무한반복 하므로 내부에 while문 필요 없음.
+ * 예외처리를 하지 않을 경우 {@link CustomThread} 내부에서 로그 처리 + */ + private void callThread_ArtsArr() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getArtsArr(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcArtsArr(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcArtsArr Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + + } + + private void callThread_ArtsDep() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getArtsDep(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcArtsDep(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcArtsDep Call " + sCnt + "건 " + diff.toMillis() + "msec"); + + } + + // Thread.sleep(3000); + + } + + private void callThread_AcdmArr() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getAcdmArr(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcAcdmArr(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcAcdmArr Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + } + + private void callThread_AcdmDep() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getAcdmDep(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcAcdmDep(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcAcdmDep Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + } + + private void callThread_Gam() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getGam(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcGam(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcGam Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + } + + + private void callThread_Amos() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getAmos(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcAmos(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcAmos Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + } + + private void callThread_Notam() throws InterruptedException { + + // if(!running) return ; + + List> dataCnt = eaiIfCheckService.getNotam(); + + String sCnt = String.valueOf(dataCnt.get(0).get("DATA_CNT")); + + if( Integer.parseInt(sCnt) > 0 ) { + + LocalDateTime dt_before = LocalDateTime.now(); + + eaiProcService.callProcNotam(); + + Duration diff = Duration.between(dt_before, LocalDateTime.now()); + logger.info("callProcNotam Call " + sCnt + "건 " + diff.toMillis() + "msec"); + } + + // Thread.sleep(3000); + } + + + +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/controller/SystemCheckManager.java b/src/main/java/kr/gmtc/gw/eyegw/controller/SystemCheckManager.java new file mode 100644 index 0000000..8572200 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/controller/SystemCheckManager.java @@ -0,0 +1,91 @@ +package kr.gmtc.gw.eyegw.controller; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component("systemCheckManager") +public class SystemCheckManager { + private final Logger logger = LoggerFactory.getLogger("scLogger"); + + private ScheduledExecutorService scheduler; + + @Value("${sc.schduler.initialDelay:3}") + private int initialDelay; + + @Value("${sc.schduler.fixedDelay:1}") + private int fixedDelay; + + private final int REST_CNT = 10; + private int ErrorCnt = REST_CNT; + private String ErrorMsg = ""; + private int WarnCnt = REST_CNT; + private String WarnMsg = ""; + + + @PostConstruct + private void initialize() { + CreateSchedules(); + } + + private void CreateSchedules() { + + scheduler = Executors.newScheduledThreadPool(1); + + Runnable ReconnTask = () -> { + + if(ErrorCnt < REST_CNT) { + ErrorCnt++; + logger.error("ERROR|" + ErrorMsg); + } + else if(WarnCnt < REST_CNT) { + WarnCnt++; + logger.warn("WARN|" + WarnMsg); + } + else { + logger.info("NORAML|Heartbeat"); + } + + }; + scheduler.scheduleAtFixedRate(ReconnTask, initialDelay, fixedDelay, TimeUnit.SECONDS); + } + + public void error (String Msg) { + logger.error("ERROR|" + Msg); + + ErrorCnt = 0; + ErrorMsg = Msg; + } + + public void warn(String Msg) { + + if(ErrorCnt >= REST_CNT) + logger.warn("WARN|" + Msg); + + WarnCnt = 5; + WarnMsg = Msg; + } + + public void info (String Msg) { + logger.info("NORMAL|" + Msg); + } + + @PreDestroy + public void finalize() { + try { + scheduler.shutdown(); + scheduler.awaitTermination(100, TimeUnit.MILLISECONDS); + } catch (Exception e) { + logger.error("", e); + } + } +} + diff --git a/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckMapper.java b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckMapper.java new file mode 100644 index 0000000..1f330fc --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckMapper.java @@ -0,0 +1,19 @@ +package kr.gmtc.gw.eyegw.db1; + +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.List; + +@Mapper +//@Repository +public interface EaiIfCheckMapper { + List> selectAarsArr(); + List> selectAarsDep(); + List> selectAcdmArr(); + List> selectAcdmDep(); + List> selectGAM(); + List> selectAMOS(); + List> selectNOTAM(); +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckService.java b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckService.java new file mode 100644 index 0000000..c1bac5f --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiIfCheckService.java @@ -0,0 +1,43 @@ +package kr.gmtc.gw.eyegw.db1; + +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; + +@Service +public class EaiIfCheckService { + private EaiIfCheckMapper checkMapper; + + public EaiIfCheckService(EaiIfCheckMapper checkMapper){ + this.checkMapper = checkMapper; + } + + public List> getArtsArr() { + return checkMapper.selectAarsArr(); + } + + public List> getArtsDep() { + return checkMapper.selectAarsDep(); + } + + public List> getAcdmArr() { + return checkMapper.selectAcdmArr(); + } + public List> getAcdmDep() { + return checkMapper.selectAcdmDep(); + } + + public List> getGam() { + return checkMapper.selectGAM(); + } + + public List> getAmos() { + return checkMapper.selectAMOS(); + } + + public List> getNotam() { + return checkMapper.selectNOTAM(); + } + +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcMapper.java b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcMapper.java new file mode 100644 index 0000000..8829a1b --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcMapper.java @@ -0,0 +1,16 @@ +package kr.gmtc.gw.eyegw.db1; + +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface EaiProcMapper { + + void callProcArtsArr(); + void callProcArtsDep(); + void callProcAcdmArr(); + void callProcAcdmDep(); + void callProcGam(); + + void callProcAmos(); + void callProcNotam(); +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcService.java b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcService.java new file mode 100644 index 0000000..3d11bc0 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db1/EaiProcService.java @@ -0,0 +1,55 @@ +package kr.gmtc.gw.eyegw.db1; + +import org.springframework.stereotype.Service; + +@Service +public class EaiProcService { + private EaiProcMapper ueaiProcMapper; + + public EaiProcService(EaiProcMapper ueaiProcMapper){ + this.ueaiProcMapper = ueaiProcMapper; + } + + public void callProcArtsArr() { + + ueaiProcMapper.callProcArtsArr(); + + } + + public void callProcArtsDep() { + + ueaiProcMapper.callProcArtsDep(); + + } + + public void callProcAcdmArr() { + + ueaiProcMapper.callProcAcdmArr(); + + } + + public void callProcAcdmDep() { + + ueaiProcMapper.callProcAcdmDep(); + + } + + public void callProcGam() { + + ueaiProcMapper.callProcGam(); + + } + + public void callProcAmos() { + + ueaiProcMapper.callProcAmos(); + + } + + public void callProcNotam() { + + ueaiProcMapper.callProcNotam(); + + } + +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcMapper.java b/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcMapper.java new file mode 100644 index 0000000..f0e9307 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcMapper.java @@ -0,0 +1,16 @@ +package kr.gmtc.gw.eyegw.db2; + +import java.util.HashMap; +import java.util.Map; + +//@Mapper +//@Repository +public interface UicProcMapper { + //List> callProc(); + HashMap callProcTest(Map map); + // void callProcArtsArr(); + // void callProcArtsDep(); + // void callProcAcdmArr(); + // void callProcAcdmDep(); + // void callProcGam(); +} diff --git a/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcService.java b/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcService.java new file mode 100644 index 0000000..4734054 --- /dev/null +++ b/src/main/java/kr/gmtc/gw/eyegw/db2/UicProcService.java @@ -0,0 +1,62 @@ +package kr.gmtc.gw.eyegw.db2; + +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +@Service +public class UicProcService { + private UicProcMapper uICProcMapper; + + public UicProcService(UicProcMapper uICProcMapper){ + this.uICProcMapper = uICProcMapper; + } + + public String callProcTest(String sParam1, String sParam2, String iParam3) { + + Map paramMap = new HashMap(); + String sRetValue = null; + + paramMap.put("ar_param1", String.valueOf(sParam1)); + paramMap.put("ar_param2", String.valueOf(sParam2)); + paramMap.put("ar_param3", String.valueOf(iParam3)); + + uICProcMapper.callProcTest(paramMap); + + sRetValue = (String) paramMap.get("ret_value"); + + return sRetValue; + } + + // public void callProcArtsArr() { + + // uICProcMapper.callProcArtsArr(); + + // } + + // public void callProcArtsDep() { + + // uICProcMapper.callProcArtsDep(); + + // } + + // public void callProcAcdmArr() { + + // uICProcMapper.callProcAcdmArr(); + + // } + + // public void callProcAcdmDep() { + + // uICProcMapper.callProcAcdmDep(); + + // } + + // public void callProcGam() { + + // uICProcMapper.callProcGam(); + + // } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..abe4dc2 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,69 @@ +spring: + profiles: + active: default + group: + default: + - winTest + +--- +spring: + config: + activate: + on-profile: default + +database: + db1: + datasource: + driver-class-name: com.tmax.tibero.jdbc.TbDriver + jdbcUrl: jdbc:tibero:thin:@10.200.31.1:8629:sacp + username: ueai + password: ueai + db2: + datasource: + driver-class-name: com.tmax.tibero.jdbc.TbDriver + jdbcUrl: jdbc:tibero:thin:@10.200.31.1:8629:sacp + username: uic + password: uic + +state: + # 공통코드 CT001의 코드 6자리 + id: LK0302 # IFToDB + # 1:Primary, 2:Secondary + type: Primary + +--- +spring: + config: + activate: + on-profile: real + +server: + port: 18089 + +# root: /home/gmt/app/... + +settings: + interval: + proc: + call: 10000 + chk: + thread: 30000 + +--- +spring: + config: + activate: + on-profile: winTest + +server: + port: 18089 + +settings: + interval: + proc: + call: 10000 + chk: + thread: 30000 +# root: D:\Workspace\... + + diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..793fff1 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + ${LOG_PATTERN} + + + + + + + + + + INFO + + + + ${LOG_PATH}${PATH_SEPARATOR}${LOG_FILE_NAME}.log + + + + ${FILE_LOG_PATTERN} + + + + + + ${LOG_PATH}${PATH_SEPARATOR}%d{yyyyMM,aux}${PATH_SEPARATOR}%d{yyyyMMdd}.log + + 10 + + 100mb + + true + + + + + + + false + 0 + 1024 + true + + + + + systemcheck${file.separator}sc.log + + %d{yyyy-MM-dd HH:mm:ss.SSS}|%msg%n + + + systemcheck${file.separator}%d{yyyyMM,aux}${file.separator}%d{yyyyMMdd}.log + 10 + 500mb + true + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/logback-spring.xml_backup b/src/main/resources/logback-spring.xml_backup new file mode 100644 index 0000000..c717225 --- /dev/null +++ b/src/main/resources/logback-spring.xml_backup @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + ${LOG_PATTERN} + + + + + ${LOGS_PATH}/logback.log + + ${FILE_LOG_PATTERN} + + + ${LOGS_PATH}/logback.%d{yyyy-MM-dd}.%i.log.gz + + + 5MB + + + 30 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DB1/eai_if_check.xml b/src/main/resources/mapper/DB1/eai_if_check.xml new file mode 100644 index 0000000..8599879 --- /dev/null +++ b/src/main/resources/mapper/DB1/eai_if_check.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DB1/eai_proc.xml b/src/main/resources/mapper/DB1/eai_proc.xml new file mode 100644 index 0000000..7fecbfa --- /dev/null +++ b/src/main/resources/mapper/DB1/eai_proc.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DB2/uci_proc.xml b/src/main/resources/mapper/DB2/uci_proc.xml new file mode 100644 index 0000000..c812286 --- /dev/null +++ b/src/main/resources/mapper/DB2/uci_proc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + \ No newline at end of file