X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fregistrator.go;h=83ed43f2c375c45a7724a385dcbe5a7fd8212ece;hb=65a53d2388547247222d144b365401056bbdffc5;hp=db46c54452a41bfad9cb2e69edc7254330cf17f3;hpb=47d0ee37691eddc290a1f9e34091dfd2020db07f;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/registrator.go b/dmaap-mediator-producer/internal/config/registrator.go index db46c544..83ed43f2 100644 --- a/dmaap-mediator-producer/internal/config/registrator.go +++ b/dmaap-mediator-producer/internal/config/registrator.go @@ -27,7 +27,6 @@ import ( log "github.com/sirupsen/logrus" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs" "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient" ) @@ -35,25 +34,38 @@ const registerTypePath = "/data-producer/v1/info-types/" const registerProducerPath = "/data-producer/v1/info-producers/" const typeSchema = `{"type": "object","properties": {},"additionalProperties": false}` +type TypeDefinition struct { + Id string `json:"id"` + DmaapTopicURL string `json:"dmaapTopicUrl"` +} + +type ProducerRegistrationInfo struct { + InfoProducerSupervisionCallbackUrl string `json:"info_producer_supervision_callback_url"` + SupportedInfoTypes []string `json:"supported_info_types"` + InfoJobCallbackUrl string `json:"info_job_callback_url"` +} + type Registrator interface { - RegisterTypes(types []*jobs.TypeData) error + RegisterTypes(types []TypeDefinition) error RegisterProducer(producerId string, producerInfo *ProducerRegistrationInfo) } type RegistratorImpl struct { infoCoordinatorAddress string + httpClient restclient.HTTPClient } -func NewRegistratorImpl(infoCoordAddr string) *RegistratorImpl { +func NewRegistratorImpl(infoCoordAddr string, client restclient.HTTPClient) *RegistratorImpl { return &RegistratorImpl{ infoCoordinatorAddress: infoCoordAddr, + httpClient: client, } } -func (r RegistratorImpl) RegisterTypes(jobTypes []jobs.TypeData) error { +func (r RegistratorImpl) RegisterTypes(jobTypes []TypeDefinition) error { for _, jobType := range jobTypes { body := fmt.Sprintf(`{"info_job_data_schema": %v}`, typeSchema) - if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.TypeId), []byte(body)); error != nil { + if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.Id), []byte(body), r.httpClient); error != nil { return error } log.Debugf("Registered type: %v", jobType) @@ -63,7 +75,7 @@ func (r RegistratorImpl) RegisterTypes(jobTypes []jobs.TypeData) error { 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 { + if putErr := restclient.Put(r.infoCoordinatorAddress+registerProducerPath+url.PathEscape(producerId), []byte(body), r.httpClient); putErr != nil { return putErr } log.Debugf("Registered producer: %v", producerId)