zhangmeng
2019-12-23 addab1a0f957d2bb545fc00b438aec9f8a9591e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package master
 
import (
    "analysis/app"
    "analysis/logo"
    "analysis/util"
    "context"
    "io/ioutil"
 
    "basic.com/libgowrapper/sdkstruct.git"
)
 
func reaper(ctxt context.Context) {
    pidChan := make(chan int, 1)
    Reap(pidChan)
    go waitForRestart(ctxt, pidChan)
}
 
// Run run
func Run(ctx context.Context, configPath string) bool {
    reaper(ctx)
 
    rPath := configPath
    configFile := configPath
    var fetcher *Fetcher
 
    fs, _ := ioutil.ReadDir(rPath)
    for _, file := range fs {
        if !file.IsDir() {
            if rPath[len(rPath)-1] != '/' {
                configFile = rPath + "/" + file.Name()
            } else {
                configFile = rPath + file.Name()
            }
 
            cfg, err := app.ReadConfig(configFile)
            if err != nil {
                logo.Errorln("Run Fetcher Master Read From File: ", configFile, " Config Error: ", err)
                continue
            }
            fetcher = NewFetcher(cfg.SoFile)
            if fetcher == nil {
                logo.Errorln("New Fetcher Load so File Funcs Error From File: ", cfg.SoFile)
                continue
            }
        }
    }
    if fetcher == nil {
        logo.Errorln("!!!!!!Read All So File, But Can't Init DB Fetcher")
        return false
    }
 
    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()
 
    return manualStart(ctx, sdks, configPath)
}
 
func manualStart(ctx context.Context, sdks []sdkstruct.SDKInfo, configPath string) bool {
    rPath := configPath
 
    for _, v := range sdks {
 
        file := rPath + v.SdkType + ".json"
        if rPath[len(rPath)-1] != '/' {
            file = rPath + "/" + v.SdkType + ".json"
        }
 
        cfg, err := app.ReadConfig(file)
        if err != nil {
            logo.Errorln("Master Read: ", file, " Config Error: ", err)
            continue
        }
 
        logo.Infoln(file, " CONFIG: ", cfg)
 
        args := []string{
            `-role=slave`,
            "-sdk=" + v.SdkType,
            "-id=" + v.IpcID,
            "-" + util.ConfigPath + "=" + file,
        }
 
        args = append(args, app.GetParams(util.ConfigPath, file)...)
        pid, err := runProc(ctx, "./analysis", args, &cfg.Env)
 
        if err != nil {
            logo.Errorf("ANALYSIS START SLAVE PROC %s IPC: %s error %+v\n", v.SdkType, v.IpcID, err)
        }
        logo.Infof("START SDK %s ID %s PID %d Env: %s\n", v.SdkType, v.IpcID, pid, cfg.Env)
    }
    return true
 
}