shjung 2 settimane fa
parent
commit
647c53575e

+ 41 - 13
rota-utic-client/src/main/java/com/utic/its/rota/utic/client/controller/RotaUticClientRestController.java

@@ -152,6 +152,37 @@ public class RotaUticClientRestController {
         return ResponseEntity.ok(result);
     }
 
+    @GetMapping(value = "/api/init/failback")
+    public ResponseEntity<?> failback() {
+        int resetCount = 0;
+        List<String> keySet = new ArrayList<>(ApplicationRepository.CENTER_MAP.keySet());
+        Collections.sort(keySet);
+        for (String key : keySet) {
+            CenterDto region = ApplicationRepository.CENTER_MAP.get(key);
+            if (region == null) {
+                continue;
+            }
+
+            if (this.clusterConfig.isEnabled()) {
+                if (region.getNetState().isAlive() &&
+                        region.getActiveClusterId() > 0 &&
+                        this.clusterConfig.getId() != region.getRealClusterId()) {
+                    // 네트워크가 연결된 상태이면서 실제 연결된 네트워크가 현재 노드가 아닌경우
+                    try {
+                        if (region.getNetState().getChannel() != null) {
+                            region.getNetState().getChannel().disconnect();
+                            region.getNetState().getChannel().close();
+                            region.getNetState().disConnect();
+                        }
+                    } catch (Exception e) {
+                        // no logging
+                    }
+                    resetCount++;
+                }
+            }
+        }
+        return ResponseEntity.ok("communication connect cluster reset failback ok. cluster: " + this.clusterConfig.getId() + ", reset count: " + resetCount);
+    }
     @GetMapping(value = "/api/init/reset")
     public ResponseEntity<?> reset() {
         int resetCount = 0;
@@ -164,21 +195,18 @@ public class RotaUticClientRestController {
             }
 
             if (this.clusterConfig.isEnabled()) {
-                if (region.getNetState().isAlive() && this.clusterConfig.getId() != region.getActiveClusterId()) {
-                    // 네트워크가 연결된 상태이면서 실제 연결된 네트워크가 현재 노드가 아닌경우
-                    if (this.clusterConfig.getId() != region.getRealClusterId()) {
-                        // 다른 노드에서 작업을 수행하기로 설정된 지역센터의 연결을 종료한다.
-                        try {
-                            if (region.getNetState().getChannel() != null) {
-                                region.getNetState().getChannel().disconnect();
-                                region.getNetState().getChannel().close();
-                                region.getNetState().disConnect();
-                            }
-                        } catch (Exception e) {
-                            // no logging
+                if (region.getNetState().isAlive() && region.getActiveClusterId() > 0) {
+                    // 네트워크가 연결된 상태이면서 실제 연결된 네트워크가 존재하는 경우
+                    try {
+                        if (region.getNetState().getChannel() != null) {
+                            region.getNetState().getChannel().disconnect();
+                            region.getNetState().getChannel().close();
+                            region.getNetState().disConnect();
                         }
-                        resetCount++;
+                    } catch (Exception e) {
+                        // no logging
                     }
+                    resetCount++;
                 }
             }
         }

+ 1 - 0
rota-utic-server/src/main/java/com/utic/its/rota/utic/server/scheduler/ApplicationScheduler.java

@@ -50,6 +50,7 @@ public class ApplicationScheduler {
                     connCount++;
                 }
             }
+            ApplicationRepository.processState.setSndCnt(this.rotaUticServerService.getSendTrafficCount());
             ApplicationRepository.processState.setEtcCnt((int)connCount);
             this.processStateService.processRunning();
         } catch(Exception e) {

+ 5 - 4
rota-utic-server/src/main/java/com/utic/its/rota/utic/server/service/RotaUticServerService.java

@@ -35,6 +35,7 @@ public class RotaUticServerService {
     private final RotaUticServerRepository repo;
     private boolean isRunning = false;
     private boolean isRunningCheckIncident = false;
+    private int sendTrafficCount;
 
     @PostConstruct
     private void init() {
@@ -101,8 +102,8 @@ public class RotaUticServerService {
                 return ++result;
             }
 
-            final int trafficCount = traffics.size();
-            log.info("[TRAF] {}: [{}], {} EA.", LogUtils.elapsedLog("NewTraffic"), currTrafficTime, trafficCount);
+            this.sendTrafficCount = traffics.size();
+            log.info("[TRAF] {}: [{}], {} EA.", LogUtils.elapsedLog("NewTraffic"), currTrafficTime, this.sendTrafficCount);
 
             // 메모리에 현재 교통정보 시각과 교통정보 목록을 저장한다.
             ApplicationRepository.updateTrafficData(currTrafficTime, traffics);
@@ -112,7 +113,7 @@ public class RotaUticServerService {
                 this.executor.executeSendTraffic(center);
             });
 
-            ApplicationRepository.processState.setSndCnt(trafficCount);
+            ApplicationRepository.processState.setSndCnt(this.sendTrafficCount);
 
             // CENTER_SEND_INFO 로깅
             TbSndLog log = TbSndLog.builder()
@@ -120,7 +121,7 @@ public class RotaUticServerService {
                     .infoKind(DbmsData.D_INFOTYPE_TRAF)
                     .fromCenterId(ApplicationRepository.CENTER.getCenterId())
                     .toCenterId(ApplicationRepository.CENTER.getCenterId())
-                    .dataCnt(trafficCount)
+                    .dataCnt(this.sendTrafficCount)
                     .clusterId(this.clusterConfig.getId())
                     .build();
             this.dbmsDataProcess.add(new DbmsData(0, ApplicationRepository.CENTER, DbmsData.DBMS_CENTER_SEND_INFO, "", log, 0));