This commit is contained in:
crusader 2018-03-26 15:55:38 +09:00
parent e6f66ad7f0
commit ca13dea9cd
20 changed files with 329 additions and 29 deletions

Binary file not shown.

View File

@ -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"]
}

View File

@ -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"]
}

0
build/config/_ Normal file
View File

0
build/jre/_ Normal file
View File

0
build/logs/_ Normal file
View File

0
build/pid/_ Normal file
View File

View File

@ -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

View File

@ -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)
}

44
config/container.go Normal file
View File

@ -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)
}

View File

@ -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
// }

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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() {