diff --git a/service/SensorConfigService.go b/service/SensorConfigService.go index 2b33463..6520ef7 100644 --- a/service/SensorConfigService.go +++ b/service/SensorConfigService.go @@ -87,7 +87,7 @@ func (s *SensorConfigService) SendInitConfig(containerType occp.ContainerType) e func (s *SensorConfigService) AddConfig(tempFilePath string) error { //sc, buf, err := s.loadConfigFile(tempFilePath) - sc, _, err := s.loadConfigFile1(tempFilePath) + sc, _, err := s.loadConfigFile([]byte(tempFilePath)) if nil != err { return err } @@ -99,25 +99,20 @@ func (s *SensorConfigService) AddConfig(tempFilePath string) error { fmt.Println(err.Error()) } - fmt.Println(sc.SensorID) - // tempfile remove - //err = os.Remove(tempFilePath) - //if nil != err { - // return err - //} + s.sensorConfigs[sc.SensorID.String()] = sc + s.sortSensorConfigPerContainer() - //s.sensorConfigs[sc.ID.String()] = sc - //s.sortSensorConfigPerContainer() - // - //if err := s.ContainerService.Send(occp.ToContainerType(sc.Crawler.Container), "SensorConfigService.AddConfig", sc); nil != err { - // return err - //} + if err := s.ContainerService.Send(occp.ToContainerType(sc.Crawler.MetaCrawlerContainerKey), "SensorConfigService.AddConfig", sc); nil != err { + return err + } return nil } func (s *SensorConfigService) UpdateConfig(tempFilePath string) error { - sc, buf, err := s.loadConfigFile(tempFilePath) + loadByte, err := ioutil.ReadFile(tempFilePath) + + sc, buf, err := s.loadConfigFile(loadByte) if nil != err { return err } @@ -196,7 +191,8 @@ func (s *SensorConfigService) loadConfigDir(dirPath string) error { return err } } else { - sc, _, err := s.loadConfigFile(filePath) + buf, err := ioutil.ReadFile(filePath) + sc, _, err := s.loadConfigFile(buf) if nil != err { return err } @@ -207,7 +203,7 @@ func (s *SensorConfigService) loadConfigDir(dirPath string) error { return nil } -func (s *SensorConfigService) loadConfigFile(filePath string) (*ocmsc.SensorConfig, []byte, error) { +func (s *SensorConfigService) loadConfigFile1(filePath string) (*ocmsc.SensorConfig, []byte, error) { logging.Logger().Debugf("filePath: %s", filePath) buf, err := ioutil.ReadFile(filePath) @@ -226,9 +222,9 @@ func (s *SensorConfigService) loadConfigFile(filePath string) (*ocmsc.SensorConf return m, buf, nil } -func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorConfig, []byte, error) { +func (s *SensorConfigService) loadConfigFile(configStrByte []byte) (*ocmsc.SensorConfig, []byte, error) { //keyStr := s.ProbeClientService.EncryptionKey - configStrByte := []byte(decodeStr) + //configStrByte := []byte(decodeStr) keyStr := "aaaaaaaa" key := []byte(keyStr) @@ -239,10 +235,10 @@ func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorCo return nil, nil, err } - out := make([]byte, len(decodeStr)) + out := make([]byte, len(configStrByte)) dst := out bs := block.BlockSize() - if len(decodeStr)%bs != 0 { + if len(configStrByte)%bs != 0 { return nil, nil, errors.New("crypto/cipher: input not full blocks") } @@ -260,21 +256,16 @@ func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorCo fmt.Println(err.Error()) } - //if b, err := ioutil.ReadAll(gr); err == nil { - // fmt.Println(string(b)) - //} - defer gr.Close() data, err := ioutil.ReadAll(gr) - fmt.Println(string(data)) + //fmt.Println(string(data)) var m = &ocmsc.SensorConfig{} if err := json.Unmarshal(data, m); nil != err { fmt.Println(err.Error()) return nil, nil, err } - //fmt.Println(string(data)) return m, data, nil } diff --git a/service/SensorService_test.go b/service/SensorService_test.go index b2b7213..5ab9eb1 100644 --- a/service/SensorService_test.go +++ b/service/SensorService_test.go @@ -9,6 +9,7 @@ func TestSensorService_AddSensor(t *testing.T) { config := "pT1QAThXECRfY+Vqe0PpaDrI5TlJ+Psf0AyM5JWiHlHHEr0oZsq8z5L01BnXV4LDHtMXGB0wDb2+L+4SDxk/zM57b7dGHt76ibmZ/R6jPXF8EZYgORbNcyy+m60sesk8fK23unH4Wc1Gqf5ekxTyYjupQ6ZSQbmdFk/WJM3iYy20G8JN3gsHHZtWVCDRVzhQU8sAg+UQ4voSlN3hWajAN8sZFL0HDSba7CjDX3rp9Z7K7VoZCkBsti9b7Z/WhFjHV23zoO786ZhKc8M8lYa69eCgcDDX4zYGJ5RUHnzLFwYkZ6GAoVX0NM8nCA8+yk59CbEcWS1qjR9Xv2C32PuZq8oWOhVW1xiXQDBD1hhAv+3c+m4gZmpHZQ==" s := &SensorService{} + s.InitService() err := s.AddSensor(config) if nil != err {