2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
35 ENV_RMR_PORT = "RMR_PORT"
36 RMR_PORT_DEFAULT = 5001
39 var rmrService *rmr.Service
43 logLevel, _ := logger.LogLevelTokenToLevel("info")
44 logger, err := logger.InitLogger(logLevel)
46 fmt.Printf("#app.main - failed to initialize logger, error: %s", err)
50 var rmrContext *rmr.Context
51 var rmrConfig = rmr.Config{Port: RMR_PORT_DEFAULT, MaxMsgSize: rmr.RMR_MAX_MSG_SIZE, MaxRetries: 10, Flags: 0}
53 if port, err := strconv.ParseUint(os.Getenv(ENV_RMR_PORT), 10, 16); err == nil {
54 rmrConfig.Port = int(port)
56 logger.Infof("#main - %s: %s, using default (%d).", ENV_RMR_PORT, err, RMR_PORT_DEFAULT)
59 rmrService = rmr.NewService(rmrConfig, rmrContext)
60 jsonSender := sender.NewJsonSender(logger)
61 dispatcherDesc := dispatcher.New(logger, rmrService, jsonSender)
63 /* Load configuration file*/
64 err = frontend.ProcessConfigurationFile("resources", "conf", ".json",
65 func(data []byte) error {
66 return frontend.JsonCommandsDecoder(data, dispatcherDesc.JsonCommandsDecoderCB)
70 logger.Errorf("#main - processing error: %s", err)
74 logger.Infof("#main - xApp Mock is up and running...")
77 cmd := flag.Arg(0) /*first remaining argument after flags have been processed*/
79 command, err := frontend.DecodeJsonCommand([]byte(cmd))
82 logger.Errorf("#main - command decoding error: %s", err)
83 rmrService.CloseContext()
84 logger.Infof("#main - xApp Mock is down")
88 c := make(chan os.Signal, 1)
89 signal.Notify(c, os.Interrupt)
90 ctx, cancel := context.WithCancel(context.Background())
94 logger.Infof("system call:%+v", oscall)
96 rmrService.CloseContext()
99 dispatcherDesc.ProcessJsonCommand(ctx, command)
100 pr := dispatcherDesc.GetProcessResult()
103 logger.Errorf("#main - command processing Error: %s", pr.Err)
106 if pr.StartTime != nil {
107 processElapsedTimeInMs := float64(time.Since(*pr.StartTime)) / float64(time.Millisecond)
108 logger.Infof("#main - processing (sending/receiving) messages took %.2f ms", processElapsedTimeInMs)
111 logger.Infof("#main - process stats: %s", pr.Stats)
113 rmrService.CloseContext() // TODO: called twice
114 logger.Infof("#main - xApp Mock is down")