diff --git a/build/bin/overflow_probe_container_discovery b/build/bin/overflow_probe_container_discovery new file mode 100755 index 0000000..1180f38 Binary files /dev/null and b/build/bin/overflow_probe_container_discovery differ diff --git a/build/bin/overflow_probe_container_discovery.logging.json b/build/bin/overflow_probe_container_discovery.logging.json new file mode 100644 index 0000000..8a2f6ee --- /dev/null +++ b/build/bin/overflow_probe_container_discovery.logging.json @@ -0,0 +1,28 @@ +{ + "level": "debug", + "development": true, + "disableCaller": true, + "disableStacktrace": true, + "sampling": { + "initial": 100, + "thereafter": 100 + }, + "encoding": "console", + "encoderConfig": { + "messageKey": "message", + "levelKey": "level", + "timeKey": "time", + "nameKey": "name", + "callerKey": "caller", + "stacktraceKey": "stacktrace", + "lineEnding": "\n", + "levelEncoder": "color", + "timeEncoder": "ISO8601", + "durationEncoder": "string", + "callerEncoder": "full", + "nameEncoder": "full" + }, + "outputPaths": ["/project/overFlow/probe/logs/overflow_probe_container_discovery.log"], + "errorOutputPaths": ["stderr"] +} + diff --git a/build/bin/overflow_probe_container_network.logging.json b/build/bin/overflow_probe_container_network.logging.json new file mode 100644 index 0000000..31003bf --- /dev/null +++ b/build/bin/overflow_probe_container_network.logging.json @@ -0,0 +1,28 @@ +{ + "level": "debug", + "development": true, + "disableCaller": true, + "disableStacktrace": true, + "sampling": { + "initial": 100, + "thereafter": 100 + }, + "encoding": "console", + "encoderConfig": { + "messageKey": "message", + "levelKey": "level", + "timeKey": "time", + "nameKey": "name", + "callerKey": "caller", + "stacktraceKey": "stacktrace", + "lineEnding": "\n", + "levelEncoder": "color", + "timeEncoder": "ISO8601", + "durationEncoder": "string", + "callerEncoder": "full", + "nameEncoder": "full" + }, + "outputPaths": ["/project/overFlow/probe/logs/overflow_probe_container_network.log"], + "errorOutputPaths": ["stderr"] +} + diff --git a/build/config/_ b/build/config/_ new file mode 100644 index 0000000..e69de29 diff --git a/build/jre/_ b/build/jre/_ new file mode 100644 index 0000000..e69de29 diff --git a/build/logs/_ b/build/logs/_ new file mode 100644 index 0000000..e69de29 diff --git a/build/pid/_ b/build/pid/_ new file mode 100644 index 0000000..e69de29 diff --git a/client/container/client.go b/client/container/client.go index adf663f..83ea267 100644 --- a/client/container/client.go +++ b/client/container/client.go @@ -3,7 +3,6 @@ package container import ( "fmt" "os/exec" - "path" crc "git.loafle.net/commons_go/rpc/client" crr "git.loafle.net/commons_go/rpc/registry" @@ -22,32 +21,26 @@ func New(port int, rpcInvoker crr.RPCInvoker) crc.Client { } func GetContainerCommand(name string) (cmd *exec.Cmd, pidPath string) { - pidPath = path.Join(config.Config.Paths["root"], ooccp.PathPID, name+".pid") + + pidPath = config.ContainerPIDPath(name) + logConfigPath := config.ContainerLogConfigPath(name) + binPath := config.ContainerBinPath(name) switch name { case ooccp.ContainerGeneralName: - logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerGeneralLogConfigFileName) - javaPath := path.Join(config.Config.Paths["root"], ooccp.PathJRE, "bin", "java") - jarPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerGeneralFileName) - // arg := fmt.Sprintf("-jar %s %s", jarPath, pidPath) + javaPath := config.JavaBinPath() - cmd = exec.Command(javaPath, "-jar", jarPath, pidPath, logConfigPath) + cmd = exec.Command(javaPath, "-jar", binPath, pidPath, logConfigPath) case ooccp.ContainerNetworkName: - logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkLogConfigFileName) - exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerNetworkFileName) - arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath) arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath) - cmd = exec.Command(exePath, arg1, arg2) + cmd = exec.Command(binPath, arg1, arg2) case ooccp.ContainerDiscoveryName: - logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryLogConfigFileName) - exePath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerDiscoveryFileName) - arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath) arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath) - cmd = exec.Command(exePath, arg1, arg2) + cmd = exec.Command(binPath, arg1, arg2) default: } return diff --git a/config/config.go b/config/config.go index 665aac8..31df221 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,8 @@ package config import ( + "path" + ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" ) @@ -11,3 +13,31 @@ var ( Config *ooccp.Config ) + +func RootDirPath() string { + return Config.Paths["root"] +} + +func BinDirPath() string { + return path.Join(RootDirPath(), ooccp.PathBin) +} + +func ConfigDirPath() string { + return path.Join(RootDirPath(), ooccp.PathConfig) +} + +func JREDirPath() string { + return path.Join(RootDirPath(), ooccp.PathJRE) +} + +func JavaBinPath() string { + return path.Join(JREDirPath(), "bin", "java") +} + +func LogsDirPath() string { + return path.Join(RootDirPath(), ooccp.PathLogs) +} + +func PIDDirPath() string { + return path.Join(RootDirPath(), ooccp.PathPID) +} diff --git a/config/container.go b/config/container.go new file mode 100644 index 0000000..7277d6e --- /dev/null +++ b/config/container.go @@ -0,0 +1,44 @@ +package config + +import ( + "fmt" + "path" + + ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" +) + +func ContainerPIDPath(name string) string { + pidName := fmt.Sprintf("%s.pid", name) + + return path.Join(PIDDirPath(), pidName) +} + +func ContainerBinPath(name string) string { + var binName string + switch name { + case ooccp.ContainerGeneralName: + binName = ooccp.ContainerGeneralFileName + case ooccp.ContainerNetworkName: + binName = ooccp.ContainerNetworkFileName + case ooccp.ContainerDiscoveryName: + binName = ooccp.ContainerDiscoveryFileName + default: + } + + return path.Join(BinDirPath(), binName) +} + +func ContainerLogConfigPath(name string) string { + var configName string + switch name { + case ooccp.ContainerGeneralName: + configName = ooccp.ContainerGeneralLogConfigFileName + case ooccp.ContainerNetworkName: + configName = ooccp.ContainerNetworkLogConfigFileName + case ooccp.ContainerDiscoveryName: + configName = ooccp.ContainerDiscoveryLogConfigFileName + default: + } + + return path.Join(BinDirPath(), configName) +} diff --git a/probe/probe.go b/probe/probe.go index 370f412..494d66f 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -75,7 +75,7 @@ func (pm *probeManagers) Start() error { pm.stopChan = make(chan struct{}) pm.stopWg.Add(1) - go pm.handleProbe() + go pm.handleProbe(services) return nil } @@ -95,13 +95,18 @@ func (pm *probeManagers) Stop(ctx context.Context) error { return nil } -func (pm *probeManagers) handleProbe() { +func (pm *probeManagers) handleProbe(services []interface{}) { // var err error defer func() { pm.stopWg.Done() + + oops.StopService(services) + pm.Stop(nil) }() + oops.StartService(services) + // if err = pm.cClient.Connect(); nil != err { // return // } diff --git a/service/CentralService.go b/service/CentralService.go index 97969e8..0bf7216 100644 --- a/service/CentralService.go +++ b/service/CentralService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" ) @@ -15,9 +17,21 @@ func init() { type CentralService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service + CentralClients map[string]oogwc.Client `annotation:"@Resource()"` } +func (cs *CentralService) Start() error { + + return nil +} + +func (cs *CentralService) Stop(ctx context.Context) error { + + return nil +} + func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) { cs.CentralClients[entryPath] = c } diff --git a/service/ConfigService.go b/service/ConfigService.go index d2fa8a6..ac45330 100644 --- a/service/ConfigService.go +++ b/service/ConfigService.go @@ -1,10 +1,15 @@ package service import ( + "context" + "io/ioutil" + "path" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" + "git.loafle.net/overflow/overflow_probes/config" ) func init() { @@ -14,4 +19,58 @@ func init() { type ConfigService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service +} + +func (cs *ConfigService) Start() error { + + return nil +} + +func (cs *ConfigService) Stop(ctx context.Context) error { + + return nil +} + +func (cs *ConfigService) loadConfigAll() error { + configDirPath := config.ConfigDirPath() + files, err := ioutil.ReadDir(configDirPath) + if nil != err { + return err + } + + for _, file := range files { + if file.IsDir() == true { + if err := cs.loadConfigDir(path.Join(configDirPath, file.Name())); nil != err { + return err + } + } + } + + return nil +} + +func (cs *ConfigService) loadConfigDir(dirPath string) error { + files, err := ioutil.ReadDir(dirPath) + if nil != err { + return err + } + + for _, file := range files { + filePath := path.Join(dirPath, file.Name()) + + if file.IsDir() == true { + cs.loadConfigDir(filePath) + } else { + _, err := ioutil.ReadFile(filePath) + if nil != err { + return err + } + // var m = config_manager.Config{} + // json.Unmarshal(b, &m) + // c.configs[file.Name()] = &m + } + } + + return nil } diff --git a/service/ContainerService.go b/service/ContainerService.go index fcc0745..2c693a2 100644 --- a/service/ContainerService.go +++ b/service/ContainerService.go @@ -1,6 +1,7 @@ package service import ( + "context" "fmt" "io/ioutil" "os" @@ -13,6 +14,7 @@ import ( "git.loafle.net/commons_go/logging" crc "git.loafle.net/commons_go/rpc/client" crr "git.loafle.net/commons_go/rpc/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" "git.loafle.net/overflow/overflow_probes/client/container" ) @@ -20,18 +22,30 @@ func init() { cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil))) } +type containerState struct { + pid int + port int + client crc.Client +} + type ContainerService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service + ProbeRPCInvoker crr.RPCInvoker `annotation:"@Resource()"` clients map[string]*containerState } -type containerState struct { - pid int - port int - client crc.Client +func (cs *ContainerService) Start() error { + + return nil +} + +func (cs *ContainerService) Stop(ctx context.Context) error { + + return nil } func (cs *ContainerService) Call(name string, result interface{}, method string, params ...interface{}) error { diff --git a/service/CrawlerService.go b/service/CrawlerService.go index 888717d..0bd50fe 100644 --- a/service/CrawlerService.go +++ b/service/CrawlerService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model" ) @@ -14,6 +16,17 @@ func init() { type CrawlerService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service +} + +func (cs *CrawlerService) Start() error { + + return nil +} + +func (cs *CrawlerService) Stop(ctx context.Context) error { + + return nil } func (cs *CrawlerService) Install() error { diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index 8a9c329..93ea018 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -1,11 +1,13 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" ) @@ -16,11 +18,22 @@ func init() { type DiscoveryService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service ContainerService *ContainerService `annotation:"@Inject()"` CentralService *CentralService `annotation:"@Inject()"` } +func (ds *DiscoveryService) Start() error { + + return nil +} + +func (ds *DiscoveryService) Stop(ctx context.Context) error { + + return nil +} + func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error { return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, dz) } diff --git a/service/LogService.go b/service/LogService.go index 46de9d5..793ece8 100644 --- a/service/LogService.go +++ b/service/LogService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" ) func init() { @@ -13,6 +15,17 @@ func init() { type LogService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service +} + +func (ls *LogService) Start() error { + + return nil +} + +func (ls *LogService) Stop(ctx context.Context) error { + + return nil } func (ls *LogService) Send() error { diff --git a/service/ProbeService.go b/service/ProbeService.go index 59e5edb..bc8018e 100644 --- a/service/ProbeService.go +++ b/service/ProbeService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" ) func init() { @@ -13,14 +15,19 @@ func init() { type ProbeService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service } func (ps *ProbeService) Start() error { + return nil } -func (ps *ProbeService) Stop() error { + +func (ps *ProbeService) Stop(ctx context.Context) error { + return nil } + func (ps *ProbeService) Update() error { return nil } diff --git a/service/SensorService.go b/service/SensorService.go index ee79a6f..26aa93e 100644 --- a/service/SensorService.go +++ b/service/SensorService.go @@ -1,10 +1,12 @@ package service import ( + "context" "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model" ) @@ -14,24 +16,35 @@ func init() { type SensorService struct { cda.TypeAnnotation `annotation:"@overFlow:Service()"` + oocmci.Service } -func (ss *SensorService) Start(id int64) error { +func (ss *SensorService) Start() error { + return nil } -func (ss *SensorService) Stop(id int64) error { +func (ss *SensorService) Stop(ctx context.Context) error { + return nil } -func (ss *SensorService) Add(config *configM.Config) error { +func (ss *SensorService) StartSensor(id int64) error { return nil } -func (ss *SensorService) Remove(id int64) error { +func (ss *SensorService) StopSensor(id int64) error { return nil } -func (ss *SensorService) Update(id int64) error { +func (ss *SensorService) AddSensor(config *configM.Config) error { + return nil +} + +func (ss *SensorService) RemoveSensor(id int64) error { + return nil +} + +func (ss *SensorService) UpdateSensor(id int64) error { return nil } diff --git a/service/service.go b/service/service.go index 801caa9..31bc976 100644 --- a/service/service.go +++ b/service/service.go @@ -1,12 +1,38 @@ package service +// "context" +// "time" + +// "git.loafle.net/commons_go/logging" +// oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" + func InitService() { } -func StartService() { +func StartService(services []interface{}) { + // 1. Sensor config + // 2. Container + // 3. Collector + + // if nil != services && 0 < len(services) { + // for _, service := range services { + // if err := service.(oocmci.Service).Start(); err != nil { + // logging.Logger().Errorf("Probe: Cannot start service %v", err) + // } + // } + // } } -func StopService() { +func StopService(services []interface{}) { + // if nil != services && 0 < len(services) { + // for _, service := range services { + // ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + // defer cancel() + // if err := service.(oocmci.Service).Stop(ctx); err != nil { + // logging.Logger().Errorf("Probe: Cannot start service %v", err) + // } + // } + // } } func DestroyService() {