X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fregistrator.go;h=bac14e6341fc2ace7bd0733cebdedc431f7af86d;hb=6f5d3d1eccb8a1857c645ba6bd0b5e1b89ca7088;hp=eaf8752f1048718323a438c335331d35f6e4e9d7;hpb=a77cd650f99b29be6c53a690157529e7e158d70e;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/registrator.go b/dmaap-mediator-producer/internal/config/registrator.go index eaf8752f..bac14e63 100644 --- a/dmaap-mediator-producer/internal/config/registrator.go +++ b/dmaap-mediator-producer/internal/config/registrator.go @@ -27,32 +27,54 @@ import ( log "github.com/sirupsen/logrus" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobtypes" "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient" ) const registerTypePath = "/data-producer/v1/info-types/" const registerProducerPath = "/data-producer/v1/info-producers/" +type TypeDefinition struct { + Identity string `json:"id"` + DMaaPTopicURL string `json:"dmaapTopicUrl"` + KafkaInputTopic string `json:"kafkaInputTopic"` + TypeSchema interface{} +} + +func (td TypeDefinition) IsKafkaType() bool { + return td.KafkaInputTopic != "" +} + +func (td TypeDefinition) IsDMaaPType() bool { + return td.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 []*jobtypes.Type) 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 []*jobtypes.Type) error { +func (r RegistratorImpl) RegisterTypes(jobTypes []TypeDefinition) 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.TypeId), []byte(body)); error != nil { + body := fmt.Sprintf(`{"info_job_data_schema": %v}`, jobType.TypeSchema) + if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.Identity), []byte(body), r.httpClient); error != nil { return error } log.Debugf("Registered type: %v", jobType) @@ -62,7 +84,7 @@ func (r RegistratorImpl) RegisterTypes(jobTypes []*jobtypes.Type) 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)