From 519e96beeaa6dab24c42d87f4555906336f902fb Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 4 Jul 2018 11:35:52 +0900 Subject: [PATCH] ing --- client/client.go | 7 ++++--- service/CollectorService.go | 32 ++++++++++++++++---------------- service/CrawlerService.go | 2 +- service/SensorConfigService.go | 24 ++++++++++++------------ 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/client/client.go b/client/client.go index 5b7629a..31ea422 100644 --- a/client/client.go +++ b/client/client.go @@ -27,12 +27,13 @@ func NewConnector(containerType occp.ContainerType, portNumber int) (*csswc.Conn connector.Name = containerType.String() connector.ReconnectInterval = 5 connector.ReconnectTryTime = 2 - connector.MaxMessageSize = 4096 - connector.ReadBufferSize = 4096 - connector.WriteBufferSize = 4096 + connector.MaxMessageSize = 8192 + connector.ReadBufferSize = 8192 + connector.WriteBufferSize = 8192 connector.PongTimeout = 60 connector.PingTimeout = 10 connector.PingPeriod = 9 + connector.CompressionThreshold = 4096 connector.RequestHeader = func() http.Header { header := make(map[string][]string) diff --git a/service/CollectorService.go b/service/CollectorService.go index ef6d2f4..504a349 100644 --- a/service/CollectorService.go +++ b/service/CollectorService.go @@ -3,13 +3,13 @@ package service import ( "fmt" "reflect" - "strconv" "sync" "time" cda "git.loafle.net/commons/di-go/annotation" cdr "git.loafle.net/commons/di-go/registry" logging "git.loafle.net/commons/logging-go" + cuej "git.loafle.net/commons/util-go/encoding/json" cuts "git.loafle.net/commons/util-go/time/scheduler" cutss "git.loafle.net/commons/util-go/time/scheduler/storage" occu "git.loafle.net/overflow/commons-go/core/util" @@ -67,12 +67,12 @@ func (s *CollectorService) AddSensorConfigs(sensorConfigs []*ocmsc.SensorConfig) } for _, sensorConfig := range sensorConfigs { - interval, err := strconv.ParseInt(sensorConfig.Schedule.Interval, 10, 64) + interval, err := cuej.NumberToInt(sensorConfig.Schedule.Interval) if nil != err { return fmt.Errorf("Cannot convert interval[%s] %v", sensorConfig.Schedule.Interval, err) } s.addSchedule(interval, sensorConfig) - logging.Logger().Debugf("scheduler of config[%s] has been added", sensorConfig.ConfigID) + logging.Logger().Debugf("scheduler of config[%s] has been added", sensorConfig.SensorID) } return nil @@ -84,47 +84,47 @@ func (s *CollectorService) RemoveSensorConfigs(sensorConfigs []*ocmsc.SensorConf } for _, sensorConfig := range sensorConfigs { - s.removeSchedule(sensorConfig.ConfigID) + s.removeSchedule(sensorConfig.SensorID.String()) } return nil } -func (s *CollectorService) addSchedule(interval int64, sensorConfig *ocmsc.SensorConfig) { - s.removeSchedule(sensorConfig.ConfigID) +func (s *CollectorService) addSchedule(interval int, sensorConfig *ocmsc.SensorConfig) { + s.removeSchedule(sensorConfig.SensorID.String()) scheduleID, err := s.scheduler.RunEvery(time.Duration(interval)*time.Second, s.collectTask, sensorConfig) if nil != err { - logging.Logger().Errorf("Cannot add schedule for config[%s] %v", sensorConfig.ConfigID, err) + logging.Logger().Errorf("Cannot add schedule for config[%s] %v", sensorConfig.SensorID, err) return } - s.scheduleMap.Store(sensorConfig.ConfigID, scheduleID) + s.scheduleMap.Store(sensorConfig.SensorID, scheduleID) } -func (s *CollectorService) removeSchedule(configID string) { - scheduleID, ok := s.scheduleMap.Load(configID) +func (s *CollectorService) removeSchedule(sensorID string) { + scheduleID, ok := s.scheduleMap.Load(sensorID) if !ok { return } - s.scheduleMap.Delete(configID) + s.scheduleMap.Delete(sensorID) s.scheduler.Cancel(scheduleID.(string)) } func (s *CollectorService) collectTask(sensorConfig *ocmsc.SensorConfig) { - logging.Logger().Debugf("CollectorService.collectTask for sensor config id[%s] of crawler[%s]", sensorConfig.ConfigID, sensorConfig.Crawler.Name) + logging.Logger().Debugf("CollectorService.collectTask for sensor config id[%s] of crawler[%s]", sensorConfig.SensorID, sensorConfig.Crawler.MetaCrawlerKey) - result, err := s.CrawlerService.Get(sensorConfig.ConfigID) + result, err := s.CrawlerService.Get(sensorConfig.SensorID.String()) if nil != err { - logging.Logger().Errorf("Cannot get data from crawler[%s] %v", sensorConfig.Crawler.Name, err) + logging.Logger().Errorf("Cannot get data from crawler[%s] %v", sensorConfig.Crawler.MetaCrawlerKey, err) return } m := &ocmd.Metric{ - SensorConfigID: sensorConfig.ConfigID, + SensorConfigID: sensorConfig.SensorID.String(), Data: result, CollectDate: occu.NowPtr(), } if err := s.ProbeService.Send("MetricService.Send", m); nil != err { - logging.Logger().Errorf("Cannot send data from config id[%s] of crawler[%s] %v", sensorConfig.ConfigID, sensorConfig.Crawler.Name, err) + logging.Logger().Errorf("Cannot send data from config id[%s] of crawler[%s] %v", sensorConfig.SensorID, sensorConfig.Crawler.MetaCrawlerKey, err) } } diff --git a/service/CrawlerService.go b/service/CrawlerService.go index e82b541..9751919 100644 --- a/service/CrawlerService.go +++ b/service/CrawlerService.go @@ -69,7 +69,7 @@ func (s *CrawlerService) Get(sensorConfigID string) (map[string]string, error) { if !ok { return nil, fmt.Errorf("There is no sensor config for id[%s]", sensorConfigID) } - _crawlerName := sensorConfig.Crawler.Name + _crawlerName := sensorConfig.Crawler.MetaCrawlerKey _crawler, ok := s.Crawlers[_crawlerName] if !ok { return nil, fmt.Errorf("There is no crawler[%s] for id[%s]", _crawlerName, sensorConfigID) diff --git a/service/SensorConfigService.go b/service/SensorConfigService.go index 50aa7ce..f37f7f4 100644 --- a/service/SensorConfigService.go +++ b/service/SensorConfigService.go @@ -52,7 +52,7 @@ func (s *SensorConfigService) InitConfig(sensorConfigs []*ocmsc.SensorConfig) er } for _, sensorConfig := range sensorConfigs { - s.sensorConfigs[sensorConfig.ConfigID] = sensorConfig + s.sensorConfigs[sensorConfig.SensorID.String()] = sensorConfig } if err := s.CollectorService.AddSensorConfigs(sensorConfigs); nil != err { @@ -69,17 +69,17 @@ func (s *SensorConfigService) AddConfig(sensorConfig *ocmsc.SensorConfig) error return fmt.Errorf("Sensor config is not valid") } - configID := sensorConfig.ConfigID - if _, ok := s.sensorConfigs[configID]; ok { - return fmt.Errorf("Sensor config[%s] is exist already", configID) + sensorID := sensorConfig.SensorID.String() + if _, ok := s.sensorConfigs[sensorID]; ok { + return fmt.Errorf("Sensor config[%s] is exist already", sensorID) } - s.sensorConfigs[configID] = sensorConfig + s.sensorConfigs[sensorID] = sensorConfig if err := s.CollectorService.AddSensorConfigs([]*ocmsc.SensorConfig{sensorConfig}); nil != err { return err } - logging.Logger().Debugf("Sensor config[%s] was added", configID) + logging.Logger().Debugf("Sensor config[%s] was added", sensorID) return nil } @@ -89,12 +89,12 @@ func (s *SensorConfigService) UpdateConfig(sensorConfig *ocmsc.SensorConfig) err return fmt.Errorf("Sensor config is not valid") } - configID := sensorConfig.ConfigID - if _, ok := s.sensorConfigs[configID]; !ok { - return fmt.Errorf("Sensor config[%s] is not exist", configID) + sensorID := sensorConfig.SensorID.String() + if _, ok := s.sensorConfigs[sensorID]; !ok { + return fmt.Errorf("Sensor config[%s] is not exist", sensorID) } - delete(s.sensorConfigs, configID) - s.sensorConfigs[configID] = sensorConfig + delete(s.sensorConfigs, sensorID) + s.sensorConfigs[sensorID] = sensorConfig if err := s.CollectorService.RemoveSensorConfigs([]*ocmsc.SensorConfig{sensorConfig}); nil != err { return err @@ -104,7 +104,7 @@ func (s *SensorConfigService) UpdateConfig(sensorConfig *ocmsc.SensorConfig) err return err } - logging.Logger().Debugf("Sensor config[%s] was updated", configID) + logging.Logger().Debugf("Sensor config[%s] was updated", sensorID) return nil }