2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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===================================
27 log "github.com/sirupsen/logrus"
28 "oransc.org/nonrtric/dmaapmediatorproducer/internal/config"
29 "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobtypes"
30 "oransc.org/nonrtric/dmaapmediatorproducer/internal/server"
33 var configuration *config.Config
34 var supervisionCallbackAddress string
35 var jobInfoCallbackAddress string
38 configuration = config.New()
39 if loglevel, err := log.ParseLevel(configuration.LogLevel); err == nil {
40 log.SetLevel(loglevel)
42 log.Warnf("Invalid log level: %v. Log level will be Info!", configuration.LogLevel)
45 log.Debug("Initializing DMaaP Mediator Producer")
46 if configuration.InfoProducerSupervisionCallbackHost == "" {
47 log.Fatal("Missing INFO_PRODUCER_SUPERVISION_CALLBACK_HOST")
49 supervisionCallbackAddress = fmt.Sprintf("%v:%v", configuration.InfoProducerSupervisionCallbackHost, configuration.InfoProducerSupervisionCallbackPort)
51 if configuration.InfoJobCallbackHost == "" {
52 log.Fatal("Missing INFO_JOB_CALLBACK_HOST")
54 jobInfoCallbackAddress = fmt.Sprintf("%v:%v", configuration.InfoJobCallbackHost, configuration.InfoJobCallbackPort)
56 registrator := config.NewRegistratorImpl(configuration.InfoCoordinatorAddress)
57 if types, err := jobtypes.GetTypes(); err == nil {
58 if regErr := registrator.RegisterTypes(types); regErr != nil {
59 log.Fatalf("Unable to register all types due to: %v", regErr)
62 log.Fatalf("Unable to get types to register due to: %v", err)
64 producer := config.ProducerRegistrationInfo{
65 InfoProducerSupervisionCallbackUrl: supervisionCallbackAddress,
66 SupportedInfoTypes: jobtypes.GetSupportedTypes(),
67 InfoJobCallbackUrl: jobInfoCallbackAddress,
69 if err := registrator.RegisterProducer("DMaaP_Mediator_Producer", &producer); err != nil {
70 log.Fatalf("Unable to register producer due to: %v", err)
75 log.Debug("Starting DMaaP Mediator Producer")
76 log.Debugf("Starting status callback server at port %v", configuration.InfoProducerSupervisionCallbackPort)
77 http.HandleFunc("/", server.StatusHandler)
79 if err := http.ListenAndServe(":"+configuration.InfoProducerSupervisionCallbackPort, nil); err != nil {
82 log.Debug("Stopping DMaaP Mediator Producer")