ing
This commit is contained in:
parent
7fe426dd07
commit
94a4f3136c
|
@ -42,7 +42,7 @@ type authManagers struct {
|
|||
|
||||
func (am *authManagers) EndableStart(doneChan chan<- error) error {
|
||||
if nil != am.stopChan {
|
||||
logging.Logger().Panic("Auth: auth is already running. Stop it before starting it again")
|
||||
logging.Logger().Panicf("Auth: auth is already running. Stop it before starting it again")
|
||||
}
|
||||
|
||||
am.configPath = path.Join(*config.ConfigDir, ooccn.ConfigFileName)
|
||||
|
@ -91,7 +91,7 @@ func (am *authManagers) Stop() {
|
|||
|
||||
func (am *authManagers) destroy(err error) {
|
||||
if am.stopChan == nil {
|
||||
logging.Logger().Warn("Auth: auth must be started before stopping it")
|
||||
logging.Logger().Warnf("Auth: auth must be started before stopping it")
|
||||
}
|
||||
close(am.stopChan)
|
||||
am.stopWg.Wait()
|
||||
|
@ -100,7 +100,7 @@ func (am *authManagers) destroy(err error) {
|
|||
am.cClient.Close()
|
||||
close(am.serviceDoneChan)
|
||||
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: stopped"))
|
||||
logging.Logger().Infof("Auth: stopped")
|
||||
am.doneChan <- err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
|
@ -21,12 +19,11 @@ type ClientHandlers struct {
|
|||
}
|
||||
|
||||
func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been initialized"))
|
||||
logging.Logger().Infof("Auth: client has been initialized")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been destroyed"))
|
||||
logging.Logger().Infof("Auth: client has been destroyed")
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,6 @@ func (sb *SocketBuilders) Validate() {
|
|||
sb.SocketBuilders.Validate()
|
||||
|
||||
if nil == sb.napService {
|
||||
logging.Logger().Panic("Auth: NoAuthProbeService must be specified")
|
||||
logging.Logger().Panicf("Auth: NoAuthProbeService must be specified")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
|
@ -18,7 +17,7 @@ type SocketHandlers struct {
|
|||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been connected res[%v]", res))
|
||||
logging.Logger().Infof("Auth: client has been connected res[%v]", res)
|
||||
|
||||
switch sh.napService.Config.State() {
|
||||
case ooccn.NoAuthProbeStateTypeNotRegisterd:
|
||||
|
@ -30,7 +29,7 @@ func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.
|
|||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: client has been disconnected soc[%v]", soc))
|
||||
logging.Logger().Infof("Auth: client has been disconnected soc[%v]", soc)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func (s *NoAuthProbeService) Accept(probeKey string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: Probe[%s] has been accepted from central", probeKey))
|
||||
logging.Logger().Infof("Auth: Probe[%s] has been accepted from central", probeKey)
|
||||
s.DoneChan <- nil
|
||||
|
||||
return nil
|
||||
|
@ -42,7 +42,7 @@ func (s *NoAuthProbeService) Deny() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
logging.Logger().Info(fmt.Sprintf("Auth: Probe has been denyed from central"))
|
||||
logging.Logger().Infof("Auth: Probe has been denyed from central")
|
||||
s.DoneChan <- nil
|
||||
return nil
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (s *NoAuthProbeService) GetRequestHeader() map[string][]string {
|
|||
func (s *NoAuthProbeService) GetRegisterRequestHeader() string {
|
||||
i, err := oopai.GetRegistHeader()
|
||||
if nil != err {
|
||||
logging.Logger().Error(fmt.Sprintf("Auth: Gathering system information has been failed %v", err))
|
||||
logging.Logger().Errorf("Auth: Gathering system information has been failed %v", err)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||
|
@ -20,11 +18,11 @@ type ClientHandlers struct {
|
|||
}
|
||||
|
||||
func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe Data: client has been initialized"))
|
||||
logging.Logger().Infof("Probe Data: client has been initialized")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe Data: client has been destroyed"))
|
||||
logging.Logger().Infof("Probe Data: client has been destroyed")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
|
@ -13,12 +12,12 @@ type SocketHandlers struct {
|
|||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been connected res[%v]", res))
|
||||
logging.Logger().Infof("Probe: client has been connected res[%v]", res)
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: client has been disconnected soc[%v]", soc))
|
||||
logging.Logger().Infof("Probe: client has been disconnected soc[%v]", soc)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ package container
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
oocc "git.loafle.net/overflow/overflow_commons_go/config"
|
||||
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
|
||||
oopcc "git.loafle.net/overflow/overflow_probe_container/client"
|
||||
"git.loafle.net/overflow/overflow_probes/config"
|
||||
|
@ -25,19 +27,24 @@ func GetContainerCommand(name string) (cmd *exec.Cmd, pidPath string) {
|
|||
|
||||
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)
|
||||
|
||||
cmd = exec.Command(javaPath, "-jar", jarPath, pidPath)
|
||||
cmd = exec.Command(javaPath, "-jar", jarPath, 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)
|
||||
arg := fmt.Sprintf("-pid-path=%s", pidPath)
|
||||
arg := fmt.Sprintf("-%s=%s -%s=%s", oocc.FlagPidFilePathName, pidPath, oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
cmd = exec.Command(exePath, arg)
|
||||
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)
|
||||
arg := fmt.Sprintf("-pid-path=%s", pidPath)
|
||||
arg := fmt.Sprintf("-%s=%s -%s=%s", oocc.FlagPidFilePathName, pidPath, oocc.FlagLogConfigFilePathName, logConfigPath)
|
||||
|
||||
log.Printf("arg:%s", arg)
|
||||
|
||||
cmd = exec.Command(exePath, arg)
|
||||
default:
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
cunu "git.loafle.net/commons_go/util/net/url"
|
||||
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
|
||||
|
@ -13,7 +11,7 @@ func NewSocketBuilder(entryPath string) *SocketBuilders {
|
|||
sb := &SocketBuilders{}
|
||||
url, err := cunu.Join(config.Config.Central.URL, entryPath)
|
||||
if nil != err {
|
||||
logging.Logger().Error(fmt.Sprintf("Probe: Cannot create SocketBuilder %v", err))
|
||||
logging.Logger().Errorf("Probe: Cannot create SocketBuilder %v", err)
|
||||
return nil
|
||||
}
|
||||
sb.URL = url
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"writeBufferSize": 8192
|
||||
},
|
||||
"probe": {
|
||||
"key": "95d8bcdc739741dca74c4a0e489e0774"
|
||||
"key": "52abd6fd57e511e7ac52080027658d13"
|
||||
},
|
||||
"paths": {
|
||||
"root": "/project/overFlow/probe"
|
||||
|
|
19
main.go
19
main.go
|
@ -49,8 +49,10 @@ func init() {
|
|||
// flag.PrintDefaults()
|
||||
// }
|
||||
|
||||
configDir = oocc.FlagConfigDir()
|
||||
configDir = oocc.FlagConfigDir("./")
|
||||
flag.Parse()
|
||||
|
||||
logging.InitializeLogger("")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -70,18 +72,18 @@ func main() {
|
|||
defer close(authDoneChan)
|
||||
|
||||
if err := instance.(commons.EndableStarter).EndableStart(authDoneChan); err != nil {
|
||||
logging.Logger().Error(err.Error())
|
||||
logging.Logger().Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = <-authDoneChan
|
||||
if nil != err {
|
||||
logging.Logger().Error(err.Error())
|
||||
logging.Logger().Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
instance = probe.New()
|
||||
if err := instance.(commons.Starter).Start(); err != nil {
|
||||
logging.Logger().Error(err.Error())
|
||||
logging.Logger().Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -103,16 +105,16 @@ func main() {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := instance.(commons.Shutdowner).Shutdown(ctx); err != nil {
|
||||
logging.Logger().Error(fmt.Sprintf("Probe error: %v", err))
|
||||
logging.Logger().Errorf("Probe error: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
if dir, err := lfcc.ABSPathify(*configDir); nil != err {
|
||||
logging.Logger().Panic(fmt.Sprintf("Config path[%s] is not valid", *configDir))
|
||||
logging.Logger().Panicf("Config path[%s] is not valid", *configDir)
|
||||
} else {
|
||||
logging.Logger().Debug(fmt.Sprintf("Config path: %s", dir))
|
||||
logging.Logger().Debugf("Config path: %s", dir)
|
||||
config.ConfigDir = &dir
|
||||
}
|
||||
cfp := path.Join(*config.ConfigDir, ooccp.ConfigFileName)
|
||||
|
@ -121,9 +123,8 @@ func loadConfig() {
|
|||
conf := lfcc.New()
|
||||
config.Config = &ooccp.Config{}
|
||||
if err := conf.Load(config.Config, *config.ConfigFilePath); nil != err {
|
||||
logging.Logger().Panic(fmt.Sprintf("Config is not valid: %v", err))
|
||||
logging.Logger().Panicf("Config is not valid: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"tempKey": "969946e1-4de3-486a-b11c-00d311244c3a"
|
||||
"tempKey": "84cdd159-2839-439c-97e1-72dc9efadc35"
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
|
@ -33,7 +32,7 @@ type probeManagers struct {
|
|||
|
||||
func (pm *probeManagers) Start() error {
|
||||
if nil != pm.stopChan {
|
||||
logging.Logger().Panic("Probe: already running. Stop it before starting it again")
|
||||
logging.Logger().Panicf("Probe: already running. Stop it before starting it again")
|
||||
}
|
||||
|
||||
oops.InitService()
|
||||
|
@ -48,7 +47,14 @@ func (pm *probeManagers) Start() error {
|
|||
}
|
||||
cdr.RegisterResource("CentralClients", centralClients)
|
||||
|
||||
services := cdr.GetInstancesByAnnotationName(oopca.ServiceTag)
|
||||
var (
|
||||
services []interface{}
|
||||
err error
|
||||
)
|
||||
|
||||
if services, err = cdr.GetInstancesByAnnotationName(oopca.ServiceTag); nil != err {
|
||||
logging.Logger().Panicf("Probe: Cannot create instances of service %v", err)
|
||||
}
|
||||
|
||||
for _, s := range services {
|
||||
probeRPCRegistry.RegisterService(s, "")
|
||||
|
@ -72,7 +78,7 @@ func (pm *probeManagers) Start() error {
|
|||
|
||||
func (pm *probeManagers) Stop() {
|
||||
if pm.stopChan == nil {
|
||||
logging.Logger().Warn("Probe: probe must be started before stopping it")
|
||||
logging.Logger().Warnf("Probe: probe must be started before stopping it")
|
||||
}
|
||||
close(pm.stopChan)
|
||||
pm.stopWg.Wait()
|
||||
|
@ -80,7 +86,7 @@ func (pm *probeManagers) Stop() {
|
|||
|
||||
// pm.cClient.Close()
|
||||
|
||||
logging.Logger().Info(fmt.Sprintf("Probe: stopped"))
|
||||
logging.Logger().Infof("Probe: stopped")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package service
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
@ -10,6 +11,7 @@ import (
|
|||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/overflow/overflow_probes/client/container"
|
||||
)
|
||||
|
@ -69,26 +71,28 @@ func (cs *ContainerService) runProcess(name string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// cmd, pidPath := container.GetContainerCommand(name)
|
||||
// if err := cmd.Start(); nil != err {
|
||||
// logging.Logger().Error(fmt.Sprintf("Probe: To run container(%s) failed err %v", name, err))
|
||||
// return err
|
||||
// }
|
||||
|
||||
// port, err := watchPidFileCreate(pidPath, time.Duration(time.Second*2))
|
||||
// if nil != err {
|
||||
// return err
|
||||
// }
|
||||
port := 60000
|
||||
|
||||
client := container.New(port, nil)
|
||||
if err := client.Connect(); nil != err {
|
||||
// cmd.Process.Kill()
|
||||
cmd, pidPath := container.GetContainerCommand(name)
|
||||
if err := cmd.Start(); nil != err {
|
||||
logging.Logger().Errorf("Probe: To run container(%s) failed err %v", name, err)
|
||||
return err
|
||||
}
|
||||
|
||||
port, err := watchPidFileCreate(pidPath, time.Duration(time.Second*2))
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
// port := 60000
|
||||
|
||||
client := container.New(port, nil)
|
||||
if err := client.Connect(); nil != err {
|
||||
cmd.Process.Kill()
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("pid: %d", cmd.Process.Pid)
|
||||
|
||||
cState := &containerState{
|
||||
pid: 29694,
|
||||
pid: cmd.Process.Pid,
|
||||
port: port,
|
||||
client: client,
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
|
||||
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"
|
||||
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
|
||||
oocmpsp "git.loafle.net/overflow/overflow_commons_go/modules/probe/service/probe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -22,19 +22,19 @@ type DiscoveryService struct {
|
|||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error {
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverZone", requesterID, dz)
|
||||
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, dz)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverHost(requesterID string, zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) error {
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverHost", requesterID, zone, dh)
|
||||
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverHost", requesterID, zone, dh)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverPort(requesterID string, host *discoveryM.Host, dp *discoveryM.DiscoveryPort) error {
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverPort", requesterID, host, dp)
|
||||
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverPort", requesterID, host, dp)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoverService(requesterID string, port *discoveryM.Port, dService *discoveryM.DiscoveryService) error {
|
||||
return ds.ContainerService.Send(oocmpsp.ProbeContainerNameDiscovery, "DiscoveryService.DiscoverZone", requesterID, port, dService)
|
||||
return ds.ContainerService.Send(ooccp.ContainerDiscoveryName, "DiscoveryService.DiscoverZone", requesterID, port, dService)
|
||||
}
|
||||
|
||||
// use by discovery
|
||||
|
|
|
@ -27,13 +27,13 @@ func DestroyService() {
|
|||
// case "SensorService":
|
||||
// t = reflect.TypeOf((*SensorService)(nil))
|
||||
// default:
|
||||
// logging.Logger().Panic(fmt.Sprintf("Probe: Service[%s] is not exist", name))
|
||||
// logging.Logger().Panicf("Probe: Service[%s] is not exist", name)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// i, err := cdr.GetInstance(t)
|
||||
// if nil != err {
|
||||
// logging.Logger().Panic(fmt.Sprintf("Probe: Getting Service[%s] is failed %v", name, err))
|
||||
// logging.Logger().Panicf("Probe: Getting Service[%s] is failed %v", name, err)
|
||||
// return nil
|
||||
// }
|
||||
// return i
|
||||
|
|
Loading…
Reference in New Issue
Block a user