diff --git a/auth/client/socket_builders.go b/auth/client/socket_builders.go index a56b5f0..08a75f2 100644 --- a/auth/client/socket_builders.go +++ b/auth/client/socket_builders.go @@ -7,14 +7,14 @@ import ( cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe" oopas "git.loafle.net/overflow/overflow_probes/auth/service" - oopcc "git.loafle.net/overflow/overflow_probes/central/client" + oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client" ) func NewSocketBuilder(napService *oopas.NoAuthProbeService) cwfc.SocketBuilder { sb := &SocketBuilders{ napService: napService, } - sb.SocketBuilders = oopcc.NewSocketBuilder(oocmn.HTTPEntry_NoAuthProbe) + sb.SocketBuilders = oopccc.NewSocketBuilder(oocmn.HTTPEntry_NoAuthProbe) if nil == sb.SocketBuilders { return nil } @@ -23,7 +23,7 @@ func NewSocketBuilder(napService *oopas.NoAuthProbeService) cwfc.SocketBuilder { } type SocketBuilders struct { - *oopcc.SocketBuilders + *oopccc.SocketBuilders napService *oopas.NoAuthProbeService } diff --git a/central/client/client.go b/commons/central/client/client.go similarity index 100% rename from central/client/client.go rename to commons/central/client/client.go diff --git a/central/client/socket_builders.go b/commons/central/client/socket_builders.go similarity index 100% rename from central/client/socket_builders.go rename to commons/central/client/socket_builders.go diff --git a/main.go b/main.go index 9fb79f6..3f61ab0 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,6 @@ func init() { configDir = oocc.FlagConfigDir() flag.Parse() - } func main() { diff --git a/manager/central/central.go b/manager/central/central.go new file mode 100644 index 0000000..538eb72 --- /dev/null +++ b/manager/central/central.go @@ -0,0 +1,17 @@ +package central + +import ( + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" +) + +type CentralManager interface { + GetClient(name string) oogwc.Client +} + +type centralManager struct { + clients map[string]oogwc.Client +} + +func (cm *centralManager) GetClient(entryPath string) oogwc.Client { + return nil +} diff --git a/client/central/data/client.go b/manager/central/client/data/client.go similarity index 100% rename from client/central/data/client.go rename to manager/central/client/data/client.go diff --git a/client/central/data/client_handlers.go b/manager/central/client/data/client_handlers.go similarity index 100% rename from client/central/data/client_handlers.go rename to manager/central/client/data/client_handlers.go diff --git a/client/central/data/socket_builders.go b/manager/central/client/data/socket_builders.go similarity index 85% rename from client/central/data/socket_builders.go rename to manager/central/client/data/socket_builders.go index b4830a0..75c9e02 100644 --- a/client/central/data/socket_builders.go +++ b/manager/central/client/data/socket_builders.go @@ -6,7 +6,7 @@ import ( "git.loafle.net/commons_go/logging" cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" - oopcc "git.loafle.net/overflow/overflow_probes/central/client" + oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client" oops "git.loafle.net/overflow/overflow_probes/service" ) @@ -14,7 +14,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { sb := &SocketBuilders{ napService: napService, } - sb.SocketBuilders = oopcc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe) + sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe) if nil == sb.SocketBuilders { return nil } @@ -23,7 +23,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { } type SocketBuilders struct { - *oopcc.SocketBuilders + *oopccc.SocketBuilders napService *oops.NoAuthProbeService } diff --git a/client/central/data/socket_handlers.go b/manager/central/client/data/socket_handlers.go similarity index 100% rename from client/central/data/socket_handlers.go rename to manager/central/client/data/socket_handlers.go diff --git a/client/central/file/client.go b/manager/central/client/file/client.go similarity index 100% rename from client/central/file/client.go rename to manager/central/client/file/client.go diff --git a/client/central/file/client_handlers.go b/manager/central/client/file/client_handlers.go similarity index 100% rename from client/central/file/client_handlers.go rename to manager/central/client/file/client_handlers.go diff --git a/client/central/file/socket_builders.go b/manager/central/client/file/socket_builders.go similarity index 85% rename from client/central/file/socket_builders.go rename to manager/central/client/file/socket_builders.go index aad0c90..2cb5fd5 100644 --- a/client/central/file/socket_builders.go +++ b/manager/central/client/file/socket_builders.go @@ -6,7 +6,7 @@ import ( "git.loafle.net/commons_go/logging" cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" - oopcc "git.loafle.net/overflow/overflow_probes/central/client" + oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client" oops "git.loafle.net/overflow/overflow_probes/service" ) @@ -14,7 +14,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { sb := &SocketBuilders{ napService: napService, } - sb.SocketBuilders = oopcc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe) + sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_NoAuthProbe) if nil == sb.SocketBuilders { return nil } @@ -23,7 +23,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { } type SocketBuilders struct { - *oopcc.SocketBuilders + *oopccc.SocketBuilders napService *oops.NoAuthProbeService } diff --git a/client/central/file/socket_handlers.go b/manager/central/client/file/socket_handlers.go similarity index 100% rename from client/central/file/socket_handlers.go rename to manager/central/client/file/socket_handlers.go diff --git a/client/central/probe/client.go b/manager/central/client/probe/client.go similarity index 100% rename from client/central/probe/client.go rename to manager/central/client/probe/client.go diff --git a/client/central/probe/client_handlers.go b/manager/central/client/probe/client_handlers.go similarity index 100% rename from client/central/probe/client_handlers.go rename to manager/central/client/probe/client_handlers.go diff --git a/client/central/probe/socket_builders.go b/manager/central/client/probe/socket_builders.go similarity index 85% rename from client/central/probe/socket_builders.go rename to manager/central/client/probe/socket_builders.go index 846e7dc..130154f 100644 --- a/client/central/probe/socket_builders.go +++ b/manager/central/client/probe/socket_builders.go @@ -6,7 +6,7 @@ import ( "git.loafle.net/commons_go/logging" cwfc "git.loafle.net/commons_go/websocket_fasthttp/client" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" - oopcc "git.loafle.net/overflow/overflow_probes/central/client" + oopccc "git.loafle.net/overflow/overflow_probes/commons/central/client" oops "git.loafle.net/overflow/overflow_probes/service" ) @@ -14,7 +14,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { sb := &SocketBuilders{ napService: napService, } - sb.SocketBuilders = oopcc.NewSocketBuilder(oocmp.HTTPEntry_Probe) + sb.SocketBuilders = oopccc.NewSocketBuilder(oocmp.HTTPEntry_Probe) if nil == sb.SocketBuilders { return nil } @@ -23,7 +23,7 @@ func NewSocketBuilder(napService *oops.NoAuthProbeService) cwfc.SocketBuilder { } type SocketBuilders struct { - *oopcc.SocketBuilders + *oopccc.SocketBuilders napService *oops.NoAuthProbeService } diff --git a/client/central/probe/socket_handlers.go b/manager/central/client/probe/socket_handlers.go similarity index 100% rename from client/central/probe/socket_handlers.go rename to manager/central/client/probe/socket_handlers.go diff --git a/client/container/container.go b/manager/container/client/client.go similarity index 95% rename from client/container/container.go rename to manager/container/client/client.go index 37e7cd1..c165670 100644 --- a/client/container/container.go +++ b/manager/container/client/client.go @@ -1,4 +1,4 @@ -package container +package client import ( crc "git.loafle.net/commons_go/rpc/client" diff --git a/client/container/client_handlers.go b/manager/container/client/client_handlers.go similarity index 97% rename from client/container/client_handlers.go rename to manager/container/client/client_handlers.go index 79c7b28..d7a804e 100644 --- a/client/container/client_handlers.go +++ b/manager/container/client/client_handlers.go @@ -1,4 +1,4 @@ -package container +package client import ( crc "git.loafle.net/commons_go/rpc/client" diff --git a/client/container/socket_handlers.go b/manager/container/client/socket_handlers.go similarity index 95% rename from client/container/socket_handlers.go rename to manager/container/client/socket_handlers.go index 04b927f..0f8a267 100644 --- a/client/container/socket_handlers.go +++ b/manager/container/client/socket_handlers.go @@ -1,4 +1,4 @@ -package container +package client import ( "net" diff --git a/manager/container/container.go b/manager/container/container.go index 054549c..4fc33e8 100644 --- a/manager/container/container.go +++ b/manager/container/container.go @@ -2,12 +2,13 @@ package container import ( "fmt" + "os" "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" + oopmcc "git.loafle.net/overflow/overflow_probes/manager/container/client" uuid "github.com/satori/go.uuid" ) @@ -49,9 +50,14 @@ func (cm *containerManager) ConnectClient(name string) error { return nil } +func (cm *containerManager) CloseClient(name string) error { + + return nil +} + func (cm *containerManager) runProcess(name string) error { sockFile := uuid.NewV4().String() - sockArg := fmt.Sprintf("-sock \"%s\"", sockFile) + sockArg := fmt.Sprintf("-sock=\"%s\"", sockFile) cmd := exec.Command("", sockArg) if err := cmd.Start(); nil != err { @@ -64,13 +70,31 @@ func (cm *containerManager) runProcess(name string) error { socketName: sockFile, pid: cmd.Process.Pid, } - cs.client = oopcc.New(sockFile, nil) + cs.client = oopmcc.New(sockFile, nil) // write pid file cm.containerClients[name] = cs return nil } +func (cm *containerManager) stopProcess(name string) error { + cs, ok := cm.containerClients[name] + if !ok || nil == cs || nil == cs.client { + return fmt.Errorf("Probe: Container[%s] is not exist", name) + } + + p, err := os.FindProcess(cs.pid) + if nil != err { + return err + } + if err = p.Kill(); nil != err { + return err + } + // remove pid file + + return nil +} + // func (cm *containerManager) { // } @@ -80,6 +104,3 @@ func (cm *containerManager) runProcess(name string) error { // func (cm *containerManager) { // } -// func (cm *containerManager) { - -// } diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index efe8cdf..444f5b6 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -2,44 +2,44 @@ 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" + oopmCentral "git.loafle.net/overflow/overflow_probes/manager/central" + oopmContainer "git.loafle.net/overflow/overflow_probes/manager/container" ) type DiscoveryService struct { - ProbeClient oogwc.Client `annotation:"@inject{name:probeClient}"` - ContainerManager oopmc.ContainerManager `annotation:"@inject{name:containerManager}"` + CentralManager oopmCentral.CentralManager `annotation:"@inject{name:probeClient}"` + ContainerManager oopmContainer.ContainerManager `annotation:"@inject{name:containerManager}"` } func (ds *DiscoveryService) DiscoverZone(dz *discoveryM.DiscoveryZone) error { - return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverZone", dz) + return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverZone", dz) } func (ds *DiscoveryService) DiscoverHost(zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) error { - return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverHost", zone, dh) + return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverHost", zone, dh) } func (ds *DiscoveryService) DiscoverPort(host *discoveryM.Host, dp *discoveryM.DiscoveryPort) error { - return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverPort", host, dp) + return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverPort", host, dp) } -func (ds *DiscoveryService) DiscoverService(port *discoveryM.Port, ds *discoveryM.DiscoveryService) error { - return ds.ContainerManager.GetClient().Send("DiscoveryService.DiscoverZone", port, ds) +func (ds *DiscoveryService) DiscoverService(port *discoveryM.Port, dService *discoveryM.DiscoveryService) error { + return ds.ContainerManager.GetClient("").Send("DiscoveryService.DiscoverZone", port, dService) } // use by discovery func (ds *DiscoveryService) DiscoveredZone(zone *discoveryM.Zone) error { - return ds.ProbeClient.Send("DiscoveryService.DiscoveredZone", zone) + return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredZone", zone) } func (ds *DiscoveryService) DiscoveredHost(host *discoveryM.Host) error { - return ds.ProbeClient.Send("DiscoveryService.DiscoveredHost", host) + return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredHost", host) } func (ds *DiscoveryService) DiscoveredPort(port *discoveryM.Port) error { - return ds.ProbeClient.Send("DiscoveryService.DiscoveredPort", port) + return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredPort", port) } func (ds *DiscoveryService) DiscoveredService(service *discoveryM.Service) error { - return ds.ProbeClient.Send("DiscoveryService.DiscoveredService", service) + return ds.CentralManager.GetClient("").Send("DiscoveryService.DiscoveredService", service) } diff --git a/service/LogService.go b/service/LogService.go index 9853291..6d946b5 100644 --- a/service/LogService.go +++ b/service/LogService.go @@ -4,5 +4,5 @@ type LogService struct { } func (ls *LogService) Send() error { - + return nil } diff --git a/service/ProbeService.go b/service/ProbeService.go index fa09dbe..46f5f65 100644 --- a/service/ProbeService.go +++ b/service/ProbeService.go @@ -4,11 +4,11 @@ type ProbeService struct { } func (ps *ProbeService) Start() error { - + return nil } func (ps *ProbeService) Stop() error { - + return nil } func (ps *ProbeService) Update() error { - + return nil } diff --git a/service/SensorService.go b/service/SensorService.go index 0ae9586..22f87c7 100644 --- a/service/SensorService.go +++ b/service/SensorService.go @@ -1,24 +1,28 @@ package service +import ( + configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model" +) + type SensorService struct { } func (ss *SensorService) Start(id int64) error { - + return nil } func (ss *SensorService) Stop(id int64) error { - + return nil } func (ss *SensorService) Add(config *configM.Config) error { - + return nil } func (ss *SensorService) Remove(id int64) error { - + return nil } func (ss *SensorService) Update(id int64) error { - + return nil }