X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Fmain.go;h=79fcb6b5881a9abbd77eb0d8929e0c75dbea4f22;hb=refs%2Fchanges%2F47%2F6747%2F2;hp=d38496ff2208307efaff394a6542fbe29aeaae7e;hpb=a77cd650f99b29be6c53a690157529e7e158d70e;p=nonrtric.git diff --git a/dmaap-mediator-producer/main.go b/dmaap-mediator-producer/main.go index d38496ff..79fcb6b5 100644 --- a/dmaap-mediator-producer/main.go +++ b/dmaap-mediator-producer/main.go @@ -21,14 +21,18 @@ package main import ( - "time" + "fmt" + "net/http" + "sync" log "github.com/sirupsen/logrus" "oransc.org/nonrtric/dmaapmediatorproducer/internal/config" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobtypes" + "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs" + "oransc.org/nonrtric/dmaapmediatorproducer/internal/server" ) var configuration *config.Config +var callbackAddress string func init() { configuration = config.New() @@ -39,15 +43,13 @@ func init() { } log.Debug("Initializing DMaaP Mediator Producer") - if configuration.InfoJobCallbackUrl == "" { - log.Fatal("Missing INFO_JOB_CALLBACK_URL") - } - if configuration.InfoProducerSupervisionCallbackUrl == "" { - log.Fatal("Missing INFO_PRODUCER_SUPERVISION_CALLBACK_URL") + if configuration.InfoProducerHost == "" { + log.Fatal("Missing INFO_PRODUCER_SUPERVISION_CALLBACK_HOST") } + callbackAddress = fmt.Sprintf("%v:%v", configuration.InfoProducerHost, configuration.InfoProducerPort) registrator := config.NewRegistratorImpl(configuration.InfoCoordinatorAddress) - if types, err := jobtypes.GetTypes(); err == nil { + if types, err := jobs.GetTypes(); err == nil { if regErr := registrator.RegisterTypes(types); regErr != nil { log.Fatalf("Unable to register all types due to: %v", regErr) } @@ -55,9 +57,9 @@ func init() { log.Fatalf("Unable to get types to register due to: %v", err) } producer := config.ProducerRegistrationInfo{ - InfoProducerSupervisionCallbackUrl: configuration.InfoProducerSupervisionCallbackUrl, - SupportedInfoTypes: jobtypes.GetSupportedTypes(), - InfoJobCallbackUrl: configuration.InfoJobCallbackUrl, + InfoProducerSupervisionCallbackUrl: callbackAddress + server.StatusCallbackPath, + SupportedInfoTypes: jobs.GetSupportedTypes(), + InfoJobCallbackUrl: callbackAddress + server.JobsCallbackPath, } if err := registrator.RegisterProducer("DMaaP_Mediator_Producer", &producer); err != nil { log.Fatalf("Unable to register producer due to: %v", err) @@ -66,5 +68,25 @@ func init() { func main() { log.Debug("Starting DMaaP Mediator Producer") - time.Sleep(1000 * time.Millisecond) + wg := new(sync.WaitGroup) + + // add two goroutines to `wg` WaitGroup, one for each running go routine + wg.Add(2) + + log.Debugf("Starting callback server at port %v", configuration.InfoProducerPort) + go func() { + http.HandleFunc(server.StatusCallbackPath, server.StatusHandler) + http.HandleFunc(server.JobsCallbackPath, server.CreateInfoJobHandler) + log.Warn(http.ListenAndServe(fmt.Sprintf(":%v", configuration.InfoProducerPort), nil)) + wg.Done() + }() + + go func() { + jobs.RunJobs(fmt.Sprintf("%v:%v", configuration.MRHost, configuration.MRPort)) + wg.Done() + }() + + // wait until WaitGroup is done + wg.Wait() + log.Debug("Stopping DMaaP Mediator Producer") }