From: ychacon Date: Fri, 11 Mar 2022 12:49:44 +0000 (+0100) Subject: Adding needed docker files X-Git-Tag: 1.1.0~6 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=nonrtric%2Frapp%2Fransliceassurance.git;a=commitdiff_plain;h=361894d226e2e8946a1e57bba2125a14ce84c009 Adding needed docker files Issue-ID: NONRTRIC-732 Signed-off-by: ychacon Change-Id: I09df58bd8d83e122c32d6dd2b663007f43f86bda --- diff --git a/icsversion/Dockerfile b/icsversion/Dockerfile new file mode 100644 index 0000000..a1be5c2 --- /dev/null +++ b/icsversion/Dockerfile @@ -0,0 +1,44 @@ +#================================================================================== +# Copyright (C) 2022: Nordix Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#================================================================================== +## +## Build +## +FROM nexus3.o-ran-sc.org:10001/golang:1.17-bullseye AS build + +WORKDIR /app + +COPY go.mod ./ +COPY go.sum ./ +RUN go mod download + +COPY . ./ + +RUN go build -o /rappconsumer-sliceassurance + +## +## Deploy +## +FROM gcr.io/distroless/base-debian10 + +WORKDIR / + +## Copy from "build" stage +COPY --from=build /rappconsumer-sliceassurance . + +USER nonroot:nonroot + +ENTRYPOINT ["/rappconsumer-sliceassurance"] \ No newline at end of file diff --git a/icsversion/Dockerfile-ProdSdnc b/icsversion/Dockerfile-ProdSdnc new file mode 100644 index 0000000..0f4fc52 --- /dev/null +++ b/icsversion/Dockerfile-ProdSdnc @@ -0,0 +1,41 @@ +# Copyright (C) 2022 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +## +## Build +## +FROM golang:1.17.1-bullseye AS build + +WORKDIR /app + +COPY . ./ + +RUN go build -o /prod-sdnr-sim ./stub/prodSdnc + +## +## Deploy +## +FROM gcr.io/distroless/base-debian10 + +WORKDIR / + +## Copy from "build" stage +COPY --from=build /prod-sdnr-sim . +COPY --from=build /app/stub/prodSdnc/test-data.csv . + +USER nonroot:nonroot + +ENTRYPOINT ["/prod-sdnr-sim"] diff --git a/icsversion/Dockerfile-ics b/icsversion/Dockerfile-ics new file mode 100644 index 0000000..9c299f1 --- /dev/null +++ b/icsversion/Dockerfile-ics @@ -0,0 +1,40 @@ +# Copyright (C) 2022 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +## +## Build +## +FROM golang:1.17.1-bullseye AS build + +WORKDIR /app + +COPY . ./ + +RUN go build -o /ics ./stub/ics/ + +## +## Deploy +## +FROM gcr.io/distroless/base-debian10 + +WORKDIR / + +## Copy from "build" stage +COPY --from=build /ics . + +USER nonroot:nonroot + +ENTRYPOINT ["/ics"] diff --git a/icsversion/docker-compose.yaml b/icsversion/docker-compose.yaml new file mode 100644 index 0000000..e0ff69c --- /dev/null +++ b/icsversion/docker-compose.yaml @@ -0,0 +1,71 @@ +# Copyright (C) 2022 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# +version: '3.5' + +networks: + default: + driver: bridge + name: nonrtric-docker-net + +services: + ics: + build: + context: . + dockerfile: Dockerfile-ics + container_name: ics-sim + networks: + default: + aliases: + - ics-sim + ports: + - 8083:8083 + environment: + - PRODUCER_ADDR=http://prod-sdnr-sim:3905/ + + prod-sdnr-sim: + build: + context: . + dockerfile: Dockerfile-ProdSdnc + container_name: prod-sdnr-sim + networks: + default: + aliases: + - prod-sdnr-sim + ports: + - 3904:3904 + - 3905:3905 + environment: + - ODU_ADDR=http://consumer-sa:8095 + + consumer-sa: + build: + context: . + dockerfile: Dockerfile + container_name: consumer-sa + networks: + default: + aliases: + - consumer-sa + ports: + - 8095:8095 + environment: + - SDNR_USER=admin + - SDNR_PASSWORD=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + - CONSUMER_HOST=http://consumer-sa + - CONSUMER_PORT=8095 + - INFO_COORD_ADDR=http://ics-sim:8083 + - SDNR_ADDR=http://prod-sdnr-sim:3904 + - LOG_LEVEL=Debug \ No newline at end of file diff --git a/icsversion/go.mod b/icsversion/go.mod index 38d2c48..7b1dee0 100644 --- a/icsversion/go.mod +++ b/icsversion/go.mod @@ -5,6 +5,11 @@ go 1.17 require ( github.com/gorilla/mux v1.8.0 github.com/sirupsen/logrus v1.8.1 + github.com/stretchr/testify v1.2.2 ) -require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect +) diff --git a/icsversion/internal/odusliceassurance/app.go b/icsversion/internal/odusliceassurance/app.go index d313192..0504a13 100644 --- a/icsversion/internal/odusliceassurance/app.go +++ b/icsversion/internal/odusliceassurance/app.go @@ -43,6 +43,18 @@ const ( jobId = "14e7bb84-a44d-44c1-90b7-6995a92ad83d" ) +var jobRegistrationInfo = struct { + InfoTypeID string `json:"info_type_id"` + JobResultURI string `json:"job_result_uri"` + JobOwner string `json:"job_owner"` + JobDefinition interface{} `json:"job_definition"` +}{ + InfoTypeID: "Performance_Measurement_Streaming", + JobResultURI: "", + JobOwner: "O-DU Slice Assurance Usecase", + JobDefinition: "{}", +} + type App struct { client *restclient.Client data *structures.SliceAssuranceMeas @@ -54,6 +66,7 @@ var sdnrConfig SdnrConfiguration func (a *App) Initialize(config *config.Configuration) { consumerPort = fmt.Sprint(config.ConsumerPort) + jobRegistrationInfo.JobResultURI = config.ConsumerHost + ":" + consumerPort sdnrConfig = SdnrConfiguration{ SDNRAddress: config.SDNRAddress, @@ -112,17 +125,7 @@ func (a *App) statusHandler(w http.ResponseWriter, r *http.Request) { func (a *App) startHandler(w http.ResponseWriter, r *http.Request) { log.Debug("startHandler: Register job in ICS.") - jobRegistrationInfo := struct { - InfoTypeID string `json:"info_type_id"` - JobResultURI string `json:"job_result_uri"` - JobOwner string `json:"job_owner"` - JobDefinition interface{} `json:"job_definition"` - }{ - InfoTypeID: "Performance_Measurement_Streaming", - JobResultURI: "", - JobOwner: "O-DU Slice Assurance Usecase", - JobDefinition: "{}", - } + putErr := a.client.Put(icsAddr+"/data-consumer/v1/info-jobs/"+jobId, jobRegistrationInfo, nil) if putErr != nil { http.Error(w, fmt.Sprintf("Unable to register consumer job due to: %v.", putErr), http.StatusBadRequest) diff --git a/icsversion/main.go b/icsversion/main.go index b9e9afc..bddac04 100644 --- a/icsversion/main.go +++ b/icsversion/main.go @@ -34,8 +34,6 @@ import ( var configuration *config.Configuration var a sliceassurance.App -const TOPIC string = "/events/unauthenticated.VES_O_RAN_SC_HELLO_WORLD_PM_STREAMING_OUTPUT/myG/C1" - func main() { configuration = config.New() diff --git a/icsversion/stub/ics/icsStub.go b/icsversion/stub/ics/icsStub.go index 71f33b6..7cd78b5 100644 --- a/icsversion/stub/ics/icsStub.go +++ b/icsversion/stub/ics/icsStub.go @@ -53,7 +53,7 @@ func getEnv(key string, defaultVal string) string { } func handleCalls(w http.ResponseWriter, r *http.Request) { - producer_addr := getEnv("PRODUCER_ADDR", "http://localhost:3905/") + producer_addr := getEnv("PRODUCER_ADDR", "http://prod-sdnr-sim:3905/") vars := mux.Vars(r) id, ok := vars["jobId"] if ok { diff --git a/icsversion/stub/DmaapSdnc/dmaapSdncStub.go b/icsversion/stub/prodSdnc/prodSdncStub.go similarity index 96% rename from icsversion/stub/DmaapSdnc/dmaapSdncStub.go rename to icsversion/stub/prodSdnc/prodSdncStub.go index 3f7ea64..15fb9c3 100644 --- a/icsversion/stub/DmaapSdnc/dmaapSdncStub.go +++ b/icsversion/stub/prodSdnc/prodSdncStub.go @@ -107,7 +107,7 @@ func main() { rand.Seed(time.Now().UnixNano()) portSdnr := flag.Int("sdnr-port", 3904, "The port this SDNR stub will listen on") - dmaapProducerPort := flag.Int("dmaap-port", 3905, "The port this Dmaap mediator will listen on") + producerPort := flag.Int("prod-port", 3905, "The port this Producer mediator will listen on") flag.Parse() loadData() @@ -133,9 +133,9 @@ func main() { r.HandleFunc("/create/{jobId}", createJobHandler).Methods(http.MethodPut) r.HandleFunc("/delete/{jobId}", deleteJobHandler).Methods(http.MethodDelete) - fmt.Println("Producer listening on port: ", *dmaapProducerPort) + fmt.Println("Producer listening on port: ", *producerPort) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *dmaapProducerPort), r)) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *producerPort), r)) wg.Done() }() @@ -143,7 +143,6 @@ func main() { } func createJobHandler(w http.ResponseWriter, r *http.Request) { - fmt.Println("createJobHandler:: ", r) vars := mux.Vars(r) id, ok := vars["jobId"] if !ok { @@ -341,8 +340,8 @@ func sendDmaapMessages() { time.Sleep(time.Duration(rand.Intn(3)) * time.Second) - oru_addr := getEnv("ORU_ADDR", "http://localhost:8095") - req, _ := http.NewRequest(http.MethodPost, oru_addr, bytes.NewBuffer(msgToSend)) + odu_addr := getEnv("ODU_ADDR", "http://consumer-sa:8095") + req, _ := http.NewRequest(http.MethodPost, odu_addr, bytes.NewBuffer(msgToSend)) req.Header.Set("Content-Type", "application/json; charset=utf-8") _, err := client.Do(req) diff --git a/icsversion/stub/DmaapSdnc/test-data.csv b/icsversion/stub/prodSdnc/test-data.csv similarity index 100% rename from icsversion/stub/DmaapSdnc/test-data.csv rename to icsversion/stub/prodSdnc/test-data.csv