Adding needed docker files
[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 func main() {
38         configuration = config.New()
39
40         log.SetLevel(configuration.LogLevel)
41         log.SetFormatter(&log.JSONFormatter{})
42
43         log.Debug("Using configuration: ", configuration)
44
45         if err := validateConfiguration(configuration); err != nil {
46                 log.Fatalf("Unable to start consumer due to configuration error: %v", err)
47         }
48
49         a = sliceassurance.App{}
50         a.Initialize(configuration)
51
52         go a.StartServer()
53         keepConsumerAlive()
54 }
55
56 func validateConfiguration(configuration *config.Configuration) error {
57         if configuration.ConsumerHost == "" || configuration.ConsumerPort == 0 {
58                 return fmt.Errorf("consumer host and port must be provided")
59         }
60         return nil
61 }
62
63 func keepConsumerAlive() {
64         exitSignal := make(chan os.Signal, 1)
65         signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
66         <-exitSignal
67
68         a.Teardown()
69 }