Adding needed docker files 24/7924/1
authorychacon <yennifer.chacon@est.tech>
Fri, 11 Mar 2022 12:49:44 +0000 (13:49 +0100)
committerychacon <yennifer.chacon@est.tech>
Fri, 11 Mar 2022 12:49:44 +0000 (13:49 +0100)
Issue-ID: NONRTRIC-732
Signed-off-by: ychacon <yennifer.chacon@est.tech>
Change-Id: I09df58bd8d83e122c32d6dd2b663007f43f86bda

icsversion/Dockerfile [new file with mode: 0644]
icsversion/Dockerfile-ProdSdnc [new file with mode: 0644]
icsversion/Dockerfile-ics [new file with mode: 0644]
icsversion/docker-compose.yaml [new file with mode: 0644]
icsversion/go.mod
icsversion/internal/odusliceassurance/app.go
icsversion/main.go
icsversion/stub/ics/icsStub.go
icsversion/stub/prodSdnc/prodSdncStub.go [moved from icsversion/stub/DmaapSdnc/dmaapSdncStub.go with 96% similarity]
icsversion/stub/prodSdnc/test-data.csv [moved from icsversion/stub/DmaapSdnc/test-data.csv with 100% similarity]

diff --git a/icsversion/Dockerfile b/icsversion/Dockerfile
new file mode 100644 (file)
index 0000000..a1be5c2
--- /dev/null
@@ -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 (file)
index 0000000..0f4fc52
--- /dev/null
@@ -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 (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/icsversion/docker-compose.yaml b/icsversion/docker-compose.yaml
new file mode 100644 (file)
index 0000000..e0ff69c
--- /dev/null
@@ -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
index 38d2c48..7b1dee0 100644 (file)
@@ -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
+)
index d313192..0504a13 100644 (file)
@@ -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)
index b9e9afc..bddac04 100644 (file)
@@ -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()
 
index 71f33b6..7cd78b5 100644 (file)
@@ -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 {
similarity index 96%
rename from icsversion/stub/DmaapSdnc/dmaapSdncStub.go
rename to icsversion/stub/prodSdnc/prodSdncStub.go
index 3f7ea64..15fb9c3 100644 (file)
@@ -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)