Consumer O-DU slice assurance rApp
[nonrtric/rapp/ransliceassurance.git] / icsversion / main.go
diff --git a/icsversion/main.go b/icsversion/main.go
new file mode 100644 (file)
index 0000000..b9e9afc
--- /dev/null
@@ -0,0 +1,71 @@
+// -
+//   ========================LICENSE_START=================================
+//   O-RAN-SC
+//   %%
+//   Copyright (C) 2022: Nordix Foundation
+//   %%
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+//   ========================LICENSE_END===================================
+//
+
+package main
+
+import (
+       "fmt"
+       "os"
+       "os/signal"
+       "syscall"
+
+       log "github.com/sirupsen/logrus"
+       "oransc.org/usecase/oduclosedloop/icsversion/internal/config"
+       sliceassurance "oransc.org/usecase/oduclosedloop/icsversion/internal/odusliceassurance"
+)
+
+var configuration *config.Configuration
+var a sliceassurance.App
+
+const TOPIC string = "/events/unauthenticated.VES_O_RAN_SC_HELLO_WORLD_PM_STREAMING_OUTPUT/myG/C1"
+
+func main() {
+       configuration = config.New()
+
+       log.SetLevel(configuration.LogLevel)
+       log.SetFormatter(&log.JSONFormatter{})
+
+       log.Debug("Using configuration: ", configuration)
+
+       if err := validateConfiguration(configuration); err != nil {
+               log.Fatalf("Unable to start consumer due to configuration error: %v", err)
+       }
+
+       a = sliceassurance.App{}
+       a.Initialize(configuration)
+
+       go a.StartServer()
+       keepConsumerAlive()
+}
+
+func validateConfiguration(configuration *config.Configuration) error {
+       if configuration.ConsumerHost == "" || configuration.ConsumerPort == 0 {
+               return fmt.Errorf("consumer host and port must be provided")
+       }
+       return nil
+}
+
+func keepConsumerAlive() {
+       exitSignal := make(chan os.Signal, 1)
+       signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
+       <-exitSignal
+
+       a.Teardown()
+}