Consumer O-DU slice assurance rApp
[nonrtric/rapp/ransliceassurance.git] / icsversion / main.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2022: Nordix Foundation
6 //   %%
7 //   Licensed under the Apache License, Version 2.0 (the "License");
8 //   you may not use this file except in compliance with the License.
9 //   You may obtain a copy of the License at
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
13 //   Unless required by applicable law or agreed to in writing, software
14 //   distributed under the License is distributed on an "AS IS" BASIS,
15 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 //   See the License for the specific language governing permissions and
17 //   limitations under the License.
18 //   ========================LICENSE_END===================================
19 //
20
21 package main
22
23 import (
24         "fmt"
25         "os"
26         "os/signal"
27         "syscall"
28
29         log "github.com/sirupsen/logrus"
30         "oransc.org/usecase/oduclosedloop/icsversion/internal/config"
31         sliceassurance "oransc.org/usecase/oduclosedloop/icsversion/internal/odusliceassurance"
32 )
33
34 var configuration *config.Configuration
35 var a sliceassurance.App
36
37 const TOPIC string = "/events/unauthenticated.VES_O_RAN_SC_HELLO_WORLD_PM_STREAMING_OUTPUT/myG/C1"
38
39 func main() {
40         configuration = config.New()
41
42         log.SetLevel(configuration.LogLevel)
43         log.SetFormatter(&log.JSONFormatter{})
44
45         log.Debug("Using configuration: ", configuration)
46
47         if err := validateConfiguration(configuration); err != nil {
48                 log.Fatalf("Unable to start consumer due to configuration error: %v", err)
49         }
50
51         a = sliceassurance.App{}
52         a.Initialize(configuration)
53
54         go a.StartServer()
55         keepConsumerAlive()
56 }
57
58 func validateConfiguration(configuration *config.Configuration) error {
59         if configuration.ConsumerHost == "" || configuration.ConsumerPort == 0 {
60                 return fmt.Errorf("consumer host and port must be provided")
61         }
62         return nil
63 }
64
65 func keepConsumerAlive() {
66         exitSignal := make(chan os.Signal, 1)
67         signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
68         <-exitSignal
69
70         a.Teardown()
71 }