From 55aa27a6ad0e012d62dcea2db37528a1b18836fb Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期四, 07 九月 2023 16:44:09 +0800
Subject: [PATCH] 裁剪集群操作的无关动作

---
 system-service/service/clusterService.go |  110 +++++++++++++++---------------------------------------
 1 files changed, 31 insertions(+), 79 deletions(-)

diff --git a/system-service/service/clusterService.go b/system-service/service/clusterService.go
index 07a9928..afe172b 100644
--- a/system-service/service/clusterService.go
+++ b/system-service/service/clusterService.go
@@ -98,12 +98,8 @@
 	return m
 }
 
-//鏍规嵁闆嗙兢鍚嶇О鍜屽瘑鐮佸垱寤洪泦缇�
+// 鏍规嵁闆嗙兢鍚嶇О鍜屽瘑鐮佸垱寤洪泦缇�
 func (s ClusterService) Create(clusterName string, pwd string, virtualIp string) (bool, string) {
-	devTyp := GetDevType(config.Server.DeviceType)
-	if devTyp != DevType_Storage && devTyp != DevType_Analysis_Storage {
-		return false, "鍙湁鍒嗘瀽鍜屽瓨鍌ㄨ妭鐐规墠鑳藉垱寤洪泦缇�"
-	}
 	clusterId := uuid.NewV4().String()
 	pwd = config.ClusterSet.PwdPre + pwd
 	var clusterE = models.Cluster{
@@ -119,19 +115,6 @@
 		b := clusterE.Create()
 		if b {
 			serf.InitAgent(context.Background())
-
-			//鍒涘缓es闆嗙兢
-			if _, err := CreateOriginalCluster("/opt/elasticsearch/config", "/opt/vasystem/script", "/opt/vasystem/indexInit"); err != nil {
-				//鍒涘缓澶辫触锛屽垯serf闆嗙兢涔熻鎺ㄥ嚭
-				s.Leave(false)
-				return false, err.Error()
-			}
-
-			//鍒涘缓weedfs闆嗙兢
-			if _, err = CreateWeedfsServer("/opt/vasystem/script"); err != nil {
-				s.Leave(false)
-				return false, err.Error()
-			}
 
 			chMsg := protomsg.DbChangeMessage{
 				Id:     clusterE.ClusterId,
@@ -186,7 +169,7 @@
 	}
 }
 
-//鍔犲叆闆嗙兢
+// 鍔犲叆闆嗙兢
 func (s ClusterService) JoinCluster(joinArg *vo.ClusterJoinVo) (bool, error) {
 	start := time.Now()
 	if config.Server.AnalyServerId == "" {
@@ -221,47 +204,31 @@
 		serf.Agent = agent
 
 		t := time.Now()
-		syncB := syncTableDataFromCluster(joinArg)
-		logger.Debugf("AddCluster syncTableDataFromCluster time=%v, syncB=%v", time.Since(t), syncB)
-		if syncB {
-			devTyp := GetDevType(config.Server.DeviceType)
-			if devTyp == DevType_Analysis_Storage || devTyp == DevType_Storage { //鍙湁鑳藉惎鍔‥S鐨勮妭鐐规墠鑳藉姞鍏S
-				go func() {
-					//娣诲姞ES鑺傜偣
-					if _, err := AddCluster("/opt/elasticsearch/config", "/opt/vasystem/script", targetIp, "9200", config.EsConfig.StorePath); err != nil {
-						s.Leave(false)
-						return
-					}
-
-					//娣诲姞weedfs鑺傜偣
-					if _, err := AddWeedfsServer("/opt/vasystem/script", targetIp, config.StorageConf.VolumePath); err != nil {
-						s.Leave(false)
-						return
-					}
-				}()
-			}
-
-			//闇�瑕侀噸鏂板垵濮嬪寲鏈湴姣斿杩涚▼
-			go serf.ReInitDbPersonCompareData()
-			chMsg := protomsg.DbChangeMessage{
-				Id:     joinArg.ClusterId,
-				Table:  protomsg.TableChanged_T_Cluster,
-				Action: protomsg.DbAction_Insert,
-				Info:   "",
-			}
-			s.AddDbMessage(&chMsg)
-			logger.Debugf("AddCluster 鍔犲叆闆嗙兢鎴愬姛 time=%v", time.Since(start))
-			return true, nil
-		} else {
-			logger.Debug("AddCluster syncTableDataFromCluster fail")
-			if agent != nil {
-				agent.Leave()
-				err = agent.Shutdown()
-				if err != nil {
-					logger.Debug("AddCluster agent shutdown err:", err)
-				}
-			}
-		}
+		syncTableDataFromCluster(joinArg)
+		logger.Debugf("AddCluster  time=%v", time.Since(t))
+		//if syncB {
+		//	//闇�瑕侀噸鏂板垵濮嬪寲鏈湴姣斿杩涚▼
+		//	go serf.ReInitDbPersonCompareData()
+		//	chMsg := protomsg.DbChangeMessage{
+		//		Id:     joinArg.ClusterId,
+		//		Table:  protomsg.TableChanged_T_Cluster,
+		//		Action: protomsg.DbAction_Insert,
+		//		Info:   "",
+		//	}
+		//
+		//	s.AddDbMessage(&chMsg)
+		logger.Debugf("AddCluster 鍔犲叆闆嗙兢鎴愬姛 time=%v", time.Since(start))
+		return true, nil
+		//} else {
+		//	logger.Debug("AddCluster syncTableDataFromCluster fail")
+		//	if agent != nil {
+		//		agent.Leave()
+		//		err = agent.Shutdown()
+		//		if err != nil {
+		//			logger.Debug("AddCluster agent shutdown err:", err)
+		//		}
+		//	}
+		//}
 	} else {
 		logger.Debug("AddCluster dbSync.Init err:", err)
 		if agent != nil {
@@ -282,7 +249,7 @@
 	DevType_Other            = "other"            //鍏朵粬璁惧绫诲瀷锛宔g锛氬簲鐢�
 )
 
-//鑾峰彇鏈満绫诲瀷锛屽彧杩涜鍒嗘瀽銆佸垎鏋愬瓨鍌ㄤ竴浣撱�佸彧瀛樺偍銆佸叾浠栥�傘��
+// 鑾峰彇鏈満绫诲瀷锛屽彧杩涜鍒嗘瀽銆佸垎鏋愬瓨鍌ㄤ竴浣撱�佸彧瀛樺偍銆佸叾浠栥�傘��
 func GetDevType(dt string) string {
 	if dt != "" {
 		if len(dt) >= 4 {
@@ -336,23 +303,6 @@
 
 func (s ClusterService) Leave(isDel bool) (bool, error) {
 	start := time.Now()
-	devType := GetDevType(config.Server.DeviceType)
-	logger.Debugf("Leave GetDevType=%v, isDel=%v", devType, isDel)
-
-	if devType == DevType_Analysis_Storage || devType == DevType_Storage { //鍙湁鍒嗘瀽鍜屽瓨鍌ㄦ墠鏈塃S闆嗙兢
-		go func() {
-			//閫�鍑簑eedfs鑺傜偣
-			if _, err := ExitWeedfsServer("/opt/vasystem/script", isDel, config.StorageConf.VolumePath); err != nil {
-				logger.Error("Leave ExitWeedfsServer err:", err)
-				return
-			}
-			//閫�鍑篹s鑺傜偣
-			if _, err := ExitCluster("/opt/elasticsearch/config", "/opt/vasystem/script"); err != nil {
-				logger.Error("Leave ExitCluster es cluster err:", err)
-				return
-			}
-		}()
-	}
 
 	var err error
 	tx := models.GetDB().Begin()
@@ -411,7 +361,7 @@
 	return false
 }
 
-//鍔犲叆闆嗙兢鍚庢竻绌烘湰鍦扮殑鍚屾搴撴暟鎹�
+// 鍔犲叆闆嗙兢鍚庢竻绌烘湰鍦扮殑鍚屾搴撴暟鎹�
 func syncTableDataFromCluster(joinArg *vo.ClusterJoinVo) bool {
 	var lc models.LocalConfig
 	e := lc.Select()
@@ -430,6 +380,7 @@
 			tx.Rollback()
 		}
 	}()
+
 	//0.鍏抽棴reference
 	tx.Exec("PRAGMA foreign_keys=OFF")
 	//1.鍒犻櫎鏈湴鐨勫悓姝ュ簱鏁版嵁
@@ -447,6 +398,7 @@
 			return false
 		}
 	}
+
 	//2.鎷夊彇闆嗙兢鍐呯殑鍚屾搴撴暟鎹埌鏈湴鏁版嵁搴撹〃涓�
 	var dumpSqls *[]string
 	dumpSqls, err = serf.GetTableDataFromCluster(serf.Agent, joinArg.ClusterId, serf.SyncTables, 20*time.Second)

--
Gitblit v1.8.0