X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fregistrator.go;h=37225eda5e850a8c9cdfa44837b2b3dda4dfb376;hb=c94a2e14a26dd4e20808189f44e567b982f92d32;hp=f846f9f52f8c1b22657138e8604ea06ece232fbf;hpb=cce95ff706e7b7d703b0bf1cfa6ce855cc2d9b68;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/registrator.go b/dmaap-mediator-producer/internal/config/registrator.go index f846f9f5..37225eda 100644 --- a/dmaap-mediator-producer/internal/config/registrator.go +++ b/dmaap-mediator-producer/internal/config/registrator.go @@ -21,19 +21,22 @@ package config import ( + "encoding/json" "fmt" "net/url" log "github.com/sirupsen/logrus" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobtypes" + "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs" "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient" ) const registerTypePath = "/data-producer/v1/info-types/" +const registerProducerPath = "/data-producer/v1/info-producers/" type Registrator interface { - RegisterTypes(types []*jobtypes.Type) error + RegisterTypes(types []*jobs.Type) error + RegisterProducer(producerId string, producerInfo *ProducerRegistrationInfo) } type RegistratorImpl struct { @@ -46,13 +49,25 @@ func NewRegistratorImpl(infoCoordAddr string) *RegistratorImpl { } } -func (r RegistratorImpl) RegisterTypes(jobTypes []*jobtypes.Type) error { +func (r RegistratorImpl) RegisterTypes(jobTypes []*jobs.Type) error { for _, jobType := range jobTypes { body := fmt.Sprintf(`{"info_job_data_schema": %v}`, jobType.Schema) - if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.Name), []byte(body)); error != nil { + if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.TypeId), []byte(body)); error != nil { return error } log.Debugf("Registered type: %v", jobType) } return nil } + +func (r RegistratorImpl) RegisterProducer(producerId string, producerInfo *ProducerRegistrationInfo) error { + if body, marshalErr := json.Marshal(producerInfo); marshalErr == nil { + if putErr := restclient.Put(r.infoCoordinatorAddress+registerProducerPath+url.PathEscape(producerId), []byte(body)); putErr != nil { + return putErr + } + log.Debugf("Registered producer: %v", producerId) + return nil + } else { + return marshalErr + } +}