From accc3295d6daacd70494ecd3a08033f505c29f66 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 20 一月 2020 11:15:27 +0800
Subject: [PATCH] replace sdkhelper with local common

---
 app/master/master.go |   49 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/app/master/master.go b/app/master/master.go
index 1561d77..1199713 100644
--- a/app/master/master.go
+++ b/app/master/master.go
@@ -5,9 +5,14 @@
 	"analysis/logo"
 	"analysis/util"
 	"context"
+	"encoding/json"
+	"os"
+	"strconv"
 	"strings"
+	"time"
 
 	"basic.com/libgowrapper/sdkstruct.git"
+	"basic.com/valib/pubsub.git"
 )
 
 func reaper(ctxt context.Context) {
@@ -28,17 +33,45 @@
 
 	logo.Infoln("~~~~~~Created Fetcher, Now Sync From DB")
 
-	fetcher.fnInitDBAPI(util.FSI.IP, util.FSI.HTTPort, util.FSI.HBPort, util.FSI.DataPort, logo.Infoln)
-	// fetcher.fnInitDBAPI("192.168.20.10", util.FSI.HTTPort, util.FSI.HBPort, util.FSI.DataPort, logo.Infoln)
-	sdks := fetcher.fnSDKInfo()
+	ip := "tcp://" + util.FSI.IP
+	url := ip + ":" + strconv.Itoa(util.FSI.DataPort)
+	hearturl := ip + ":" + strconv.Itoa(util.FSI.HBPort)
+
+	chMsg, err := fetcher.fnInit(url, hearturl, 0, []string{pubsub.Topic_Sdk}, "analysis-master"+strconv.Itoa(os.Getpid()))
 	for {
-		if len(sdks) == 0 {
-			logo.Errorln("!!!!!!Fetcher Can't Get SDK Infos From Remote DB")
-			continue
+		if err == nil {
+			break
 		}
-		break
+		logo.Infoln("Analysis Fetcher INIT Error! URL:", url)
+		time.Sleep(time.Second)
+		chMsg, err = fetcher.fnInit(url, hearturl, 0, []string{pubsub.Topic_Sdk}, "analysis-master"+strconv.Itoa(os.Getpid()))
 	}
-	return manualStart(ctx, sdks, configPath)
+
+	for {
+		select {
+		case <-ctx.Done():
+			return true
+		case msg := <-chMsg:
+			//      		sdktype	   process_name   topic		null
+			//				yolo/face  yolo_0/yolo_1  channel
+			var sdk map[string](map[string](map[string]interface{}))
+
+			if err := json.Unmarshal(msg.Msg, &sdk); err != nil {
+				logo.Infoln("Fetcher SDK unmarshal err:", err)
+				continue
+			}
+
+			logo.Infoln("~~~~~~Recv New SDKInfos")
+			chCameras <- CameraInfo{
+				Cameras: cameras,
+			}
+			logo.Infoln("~~~~~~Recv New SDKInfos Over")
+
+		default:
+			time.Sleep(10 * time.Millisecond)
+		}
+	}
+
 }
 
 func manualStart(ctx context.Context, sdks []sdkstruct.SDKInfo, configPath string) bool {

--
Gitblit v1.8.0