From 3b2f07a98d1d5e2f83aaf05fede3f07379d48b88 Mon Sep 17 00:00:00 2001 From: ecaiyanlinux Date: Mon, 14 Feb 2022 13:57:49 +0100 Subject: [PATCH] Minor bugs fix in ORU-app simulator Add docker-compose file for oru-app Signed-off-by: ecaiyanlinux Change-Id: Ifead8b18fe103ef64cba4e4d0370880802c2b11d Issue-ID: NONRTRIC-727 --- .../oruclosedlooprecovery/goversion/Dockerfile | 2 +- .../oruclosedlooprecovery/goversion/Dockerfile-ics | 40 +++++++++++ .../goversion/Dockerfile-producer | 40 +++++++++++ .../goversion/Dockerfile-sdnr | 40 +++++++++++ .../oruclosedlooprecovery/goversion/README.md | 2 +- .../goversion/docker-compose.yaml | 82 ++++++++++++++++++++++ .../goversion/stub/ics/ics.go | 14 +++- .../goversion/stub/producer/producerstub.go | 12 +++- 8 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 test/usecases/oruclosedlooprecovery/goversion/Dockerfile-ics create mode 100644 test/usecases/oruclosedlooprecovery/goversion/Dockerfile-producer create mode 100644 test/usecases/oruclosedlooprecovery/goversion/Dockerfile-sdnr create mode 100644 test/usecases/oruclosedlooprecovery/goversion/docker-compose.yaml diff --git a/test/usecases/oruclosedlooprecovery/goversion/Dockerfile b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile index 2462c442..97bedddf 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/Dockerfile +++ b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile @@ -22,7 +22,7 @@ WORKDIR / ## Copy from "build" stage COPY --from=build /docker-oruclosedloop . - +COPY --from=build /app/security/ ./security/ COPY --from=build /app/o-ru-to-o-du-map.csv . USER nonroot:nonroot diff --git a/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-ics b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-ics new file mode 100644 index 00000000..9c299f1a --- /dev/null +++ b/test/usecases/oruclosedlooprecovery/goversion/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/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-producer b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-producer new file mode 100644 index 00000000..8693bbb8 --- /dev/null +++ b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-producer @@ -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 /producer ./stub/producer/ + +## +## Deploy +## +FROM gcr.io/distroless/base-debian10 + +WORKDIR / + +## Copy from "build" stage +COPY --from=build /producer . + +USER nonroot:nonroot + +ENTRYPOINT ["/producer"] diff --git a/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-sdnr b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-sdnr new file mode 100644 index 00000000..49cb4445 --- /dev/null +++ b/test/usecases/oruclosedlooprecovery/goversion/Dockerfile-sdnr @@ -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 /sdnrstub ./stub/sdnr/ + +## +## Deploy +## +FROM gcr.io/distroless/base-debian10 + +WORKDIR / + +## Copy from "build" stage +COPY --from=build /sdnrstub . + +USER nonroot:nonroot + +ENTRYPOINT ["/sdnrstub"] diff --git a/test/usecases/oruclosedlooprecovery/goversion/README.md b/test/usecases/oruclosedlooprecovery/goversion/README.md index 06c44b29..15c53364 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/README.md +++ b/test/usecases/oruclosedlooprecovery/goversion/README.md @@ -11,7 +11,7 @@ The consumer takes a number of environment variables, described below, as config >- CONSUMER_CERT_PATH **Required**. The path to the certificate to use for https. Defaults to `security/producer.crt` >- CONSUMER_KEY_PATH **Required**. The path to the key to the certificate to use for https. Defaults to `security/producer.key` >- INFO_COORD_ADDR Optional. The address of the Information Coordinator. Defaults to `http://enrichmentservice:8083`. ->- SDNR_ADDRESS Optional. The address for SDNR. Defaults to `http://localhost:3904`. +>- SDNR_ADDR Optional. The address for SDNR. Defaults to `http://localhost:3904`. >- SDNR_USER Optional. The user for the SDNR. Defaults to `admin`. >- SDNR_PASSWORD Optional. The password for the SDNR user. Defaults to `Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U`. >- ORU_TO_ODU_MAP_FILE Optional. The file containing the mapping from O-RU ID to O-DU ID. Defaults to `o-ru-to-o-du-map.csv`. diff --git a/test/usecases/oruclosedlooprecovery/goversion/docker-compose.yaml b/test/usecases/oruclosedlooprecovery/goversion/docker-compose.yaml new file mode 100644 index 00000000..ef5340b7 --- /dev/null +++ b/test/usecases/oruclosedlooprecovery/goversion/docker-compose.yaml @@ -0,0 +1,82 @@ +# 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://producer-sim:8085/ + + sdnr-simulator: + build: + context: . + dockerfile: Dockerfile-sdnr + container_name: sdnr-sim + networks: + default: + aliases: + - sdnr-sim + ports: + - 3904:3904 + + producer: + build: + context: . + dockerfile: Dockerfile-producer + container_name: producer-sim + networks: + default: + aliases: + - producer-sim + ports: + - 8085:8085 + environment: + - ORU_ADDR=http://oru-app:8086 + + oru-app: + build: + context: . + dockerfile: Dockerfile + container_name: oru-app + networks: + default: + aliases: + - oru-app + ports: + - 8086:8086 + environment: + - CONSUMER_HOST=http://producer-sim + - CONSUMER_PORT=8086 + - INFO_COORD_ADDR=http://ics-sim:8083 + - SDNR_ADDR=http://sdnr-sim:3904 + - CONSUMER_CERT_PATH=security/consumer.crt + - CONSUMER_KEY_PATH=security/consumer.key + - LOG_LEVEL=Debug \ No newline at end of file diff --git a/test/usecases/oruclosedlooprecovery/goversion/stub/ics/ics.go b/test/usecases/oruclosedlooprecovery/goversion/stub/ics/ics.go index 83170e0e..ee979fd1 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/stub/ics/ics.go +++ b/test/usecases/oruclosedlooprecovery/goversion/stub/ics/ics.go @@ -24,6 +24,7 @@ import ( "flag" "fmt" "net/http" + "os" "time" "github.com/gorilla/mux" @@ -43,13 +44,22 @@ func main() { fmt.Println(http.ListenAndServe(fmt.Sprintf(":%v", *port), r)) } +func getEnv(key string, defaultVal string) string { + if value, exists := os.LookupEnv(key); exists { + return value + } + + return defaultVal +} + func handleCalls(w http.ResponseWriter, r *http.Request) { + producer_addr := getEnv("PRODUCER_ADDR", "http://producer-sim:8085/") vars := mux.Vars(r) id, ok := vars["jobId"] if ok { fmt.Println(r.Method, " of job ", id) if r.Method == http.MethodPut { - req, _ := http.NewRequest(http.MethodPut, "http://localhost:8085/create/"+id, nil) + req, _ := http.NewRequest(http.MethodPut, producer_addr+"create/"+id, nil) r, err := client.Do(req) if err != nil { fmt.Println("Failed to create job in producer ", err) @@ -57,7 +67,7 @@ func handleCalls(w http.ResponseWriter, r *http.Request) { } fmt.Println("Created job in producer ", r.Status) } else { - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8085/delete/"+id, nil) + req, _ := http.NewRequest(http.MethodDelete, producer_addr+"delete/"+id, nil) r, err := client.Do(req) if err != nil { fmt.Println("Failed to delete job in producer ", err) diff --git a/test/usecases/oruclosedlooprecovery/goversion/stub/producer/producerstub.go b/test/usecases/oruclosedlooprecovery/goversion/stub/producer/producerstub.go index e219e19d..79947142 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/stub/producer/producerstub.go +++ b/test/usecases/oruclosedlooprecovery/goversion/stub/producer/producerstub.go @@ -25,6 +25,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "time" "github.com/gorilla/mux" @@ -67,6 +68,14 @@ func deleteJobHandler(w http.ResponseWriter, r *http.Request) { started = false } +func getEnv(key string, defaultVal string) string { + if value, exists := os.LookupEnv(key); exists { + return value + } + + return defaultVal +} + func startPushingMessages() { message := ves.FaultMessage{ Event: ves.Event{ @@ -99,7 +108,8 @@ func startPushingMessages() { m, _ := json.Marshal(message) msgToSend, _ := json.Marshal([]string{string(m)}) - req, _ := http.NewRequest(http.MethodPost, "http://localhost:40935", bytes.NewBuffer(msgToSend)) + oru_addr := getEnv("ORU_ADDR", "http://oru-app:8086") + req, _ := http.NewRequest(http.MethodPost, oru_addr, bytes.NewBuffer(msgToSend)) req.Header.Set("Content-Type", "application/json; charset=utf-8") r, err := client.Do(req) -- 2.16.6