Forráskód Böngészése

its-cluster update

HANTE 1 hónapja
szülő
commit
5efb64386c

+ 1 - 1
its-cluster/src/main/java/com/its/common/ClusterMain.java

@@ -2,6 +2,6 @@ package com.its.common;
 
 public class ClusterMain {
     public static void main(String[] args) {
-        System.out.printf("com.its.common.cluster!");
+        System.out.println("com.its.common.cluster!");
     }
 }

+ 4 - 4
its-cluster/src/main/java/com/its/common/cluster/handler/ClusterMasterHandler.java

@@ -27,9 +27,9 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
             ClusterMessage clusterMsg = (ClusterMessage) msg;
             ClusterNode cluster = ctx.channel().attr(AbstractClusterConfig.CLUSTER_ATTRIBUTE_KEY).get();
             if (cluster == null) {
-                log.error("ClusterMasterHandler.channelRead: [{}], {}, [FROM: nodeId: {}, master: {}, serverTime: {}], Not Found Channel Cluster Object. Will be closed.",
+                log.error("ClusterMasterHandler.channelRead: [{}], {}, [FROM: clusterId: {}, master: {}, serverTime: {}], Not Found Channel Cluster Object. Will be closed.",
                         this.clusterConfig.getId(), ClusterUtils.getTcpAddress(ctx.channel()),
-                        clusterMsg.getNodeId(), clusterMsg.isMaster(), clusterMsg.getServerTime());
+                        clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getServerTime());
 
                 closeChannel(ctx.channel());
                 return;
@@ -38,9 +38,9 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
             if (this.clusterConfig.isLogging()) {
                 MDC.put("id", cluster.getLogKey());
 
-                log.info("ClusterMasterHandler.channelRead: [{}], {}, [FROM: nodeId: {}, master: {}, serverTime: {}]",
+                log.info("ClusterMasterHandler.channelRead: [{}], {}, [FROM: clusterId: {}, master: {}, serverTime: {}]",
                         this.clusterConfig.getId(), ClusterUtils.getTcpAddress(ctx.channel()),
-                        clusterMsg.getNodeId(), clusterMsg.isMaster(), clusterMsg.getServerTime());
+                        clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getServerTime());
 
                 MDC.remove(cluster.getLogKey());
                 MDC.clear();

+ 1 - 1
its-cluster/src/main/java/com/its/common/cluster/handler/ClusterSlaveHandler.java

@@ -27,7 +27,7 @@ public class ClusterSlaveHandler extends ChannelInboundHandlerAdapter {
 //    public void channelRead(ChannelHandlerContext ctx, Object msg) {
 //        if (msg instanceof ClusterMessage) {
 //            ClusterMessage clusterMsg = (ClusterMessage) msg;
-//            log.info("ClusterSlaveHandler.channelRead: nodeId: {}, serverTime: {}, infos: {}",
+//            log.info("ClusterSlaveHandler.channelRead: clusterId: {}, serverTime: {}, infos: {}",
 //                    clusterMsg.getNodeId(), clusterMsg.getServerTime(), clusterMsg.getInfos().size());
 //        }
 //    }

+ 3 - 3
its-cluster/src/main/java/com/its/common/cluster/service/AbstractClusterMasterService.java

@@ -103,7 +103,7 @@ public abstract class AbstractClusterMasterService {
         return serverBootstrap;
     }
 
-    public abstract void election(int nodeId, boolean isMaster);
+    public abstract void election(int clusterId, boolean isMaster);
     public abstract void onClusterMessage(ClusterMessage message);
 
     private void electionMasterSchedule() {
@@ -117,7 +117,7 @@ public abstract class AbstractClusterMasterService {
                     }
                 }
             }
-//            log.info("ClusterMasterService:electionMasterSchedule: nodeId: {}, masterId: {}", this.clusterConfig.getNodeId(), masterId);
+//            log.info("ClusterMasterService:electionMasterSchedule: clusterId: {}, masterId: {}", this.clusterConfig.getId(), masterId);
             if (masterId == Integer.MAX_VALUE || masterId > this.clusterConfig.getId()) {
                 this.clusterConfig.setMaster(true);
             }
@@ -126,7 +126,7 @@ public abstract class AbstractClusterMasterService {
             }
 
             if (this.clusterConfig.isLogging()) {
-                log.info("ClusterMasterService:electionMasterSchedule: nodeId: {}, Master: {}.",
+                log.info("ClusterMasterService:electionMasterSchedule: clusterId: {}, Master: {}.",
                         this.clusterConfig.getId(), this.clusterConfig.isMaster());
             }
 

+ 5 - 5
its-cluster/src/main/java/com/its/common/cluster/service/AbstractClusterSlaveService.java

@@ -113,7 +113,7 @@ public abstract class AbstractClusterSlaveService {
     private ClusterMessage getClusterMessage() {
         List<ClusterMessageData> details = getClusterMessageData();
         return ClusterMessage.builder()
-                .nodeId(this.clusterConfig.getId())
+                .clusterId(this.clusterConfig.getId())
                 .master(this.clusterConfig.isMaster())
                 .serverTime(getSysTime())
                 .infos(details)
@@ -159,16 +159,16 @@ public abstract class AbstractClusterSlaveService {
             f.awaitUninterruptibly();
             if (f.isDone() || f.isSuccess()) {
                 if (this.clusterConfig.isLogging()) {
-                    log.info("ClusterSlaveService.sendSyncData: [{}], {}, [--TO: nodeId: {}, (nodeId: {}, serverTime: {})]",
+                    log.info("ClusterSlaveService.sendSyncData: [{}], {}, [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
                             this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
-                            cluster.getId(), clusterMsg.getNodeId(), clusterMsg.getServerTime());
+                            cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getServerTime());
                 }
             }
         }
         catch (Exception e) {
-            log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: [--TO: nodeId: {}, (nodeId: {}, serverTime: {})]",
+            log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
                     this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
-                    cluster.getId(), clusterMsg.getNodeId(), clusterMsg.getServerTime());
+                    cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getServerTime());
             log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: {}",
                     this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel), e.getMessage());
         }

+ 5 - 5
its-cluster/src/main/java/com/its/common/cluster/service/ClusterMasterInitializer.java

@@ -34,23 +34,23 @@ public class ClusterMasterInitializer extends ChannelInitializer<Channel> {
 
         String ipAddress  = ClusterUtils.getRemoteIpAddress(channel);
         int clientPort = ClusterUtils.getRemotePort(channel);
-        int nodeId = clientPort - this.clusterConfig.getPort();
+        int clusterId = clientPort - this.clusterConfig.getPort();
 
         if (this.clusterConfig.isLogging()) {
-            log.info("ClusterMasterInitializer.initChannel: connected from: {}:{}, nodeId: {}.", ipAddress, clientPort, nodeId);
+            log.info("ClusterMasterInitializer.initChannel: connected from: {}:{}, clusterId: {}.", ipAddress, clientPort, clusterId);
         }
 
         // 하나의 서버에 여러 개의 클러스터가 있을 수 있기 때문에 IP Address 로 찾는 것은 위험함.
         // HaClusterConfig.HaCluster cluster = this.clusterConfig.get(ipAddress);
-        ClusterNode cluster = this.clusterConfig.getClusterMap().get(nodeId);
+        ClusterNode cluster = this.clusterConfig.getClusterMap().get(clusterId);
         if (cluster == null) {
-            log.error("ClusterMasterInitializer.initChannel: [nodeId: {}, IP Address: {}], Unknown Server Id. will be closed.", nodeId, ipAddress);
+            log.error("ClusterMasterInitializer.initChannel: [clusterId: {}, IP Address: {}], Unknown Server Id. will be closed.", clusterId, ipAddress);
             channel.disconnect();
             channel.close();
             return;
         }
         if (!cluster.getIp().equals(ipAddress)) {
-            log.error("ClusterMasterInitializer.initChannel: [nodeId: {}, IP Address: {}], Unknown IP Address. will be closed.", nodeId, ipAddress);
+            log.error("ClusterMasterInitializer.initChannel: [clusterId: {}, IP Address: {}], Unknown IP Address. will be closed.", clusterId, ipAddress);
             channel.disconnect();
             channel.close();
             return;

+ 12 - 0
its-cluster/src/main/java/com/its/common/cluster/vo/AbstractClusterConfig.java

@@ -55,6 +55,7 @@ public abstract class AbstractClusterConfig {
     }
 
     private void setDefaults() {
+        // 클러스터가 하나라 단일 클러스터 정보로 설정
         this.master = true;
         this.id = 1;
         this.syncSeconds = 5;
@@ -62,7 +63,18 @@ public abstract class AbstractClusterConfig {
         this.port = 13888;
         this.logging = false;
         this.packetLogging = false;
+
+        // 단일 노드 정보 설정
         this.nodes = new ArrayList<>();
+        ClusterNode masterNode = new ClusterNode();
+        masterNode.setMaster(this.master);
+        masterNode.setId(this.id);
+        masterNode.setSyncSeconds(this.syncSeconds);
+        masterNode.setIp(this.ip);
+        masterNode.setPort(this.port);
+        masterNode.setLogging(this.logging);
+        masterNode.setPacketLogging(this.packetLogging);
+        this.nodes.add(masterNode);
     }
 
     public boolean validateClusterInfo() {

+ 1 - 1
its-cluster/src/main/java/com/its/common/cluster/vo/ClusterMessage.java

@@ -11,7 +11,7 @@ import java.util.List;
 public class ClusterMessage implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private int nodeId;
+    private int clusterId;
     private boolean master;
     private String serverTime;