ing
This commit is contained in:
parent
7a567199a9
commit
9c89a2fe90
30
client/container/client_handlers.go
Normal file
30
client/container/client_handlers.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
crc "git.loafle.net/commons_go/rpc/client"
|
||||||
|
crr "git.loafle.net/commons_go/rpc/registry"
|
||||||
|
oopcc "git.loafle.net/overflow/overflow_probe_container/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClientHandlers struct {
|
||||||
|
oopcc.ClientHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ch *ClientHandlers) Init(clientCTX crc.ClientContext) error {
|
||||||
|
|
||||||
|
return ch.ClientHandler.Init(clientCTX)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ch *ClientHandlers) Destroy(clientCTX crc.ClientContext) {
|
||||||
|
ch.ClientHandler.Destroy(clientCTX)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ch *ClientHandlers) Validate() {
|
||||||
|
ch.ClientHandler.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClientHandler(rpcInvoker crr.RPCInvoker) oopcc.ClientHandler {
|
||||||
|
ch := &ClientHandlers{}
|
||||||
|
ch.ClientHandler = oopcc.NewClientHandler(rpcInvoker)
|
||||||
|
return ch
|
||||||
|
}
|
16
client/container/container.go
Normal file
16
client/container/container.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
crc "git.loafle.net/commons_go/rpc/client"
|
||||||
|
crr "git.loafle.net/commons_go/rpc/registry"
|
||||||
|
oopcc "git.loafle.net/overflow/overflow_probe_container/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(addr string, rpcInvoker crr.RPCInvoker) crc.Client {
|
||||||
|
ch := oopcc.NewClientHandler(rpcInvoker)
|
||||||
|
socketHandler := NewSocketHandler()
|
||||||
|
|
||||||
|
c := oopcc.New(addr, ch, socketHandler)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
26
client/container/socket_handlers.go
Normal file
26
client/container/socket_handlers.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
csc "git.loafle.net/commons_go/server/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SocketHandlers struct {
|
||||||
|
csc.SocketHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) Validate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSocketHandler() csc.SocketHandler {
|
||||||
|
return &SocketHandlers{}
|
||||||
|
}
|
|
@ -2,12 +2,8 @@ package: git.loafle.net/overflow/overflow_probes
|
||||||
import:
|
import:
|
||||||
- package: git.loafle.net/commons_go/config
|
- package: git.loafle.net/commons_go/config
|
||||||
- package: git.loafle.net/commons_go/logging
|
- package: git.loafle.net/commons_go/logging
|
||||||
- package: github.com/gorilla/websocket
|
|
||||||
version: v1.2.0
|
|
||||||
- package: git.loafle.net/commons_go/util
|
- package: git.loafle.net/commons_go/util
|
||||||
- package: github.com/shirou/gopsutil
|
- package: github.com/shirou/gopsutil
|
||||||
version: v2.17.08
|
version: v2.17.08
|
||||||
- package: github.com/takama/daemon
|
|
||||||
version: 0.9.1
|
|
||||||
- package: github.com/dgrijalva/jwt-go
|
- package: github.com/dgrijalva/jwt-go
|
||||||
version: v3.1.0
|
version: v3.1.0
|
||||||
|
|
85
manager/container/container.go
Normal file
85
manager/container/container.go
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.loafle.net/commons_go/logging"
|
||||||
|
crc "git.loafle.net/commons_go/rpc/client"
|
||||||
|
oopcc "git.loafle.net/overflow/overflow_probes/client/container"
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ContainerManager interface {
|
||||||
|
GetClient(name string) crc.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type containerManager struct {
|
||||||
|
containerClients map[string]*containerState
|
||||||
|
}
|
||||||
|
|
||||||
|
type containerState struct {
|
||||||
|
socketName string
|
||||||
|
pid int
|
||||||
|
client crc.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *containerManager) GetClient(name string) crc.Client {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *containerManager) CheckClient(name string) bool {
|
||||||
|
cs, ok := cm.containerClients[name]
|
||||||
|
if !ok || nil == cs || nil == cs.client {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
stateOk := false
|
||||||
|
if err := cs.client.Call(&stateOk, "StateService.State"); nil != err {
|
||||||
|
logging.Logger().Error(fmt.Sprintf("Probe: Call[%s(%s)] err %v", name, "StateService.State", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateOk
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *containerManager) ConnectClient(name string) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *containerManager) runProcess(name string) error {
|
||||||
|
sockFile := uuid.NewV4().String()
|
||||||
|
sockArg := fmt.Sprintf("-sock \"%s\"", sockFile)
|
||||||
|
|
||||||
|
cmd := exec.Command("", sockArg)
|
||||||
|
if err := cmd.Start(); nil != err {
|
||||||
|
logging.Logger().Error(fmt.Sprintf("Probe: To run container(%s) failed err %v", name, err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
time.Sleep(time.Duration(time.Second * 2))
|
||||||
|
|
||||||
|
cs := &containerState{
|
||||||
|
socketName: sockFile,
|
||||||
|
pid: cmd.Process.Pid,
|
||||||
|
}
|
||||||
|
cs.client = oopcc.New(sockFile, nil)
|
||||||
|
// write pid file
|
||||||
|
cm.containerClients[name] = cs
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// func (cm *containerManager) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// func (cm *containerManager) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// func (cm *containerManager) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// func (cm *containerManager) {
|
||||||
|
|
||||||
|
// }
|
|
@ -1,20 +1,28 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
||||||
|
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||||
|
oopmc "git.loafle.net/overflow/overflow_probes/manager/container"
|
||||||
|
)
|
||||||
|
|
||||||
type CrawlerService struct {
|
type CrawlerService struct {
|
||||||
|
ProbeClient oogwc.Client `annotation:"@inject{name:probeClient}"`
|
||||||
|
ContainerManager oopmc.ContainerManager `annotation:"@inject{name:containerManager}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CrawlerService) Install() error {
|
func (cs *CrawlerService) Install() error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CrawlerService) Uninstall() error {
|
func (cs *CrawlerService) Uninstall() error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CrawlerService) Update() error {
|
func (cs *CrawlerService) Update() error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CrawlerService) Authenticate(crawler *configM.Crawler, target *configM.Target) error {
|
func (cs *CrawlerService) Authenticate(crawler *configM.Crawler, target *configM.Target) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,45 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
|
||||||
|
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
|
||||||
|
oopmc "git.loafle.net/overflow/overflow_probes/manager/container"
|
||||||
|
)
|
||||||
|
|
||||||
type DiscoveryService struct {
|
type DiscoveryService struct {
|
||||||
|
ProbeClient oogwc.Client `annotation:"@inject{name:probeClient}"`
|
||||||
|
ContainerManager oopmc.ContainerManager `annotation:"@inject{name:containerManager}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoverZone(dz *discoveryM.DiscoveryZone) error {
|
func (ds *DiscoveryService) DiscoverZone(dz *discoveryM.DiscoveryZone) error {
|
||||||
return nil
|
return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverZone", dz)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoverHost(zone *discoveryM.Zone, dz *discoveryM.DiscoveryHost) error {
|
func (ds *DiscoveryService) DiscoverHost(zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) error {
|
||||||
return nil
|
return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverHost", zone, dh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoverPort(host *discoveryM.Host, dz *discoveryM.DiscoveryPort) error {
|
func (ds *DiscoveryService) DiscoverPort(host *discoveryM.Host, dp *discoveryM.DiscoveryPort) error {
|
||||||
return nil
|
return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverPort", host, dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoverService(port *discoveryM.Port, dz *discoveryM.DiscoveryService) error {
|
func (ds *DiscoveryService) DiscoverService(port *discoveryM.Port, ds *discoveryM.DiscoveryService) error {
|
||||||
return nil
|
return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverZone", port, ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use by discovery
|
||||||
func (ds *DiscoveryService) DiscoveredZone(zone *discoveryM.Zone) error {
|
func (ds *DiscoveryService) DiscoveredZone(zone *discoveryM.Zone) error {
|
||||||
return nil
|
return ds.ProbeClient.Send("DiscoveryService.DiscoveredZone", zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoveredHost(host *discoveryM.Host) error {
|
func (ds *DiscoveryService) DiscoveredHost(host *discoveryM.Host) error {
|
||||||
return nil
|
return ds.ProbeClient.Send("DiscoveryService.DiscoveredHost", host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoveredPort(port *discoveryM.Port) error {
|
func (ds *DiscoveryService) DiscoveredPort(port *discoveryM.Port) error {
|
||||||
return nil
|
return ds.ProbeClient.Send("DiscoveryService.DiscoveredPort", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiscoveryService) DiscoveredService(service *discoveryM.Service) error {
|
func (ds *DiscoveryService) DiscoveredService(service *discoveryM.Service) error {
|
||||||
return nil
|
return ds.ProbeClient.Send("DiscoveryService.DiscoveredService", service)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user