Merge "Minor bugs fix in ORU-app simulator" into e-release e-release
authorHenrik Andersson <henrik.b.andersson@est.tech>
Tue, 15 Feb 2022 08:35:06 +0000 (08:35 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Tue, 15 Feb 2022 08:35:06 +0000 (08:35 +0000)
test/usecases/oruclosedlooprecovery/goversion/Dockerfile
test/usecases/oruclosedlooprecovery/goversion/Dockerfile-ics [new file with mode: 0644]
test/usecases/oruclosedlooprecovery/goversion/Dockerfile-producer [new file with mode: 0644]
test/usecases/oruclosedlooprecovery/goversion/Dockerfile-sdnr [new file with mode: 0644]
test/usecases/oruclosedlooprecovery/goversion/README.md
test/usecases/oruclosedlooprecovery/goversion/docker-compose.yaml [new file with mode: 0644]
test/usecases/oruclosedlooprecovery/goversion/stub/ics/ics.go
test/usecases/oruclosedlooprecovery/goversion/stub/producer/producerstub.go

index 2462c44..97beddd 100644 (file)
@@ -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 (file)
index 0000000..9c299f1
--- /dev/null
@@ -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 (file)
index 0000000..8693bbb
--- /dev/null
@@ -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 (file)
index 0000000..49cb444
--- /dev/null
@@ -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"]
index 06c44b2..15c5336 100644 (file)
@@ -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 (file)
index 0000000..ef5340b
--- /dev/null
@@ -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
index 83170e0..ee979fd 100644 (file)
@@ -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)
index e219e19..7994714 100644 (file)
@@ -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)