This commit is contained in:
crusader 2018-04-26 17:39:32 +09:00
parent 3d1a0e1686
commit 9133090b72
17 changed files with 99 additions and 102 deletions

View File

@ -1,4 +1,3 @@
{ {
"tempKey": "f2d22c4c448111e89c0ad28d1c524cb3", "tempKey": "21de17fd48af11e8b18802422708bd74"
"acceptedDate": "2018-04-20T19:03:12.521576174+09:00"
} }

View File

@ -17,6 +17,5 @@
} }
}, },
"probe": { "probe": {
"key": "7771f55d42de11e8b0460242ac120002"
} }
} }

View File

@ -8,8 +8,8 @@ import (
"git.loafle.net/commons/configuration-go" "git.loafle.net/commons/configuration-go"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
logging "git.loafle.net/commons/logging-go" logging "git.loafle.net/commons/logging-go"
occn "git.loafle.net/overflow/commons-go/config/noauthprobe"
occi "git.loafle.net/overflow/commons-go/core/interfaces" occi "git.loafle.net/overflow/commons-go/core/interfaces"
ocnc "git.loafle.net/overflow/commons-go/noauthprobe/config"
"git.loafle.net/overflow/probe/auth/annotation" "git.loafle.net/overflow/probe/auth/annotation"
"git.loafle.net/overflow/probe/auth/service" "git.loafle.net/overflow/probe/auth/service"
@ -17,7 +17,7 @@ import (
) )
type Authenticator struct { type Authenticator struct {
authConfig ocnc.Auth authConfig occn.Auth
services []interface{} services []interface{}

View File

@ -8,7 +8,7 @@ import (
"net" "net"
"git.loafle.net/commons/util-go/net/gateway" "git.loafle.net/commons/util-go/net/gateway"
noauthprobeM "git.loafle.net/overflow/commons-go/noauthprobe/model" noauthprobeM "git.loafle.net/overflow/commons-go/model/noauthprobe"
"github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/host"
) )

View File

@ -3,14 +3,14 @@ package service
import ( import (
"context" "context"
"reflect" "reflect"
"time"
"git.loafle.net/commons/configuration-go" "git.loafle.net/commons/configuration-go"
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
logging "git.loafle.net/commons/logging-go" logging "git.loafle.net/commons/logging-go"
crc "git.loafle.net/commons/rpc-go/client" crc "git.loafle.net/commons/rpc-go/client"
ocnc "git.loafle.net/overflow/commons-go/noauthprobe/config" occn "git.loafle.net/overflow/commons-go/config/noauthprobe"
"git.loafle.net/overflow/commons-go/core/util"
"git.loafle.net/overflow/probe/client/central" "git.loafle.net/overflow/probe/client/central"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
@ -28,7 +28,7 @@ type NoAuthProbeService struct {
cda.TypeAnnotation `annotation:"@overflow:AuthRPCService()"` cda.TypeAnnotation `annotation:"@overflow:AuthRPCService()"`
Config *config.Config `annotation:"@Resource(name='Config')"` Config *config.Config `annotation:"@Resource(name='Config')"`
AuthConfig *ocnc.Auth `annotation:"@Resource(name='AuthConfig')"` AuthConfig *occn.Auth `annotation:"@Resource(name='AuthConfig')"`
AuthDoneChan chan error `annotation:"@Resource(name='AuthDoneChan')"` AuthDoneChan chan error `annotation:"@Resource(name='AuthDoneChan')"`
client *crc.Client client *crc.Client
@ -65,7 +65,7 @@ func (s *NoAuthProbeService) DestroyService() {
func (s *NoAuthProbeService) Accept(probeKey string) error { func (s *NoAuthProbeService) Accept(probeKey string) error {
logging.Logger().Infof("accepted by central") logging.Logger().Infof("accepted by central")
n := time.Now() n := util.Now()
s.AuthConfig.AcceptedDate = &n s.AuthConfig.AcceptedDate = &n
if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err { if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err {
logging.Logger().Error(err) logging.Logger().Error(err)
@ -86,7 +86,7 @@ func (s *NoAuthProbeService) Accept(probeKey string) error {
func (s *NoAuthProbeService) Deny() error { func (s *NoAuthProbeService) Deny() error {
logging.Logger().Infof("denied by central") logging.Logger().Infof("denied by central")
n := time.Now() n := util.Now()
s.AuthConfig.DeniedDate = &n s.AuthConfig.DeniedDate = &n
if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err { if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err {
logging.Logger().Error(err) logging.Logger().Error(err)

View File

@ -10,8 +10,7 @@ import (
crc "git.loafle.net/commons/rpc-go/client" crc "git.loafle.net/commons/rpc-go/client"
csc "git.loafle.net/commons/server-go/client" csc "git.loafle.net/commons/server-go/client"
cur "git.loafle.net/commons/util-go/reflect" cur "git.loafle.net/commons/util-go/reflect"
ocnc "git.loafle.net/overflow/commons-go/noauthprobe/config" occn "git.loafle.net/overflow/commons-go/config/noauthprobe"
ocncc "git.loafle.net/overflow/commons-go/noauthprobe/constants"
"git.loafle.net/overflow/probe/auth/info" "git.loafle.net/overflow/probe/auth/info"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
) )
@ -26,7 +25,7 @@ func NewAuth(tempKeyHandler func(tempKey string), services ...interface{}) (*crc
return nil, fmt.Errorf("AuthConfig is not available") return nil, fmt.Errorf("AuthConfig is not available")
} }
connector, err := newConnector("Auth", ocncc.HTTPEntry_Auth) connector, err := newConnector("Auth", occn.HTTPEntry_Auth)
if nil != err { if nil != err {
return nil, err return nil, err
} }
@ -34,24 +33,24 @@ func NewAuth(tempKeyHandler func(tempKey string), services ...interface{}) (*crc
connector.RequestHeader = func() http.Header { connector.RequestHeader = func() http.Header {
header := make(map[string][]string) header := make(map[string][]string)
switch authConfig.State() { switch authConfig.State() {
case ocnc.AuthStateTypeRegisterd: case occn.AuthStateTypeRegisterd:
header[ocncc.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{ocncc.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect} header[occn.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{occn.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect}
header[ocncc.HTTPRequestHeaderKey_NoAuthProbe_TempProbeKey] = []string{*authConfig.TempKey} header[occn.HTTPRequestHeaderKey_NoAuthProbe_TempProbeKey] = []string{*authConfig.TempKey}
default: default:
rh, err := info.GetRegistHeader(config.Account.APIKey) rh, err := info.GetRegistHeader(config.Account.APIKey)
if nil != err { if nil != err {
logging.Logger().Error(err) logging.Logger().Error(err)
return header return header
} }
header[ocncc.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{ocncc.HTTPRequestHeaderValue_NoAuthProbe_Method_Regist} header[occn.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{occn.HTTPRequestHeaderValue_NoAuthProbe_Method_Regist}
header[ocncc.HTTPRequestHeaderKey_NoAuthProbe_Info] = []string{rh} header[occn.HTTPRequestHeaderKey_NoAuthProbe_Info] = []string{rh}
} }
return header return header
} }
connector.ResponseHandler = func(res *http.Response) { connector.ResponseHandler = func(res *http.Response) {
switch authConfig.State() { switch authConfig.State() {
case ocnc.AuthStateTypeNotRegisterd: case occn.AuthStateTypeNotRegisterd:
tempProbeKey := res.Header.Get(ocncc.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey) tempProbeKey := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey)
if nil != tempKeyHandler { if nil != tempKeyHandler {
tempKeyHandler(tempProbeKey) tempKeyHandler(tempProbeKey)
} }
@ -66,13 +65,13 @@ func NewAuth(tempKeyHandler func(tempKey string), services ...interface{}) (*crc
return newClient("Auth", connector, services), nil return newClient("Auth", connector, services), nil
} }
func getAuthConfig() *ocnc.Auth { func getAuthConfig() *occn.Auth {
_config, err := cdr.GetInstanceByName("AuthConfig") _config, err := cdr.GetInstanceByName("AuthConfig")
if nil != err { if nil != err {
logging.Logger().Error(err) logging.Logger().Error(err)
return nil return nil
} }
config, ok := _config.(*ocnc.Auth) config, ok := _config.(*occn.Auth)
if !ok { if !ok {
_, pkg, n := cur.GetTypeInfo(reflect.TypeOf(_config)) _, pkg, n := cur.GetTypeInfo(reflect.TypeOf(_config))
logging.Logger().Errorf("Cannot convert [%s]%s to Config type", pkg, n) logging.Logger().Errorf("Cannot convert [%s]%s to Config type", pkg, n)

View File

@ -7,7 +7,7 @@ import (
logging "git.loafle.net/commons/logging-go" logging "git.loafle.net/commons/logging-go"
crc "git.loafle.net/commons/rpc-go/client" crc "git.loafle.net/commons/rpc-go/client"
csc "git.loafle.net/commons/server-go/client" csc "git.loafle.net/commons/server-go/client"
ocpc "git.loafle.net/overflow/commons-go/probe/constants" occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
) )
@ -17,15 +17,15 @@ func NewData() (*crc.Client, error) {
return nil, fmt.Errorf("Config is not available") return nil, fmt.Errorf("Config is not available")
} }
connector, err := newConnector("Data", ocpc.HTTPEntry_Data) connector, err := newConnector("Data", occp.HTTPEntry_Data)
if nil != err { if nil != err {
return nil, err return nil, err
} }
connector.RequestHeader = func() http.Header { connector.RequestHeader = func() http.Header {
header := make(map[string][]string) header := make(map[string][]string)
header[ocpc.HTTPRequestHeaderKey_Probe_Method] = []string{ocpc.HTTPRequestHeaderValue_Probe_Method_Connect} header[occp.HTTPRequestHeaderKey_Probe_Method] = []string{occp.HTTPRequestHeaderValue_Probe_Method_Connect}
header[ocpc.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*config.Probe.Key} header[occp.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*config.Probe.Key}
return header return header
} }
connector.ResponseHandler = func(res *http.Response) { connector.ResponseHandler = func(res *http.Response) {

View File

@ -7,7 +7,7 @@ import (
logging "git.loafle.net/commons/logging-go" logging "git.loafle.net/commons/logging-go"
crc "git.loafle.net/commons/rpc-go/client" crc "git.loafle.net/commons/rpc-go/client"
csc "git.loafle.net/commons/server-go/client" csc "git.loafle.net/commons/server-go/client"
ocpc "git.loafle.net/overflow/commons-go/probe/constants" occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
) )
@ -17,19 +17,19 @@ func NewProbe(encryptionKeyHandler func(encryptionKey string), services ...inter
return nil, fmt.Errorf("Config is not available") return nil, fmt.Errorf("Config is not available")
} }
connector, err := newConnector("Probe", ocpc.HTTPEntry_Probe) connector, err := newConnector("Probe", occp.HTTPEntry_Probe)
if nil != err { if nil != err {
return nil, err return nil, err
} }
connector.RequestHeader = func() http.Header { connector.RequestHeader = func() http.Header {
header := make(map[string][]string) header := make(map[string][]string)
header[ocpc.HTTPRequestHeaderKey_Probe_Method] = []string{ocpc.HTTPRequestHeaderValue_Probe_Method_Connect} header[occp.HTTPRequestHeaderKey_Probe_Method] = []string{occp.HTTPRequestHeaderValue_Probe_Method_Connect}
header[ocpc.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*config.Probe.Key} header[occp.HTTPRequestHeaderKey_Probe_ProbeKey] = []string{*config.Probe.Key}
return header return header
} }
connector.ResponseHandler = func(res *http.Response) { connector.ResponseHandler = func(res *http.Response) {
encryptionKey := res.Header.Get(ocpc.HTTPResponseHeaderKey_Probe_SetEncryptionKey) encryptionKey := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_SetEncryptionKey)
if nil != encryptionKeyHandler { if nil != encryptionKeyHandler {
encryptionKeyHandler(encryptionKey) encryptionKeyHandler(encryptionKey)
} }

View File

@ -9,7 +9,7 @@ import (
crr "git.loafle.net/commons/rpc-go/registry" crr "git.loafle.net/commons/rpc-go/registry"
csc "git.loafle.net/commons/server-go/client" csc "git.loafle.net/commons/server-go/client"
cssnc "git.loafle.net/commons/server-go/socket/net/client" cssnc "git.loafle.net/commons/server-go/socket/net/client"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants" occp "git.loafle.net/overflow/commons-go/config/probe"
) )
func newConnector(name string, port int) (*cssnc.Connectors, error) { func newConnector(name string, port int) (*cssnc.Connectors, error) {
@ -51,7 +51,7 @@ func newClient(name string, connector csc.Connector, services []interface{}) *cr
} }
} }
func NewClient(containerType ocpcc.ContainerType, port int, services []interface{}) (*crc.Client, error) { func NewClient(containerType occp.ContainerType, port int, services []interface{}) (*crc.Client, error) {
connector, err := newConnector(containerType.String(), port) connector, err := newConnector(containerType.String(), port)
if nil != err { if nil != err {
return nil, err return nil, err

View File

@ -6,7 +6,7 @@ import (
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
cur "git.loafle.net/commons/util-go/reflect" cur "git.loafle.net/commons/util-go/reflect"
ocpc "git.loafle.net/overflow/commons-go/probe/config" occp "git.loafle.net/overflow/commons-go/config/probe"
) )
const ( const (
@ -14,9 +14,9 @@ const (
) )
type Config struct { type Config struct {
Account *ocpc.Account `required:"true" json:"account" yaml:"account" toml:"account"` Account *occp.Account `required:"true" json:"account" yaml:"account" toml:"account"`
Central *ocpc.Central `required:"true" json:"central" yaml:"central" toml:"central"` Central *occp.Central `required:"true" json:"central" yaml:"central" toml:"central"`
Probe *ocpc.Probe `required:"true" json:"probe" yaml:"probe" toml:"probe"` Probe *occp.Probe `required:"true" json:"probe" yaml:"probe" toml:"probe"`
} }
func GetConfig() *Config { func GetConfig() *Config {

View File

@ -5,17 +5,17 @@ import (
"path" "path"
"strings" "strings"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants" occp "git.loafle.net/overflow/commons-go/config/probe"
) )
func ContainerPIDFilePath(containerType ocpcc.ContainerType) string { func ContainerPIDFilePath(containerType occp.ContainerType) string {
return path.Join(PIDDir(), fmt.Sprintf("%s.pid", strings.ToLower(containerType.String()))) return path.Join(PIDDir(), fmt.Sprintf("%s.pid", strings.ToLower(containerType.String())))
} }
func ContainerBinFilePath(containerType ocpcc.ContainerType) string { func ContainerBinFilePath(containerType occp.ContainerType) string {
return path.Join(BinDir(), ocpcc.ContainerBinFileName[containerType]) return path.Join(BinDir(), occp.ContainerBinFileName[containerType])
} }
func ContainerLoggingConfigFilePath(containerType ocpcc.ContainerType) string { func ContainerLoggingConfigFilePath(containerType occp.ContainerType) string {
return path.Join(BinDir(), ocpcc.ContainerLoggingConfigFileName[containerType]) return path.Join(BinDir(), occp.ContainerLoggingConfigFileName[containerType])
} }

View File

@ -3,13 +3,13 @@ package config
import ( import (
"path" "path"
ocscm "git.loafle.net/overflow/commons-go/sensorconfig/model" ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
) )
func SensorConfigContainerDir(name string) string { func SensorConfigContainerDir(name string) string {
return path.Join(ConfigDir(), name) return path.Join(ConfigDir(), name)
} }
func SensorConfigFilePath(sensorConfig *ocscm.SensorConfig) string { func SensorConfigFilePath(sensorConfig *ocmsc.SensorConfig) string {
return path.Join(SensorConfigContainerDir(sensorConfig.Crawler.Container), sensorConfig.Crawler.Name, sensorConfig.ID.String()) return path.Join(SensorConfigContainerDir(sensorConfig.Crawler.Container), sensorConfig.Crawler.Name, sensorConfig.ID.String())
} }

View File

@ -6,10 +6,11 @@ import (
"path" "path"
"path/filepath" "path/filepath"
ocncc "git.loafle.net/overflow/commons-go/noauthprobe/constants"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
"log" "log"
"os/user" "os/user"
occn "git.loafle.net/overflow/commons-go/config/noauthprobe"
occp "git.loafle.net/overflow/commons-go/config/probe"
) )
var ( var (
@ -42,15 +43,15 @@ func RootDir() string {
} }
func BinDir() string { func BinDir() string {
return path.Join(RootDir(), ocpcc.PathBin) return path.Join(RootDir(), occp.PathBin)
} }
func ConfigDir() string { func ConfigDir() string {
return path.Join(RootDir(), ocpcc.PathConfig) return path.Join(RootDir(), occp.PathConfig)
} }
func JREDir() string { func JREDir() string {
return path.Join(RootDir(), ocpcc.PathJRE) return path.Join(RootDir(), occp.PathJRE)
} }
func JavaBinPath() string { func JavaBinPath() string {
@ -58,21 +59,21 @@ func JavaBinPath() string {
} }
func LogsDir() string { func LogsDir() string {
return path.Join(RootDir(), ocpcc.PathLogs) return path.Join(RootDir(), occp.PathLogs)
} }
func PIDDir() string { func PIDDir() string {
return path.Join(RootDir(), ocpcc.PathPID) return path.Join(RootDir(), occp.PathPID)
} }
func ProbeConfigFilePath() string { func ProbeConfigFilePath() string {
return path.Join(BinDir(), ocpcc.ConfigFileName) return path.Join(BinDir(), occp.ConfigFileName)
} }
func ProbeLoggingConfigFilePath() string { func ProbeLoggingConfigFilePath() string {
return path.Join(BinDir(), ocpcc.LoggingConfigFileName) return path.Join(BinDir(), occp.LoggingConfigFileName)
} }
func NoAuthProbeConfigFilePath() string { func NoAuthProbeConfigFilePath() string {
return path.Join(BinDir(), ocncc.ConfigFileName) return path.Join(BinDir(), occn.ConfigFileName)
} }

View File

@ -10,8 +10,8 @@ import (
"git.loafle.net/commons/configuration-go" "git.loafle.net/commons/configuration-go"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
occp "git.loafle.net/overflow/commons-go/config/probe"
occi "git.loafle.net/overflow/commons-go/core/interfaces" occi "git.loafle.net/overflow/commons-go/core/interfaces"
ocpc "git.loafle.net/overflow/commons-go/probe/config"
"git.loafle.net/overflow/probe/auth" "git.loafle.net/overflow/probe/auth"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
"git.loafle.net/overflow/probe/probe" "git.loafle.net/overflow/probe/probe"
@ -32,7 +32,7 @@ func main() {
var instance interface{} var instance interface{}
go func() { go func() {
if ocpc.ProbeStateTypeNotAuthorized == _config.Probe.State() { if occp.ProbeStateTypeNotAuthorized == _config.Probe.State() {
instance = &auth.Authenticator{} instance = &auth.Authenticator{}
doneChan, err := instance.(occi.EndableStarter).EndableStart() doneChan, err := instance.(occi.EndableStarter).EndableStart()
if nil != err { if nil != err {

View File

@ -15,7 +15,7 @@ import (
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
crc "git.loafle.net/commons/rpc-go/client" crc "git.loafle.net/commons/rpc-go/client"
csc "git.loafle.net/commons/server-go/client" csc "git.loafle.net/commons/server-go/client"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants" occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/probe/client/container" "git.loafle.net/overflow/probe/client/container"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
@ -34,25 +34,25 @@ type ContainerService struct {
DiscoveryService *DiscoveryService `annotation:"@Inject()"` DiscoveryService *DiscoveryService `annotation:"@Inject()"`
rpcServiceMap map[ocpcc.ContainerType][]interface{} rpcServiceMap map[occp.ContainerType][]interface{}
containerStates map[ocpcc.ContainerType]*containerState containerStates map[occp.ContainerType]*containerState
connectorMap map[csc.Connector]*containerState connectorMap map[csc.Connector]*containerState
} }
func (s *ContainerService) InitService() error { func (s *ContainerService) InitService() error {
s.containerStates = make(map[ocpcc.ContainerType]*containerState) s.containerStates = make(map[occp.ContainerType]*containerState)
s.rpcServiceMap = make(map[ocpcc.ContainerType][]interface{}) s.rpcServiceMap = make(map[occp.ContainerType][]interface{})
s.connectorMap = make(map[csc.Connector]*containerState) s.connectorMap = make(map[csc.Connector]*containerState)
return nil return nil
} }
func (s *ContainerService) StartService() error { func (s *ContainerService) StartService() error {
s.rpcServiceMap[ocpcc.ContainerDiscovery] = []interface{}{ s.rpcServiceMap[occp.ContainerDiscovery] = []interface{}{
s.DiscoveryService, s.DiscoveryService,
} }
s.rpcServiceMap[ocpcc.ContainerNetwork] = []interface{}{} s.rpcServiceMap[occp.ContainerNetwork] = []interface{}{}
s.rpcServiceMap[ocpcc.ContainerGenernal] = []interface{}{} s.rpcServiceMap[occp.ContainerGenernal] = []interface{}{}
return nil return nil
} }
@ -67,7 +67,7 @@ func (s *ContainerService) DestroyService() {
} }
func (s *ContainerService) Call(containerType ocpcc.ContainerType, result interface{}, method string, params ...interface{}) error { func (s *ContainerService) Call(containerType occp.ContainerType, result interface{}, method string, params ...interface{}) error {
client, err := s.getClient(containerType) client, err := s.getClient(containerType)
if nil != err { if nil != err {
return err return err
@ -75,7 +75,7 @@ func (s *ContainerService) Call(containerType ocpcc.ContainerType, result interf
return client.Call(result, method, params...) return client.Call(result, method, params...)
} }
func (s *ContainerService) Send(containerType ocpcc.ContainerType, method string, params ...interface{}) error { func (s *ContainerService) Send(containerType occp.ContainerType, method string, params ...interface{}) error {
client, err := s.getClient(containerType) client, err := s.getClient(containerType)
if nil != err { if nil != err {
return err return err
@ -83,7 +83,7 @@ func (s *ContainerService) Send(containerType ocpcc.ContainerType, method string
return client.Send(method, params...) return client.Send(method, params...)
} }
func (s *ContainerService) getClient(containerType ocpcc.ContainerType) (*crc.Client, error) { func (s *ContainerService) getClient(containerType occp.ContainerType) (*crc.Client, error) {
cs := s.checkContainer(containerType) cs := s.checkContainer(containerType)
if nil == cs { if nil == cs {
_cs, err := s.runContainer(containerType) _cs, err := s.runContainer(containerType)
@ -121,7 +121,7 @@ func (s *ContainerService) onDisconnected(connector csc.Connector) {
s.refreshContainer(cs.containerType) s.refreshContainer(cs.containerType)
} }
func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*containerState, error) { func (s *ContainerService) runContainer(containerType occp.ContainerType) (*containerState, error) {
if cs := s.checkContainer(containerType); nil != cs { if cs := s.checkContainer(containerType); nil != cs {
return cs, nil return cs, nil
} }
@ -139,7 +139,7 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
return nil, err return nil, err
} }
go func(containerType ocpcc.ContainerType, cmd *exec.Cmd) { go func(containerType occp.ContainerType, cmd *exec.Cmd) {
if err := cmd.Wait(); nil != err { if err := cmd.Wait(); nil != err {
logging.Logger().Error(err) logging.Logger().Error(err)
} }
@ -156,8 +156,7 @@ func (s *ContainerService) runContainer(containerType ocpcc.ContainerType) (*con
return cs, nil return cs, nil
} }
func (s *ContainerService) refreshContainer(containerType occp.ContainerType) {
func (s *ContainerService) refreshContainer(containerType ocpcc.ContainerType) {
cs := s.checkContainer(containerType) cs := s.checkContainer(containerType)
if nil == cs { if nil == cs {
if _, err := s.getClient(containerType); nil != err { if _, err := s.getClient(containerType); nil != err {
@ -221,7 +220,7 @@ func (s *ContainerService) refreshContainer(containerType ocpcc.ContainerType) {
//} //}
} }
func (s *ContainerService) debugContainer(containerType ocpcc.ContainerType) (*containerState, error) { func (s *ContainerService) debugContainer(containerType occp.ContainerType) (*containerState, error) {
cs := &containerState{ cs := &containerState{
containerType: containerType, containerType: containerType,
cmd: nil, cmd: nil,
@ -231,7 +230,7 @@ func (s *ContainerService) debugContainer(containerType ocpcc.ContainerType) (*c
return cs, nil return cs, nil
} }
func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *containerState { func (s *ContainerService) checkContainer(containerType occp.ContainerType) *containerState {
cs, ok := s.containerStates[containerType] cs, ok := s.containerStates[containerType]
if !ok || nil == cs { if !ok || nil == cs {
return nil return nil
@ -255,7 +254,7 @@ func (s *ContainerService) checkContainer(containerType ocpcc.ContainerType) *co
return cs return cs
} }
func (s *ContainerService) killContainer(containerType ocpcc.ContainerType) error { func (s *ContainerService) killContainer(containerType occp.ContainerType) error {
cs, ok := s.containerStates[containerType] cs, ok := s.containerStates[containerType]
if !ok || nil == cs { if !ok || nil == cs {
return nil return nil
@ -269,7 +268,7 @@ func (s *ContainerService) killContainer(containerType ocpcc.ContainerType) erro
return nil return nil
} }
func (s *ContainerService) removeContainerState(containerType ocpcc.ContainerType) { func (s *ContainerService) removeContainerState(containerType occp.ContainerType) {
cs, ok := s.containerStates[containerType] cs, ok := s.containerStates[containerType]
if !ok || nil == cs { if !ok || nil == cs {
return return
@ -281,19 +280,19 @@ func (s *ContainerService) removeContainerState(containerType ocpcc.ContainerTyp
delete(s.containerStates, containerType) delete(s.containerStates, containerType)
} }
func cotainerCommand(containerType ocpcc.ContainerType) (cmd *exec.Cmd, pidFilePath string) { func cotainerCommand(containerType occp.ContainerType) (cmd *exec.Cmd, pidFilePath string) {
pidFilePath = config.ContainerPIDFilePath(containerType) pidFilePath = config.ContainerPIDFilePath(containerType)
loggingConfigFilePath := config.ContainerLoggingConfigFilePath(containerType) loggingConfigFilePath := config.ContainerLoggingConfigFilePath(containerType)
binFilePath := config.ContainerBinFilePath(containerType) binFilePath := config.ContainerBinFilePath(containerType)
switch containerType { switch containerType {
case ocpcc.ContainerDiscovery, ocpcc.ContainerNetwork: case occp.ContainerDiscovery, occp.ContainerNetwork:
args := []string{ args := []string{
fmt.Sprintf("-%s=%s", ocpcc.FlagPidFilePathName, pidFilePath), fmt.Sprintf("-%s=%s", occp.FlagPidFilePathName, pidFilePath),
fmt.Sprintf("-%s=%s", ocpcc.FlagLoggingConfigFilePathName, loggingConfigFilePath), fmt.Sprintf("-%s=%s", occp.FlagLoggingConfigFilePathName, loggingConfigFilePath),
} }
cmd = exec.Command(binFilePath, args...) cmd = exec.Command(binFilePath, args...)
case ocpcc.ContainerGenernal: case occp.ContainerGenernal:
args := []string{ args := []string{
"-jar", "-jar",
binFilePath, binFilePath,
@ -339,7 +338,7 @@ func watchPidFileCreate(pidFilePath string, waitTime time.Duration) (int, error)
} }
type containerState struct { type containerState struct {
containerType ocpcc.ContainerType containerType occp.ContainerType
cmd *exec.Cmd cmd *exec.Cmd
port int port int
client *crc.Client client *crc.Client

View File

@ -6,8 +6,8 @@ import (
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
ocdm "git.loafle.net/overflow/commons-go/discovery/model" occp "git.loafle.net/overflow/commons-go/config/probe"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
@ -44,20 +44,20 @@ func (s *DiscoveryService) DestroyService() {
} }
func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocdm.DiscoveryZone) error { func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocmd.DiscoveryZone) error {
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverZone", requesterID, dz) return s.ContainerService.Send(occp.ContainerDiscovery, "DiscoveryService.DiscoverZone", requesterID, dz)
} }
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocdm.Zone, dh *ocdm.DiscoveryHost) error { func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) error {
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverHost", requesterID, zone, dh) return s.ContainerService.Send(occp.ContainerDiscovery, "DiscoveryService.DiscoverHost", requesterID, zone, dh)
} }
func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocdm.Host, dp *ocdm.DiscoveryPort) error { func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocmd.Host, dp *ocmd.DiscoveryPort) error {
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverPort", requesterID, host, dp) return s.ContainerService.Send(occp.ContainerDiscovery, "DiscoveryService.DiscoverPort", requesterID, host, dp)
} }
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocdm.Port, dService *ocdm.DiscoveryService) error { func (s *DiscoveryService) DiscoverService(requesterID string, port *ocmd.Port, dService *ocmd.DiscoveryService) error {
return s.ContainerService.Send(ocpcc.ContainerDiscovery, "DiscoveryService.DiscoverService", requesterID, port, dService) return s.ContainerService.Send(occp.ContainerDiscovery, "DiscoveryService.DiscoverService", requesterID, port, dService)
} }
// use by discovery // use by discovery
@ -69,18 +69,18 @@ func (s *DiscoveryService) DiscoveryStop(requesterID string, t *time.Time) error
return s.ProbeClientService.Send("DiscoveryService.discoveryStop", requesterID, t) return s.ProbeClientService.Send("DiscoveryService.discoveryStop", requesterID, t)
} }
func (s *DiscoveryService) DiscoveredZone(requesterID string, zone *ocdm.Zone) error { func (s *DiscoveryService) DiscoveredZone(requesterID string, zone *ocmd.Zone) error {
return s.ProbeClientService.Send("DiscoveryService.discoveredZone", requesterID, zone) return s.ProbeClientService.Send("DiscoveryService.discoveredZone", requesterID, zone)
} }
func (s *DiscoveryService) DiscoveredHost(requesterID string, host *ocdm.Host) error { func (s *DiscoveryService) DiscoveredHost(requesterID string, host *ocmd.Host) error {
return s.ProbeClientService.Send("DiscoveryService.discoveredHost", requesterID, host) return s.ProbeClientService.Send("DiscoveryService.discoveredHost", requesterID, host)
} }
func (s *DiscoveryService) DiscoveredPort(requesterID string, port *ocdm.Port) error { func (s *DiscoveryService) DiscoveredPort(requesterID string, port *ocmd.Port) error {
return s.ProbeClientService.Send("DiscoveryService.discoveredPort", requesterID, port) return s.ProbeClientService.Send("DiscoveryService.discoveredPort", requesterID, port)
} }
func (s *DiscoveryService) DiscoveredService(requesterID string, service *ocdm.Service) error { func (s *DiscoveryService) DiscoveredService(requesterID string, service *ocmd.Service) error {
return s.ProbeClientService.Send("DiscoveryService.discoveredService", requesterID, service) return s.ProbeClientService.Send("DiscoveryService.discoveredService", requesterID, service)
} }

View File

@ -10,7 +10,7 @@ import (
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
ocscm "git.loafle.net/overflow/commons-go/sensorconfig/model" ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
// For annotation // For annotation
@ -26,11 +26,11 @@ func init() {
type SensorConfigService struct { type SensorConfigService struct {
cda.TypeAnnotation `annotation:"@overflow:RPCService()"` cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
sensorConfigs map[string]*ocscm.SensorConfig sensorConfigs map[string]*ocmsc.SensorConfig
} }
func (s *SensorConfigService) InitService() error { func (s *SensorConfigService) InitService() error {
s.sensorConfigs = make(map[string]*ocscm.SensorConfig) s.sensorConfigs = make(map[string]*ocmsc.SensorConfig)
return nil return nil
} }
@ -131,13 +131,13 @@ func (s *SensorConfigService) loadConfigDir(dirPath string) error {
return nil return nil
} }
func (s *SensorConfigService) loadConfigFile(filePath string) (*ocscm.SensorConfig, []byte, error) { func (s *SensorConfigService) loadConfigFile(filePath string) (*ocmsc.SensorConfig, []byte, error) {
buf, err := ioutil.ReadFile(filePath) buf, err := ioutil.ReadFile(filePath)
if nil != err { if nil != err {
return nil, nil, err return nil, nil, err
} }
var m = &ocscm.SensorConfig{} var m = &ocmsc.SensorConfig{}
if err := json.Unmarshal(buf, m); nil != err { if err := json.Unmarshal(buf, m); nil != err {
return nil, nil, err return nil, nil, err
} }