Fix registration of types for DMaaP Mediator
Issue-ID: NONRTRIC-702
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Iee9ac0cf831e216639f77d0a08aa0b7d54091aa5
diff --git a/dmaap-mediator-producer/Dockerfile b/dmaap-mediator-producer/Dockerfile
index 1c7f45c..6d9b2b8 100644
--- a/dmaap-mediator-producer/Dockerfile
+++ b/dmaap-mediator-producer/Dockerfile
@@ -30,7 +30,7 @@
##
## Deploy
##
-FROM gcr.io/distroless/base-debian10
+FROM gcr.io/distroless/base-debian11
WORKDIR /
## Copy from "build" stage
COPY --from=build /dmaapmediatorproducer .
diff --git a/dmaap-mediator-producer/internal/config/registrator.go b/dmaap-mediator-producer/internal/config/registrator.go
index bac14e6..1dd0ad1 100644
--- a/dmaap-mediator-producer/internal/config/registrator.go
+++ b/dmaap-mediator-producer/internal/config/registrator.go
@@ -73,7 +73,8 @@
func (r RegistratorImpl) RegisterTypes(jobTypes []TypeDefinition) error {
for _, jobType := range jobTypes {
- body := fmt.Sprintf(`{"info_job_data_schema": %v}`, jobType.TypeSchema)
+ s, _ := json.Marshal(jobType.TypeSchema)
+ body := fmt.Sprintf(`{"info_job_data_schema": %v}`, string(s))
if error := restclient.Put(r.infoCoordinatorAddress+registerTypePath+url.PathEscape(jobType.Identity), []byte(body), r.httpClient); error != nil {
return error
}
diff --git a/dmaap-mediator-producer/internal/config/registrator_test.go b/dmaap-mediator-producer/internal/config/registrator_test.go
index d1b61d8..b2f10cc 100644
--- a/dmaap-mediator-producer/internal/config/registrator_test.go
+++ b/dmaap-mediator-producer/internal/config/registrator_test.go
@@ -21,6 +21,7 @@
package config
import (
+ "encoding/json"
"io/ioutil"
"net/http"
"testing"
@@ -39,9 +40,17 @@
StatusCode: http.StatusCreated,
}, nil)
+ schemaString := `{
+ "type": "object",
+ "properties": {},
+ "additionalProperties": false
+ }`
+ var schemaObj interface{}
+ json.Unmarshal([]byte(schemaString), &schemaObj)
+
type1 := TypeDefinition{
Identity: "Type1",
- TypeSchema: `{"type": "object","properties": {},"additionalProperties": false}`,
+ TypeSchema: schemaObj,
}
types := []TypeDefinition{type1}
@@ -60,7 +69,7 @@
assertions.Equal("/data-producer/v1/info-types/Type1", actualRequest.URL.Path)
assertions.Equal("application/json", actualRequest.Header.Get("Content-Type"))
body, _ := ioutil.ReadAll(actualRequest.Body)
- expectedBody := []byte(`{"info_job_data_schema": {"type": "object","properties": {},"additionalProperties": false}}`)
+ expectedBody := []byte(`{"info_job_data_schema": {"additionalProperties":false,"properties":{},"type":"object"}}`)
assertions.Equal(expectedBody, body)
clientMock.AssertNumberOfCalls(t, "Do", 1)
}
diff --git a/dmaap-mediator-producer/stub/ics/ics.go b/dmaap-mediator-producer/stub/ics/ics.go
index 0818d5e..87457c2 100644
--- a/dmaap-mediator-producer/stub/ics/ics.go
+++ b/dmaap-mediator-producer/stub/ics/ics.go
@@ -23,6 +23,7 @@
import (
"flag"
"fmt"
+ "io/ioutil"
"net/http"
"github.com/gorilla/mux"
@@ -43,7 +44,7 @@
vars := mux.Vars(r)
id, ok := vars["typeId"]
if ok {
- fmt.Println("Registered type ", id)
+ fmt.Printf("Registered type %v with schema: %v\n", id, readBody(r))
}
}
@@ -51,6 +52,14 @@
vars := mux.Vars(r)
id, ok := vars["producerId"]
if ok {
- fmt.Println("Registered producer ", id)
+ fmt.Printf("Registered producer %v with data: %v\n", id, readBody(r))
}
}
+
+func readBody(r *http.Request) string {
+ b, readErr := ioutil.ReadAll(r.Body)
+ if readErr != nil {
+ return fmt.Sprintf("Unable to read body due to: %v", readErr)
+ }
+ return string(b)
+}