X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=dmaap-mediator-producer%2Fmain.go;h=ab28c6bc84658cbb16410a31dc0c07a24a327ceb;hb=8170f78af913d337f874477ba5dd93411e9e69da;hp=819ffa9d811ee143a8b4b109619ccaa799646dee;hpb=1b732d17463fad74721391b3a87a2a12172da63c;p=nonrtric.git diff --git a/dmaap-mediator-producer/main.go b/dmaap-mediator-producer/main.go index 819ffa9d..ab28c6bc 100644 --- a/dmaap-mediator-producer/main.go +++ b/dmaap-mediator-producer/main.go @@ -26,12 +26,16 @@ import ( "net/http" "time" + "github.com/gorilla/mux" log "github.com/sirupsen/logrus" + _ "oransc.org/nonrtric/dmaapmediatorproducer/docs" "oransc.org/nonrtric/dmaapmediatorproducer/internal/config" "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs" "oransc.org/nonrtric/dmaapmediatorproducer/internal/kafkaclient" "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient" "oransc.org/nonrtric/dmaapmediatorproducer/internal/server" + + httpSwagger "github.com/swaggo/http-swagger" ) var configuration *config.Config @@ -41,6 +45,12 @@ func init() { configuration = config.New() } +// @title DMaaP Mediator Producer +// @version 1.1.0 + +// @license.name Apache 2.0 +// @license.url http://www.apache.org/licenses/LICENSE-2.0.html + func main() { log.SetLevel(configuration.LogLevel) log.Debug("Initializing DMaaP Mediator Producer") @@ -87,20 +97,20 @@ func validateConfiguration(configuration *config.Config) error { } return nil } -func registerTypesAndProducer(jobTypesHandler jobs.JobTypesManager, infoCoordinatorAddress string, callbackAddress string, client restclient.HTTPClient) error { +func registerTypesAndProducer(jobTypesManager jobs.JobTypesManager, infoCoordinatorAddress string, callbackAddress string, client restclient.HTTPClient) error { registrator := config.NewRegistratorImpl(infoCoordinatorAddress, client) configTypes, err := config.GetJobTypesFromConfiguration("configs") if err != nil { return fmt.Errorf("unable to register all types due to: %v", err) } - regErr := registrator.RegisterTypes(jobTypesHandler.LoadTypesFromConfiguration(configTypes)) + regErr := registrator.RegisterTypes(jobTypesManager.LoadTypesFromConfiguration(configTypes)) if regErr != nil { return fmt.Errorf("unable to register all types due to: %v", regErr) } producer := config.ProducerRegistrationInfo{ InfoProducerSupervisionCallbackUrl: callbackAddress + server.HealthCheckPath, - SupportedInfoTypes: jobTypesHandler.GetSupportedTypes(), + SupportedInfoTypes: jobTypesManager.GetSupportedTypes(), InfoJobCallbackUrl: callbackAddress + server.AddJobPath, } if err := registrator.RegisterProducer("DMaaP_Mediator_Producer", &producer); err != nil { @@ -112,6 +122,7 @@ func registerTypesAndProducer(jobTypesHandler jobs.JobTypesManager, infoCoordina func startCallbackServer(jobsManager jobs.JobsManager, callbackAddress string) { log.Debugf("Starting callback server at port %v", configuration.InfoProducerPort) r := server.NewRouter(jobsManager, statusHandler) + addSwaggerHandler(r) if restclient.IsUrlSecure(callbackAddress) { log.Fatalf("Server stopped: %v", http.ListenAndServeTLS(fmt.Sprintf(":%v", configuration.InfoProducerPort), configuration.ProducerCertPath, configuration.ProducerKeyPath, r)) } else { @@ -119,6 +130,11 @@ func startCallbackServer(jobsManager jobs.JobsManager, callbackAddress string) { } } +// @Summary Get status +// @Description Get the status of the producer. Will show if the producer has registered in ICS. +// @Tags Data producer (callbacks) +// @Success 200 +// @Router /health_check [get] func statusHandler(w http.ResponseWriter, r *http.Request) { registeredStatus := "not registered" if registered { @@ -127,6 +143,15 @@ func statusHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, `{"status": "%v"}`, registeredStatus) } +// @Summary Get Swagger Documentation +// @Description Get the Swagger API documentation for the producer. +// @Tags Admin +// @Success 200 +// @Router /swagger [get] +func addSwaggerHandler(r *mux.Router) { + r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler) +} + func keepProducerAlive() { forever := make(chan int) <-forever