|
|
@ -1,17 +1,18 @@
|
|
|
|
package server
|
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"FRMS/internal/pkg/config"
|
|
|
|
"fmt"
|
|
|
|
pb "FRMS/internal/pkg/grpc"
|
|
|
|
"net"
|
|
|
|
"FRMS/internal/pkg/influxdb"
|
|
|
|
"context"
|
|
|
|
_ "FRMS/internal/pkg/influxdb"
|
|
|
|
"errors"
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"errors"
|
|
|
|
pb "FRMS/internal/pkg/grpc"
|
|
|
|
"fmt"
|
|
|
|
"FRMS/internal/pkg/config"
|
|
|
|
"net"
|
|
|
|
_ "FRMS/internal/pkg/influxdb"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// this package creates the central coordiantor and sub coordiantors for clients
|
|
|
|
// this package creates the central coordiantor and sub coordiantors for clients
|
|
|
@ -19,339 +20,324 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
// config interface
|
|
|
|
// config interface
|
|
|
|
func LoadConfig() Config {
|
|
|
|
func LoadConfig() Config {
|
|
|
|
// returns a ServerConfig that we can query and update
|
|
|
|
// returns a ServerConfig that we can query and update
|
|
|
|
return config.LoadConfig()
|
|
|
|
return config.LoadConfig()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Config interface { // PROPOSED RENAMING: ServerConfig to avoid confusion w/ reactor variant
|
|
|
|
type Config interface { // PROPOSED RENAMING: ServerConfig to avoid confusion w/ reactor variant
|
|
|
|
|
|
|
|
|
|
|
|
// getters
|
|
|
|
// getters
|
|
|
|
GetURL() (string, error)
|
|
|
|
GetURL() (string, error)
|
|
|
|
GetOrg() (string, error)
|
|
|
|
GetOrg() (string, error)
|
|
|
|
GetPort(string) (int, error)
|
|
|
|
GetPort(string) (int, error)
|
|
|
|
GetServerToken() (string, error)
|
|
|
|
GetServerToken() (string, error)
|
|
|
|
GetReactorClient(uint32) (string, string, error) // ret (bucket, token, err)
|
|
|
|
GetReactorClient(uint32) (string, string, error) // ret (bucket, token, err)
|
|
|
|
// setters
|
|
|
|
// setters
|
|
|
|
// save on write
|
|
|
|
// save on write
|
|
|
|
UpdateURL(string) error
|
|
|
|
//UpdateURL(string) error
|
|
|
|
UpdateOrg(string) error
|
|
|
|
//UpdateOrg(string) error
|
|
|
|
UpdateServerToken(string) error
|
|
|
|
//UpdateServerToken(string) error
|
|
|
|
UpdateReactorClient(uint32, string, string) error // call (id, bucket, token)
|
|
|
|
UpdateReactorClient(uint32, string, string) error // call (id, bucket, token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// db client interface
|
|
|
|
// db client interface
|
|
|
|
type DB interface{
|
|
|
|
type DB interface {
|
|
|
|
// getters (all create if doesnt exist)
|
|
|
|
// getters (all create if doesnt exist)
|
|
|
|
GetToken() (string, error) // returns admin token (Creates if it doesnt exist)
|
|
|
|
//GetToken() (string, error) // returns admin token (Creates if it doesnt exist)
|
|
|
|
GetReactorClient(uint32) (string, string, error) // returns (bucket, token, err)
|
|
|
|
GetReactorClient(string) (string, string, error) // returns (bucket, token, err)
|
|
|
|
// delete
|
|
|
|
// delete
|
|
|
|
DeleteReactorClient(uint32) error // removes client token but maintains bucket
|
|
|
|
DeleteReactorClient(string) error // removes client token but maintains bucket
|
|
|
|
PurgeReactorClientData(uint32) error // perm deletes all assocaited reactor data (token, bucket etc)
|
|
|
|
PurgeReactorClientData(string) error // perm deletes all assocaited reactor data (token, bucket etc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*func NewDBClient() DBClient {
|
|
|
|
func NewDBAdmin(url, org, token string) DB {
|
|
|
|
return influxdb.NewServerClient()
|
|
|
|
return influxdb.NewDBAdmin(token, org, url)
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type CentralCoordinator struct {
|
|
|
|
type CentralCoordinator struct {
|
|
|
|
ClientConnections *ClientPacket
|
|
|
|
ClientConnections *ClientPacket
|
|
|
|
//CLisPort int
|
|
|
|
//CLisPort int
|
|
|
|
*SubCoordinators
|
|
|
|
*SubCoordinators
|
|
|
|
*SystemViewer
|
|
|
|
*SystemViewer
|
|
|
|
DB
|
|
|
|
DB
|
|
|
|
Config
|
|
|
|
Config
|
|
|
|
Err chan error
|
|
|
|
Err chan error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SubCoordinators struct {
|
|
|
|
type SubCoordinators struct {
|
|
|
|
Directory map [string]*SubCoordinator
|
|
|
|
Directory map[string]*SubCoordinator
|
|
|
|
sync.Mutex
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewCentralCoordinator(ch chan error) *CentralCoordinator {
|
|
|
|
func NewCentralCoordinator(ch chan error) *CentralCoordinator {
|
|
|
|
c := &CentralCoordinator{Err: ch}
|
|
|
|
c := &CentralCoordinator{Err: ch}
|
|
|
|
c.SystemViewer = NewSystemViewer()
|
|
|
|
c.SystemViewer = NewSystemViewer()
|
|
|
|
go c.SystemViewer.Start()
|
|
|
|
go c.SystemViewer.Start()
|
|
|
|
s := make(map[string]*SubCoordinator)
|
|
|
|
s := make(map[string]*SubCoordinator)
|
|
|
|
sub := &SubCoordinators{Directory:s}
|
|
|
|
sub := &SubCoordinators{Directory: s}
|
|
|
|
c.SubCoordinators = sub
|
|
|
|
c.SubCoordinators = sub
|
|
|
|
return c
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *CentralCoordinator) Start() {
|
|
|
|
func (c *CentralCoordinator) Start() {
|
|
|
|
// starts up associated funcs
|
|
|
|
// starts up associated funcs
|
|
|
|
// begin with config and client
|
|
|
|
// begin with config and client
|
|
|
|
c.LoadCfg()
|
|
|
|
c.LoadCfg()
|
|
|
|
clientChan := make(chan *ClientPacket)
|
|
|
|
clientChan := make(chan *ClientPacket)
|
|
|
|
l := NewListener(clientChan,c.Err)
|
|
|
|
l := NewListener(clientChan, c.Err)
|
|
|
|
go l.Start()
|
|
|
|
go l.Start()
|
|
|
|
go c.ClientListener(clientChan)
|
|
|
|
go c.ClientListener(clientChan)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *CentralCoordinator) LoadCfg() {
|
|
|
|
func (c *CentralCoordinator) LoadCfg() {
|
|
|
|
// loads db client info and updates if anything is missing
|
|
|
|
// loads db client info and updates if anything is missing
|
|
|
|
c.Config = LoadConfig()
|
|
|
|
c.Config = LoadConfig()
|
|
|
|
_, err := c.Config.GetURL()
|
|
|
|
_, err := c.Config.GetURL()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logging.Debug(logging.DError,"CCO 01 Err: %v", err)
|
|
|
|
logging.Debug(logging.DError, "CCO 01 Err: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
token, err := c.Config.GetServerToken()
|
|
|
|
token, err := c.Config.GetServerToken()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logging.Debug(logging.DError,"CCO 01 Err: %v", err)
|
|
|
|
logging.Debug(logging.DError, "CCO 01 Err: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
} else if token == "" {
|
|
|
|
}
|
|
|
|
if token, err = c.DB.GetToken(); err != nil {
|
|
|
|
org, err := c.Config.GetOrg()
|
|
|
|
logging.Debug(logging.DError,"CCO 01 Err: %v", err)
|
|
|
|
if err != nil {
|
|
|
|
c.Err <-err
|
|
|
|
logging.Debug(logging.DError, "CCO 01 Err: %v", err)
|
|
|
|
}
|
|
|
|
c.Err <- err
|
|
|
|
c.Config.UpdateServerToken(token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
org, err := c.Config.GetOrg()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logging.Debug(logging.DError,"CCO 01 Err: %v", err)
|
|
|
|
|
|
|
|
c.Err <-err
|
|
|
|
|
|
|
|
} else if token == "" {
|
|
|
|
|
|
|
|
if token, err = c.DB.GetToken(); err != nil {
|
|
|
|
|
|
|
|
logging.Debug(logging.DError,"CCO 01 Err: %v", err)
|
|
|
|
|
|
|
|
c.Err <-err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Config.UpdateOrg(org)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *CentralCoordinator) ClientListener(ch chan *ClientPacket) {
|
|
|
|
func (c *CentralCoordinator) ClientListener(ch chan *ClientPacket) {
|
|
|
|
for client := range ch {
|
|
|
|
for client := range ch {
|
|
|
|
// basically loops until channel is closed
|
|
|
|
// basically loops until channel is closed
|
|
|
|
cr := c.ClientHandler(client.Client)
|
|
|
|
cr := c.ClientHandler(client.Client)
|
|
|
|
client.Response <-cr
|
|
|
|
client.Response <- cr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *CentralCoordinator) ClientHandler(cl *Client) *ClientResponse {
|
|
|
|
func (c *CentralCoordinator) ClientHandler(cl *Client) *ClientResponse {
|
|
|
|
c.SubCoordinators.Lock()
|
|
|
|
c.SubCoordinators.Lock()
|
|
|
|
defer c.SubCoordinators.Unlock()
|
|
|
|
defer c.SubCoordinators.Unlock()
|
|
|
|
subcoord, ok := c.SubCoordinators.Directory[cl.Type]
|
|
|
|
subcoord, ok := c.SubCoordinators.Directory[cl.Type]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
// Sub Coordinator does not exists
|
|
|
|
// Sub Coordinator does not exists
|
|
|
|
logging.Debug(logging.DSpawn,"CC0 01 Created %v Coordinator",cl.Type)
|
|
|
|
logging.Debug(logging.DSpawn, "CC0 01 Created %v Coordinator", cl.Type)
|
|
|
|
subcoord = NewSubCoordinator(cl.Type,c.SystemViewer, c.Err)
|
|
|
|
subcoord = NewSubCoordinator(cl.Type, c.SystemViewer, c.Err)
|
|
|
|
c.SubCoordinators.Directory[cl.Type] = subcoord
|
|
|
|
c.SubCoordinators.Directory[cl.Type] = subcoord
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go subcoord.ClientHandler(cl)
|
|
|
|
go subcoord.ClientHandler(cl)
|
|
|
|
// setting up client response
|
|
|
|
// setting up client response
|
|
|
|
var url, org, token, bucket string
|
|
|
|
var url, org, token, bucket string
|
|
|
|
var port int
|
|
|
|
var port int
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
if url, err = c.Config.GetURL(); err != nil {
|
|
|
|
if url, err = c.Config.GetURL(); err != nil {
|
|
|
|
logging.Debug(logging.DError,"Error: %v", err)
|
|
|
|
logging.Debug(logging.DError, "Error: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
} else if org, err = c.Config.GetOrg(); err != nil {
|
|
|
|
} else if org, err = c.Config.GetOrg(); err != nil {
|
|
|
|
logging.Debug(logging.DError,"Error: %v", err)
|
|
|
|
logging.Debug(logging.DError, "Error: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
} else if bucket, token, err = c.Config.GetReactorClient(cl.Id); err != nil {
|
|
|
|
} else if bucket, token, err = c.Config.GetReactorClient(cl.Id); err != nil {
|
|
|
|
logging.Debug(logging.DError,"Error: %v", err)
|
|
|
|
logging.Debug(logging.DError, "Error: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
} else if port, err = c.Config.GetPort(cl.Type); err != nil {
|
|
|
|
} else if port, err = c.Config.GetPort(cl.Type); err != nil {
|
|
|
|
logging.Debug(logging.DError,"Error: %v", err)
|
|
|
|
logging.Debug(logging.DError, "Error: %v", err)
|
|
|
|
c.Err <-err
|
|
|
|
c.Err <- err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cr := &ClientResponse{URL:url, Org:org, Token:token, Bucket:bucket, Port:port}
|
|
|
|
cr := &ClientResponse{URL: url, Org: org, Token: token, Bucket: bucket, Port: port}
|
|
|
|
return cr
|
|
|
|
return cr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ManagerInterface interface {
|
|
|
|
type ManagerInterface interface {
|
|
|
|
Start()
|
|
|
|
Start()
|
|
|
|
NewManager(*Client,*SystemViewer, chan error) GeneralManager
|
|
|
|
NewManager(*Client, *SystemViewer, chan error) GeneralManager
|
|
|
|
GetManager(uint32) (GeneralManager, bool)
|
|
|
|
GetManager(uint32) (GeneralManager, bool)
|
|
|
|
AddManager(uint32, GeneralManager)
|
|
|
|
AddManager(uint32, GeneralManager)
|
|
|
|
Register()
|
|
|
|
Register()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type GeneralManager interface {
|
|
|
|
type GeneralManager interface {
|
|
|
|
// used by sub coordinator to interact with manager
|
|
|
|
// used by sub coordinator to interact with manager
|
|
|
|
Start()
|
|
|
|
Start()
|
|
|
|
UpdateClient(*Client)
|
|
|
|
UpdateClient(*Client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SubCoordinator struct {
|
|
|
|
type SubCoordinator struct {
|
|
|
|
Port int // port that we set up gRPC endpoint on
|
|
|
|
Port int // port that we set up gRPC endpoint on
|
|
|
|
ManagerInterface // embed an interface to create/manager managers
|
|
|
|
ManagerInterface // embed an interface to create/manager managers
|
|
|
|
*SystemViewer
|
|
|
|
*SystemViewer
|
|
|
|
Err chan error
|
|
|
|
Err chan error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Managers struct {
|
|
|
|
type Managers struct {
|
|
|
|
Directory map[uint32]interface{} // support for either manager
|
|
|
|
Directory map[uint32]interface{} // support for either manager
|
|
|
|
sync.RWMutex // potential perf
|
|
|
|
sync.RWMutex // potential perf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// interface stuff
|
|
|
|
// interface stuff
|
|
|
|
func NewSubCoordinator(clientType string, sys *SystemViewer, err chan error) *SubCoordinator {
|
|
|
|
func NewSubCoordinator(clientType string, sys *SystemViewer, err chan error) *SubCoordinator {
|
|
|
|
c := &SubCoordinator{Err:err}
|
|
|
|
c := &SubCoordinator{Err: err}
|
|
|
|
c.SystemViewer = sys
|
|
|
|
c.SystemViewer = sys
|
|
|
|
man, errs := NewCoordinatorType(clientType, err)
|
|
|
|
man, errs := NewCoordinatorType(clientType, err)
|
|
|
|
if errs != nil {
|
|
|
|
if errs != nil {
|
|
|
|
err <-errs
|
|
|
|
err <- errs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.ManagerInterface = man
|
|
|
|
c.ManagerInterface = man
|
|
|
|
go man.Start()
|
|
|
|
go man.Start()
|
|
|
|
go man.Register()
|
|
|
|
go man.Register()
|
|
|
|
return c
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *SubCoordinator) ClientHandler(cl *Client) {
|
|
|
|
func (c *SubCoordinator) ClientHandler(cl *Client) {
|
|
|
|
// (creates and) notifies manager of client connection
|
|
|
|
// (creates and) notifies manager of client connection
|
|
|
|
|
|
|
|
|
|
|
|
c.UpdateManager(cl)
|
|
|
|
c.UpdateManager(cl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *SubCoordinator) UpdateManager(cl *Client) {
|
|
|
|
func (c *SubCoordinator) UpdateManager(cl *Client) {
|
|
|
|
// shouldn't happen all that often so should be fine to lock
|
|
|
|
// shouldn't happen all that often so should be fine to lock
|
|
|
|
m, exists := c.GetManager(cl.Id)
|
|
|
|
m, exists := c.GetManager(cl.Id)
|
|
|
|
if !exists {
|
|
|
|
if !exists {
|
|
|
|
m = c.NewManager(cl, c.SystemViewer, c.Err)
|
|
|
|
m = c.NewManager(cl, c.SystemViewer, c.Err)
|
|
|
|
m.UpdateClient(cl)
|
|
|
|
m.UpdateClient(cl)
|
|
|
|
go c.AddManager(cl.Id, m)
|
|
|
|
go c.AddManager(cl.Id, m)
|
|
|
|
go m.Start()
|
|
|
|
go m.Start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go m.UpdateClient(cl)
|
|
|
|
go m.UpdateClient(cl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *Managers) AddManager(id uint32, man GeneralManager) {
|
|
|
|
func (m *Managers) AddManager(id uint32, man GeneralManager) {
|
|
|
|
m.Lock()
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
defer m.Unlock()
|
|
|
|
m.Directory[id] = man
|
|
|
|
m.Directory[id] = man
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *Managers) GetManager(id uint32) (GeneralManager, bool) {
|
|
|
|
func (m *Managers) GetManager(id uint32) (GeneralManager, bool) {
|
|
|
|
// just read locks and reuturns
|
|
|
|
// just read locks and reuturns
|
|
|
|
m.RLock()
|
|
|
|
m.RLock()
|
|
|
|
defer m.RUnlock()
|
|
|
|
defer m.RUnlock()
|
|
|
|
man, exists := m.Directory[id]
|
|
|
|
man, exists := m.Directory[id]
|
|
|
|
if !exists {
|
|
|
|
if !exists {
|
|
|
|
return nil, exists
|
|
|
|
return nil, exists
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return man.(GeneralManager), exists
|
|
|
|
return man.(GeneralManager), exists
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewCoordinatorType(clientType string, err chan error) (ManagerInterface, error) {
|
|
|
|
func NewCoordinatorType(clientType string, err chan error) (ManagerInterface, error) {
|
|
|
|
|
|
|
|
|
|
|
|
m := make(map[uint32]interface{})
|
|
|
|
m := make(map[uint32]interface{})
|
|
|
|
if clientType == "reactor" {
|
|
|
|
if clientType == "reactor" {
|
|
|
|
c := &reactorCoordinator{}
|
|
|
|
c := &reactorCoordinator{}
|
|
|
|
//m := make(map[uint32]*ReactorManager)
|
|
|
|
//m := make(map[uint32]*ReactorManager)
|
|
|
|
c.Managers = &Managers{Directory:m}
|
|
|
|
c.Managers = &Managers{Directory: m}
|
|
|
|
return c, nil
|
|
|
|
return c, nil
|
|
|
|
} else if clientType == "tui" {
|
|
|
|
} else if clientType == "tui" {
|
|
|
|
c := &tuiCoordinator{}
|
|
|
|
c := &tuiCoordinator{}
|
|
|
|
//m := make(map[uint32]*TUIManager)
|
|
|
|
//m := make(map[uint32]*TUIManager)
|
|
|
|
c.Managers = &Managers{Directory:m}
|
|
|
|
c.Managers = &Managers{Directory: m}
|
|
|
|
return c, nil
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &reactorCoordinator{}, errors.New("Unrecognized client type")
|
|
|
|
return &reactorCoordinator{}, errors.New("Unrecognized client type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// creating sub coordinators for associated gRPC handlers
|
|
|
|
// creating sub coordinators for associated gRPC handlers
|
|
|
|
// reactor coordinator
|
|
|
|
// reactor coordinator
|
|
|
|
type reactorCoordinator struct {
|
|
|
|
type reactorCoordinator struct {
|
|
|
|
*Managers
|
|
|
|
*Managers
|
|
|
|
pb.UnimplementedMonitoringServer
|
|
|
|
pb.UnimplementedMonitoringServer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *reactorCoordinator) Start() {
|
|
|
|
func (r *reactorCoordinator) Start() {
|
|
|
|
logging.Debug(logging.DStart,"RCO 01 Starting!")
|
|
|
|
logging.Debug(logging.DStart, "RCO 01 Starting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *reactorCoordinator) NewManager(cl *Client, sys *SystemViewer, err chan error) GeneralManager {
|
|
|
|
func (r *reactorCoordinator) NewManager(cl *Client, sys *SystemViewer, err chan error) GeneralManager {
|
|
|
|
logging.Debug(logging.DClient, "RCO 01 starting manager for %v client %v",cl.Type,cl.Id)
|
|
|
|
logging.Debug(logging.DClient, "RCO 01 starting manager for %v client %v", cl.Type, cl.Id)
|
|
|
|
return NewReactorManager(cl,sys,err)
|
|
|
|
return NewReactorManager(cl, sys, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *reactorCoordinator) Register() {
|
|
|
|
func (r *reactorCoordinator) Register() {
|
|
|
|
conf := LoadConfig()
|
|
|
|
conf := LoadConfig()
|
|
|
|
port, err := conf.GetPort("reactor")
|
|
|
|
port, err := conf.GetPort("reactor")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%v",port))
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%v", port))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
pb.RegisterMonitoringServer(grpcServer,r)
|
|
|
|
pb.RegisterMonitoringServer(grpcServer, r)
|
|
|
|
go grpcServer.Serve(lis)
|
|
|
|
go grpcServer.Serve(lis)
|
|
|
|
logging.Debug(logging.DClient, "RCO ready for client requests")
|
|
|
|
logging.Debug(logging.DClient, "RCO ready for client requests")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *reactorCoordinator) ReactorStatusHandler(ctx context.Context, req *pb.ReactorStatusPing) (*pb.ReactorStatusResponse, error) {
|
|
|
|
func (r *reactorCoordinator) ReactorStatusHandler(ctx context.Context, req *pb.ReactorStatusPing) (*pb.ReactorStatusResponse, error) {
|
|
|
|
m, exists := r.GetManager(req.GetId())
|
|
|
|
m, exists := r.GetManager(req.GetId())
|
|
|
|
if !exists {
|
|
|
|
if !exists {
|
|
|
|
return &pb.ReactorStatusResponse{}, errors.New("Manager doesn't exists for that client")
|
|
|
|
return &pb.ReactorStatusResponse{}, errors.New("Manager doesn't exists for that client")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rm, ok := m.(*ReactorManager)
|
|
|
|
rm, ok := m.(*ReactorManager)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return &pb.ReactorStatusResponse{}, errors.New("Manager is not a reactor manager!")
|
|
|
|
return &pb.ReactorStatusResponse{}, errors.New("Manager is not a reactor manager!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rm.ReactorStatusHandler(ctx, req)
|
|
|
|
return rm.ReactorStatusHandler(ctx, req)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//tui coordinator
|
|
|
|
//tui coordinator
|
|
|
|
type tuiCoordinator struct {
|
|
|
|
type tuiCoordinator struct {
|
|
|
|
*Managers // by embedding general struct we allow coordinator to still call general funcs
|
|
|
|
*Managers // by embedding general struct we allow coordinator to still call general funcs
|
|
|
|
pb.UnimplementedManagementServer
|
|
|
|
pb.UnimplementedManagementServer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *tuiCoordinator) Start() {
|
|
|
|
func (t *tuiCoordinator) Start() {
|
|
|
|
logging.Debug(logging.DStart,"TCO 01 Starting!")
|
|
|
|
logging.Debug(logging.DStart, "TCO 01 Starting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *tuiCoordinator) NewManager(cl *Client, sys *SystemViewer, err chan error) GeneralManager {
|
|
|
|
func (t *tuiCoordinator) NewManager(cl *Client, sys *SystemViewer, err chan error) GeneralManager {
|
|
|
|
logging.Debug(logging.DClient, "TCO 01 starting manager for %v client %v",cl.Type,cl.Id)
|
|
|
|
logging.Debug(logging.DClient, "TCO 01 starting manager for %v client %v", cl.Type, cl.Id)
|
|
|
|
return NewTUIManager(cl,sys,err)
|
|
|
|
return NewTUIManager(cl, sys, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *tuiCoordinator) Register() {
|
|
|
|
func (t *tuiCoordinator) Register() {
|
|
|
|
conf := LoadConfig()
|
|
|
|
conf := LoadConfig()
|
|
|
|
port, err := conf.GetPort("tui")
|
|
|
|
port, err := conf.GetPort("tui")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%v",port))
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%v", port))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
// rip
|
|
|
|
// rip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
pb.RegisterManagementServer(grpcServer,t)
|
|
|
|
pb.RegisterManagementServer(grpcServer, t)
|
|
|
|
go grpcServer.Serve(lis)
|
|
|
|
go grpcServer.Serve(lis)
|
|
|
|
logging.Debug(logging.DClient, "TCO ready for client requests")
|
|
|
|
logging.Debug(logging.DClient, "TCO ready for client requests")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *tuiCoordinator) GetDevices(ctx context.Context, req *pb.GetDevicesRequest) (*pb.GetDevicesResponse, error) {
|
|
|
|
func (t *tuiCoordinator) GetDevices(ctx context.Context, req *pb.GetDevicesRequest) (*pb.GetDevicesResponse, error) {
|
|
|
|
// grpc handler to fwd to manager
|
|
|
|
// grpc handler to fwd to manager
|
|
|
|
m, exists := t.GetManager(req.GetClientId())
|
|
|
|
m, exists := t.GetManager(req.GetClientId())
|
|
|
|
if !exists {
|
|
|
|
if !exists {
|
|
|
|
// doesnt exist for some reason
|
|
|
|
// doesnt exist for some reason
|
|
|
|
return &pb.GetDevicesResponse{}, errors.New("Manager doesn't exists for client")
|
|
|
|
return &pb.GetDevicesResponse{}, errors.New("Manager doesn't exists for client")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tm, ok := m.(*TUIManager)
|
|
|
|
tm, ok := m.(*TUIManager)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return &pb.GetDevicesResponse{}, errors.New("Manager is not of type TUI")
|
|
|
|
return &pb.GetDevicesResponse{}, errors.New("Manager is not of type TUI")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tm.GetDevices(ctx,req)
|
|
|
|
return tm.GetDevices(ctx, req)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// unimplemented bs for grpc
|
|
|
|
// unimplemented bs for grpc
|
|
|
|
func (t *tuiCoordinator) DeleteReactor(ctx context.Context, req *pb.DeleteReactorRequest) (*pb.DeleteReactorResponse, error) {
|
|
|
|
func (t *tuiCoordinator) DeleteReactor(ctx context.Context, req *pb.DeleteReactorRequest) (*pb.DeleteReactorResponse, error) {
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
return &pb.DeleteReactorResponse{}, nil
|
|
|
|
return &pb.DeleteReactorResponse{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *tuiCoordinator) DeleteReactorDevice(ctx context.Context, req *pb.DeleteReactorDeviceRequest) (*pb.DeleteReactorDeviceResponse, error) {
|
|
|
|
func (t *tuiCoordinator) DeleteReactorDevice(ctx context.Context, req *pb.DeleteReactorDeviceRequest) (*pb.DeleteReactorDeviceResponse, error) {
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
return &pb.DeleteReactorDeviceResponse{}, nil
|
|
|
|
return &pb.DeleteReactorDeviceResponse{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|