RIC:1060: Change in PTL
[ric-plt/rtmgr.git] / cmd / rtmgr.go
1 /*
2 ==================================================================================
3    Copyright (c) 2019 AT&T Intellectual Property.
4    Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18
19    This source code is part of the near-RT RIC (RAN Intelligent Controller)
20    platform project (RICP).
21
22
23 ==================================================================================
24 */
25 /*
26         Mnemonic:       rtmgr.go
27         Abstract:       Routing Manager Main file. Implemets the following functions:
28                         - parseArgs: reading command line arguments
29                         - init:Rtmgr initializing the service modules
30                         - serve: running the loop
31         Date:           12 March 2019
32 */
33 package main
34
35 import (
36         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37         "os"
38         "os/signal"
39         "routing-manager/pkg/nbi"
40         "routing-manager/pkg/nbi/restful"
41         "routing-manager/pkg/rtmgr"
42         "syscall"
43         "time"
44 )
45
46 const SERVICENAME = "rtmgr"
47
48 func SetupCloseHandler() {
49         c := make(chan os.Signal, 2)
50         signal.Notify(c, os.Interrupt, syscall.SIGTERM)
51         go func() {
52                 <-c
53                 xapp.Logger.Info("\r- Ctrl+C pressed in Terminal")
54                 os.Exit(0)
55         }()
56 }
57
58 func main() {
59
60         SetupCloseHandler()
61
62         xapp.Logger.Info("Start " + SERVICENAME + " service")
63         rtmgr.Eps = make(rtmgr.Endpoints)
64         rtmgr.Mtype = make(rtmgr.MessageTypeList)
65         rtmgr.Rtmgr_ready = false
66         rtmgr.RMRConnStatus = make(map[string]bool)
67
68         // RMR thread is starting port: 4560
69         c := nbi.NewControl()
70         go c.Run()
71
72         // Waiting for RMR to be ready
73         time.Sleep(time.Duration(2) * time.Second)
74         for xapp.Rmr.IsReady() == false {
75                 time.Sleep(time.Duration(2) * time.Second)
76         }
77
78         dummy_whid := int(xapp.Rmr.Openwh("rtmgr:4560"))
79         xapp.Logger.Info("Wormhole ID created for routingmanager:%d", dummy_whid)
80
81         go func() {
82                 restful.LaunchRest(xapp.Config.GetString("nbiurl"))
83         }()
84
85         nbi.Serve()
86         os.Exit(0)
87 }