shjung 9 ヶ月 前
コミット
12fe970b18

+ 10 - 5
evps-comm-server/src/main/java/com/evps/comm/server/EvpsCommServerApplication.java

@@ -19,6 +19,7 @@ import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
+import sun.misc.Signal;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -76,22 +77,26 @@ public class EvpsCommServerApplication implements CommandLineRunner, Application
     public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
         SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
+        log.error("************************************************************************************");
+        log.error("**    Application Terminated: {}, {}, {}",
+                sdfDate.format(new Date()), contextClosedEvent.getTimestamp(), contextClosedEvent);
         EvpsCommServerService cvimServer = SpringUtils.getBean(EvpsCommServerService.class);
         try {
             cvimServer.stop();
-        } catch (Exception e) {
-            log.error("{}", e.getMessage());
         }
-        log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent);
+        catch (Exception e) {
+            log.error("**    onApplicationEvent Exception: {}", e.getMessage());
+        }
+        log.error("************************************************************************************");
     }
 
     @Override
     public void destroy() throws Exception {
-        log.error("Application destroy");
+        log.error("Application destroy.");
     }
 
     @Override
     public void afterPropertiesSet() throws Exception {
-        log.info("Application afterPropertiesSet");
+        log.info("Application afterPropertiesSet.");
     }
 }

+ 1 - 0
evps-comm-server/src/main/java/com/evps/comm/server/dao/mapper/EvpsServiceMapper.java

@@ -17,5 +17,6 @@ public interface EvpsServiceMapper {
     int insertEvpNode(Map<String, Object> obj);
     int insertEvpPhase(Map<String, Object> obj);
     int insertEvpSignal(Map<String, Object> obj);
+    int insertEvpSignalCurr(Map<String, Object> obj);
 
 }

+ 7 - 0
evps-comm-server/src/main/java/com/evps/comm/server/dao/mapper/batch/EvpCommServerDao.java

@@ -48,4 +48,11 @@ public class EvpCommServerDao extends BatchDaoService {
         log.info("{}.insertEvpSignal: ..END. {} EA. {} ms.", this.serviceName, total, elapsed.milliSeconds());
         return total;
     }
+    public int insertEvpSignalCurr(List<HashMap<String, Object>> req) {
+        log.info("{}.insertEvpSignalCurr: START. {} EA", this.serviceName, req.size());
+        Elapsed elapsed = new Elapsed();
+        int total = insertBatch("insertEvpSignalCurr", req);
+        log.info("{}.insertEvpSignalCurr: ..END. {} EA. {} ms.", this.serviceName, total, elapsed.milliSeconds());
+        return total;
+    }
 }

+ 13 - 1
evps-comm-server/src/main/java/com/evps/comm/server/process/dbms/DbmsDataProcess.java

@@ -89,39 +89,47 @@ public class DbmsDataProcess {
                 case DbmsData.DBMS_DATA_INS_SERVICE:
                     typeDesc = "DBMS_DATA_INS_SERVICE";
                     KafkaEvpsServiceDto newService = (KafkaEvpsServiceDto)data.getData();
+                    log.info("{}, {}", typeDesc, newService);
                     result = this.serviceMapper.insertEvpService(newService);
                     break;
                 case DbmsData.DBMS_DATA_UPD_SERVICE:
                     typeDesc = "DBMS_DATA_UPD_SERVICE";
                     KafkaEvpsServiceDto updService = (KafkaEvpsServiceDto)data.getData();
+                    log.info("{}, {}", typeDesc, updService);
                     result = this.serviceMapper.updateEvpService(updService);
                     break;
 
                 case DbmsData.DBMS_DATA_INS_EVENT:
                     typeDesc = "DBMS_DATA_INS_EVENT";
                     KafkaEvpsEventDto event = (KafkaEvpsEventDto)data.getData();
+                    log.info("{}, {}", typeDesc, event);
                     result = this.serviceMapper.insertEvpEvent(event);
                     break;
                 case DbmsData.DBMS_DATA_INS_ROUTE:
                     typeDesc = "DBMS_DATA_INS_ROUTE";
                     List<HashMap<String, Object>> routeList = (List<HashMap<String, Object>>) data.getData();
+                    log.info("{}, {}", typeDesc, routeList);
                     result = this.evpCommServerDao.insertEvpRoute(routeList);
                     break;
                 case DbmsData.DBMS_DATA_INS_NODE:
                     typeDesc = "DBMS_DATA_INS_NODE";
                     List<HashMap<String, Object>> nodeList = (List<HashMap<String, Object>>)data.getData();
+                    log.info("{}, {}", typeDesc, nodeList);
                     result = this.evpCommServerDao.insertEvpNode(nodeList);
                     break;
 
                 case DbmsData.DBMS_DATA_INS_PHASE:
                     typeDesc = "DBMS_DATA_INS_PHASE";
                     List<HashMap<String, Object>> phaseList = (List<HashMap<String, Object>>)data.getData();
+                    log.info("{}, {}", typeDesc, phaseList);
                     result = this.evpCommServerDao.insertEvpPhase(phaseList);
                     break;
 
                 case DbmsData.DBMS_DATA_INS_SIGNAL:
                     typeDesc = "DBMS_DATA_INS_SIGNAL";
                     List<HashMap<String, Object>> signalList = (List<HashMap<String, Object>>)data.getData();
+                    log.info("{}, {}", typeDesc, signalList);
+                    result = this.evpCommServerDao.insertEvpSignalCurr(signalList);
                     result = this.evpCommServerDao.insertEvpSignal(signalList);
                     break;
 
@@ -129,11 +137,14 @@ public class DbmsDataProcess {
                 case DbmsData.DBMS_DATA_CENTER_STTS_UPDATE:
                     typeDesc = "DBMS_DATA_CENTER_STTS_UPDATE";
                     TbRegionCenterComm updStts = (TbRegionCenterComm) data.getData();
+//                    log.info("{}, {}", typeDesc, updStts);
 //                    this.centerMapper.updateCommState(updStts);
                     break;
 
                 case DbmsData.DBMS_DATA_CENTER_STTS:
+                    typeDesc = "DBMS_DATA_CENTER_STTS";
                     TbRegionCenterComm stts = (TbRegionCenterComm) data.getData();
+                    //log.info("{}, {}", typeDesc, stts);
                     switch(stts.getCommState()) {
                         case TbRegionCenterComm.CENTER_COMM_START:
                             typeDesc = "CENTER_COMM_START";
@@ -157,7 +168,8 @@ public class DbmsDataProcess {
                     center.getLogKey(), typeDesc, result, Elapsed.elapsedTimeStr(elapsed1.nanoSeconds()));
         }
         catch (Exception e) {
-            log.error("DbmsJobProcess.process: [{}]. {}, Exception: {}", center.getLogKey(), type, e.toString());
+            log.error("DbmsJobProcess.process: [{}]. {}, Exception: {}", center.getLogKey(), typeDesc, e.toString());
+            log.error("DbmsJobProcess.process: [{}]. {}, {}", center.getLogKey(), typeDesc, data.getData());
         }
         finally {
             MDC.remove(center.getLogKey());

+ 9 - 2
evps-comm-server/src/main/java/com/evps/comm/server/scheduler/ApplicationScheduler.java

@@ -11,6 +11,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.PreDestroy;
+
 @Slf4j
 @RequiredArgsConstructor
 @EnableScheduling
@@ -21,6 +23,11 @@ public class ApplicationScheduler {
     private final UnitSystService unitSystService;
     private final ApplicationRepository applicationRepository;
 
+    @PreDestroy
+    public void onShutDown() {
+        log.info("ApplicationScheduler.onShutDown: Shutting down...");
+    }
+
 //    @ScheduleElapsed
     @Async
     @Scheduled(cron = "0 * * * * *")  // 10초 주기 작업 실행
@@ -33,7 +40,7 @@ public class ApplicationScheduler {
         }
     }
 
-    @ScheduleElapsed
+//    @ScheduleElapsed
     @Async
     @Scheduled(cron = "20 * * * * *")  // 1분주기 작업 실행
     public void loadTraceConfig() {
@@ -46,7 +53,7 @@ public class ApplicationScheduler {
     }
 
 //    @ScheduleElapsed
-//    @Async
+    @Async
     @Scheduled(cron = "20 * * * * *")  // 1분주기 작업 실행
     public void reportCenterSessions() {
         try {

+ 17 - 8
evps-comm-server/src/main/java/com/evps/comm/server/xnet/server/EvpsCommServerInitializer.java

@@ -19,6 +19,7 @@ import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
 import io.netty.handler.timeout.IdleStateHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.slf4j.MDC;
 
 @Slf4j
 public class EvpsCommServerInitializer extends ChannelInitializer<Channel> {
@@ -47,15 +48,23 @@ public class EvpsCommServerInitializer extends ChannelInitializer<Channel> {
             channel.close();
             return;
         }
-        log.info("EvpsCommServerInitializer.----initChannel: {}, {},.", center.getCenterId(), ipAddress);
-        if (center.getNetState().getChannel() != null) {
-            log.warn("EvpsCommServerInitializer.----initChannel: {}, {}, Already Connected. Old Connection will be closed.", ipAddress, center.getCenterId());
-            // 이벤트 핸들러 에서 중복 처리 되지 않도록 속성 값을 제거
-            channel.attr(ApplicationRepository.SIG_REGION_ATTRIBUTE_KEY).set(null);
-            center.getNetState().disConnect();
+        try {
+            MDC.put("id", center.getLogKey());
 
-            channel.disconnect();
-            channel.close();
+            log.info("EvpsCommServerInitializer.----initChannel: {}, {},.", center.getCenterId(), ipAddress);
+            if (center.getNetState().getChannel() != null) {
+                log.warn("EvpsCommServerInitializer.----initChannel: {}, {}, Already Connected. Old Connection will be closed.", ipAddress, center.getCenterId());
+                // 이벤트 핸들러 에서 중복 처리 되지 않도록 속성 값을 제거
+                channel.attr(ApplicationRepository.SIG_REGION_ATTRIBUTE_KEY).set(null);
+                center.getNetState().disConnect();
+
+                channel.disconnect();
+                channel.close();
+            }
+        }
+        finally {
+            MDC.remove(center.getLogKey());
+            MDC.clear();
         }
 
         TbRegionCenterComm stts = TbRegionCenterComm.builder()

+ 6 - 1
evps-comm-server/src/main/java/com/evps/comm/server/xnet/server/handler/EvpsCommServerInboundMessageHandler.java

@@ -48,7 +48,12 @@ public class EvpsCommServerInboundMessageHandler extends SimpleChannelInboundHan
             EvpsCommPacket evpsCommPacket = new EvpsCommPacket(center, byteBuf);
 
             if (center.isDump()) {
-                log.info("RECV: [{}]. {} Bytes. {}", center.getLogKey(), evpsCommPacket.getBuffer().length, ByteUtils.byteArrayToHex(evpsCommPacket.getBuffer()));
+                log.info("RECV: [{}]. {} Bytes.\r\nService Id: {}. Time: {}. Head: {} Bytes. Body: {} Bytes. {}{}",
+                        center.getLogKey(), evpsCommPacket.getFrameLength(),
+                        evpsCommPacket.getServiceId(), evpsCommPacket.getCommDate(),
+                        evpsCommPacket.getHeadBuffer().length, evpsCommPacket.getBuffer().length,
+                        ByteUtils.byteArrayToHex(evpsCommPacket.getHeadBuffer()),
+                        ByteUtils.byteArrayToHex(evpsCommPacket.getBuffer()));
             }
             else {
                 log.info("RECV: [{}]. {} Bytes.", center.getLogKey(), evpsCommPacket.getBuffer().length);

+ 4 - 0
evps-comm-server/src/main/resources/application.yml

@@ -19,8 +19,12 @@ spring:
       minimumIdle: 5
       maximumPoolSize: 20
       idleTimeout: 30000
+  lifecycle:
+    timeout-per-shutdown-phase: 10s
+
 server:
   port: 9870
+  shutdown: graceful
 management:
   endpoints:
     web:

+ 13 - 1
evps-comm-server/src/main/resources/logback-spring.xml

@@ -38,7 +38,7 @@
         <appender-ref ref="FILE_ERROR"/>
     </root>
 
-    <springProfile name="dev">
+    <springProfile name="!prod">
         <logger name="${APP_CLASS_PATH}.aspect" level="INFO" additivity="false">
             <appender-ref ref="CONSOLE"/>
             <appender-ref ref="FILE_ASPECT"/>
@@ -56,6 +56,12 @@
             <appender-ref ref="FILE_PACKET"/>
             <appender-ref ref="FILE_ERROR"/>
         </logger>
+        <logger name="${APP_CLASS_PATH}.xnet.server.EvpsCommServerInitializer" level="INFO" additivity="false">
+            <appender-ref ref="CONSOLE"/>
+            <appender-ref ref="FILE_SESSION"/>
+            <appender-ref ref="FILE_PACKET"/>
+            <appender-ref ref="FILE_ERROR"/>
+        </logger>
     </springProfile>
 
     <springProfile name="prod">
@@ -76,5 +82,11 @@
             <appender-ref ref="FILE_PACKET"/>
             <appender-ref ref="FILE_ERROR"/>
         </logger>
+        <logger name="${APP_CLASS_PATH}.xnet.server.EvpsCommServerInitializer" level="INFO" additivity="false">
+            <appender-ref ref="CONSOLE"/>
+            <appender-ref ref="FILE_SESSION"/>
+            <appender-ref ref="FILE_PACKET"/>
+            <appender-ref ref="FILE_ERROR"/>
+        </logger>
     </springProfile>
 </configuration>

+ 3 - 3
evps-comm-server/src/main/resources/mybatis/mapper/EvpsCenterMapper.xml

@@ -26,7 +26,7 @@
     <![CDATA[
         UPDATE tb_evp_center
         SET comm_sts = 1,
-            comm_dt  = current_timestamp()
+            comm_dt  = current_timestamp(3)
         WHERE center_id  = #{centerId}
         ]]>
     </update>
@@ -35,7 +35,7 @@
     <![CDATA[
         UPDATE tb_evp_center
         SET comm_sts = 1,
-            conn_dt  = current_timestamp()
+            conn_dt  = current_timestamp(3)
         WHERE center_id  = #{centerId}
         ]]>
     </update>
@@ -44,7 +44,7 @@
     <![CDATA[
         UPDATE tb_evp_center
         SET comm_sts = 0,
-            disconn_dt = current_timestamp()
+            disconn_dt = current_timestamp(3)
         WHERE center_id  = #{centerId}
         ]]>
     </update>

+ 39 - 5
evps-comm-server/src/main/resources/mybatis/mapper/EvpsServiceMapper.xml

@@ -20,7 +20,7 @@
                                     service_dist,
                                     status_cd)
                           VALUES ( #{obj.serviceId},
-                                   current_timestamp(),
+                                   current_timestamp(3),
                                    #{obj.evNo},
                                    #{obj.curLat},
                                    #{obj.curLng},
@@ -54,7 +54,7 @@
                                   cur_lng,
                                   cur_spd,
                                   rem_dist)
-        VALUES ( current_timestamp(),
+        VALUES ( current_timestamp(3),
                  #{obj.serviceId},
                  #{obj.eventCd},
                  #{obj.curLat},
@@ -145,7 +145,7 @@
                                    a_ring_phase,
                                    b_ring_phase,
                                    hold_phase)
-        VALUES ( current_timestamp(),
+        VALUES ( current_timestamp(3),
                  #{SERVICE_ID},
                  #{NODE_ID},
                  #{SEQ_NO},
@@ -159,6 +159,40 @@
         ]]>
     </insert>
 
+    <insert id="insertEvpSignalCurr" parameterType="java.util.Map">
+    <![CDATA[
+        INSERT INTO tb_evp_signal_curr (service_id,
+                                   node_id,
+                                   seq_no,
+                                   clct_dt,
+                                   rem_dist,
+                                   state,
+                                   plan_class,
+                                   a_ring_phase,
+                                   b_ring_phase,
+                                   hold_phase)
+        VALUES ( #{SERVICE_ID},
+                 #{NODE_ID},
+                 #{SEQ_NO},
+                 current_timestamp(3),
+                 #{REM_DIST},
+                 #{STATE},
+                 #{PLAN_CLASS},
+                 #{A_RING_PHASE},
+                 #{B_RING_PHASE},
+                 #{HOLD_PHASE}
+               )
+            ON DUPLICATE KEY UPDATE
+                                 clct_dt       = current_timestamp(3),
+                                 rem_dist      = #{REM_DIST},
+                                 state         = #{STATE},
+                                 plan_class    = #{PLAN_CLASS},
+                                 a_ring_phase  = #{A_RING_PHASE},
+                                 b_ring_phase  = #{B_RING_PHASE},
+                                 hold_phase    = #{HOLD_PHASE}
+        ]]>
+    </insert>
+
     <insert id="insertEvpSignal2" parameterType="java.util.Map">
     <![CDATA[
         INSERT INTO tb_evp_signal (service_id,
@@ -174,7 +208,7 @@
         VALUES ( #{SERVICE_ID},
                  #{NODE_ID},
                  #{SEQ_NO},
-                 current_timestamp(),
+                 current_timestamp(3),
                  #{REM_DIST},
                  #{STATE},
                  #{PLAN_CLASS},
@@ -183,7 +217,7 @@
                  #{HOLD_PHASE}
                )
         ON DUPLICATE KEY UPDATE
-             clct_dt       = current_timestamp(),
+             clct_dt       = current_timestamp(3),
              rem_dist      = #{REM_DIST},
              state         = #{STATE},
              plan_class    = #{PLAN_CLASS},

+ 5 - 5
evps-comm-server/src/main/resources/mybatis/mapper/ProcessMapper.xml

@@ -7,7 +7,7 @@
     <![CDATA[
         UPDATE tb_tsc_process
         SET process_state  = 1,
-            update_tm   =  current_timestamp()
+            update_tm   =  current_timestamp(3)
         WHERE process_id = #{processId}
         ]]>
     </update>
@@ -16,8 +16,8 @@
     <![CDATA[
         UPDATE tb_tsc_process
         SET process_state  = 1,
-            update_tm   =  current_timestamp(),
-            start_tm = current_timestamp()
+            update_tm   =  current_timestamp(3),
+            start_tm = current_timestamp(3)
         WHERE process_id = #{processId}
         ]]>
     </update>
@@ -26,8 +26,8 @@
     <![CDATA[
         UPDATE tb_tsc_process
         SET process_state = 0,
-            update_tm   =  current_timestamp(),
-            end_tm   =  current_timestamp()
+            update_tm   =  current_timestamp(3),
+            end_tm   =  current_timestamp(3)
         WHERE process_id = #{processId}
         ]]>
     </update>

ファイルの差分が大きいため隠しています
+ 32 - 21
evps-comm-server/src/test/java/com/evps/comm/server/EvpsCommServerApplicationTest.java


+ 1 - 0
evps-common/src/main/java/com/evps/common/kafka/dto/KafkaEvpsNodeDto.java

@@ -52,6 +52,7 @@ public class KafkaEvpsNodeDto {
         private List<EvpsPhaseInfo> phaseList = new ArrayList<>();
     }
 
+    @ToString
     @Getter
     @Builder
     @NoArgsConstructor

+ 1 - 1
evps-common/src/main/java/com/evps/common/protocol/EvpsCommPacket.java

@@ -123,7 +123,7 @@ public class EvpsCommPacket implements Serializable {
         this.dataLength = ((this.headBuffer[idx++] & 0xFF) << 8) | (this.headBuffer[idx] & 0xFF);
 //        this.dataLength = ((this.headBuffer[idx++] & 0xFF) << 24) | ((this.headBuffer[idx++] & 0xFF) << 16) | ((this.headBuffer[idx++] & 0xFF) << 8) | (this.headBuffer[idx++] & 0xFF);
         this.commDate = String.format("%4d%02d%02d%02d%02d%02d", this.year, this.month, this.day, this.hour, this.min, this.sec);
-        this.serviceId = EvpsByteUtils.toString(this.serviceIdArr).trim();
+        this.serviceId = EvpsByteUtils.toString(this.serviceIdArr);
         this.isValid = true;
     }
 

+ 4 - 2
evps-common/src/main/java/com/evps/common/utils/EvpsByteUtils.java

@@ -1,5 +1,7 @@
 package com.evps.common.utils;
 
+import java.nio.charset.StandardCharsets;
+
 public class EvpsByteUtils {
 
 	private EvpsByteUtils() {}
@@ -8,8 +10,8 @@ public class EvpsByteUtils {
 		if (decBytes == null || decBytes.length == 0) {
 			return "";
 		}
-		//String eucKrString = new String(decBytes, "EUC-KR");
-		return new String(decBytes);
+		return new String(decBytes, StandardCharsets.UTF_8).trim();
+//		return new String(decBytes);
 	}
 
 }

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません