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 ( import (
"fmt" "fmt"
"os/exec" "os/exec"
"path"
crc "git.loafle.net/commons_go/rpc/client" crc "git.loafle.net/commons_go/rpc/client"
crr "git.loafle.net/commons_go/rpc/registry" 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) { 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 { switch name {
case ooccp.ContainerGeneralName: case ooccp.ContainerGeneralName:
logConfigPath := path.Join(config.Config.Paths["root"], ooccp.PathBin, ooccp.ContainerGeneralLogConfigFileName) javaPath := config.JavaBinPath()
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)
cmd = exec.Command(javaPath, "-jar", jarPath, pidPath, logConfigPath) cmd = exec.Command(javaPath, "-jar", binPath, pidPath, logConfigPath)
case ooccp.ContainerNetworkName: 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) arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath) arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
cmd = exec.Command(exePath, arg1, arg2) cmd = exec.Command(binPath, arg1, arg2)
case ooccp.ContainerDiscoveryName: 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) arg1 := fmt.Sprintf("-%s=%s", oocc.FlagPidFilePathName, pidPath)
arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath) arg2 := fmt.Sprintf("-%s=%s", oocc.FlagLogConfigFilePathName, logConfigPath)
cmd = exec.Command(exePath, arg1, arg2) cmd = exec.Command(binPath, arg1, arg2)
default: default:
} }
return return

View File

@ -1,6 +1,8 @@
package config package config
import ( import (
"path"
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
) )
@ -11,3 +13,31 @@ var (
Config *ooccp.Config 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.stopChan = make(chan struct{})
pm.stopWg.Add(1) pm.stopWg.Add(1)
go pm.handleProbe() go pm.handleProbe(services)
return nil return nil
} }
@ -95,13 +95,18 @@ func (pm *probeManagers) Stop(ctx context.Context) error {
return nil return nil
} }
func (pm *probeManagers) handleProbe() { func (pm *probeManagers) handleProbe(services []interface{}) {
// var err error // var err error
defer func() { defer func() {
pm.stopWg.Done() pm.stopWg.Done()
oops.StopService(services)
pm.Stop(nil) pm.Stop(nil)
}() }()
oops.StartService(services)
// if err = pm.cClient.Connect(); nil != err { // if err = pm.cClient.Connect(); nil != err {
// return // return
// } // }

View File

@ -1,10 +1,12 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" 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" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
) )
@ -15,9 +17,21 @@ func init() {
type CentralService struct { type CentralService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` cda.TypeAnnotation `annotation:"@overFlow:Service()"`
oocmci.Service
CentralClients map[string]oogwc.Client `annotation:"@Resource()"` 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) { func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) {
cs.CentralClients[entryPath] = c cs.CentralClients[entryPath] = c
} }

View File

@ -1,10 +1,15 @@
package service package service
import ( import (
"context"
"io/ioutil"
"path"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" 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() { func init() {
@ -14,4 +19,58 @@ func init() {
type ConfigService struct { type ConfigService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` 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 package service
import ( import (
"context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -13,6 +14,7 @@ import (
"git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/logging"
crc "git.loafle.net/commons_go/rpc/client" crc "git.loafle.net/commons_go/rpc/client"
crr "git.loafle.net/commons_go/rpc/registry" 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" "git.loafle.net/overflow/overflow_probes/client/container"
) )
@ -20,18 +22,30 @@ func init() {
cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil))) cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil)))
} }
type containerState struct {
pid int
port int
client crc.Client
}
type ContainerService struct { type ContainerService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` cda.TypeAnnotation `annotation:"@overFlow:Service()"`
oocmci.Service
ProbeRPCInvoker crr.RPCInvoker `annotation:"@Resource()"` ProbeRPCInvoker crr.RPCInvoker `annotation:"@Resource()"`
clients map[string]*containerState clients map[string]*containerState
} }
type containerState struct { func (cs *ContainerService) Start() error {
pid int
port int return nil
client crc.Client }
func (cs *ContainerService) Stop(ctx context.Context) error {
return nil
} }
func (cs *ContainerService) Call(name string, result interface{}, method string, params ...interface{}) error { func (cs *ContainerService) Call(name string, result interface{}, method string, params ...interface{}) error {

View File

@ -1,10 +1,12 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" 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" configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
) )
@ -14,6 +16,17 @@ func init() {
type CrawlerService struct { type CrawlerService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` 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 { func (cs *CrawlerService) Install() error {

View File

@ -1,11 +1,13 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" cdr "git.loafle.net/commons_go/di/registry"
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" 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" discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
) )
@ -16,11 +18,22 @@ func init() {
type DiscoveryService struct { type DiscoveryService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` cda.TypeAnnotation `annotation:"@overFlow:Service()"`
oocmci.Service
ContainerService *ContainerService `annotation:"@Inject()"` ContainerService *ContainerService `annotation:"@Inject()"`
CentralService *CentralService `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 { func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error {
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, dz) return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, dz)
} }

View File

@ -1,10 +1,12 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" cdr "git.loafle.net/commons_go/di/registry"
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
) )
func init() { func init() {
@ -13,6 +15,17 @@ func init() {
type LogService struct { type LogService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` 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 { func (ls *LogService) Send() error {

View File

@ -1,10 +1,12 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" cdr "git.loafle.net/commons_go/di/registry"
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
) )
func init() { func init() {
@ -13,14 +15,19 @@ func init() {
type ProbeService struct { type ProbeService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` cda.TypeAnnotation `annotation:"@overFlow:Service()"`
oocmci.Service
} }
func (ps *ProbeService) Start() error { func (ps *ProbeService) Start() error {
return nil return nil
} }
func (ps *ProbeService) Stop() error {
func (ps *ProbeService) Stop(ctx context.Context) error {
return nil return nil
} }
func (ps *ProbeService) Update() error { func (ps *ProbeService) Update() error {
return nil return nil
} }

View File

@ -1,10 +1,12 @@
package service package service
import ( import (
"context"
"reflect" "reflect"
cda "git.loafle.net/commons_go/di/annotation" cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry" 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" configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
) )
@ -14,24 +16,35 @@ func init() {
type SensorService struct { type SensorService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"` cda.TypeAnnotation `annotation:"@overFlow:Service()"`
oocmci.Service
} }
func (ss *SensorService) Start(id int64) error { func (ss *SensorService) Start() error {
return nil return nil
} }
func (ss *SensorService) Stop(id int64) error { func (ss *SensorService) Stop(ctx context.Context) error {
return nil return nil
} }
func (ss *SensorService) Add(config *configM.Config) error { func (ss *SensorService) StartSensor(id int64) error {
return nil return nil
} }
func (ss *SensorService) Remove(id int64) error { func (ss *SensorService) StopSensor(id int64) error {
return nil 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 return nil
} }

View File

@ -1,12 +1,38 @@
package service package service
// "context"
// "time"
// "git.loafle.net/commons_go/logging"
// oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
func InitService() { 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() { func DestroyService() {