ing
This commit is contained in:
parent
bf761f7a63
commit
c281424878
|
@ -1 +1,5 @@
|
|||
package overflow_probe_container
|
||||
|
||||
const (
|
||||
PROBE_CONTAINER_CRAWLERS = "PROBE_CONTAINER_CRAWLERS"
|
||||
)
|
||||
|
|
10
crawler/Crawler.go
Normal file
10
crawler/Crawler.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package crawler
|
||||
|
||||
import (
|
||||
sensorConfigM "git.loafle.net/overflow/overflow_commons_go/modules/sensor_config/model"
|
||||
)
|
||||
|
||||
type Crawler interface {
|
||||
Name() string
|
||||
Get(sensorConfig *sensorConfigM.SensorConfig) (map[string]string, error)
|
||||
}
|
|
@ -80,6 +80,11 @@ func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
|||
sh.ServerHandlers.OnStop(serverCTX)
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Destroy(serverCTX server.ServerContext) {
|
||||
|
||||
sh.ServerHandlers.Destroy(serverCTX)
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Validate() {
|
||||
sh.ServerHandlers.Validate()
|
||||
|
||||
|
|
56
service/CrawlerService.go
Normal file
56
service/CrawlerService.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
|
||||
"git.loafle.net/overflow/overflow_probe_container/crawler"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cdr.RegisterType(reflect.TypeOf((*ProbeService)(nil)))
|
||||
}
|
||||
|
||||
type CrawlerService struct {
|
||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||
oocmci.Service
|
||||
|
||||
SensorConfigService *SensorConfigService `annotation:"@Inject()"`
|
||||
Crawlers map[string]crawler.Crawler `annotation:"@Resource(name=PROBE_CONTAINER_CRAWLERS)"`
|
||||
}
|
||||
|
||||
func (cs *CrawlerService) Start() error {
|
||||
if nil == cs.Crawlers {
|
||||
return fmt.Errorf("Crawlers is not set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *CrawlerService) Stop(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *CrawlerService) GetData(sensorConfigID string) (map[string]string, error) {
|
||||
sensorConfig, ok := cs.SensorConfigService.sensorConfigs[sensorConfigID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("There is no sensor config for id[%s]", sensorConfigID)
|
||||
}
|
||||
_crawlerName := sensorConfig.Crawler.Name
|
||||
_crawler, ok := cs.Crawlers[_crawlerName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("There is no crawler[%s] for id[%s]", _crawlerName, sensorConfigID)
|
||||
}
|
||||
|
||||
result, err := _crawler.Get(sensorConfig)
|
||||
if nil != err {
|
||||
return nil, fmt.Errorf("Failed to get data from crawler[%s] for id[%s] %v", _crawlerName, sensorConfigID, err)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
cr "git.loafle.net/commons_go/rpc"
|
||||
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -14,10 +16,21 @@ func init() {
|
|||
|
||||
type ProbeService struct {
|
||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||
oocmci.Service
|
||||
|
||||
RPCServlet cr.Servlet
|
||||
}
|
||||
|
||||
func (ps *ProbeService) Start() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *ProbeService) Stop(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *ProbeService) Send(method string, params ...interface{}) error {
|
||||
return ps.RPCServlet.Send(method, params...)
|
||||
}
|
||||
|
|
80
service/SensorConfigService.go
Normal file
80
service/SensorConfigService.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
|
||||
sensorConfigM "git.loafle.net/overflow/overflow_commons_go/modules/sensor_config/model"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cdr.RegisterType(reflect.TypeOf((*SensorConfigService)(nil)))
|
||||
}
|
||||
|
||||
type SensorConfigService struct {
|
||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||
oocmci.Service
|
||||
|
||||
sensorConfigs map[string]*sensorConfigM.SensorConfig
|
||||
}
|
||||
|
||||
func (scs *SensorConfigService) Start() error {
|
||||
scs.sensorConfigs = make(map[string]*sensorConfigM.SensorConfig, 0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (scs *SensorConfigService) Stop(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (scs *SensorConfigService) Init(sensorConfigs []*sensorConfigM.SensorConfig) error {
|
||||
if nil == sensorConfigs || 0 == len(sensorConfigs) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, sensorConfig := range sensorConfigs {
|
||||
scs.sensorConfigs[sensorConfig.ID.String()] = sensorConfig
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (scs *SensorConfigService) AddConfig(sensorConfig *sensorConfigM.SensorConfig) error {
|
||||
if nil == sensorConfig {
|
||||
return fmt.Errorf("Sensor config is not valid")
|
||||
}
|
||||
|
||||
sensorConfigID := sensorConfig.ID.String()
|
||||
if _, ok := scs.sensorConfigs[sensorConfigID]; ok {
|
||||
return fmt.Errorf("Sensor config[%s] is exist already", sensorConfigID)
|
||||
}
|
||||
scs.sensorConfigs[sensorConfigID] = sensorConfig
|
||||
return nil
|
||||
}
|
||||
func (scs *SensorConfigService) UpdateConfig(sensorConfig *sensorConfigM.SensorConfig) error {
|
||||
if nil == sensorConfig {
|
||||
return fmt.Errorf("Sensor config is not valid")
|
||||
}
|
||||
|
||||
sensorConfigID := sensorConfig.ID.String()
|
||||
if _, ok := scs.sensorConfigs[sensorConfigID]; !ok {
|
||||
return fmt.Errorf("Sensor config[%s] is not exist", sensorConfigID)
|
||||
}
|
||||
delete(scs.sensorConfigs, sensorConfigID)
|
||||
scs.sensorConfigs[sensorConfigID] = sensorConfig
|
||||
|
||||
return nil
|
||||
}
|
||||
func (scs *SensorConfigService) RemoveConfig(sensorConfigID string) error {
|
||||
if _, ok := scs.sensorConfigs[sensorConfigID]; !ok {
|
||||
return fmt.Errorf("Sensor config[%s] is not exist", sensorConfigID)
|
||||
}
|
||||
delete(scs.sensorConfigs, sensorConfigID)
|
||||
|
||||
return nil
|
||||
}
|
31
service/StateService.go
Normal file
31
service/StateService.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdr "git.loafle.net/commons_go/di/registry"
|
||||
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cdr.RegisterType(reflect.TypeOf((*StateService)(nil)))
|
||||
}
|
||||
|
||||
type StateService struct {
|
||||
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
|
||||
oocmci.Service
|
||||
}
|
||||
|
||||
func (s *StateService) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StateService) Stop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StateService) State() (bool, error) {
|
||||
return true, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user