|
@@ -18,6 +18,9 @@ var (
|
|
|
applicationName = "pji-control"
|
|
|
localStatus = "idle"
|
|
|
cloudStatus = "NONE"
|
|
|
+ lastLocalStatus = "idle"
|
|
|
+ lastCloudStatus = "NONE"
|
|
|
+ launchedFlag = false
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
@@ -37,108 +40,143 @@ func init() {
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- localTurnLength := 2
|
|
|
- cloudTurnLength := 60
|
|
|
+ localTurnLength := 2
|
|
|
+ cloudTurnLength := 60
|
|
|
overallTurnLength := localTurnLength
|
|
|
-
|
|
|
+ stopTimeWindow := 10
|
|
|
|
|
|
- go pkg.GetLocalStatus(&localStatus, localTurnLength)
|
|
|
- go pkg.GetCloudStatus(&cloudStatus, cloudTurnLength)
|
|
|
+
|
|
|
+ go pkg.GetLocalStatus(&localStatus, &lastLocalStatus, localTurnLength)
|
|
|
+
|
|
|
+ go pkg.GetCloudStatus(&cloudStatus, &lastCloudStatus, cloudTurnLength)
|
|
|
|
|
|
for {
|
|
|
time.Sleep(time.Duration(overallTurnLength) * time.Second)
|
|
|
- fmt.Println("localStatus: ", localStatus)
|
|
|
- fmt.Println("cloudStatus: ", cloudStatus)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+ fmt.Println("localStatus: ", localStatus, "lastLocalStatus: ", lastLocalStatus)
|
|
|
+ fmt.Println("cloudStatus: ", cloudStatus, "lastCloudStatus: ", lastCloudStatus)
|
|
|
|
|
|
-func judgeState1() {
|
|
|
- init := true
|
|
|
- turnLength := 60
|
|
|
- lastStatus := "NONE"
|
|
|
-
|
|
|
- for {
|
|
|
- c_log.GlobalLogger.Errorf("一轮次扫描时间【%v】秒:", turnLength)
|
|
|
- if init {
|
|
|
- time.Sleep(time.Duration(1) * time.Second)
|
|
|
- init = false
|
|
|
- } else {
|
|
|
- time.Sleep(time.Duration(turnLength) * time.Second)
|
|
|
- }
|
|
|
-
|
|
|
- status, err := commonConfig.GetStatus(commonConfig.PlatformConfig.TaskConfigId)
|
|
|
- if err != nil {
|
|
|
- c_log.GlobalLogger.Error("获取配置status失败:", err)
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if status == "UN_CHANGE" {
|
|
|
- lastStatus = "UN_CHANGE"
|
|
|
- continue
|
|
|
- } else if status == "CHANGE" || status == "NONE" {
|
|
|
- if lastStatus == "CHANGE" && status == "CHANGE" {
|
|
|
- commonConfig.InitPlatformConfig()
|
|
|
- continue
|
|
|
- }
|
|
|
- if lastStatus == "NONE" && status == "NONE" {
|
|
|
- continue
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- if lastStatus == "NONE" && status == "CHANGE" {
|
|
|
+
|
|
|
+ if lastLocalStatus == "idle" && localStatus == "running" {
|
|
|
+ if !launchedFlag {
|
|
|
if _, err := util.ExecuteWithPath(commonConfig.LocalConfig.RestartCmd.Dir, commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args...); err != nil {
|
|
|
c_log.GlobalLogger.Info("启动新程序失败,【path】=", commonConfig.LocalConfig.RestartCmd.Dir, "【cmd】=", commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args, ":", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
c_log.GlobalLogger.Info("启动任务,本地执行启动命令:【path】=", commonConfig.LocalConfig.RestartCmd.Dir, "【cmd】=", commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args)
|
|
|
- lastStatus = status
|
|
|
c_log.GlobalLogger.Info("获取数据闭环平台最新配置。")
|
|
|
commonConfig.InitPlatformConfig()
|
|
|
- continue
|
|
|
+ launchedFlag = true
|
|
|
}
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- var killArgs commonService.KillSignal
|
|
|
- if lastStatus == "UN_CHANGE" && status == "CHANGE" {
|
|
|
- killArgs = commonService.KillSignal{NodeName: "master", DropUploadData: commonConfig.PlatformConfig.DropUploadData, Restart: true}
|
|
|
- c_log.GlobalLogger.Info("更新任务,发送rpc重启信号:", killArgs)
|
|
|
- }
|
|
|
- if lastStatus == "UN_CHANGE" && status == "NONE" {
|
|
|
+ if lastLocalStatus == "running" && localStatus == "idle" {
|
|
|
+ if launchedFlag {
|
|
|
+
|
|
|
+ time.Sleep(time.Duration(stopTimeWindow) * time.Minute)
|
|
|
+
|
|
|
+ var killArgs commonService.KillSignal
|
|
|
killArgs = commonService.KillSignal{NodeName: "master", DropUploadData: commonConfig.PlatformConfig.DropUploadData, Restart: false}
|
|
|
c_log.GlobalLogger.Info("杀死任务,发送rpc结束信号:", killArgs)
|
|
|
- }
|
|
|
+ KillRpcClient, err := rpc.Dial("tcp", commonConfig.LocalConfig.Node.Ip+":"+commonConfig.CloudConfig.RpcPort)
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ lastCloudStatus = "NONE"
|
|
|
+ c_log.GlobalLogger.Error("采集程序已经停止:", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
- KillRpcClient, err := rpc.Dial("tcp", commonConfig.LocalConfig.Node.Ip+":"+commonConfig.CloudConfig.RpcPort)
|
|
|
- if err != nil {
|
|
|
-
|
|
|
- lastStatus = "NONE"
|
|
|
- c_log.GlobalLogger.Error("采集程序已经停止:", err)
|
|
|
- continue
|
|
|
- }
|
|
|
+ reply := 0
|
|
|
+ if err = KillRpcClient.Call("KillService.Kill", killArgs, &reply); err != nil {
|
|
|
+ c_log.GlobalLogger.Error("发送 rpc 请求到 master 报错:", err)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- reply := 0
|
|
|
- if err = KillRpcClient.Call("KillService.Kill", killArgs, &reply); err != nil {
|
|
|
- c_log.GlobalLogger.Error("发送 rpc 请求到 master 报错:", err)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- lastStatus = status
|
|
|
- c_log.GlobalLogger.Info("结束任务后,将数据闭环平台配置置空。")
|
|
|
- commonConfig.PlatformConfig = commonConfig.PlatformConfigStruct{}
|
|
|
- if err = KillRpcClient.Close(); err != nil {
|
|
|
-
|
|
|
+ c_log.GlobalLogger.Info("结束任务后,将数据闭环平台配置置空。")
|
|
|
+ commonConfig.PlatformConfig = commonConfig.PlatformConfigStruct{}
|
|
|
+ if err = KillRpcClient.Close(); err != nil {
|
|
|
+
|
|
|
+ }
|
|
|
+ launchedFlag = false
|
|
|
}
|
|
|
- } else {
|
|
|
- c_log.GlobalLogger.Error("未知的采集任务状态。【status】=", status)
|
|
|
+ continue
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if cloudStatus == "CHANGE" {
|
|
|
+ commonConfig.InitPlatformConfig()
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
-func judgeState3() {}
|