Parse message names from xApp configMap 87/187/2
authorAbukar Mohamed <abukar.mohamed@nokia.com>
Wed, 22 May 2019 14:48:10 +0000 (14:48 +0000)
committerAbukar Mohamed <abukar.mohamed@nokia.com>
Thu, 23 May 2019 07:20:55 +0000 (07:20 +0000)
Change-Id: I6567dac57a92179385baf95e8b0f2cd33f45d71e
Signed-off-by: Abukar Mohamed <abukar.mohamed@nokia.com>
12 files changed:
Dockerfile
Makefile
api/appmgr_rest_api.json
api/appmgr_rest_api.yaml
build/make.docker.mk
build/make.go.mk
cmd/appmgr/desc.go
cmd/appmgr/desc_test.go
cmd/appmgr/helm.go
cmd/appmgr/types.go
go.mod
go.sum

index b2b314b..fcf2abd 100755 (executable)
@@ -16,7 +16,7 @@
 #----------------------------------------------------------
 #
 #----------------------------------------------------------
-FROM ubuntu:16.04 as xapp-base
+FROM ubuntu:16.04 as appmgr-xapp-base
 
 RUN apt-get update -y && \
     apt-get install -y wget
@@ -59,14 +59,14 @@ ENV PATH="/usr/local/go/bin:${PATH}"
 # rancodev libs
 #
 RUN mkdir -p /opt/build \
+    && cd /opt/build && git clone https://gerrit.oran-osc.org/r/ric-plt/lib/rmr \
+    && cd rmr/; mkdir build; cd build; cmake ..; make install \
     && cd /opt/build && git clone https://gerrit.oran-osc.org/r/com/log \
     && cd log/ ; ./autogen.sh ; ./configure ; make ; make install \
     && ldconfig
 
-COPY build/build_entrypoint.sh /
 COPY build/user_entrypoint.sh /
 
-RUN chmod +x /build_entrypoint.sh
 RUN chmod +x /user_entrypoint.sh
 
 RUN mkdir -p /ws
@@ -77,12 +77,9 @@ CMD ["/bin/bash"]
 #----------------------------------------------------------
 #
 #----------------------------------------------------------
-FROM xapp-base as appmgr-build
+FROM appmgr-xapp-base as appmgr-build
 
 ARG PACKAGEURL
-ARG PACKAGEREPO
-ARG SSH_PRIVATE_KEY
-ARG NETRC_CONFIG
 ARG HELMVERSION
 
 
@@ -105,13 +102,12 @@ ENV GOPATH="/go"
 # Module prepare (if go.mod/go.sum updated)
 COPY go.mod /go/src/${PACKAGEURL}
 COPY go.sum /go/src/${PACKAGEURL}
-RUN GO111MODULE=on /build_entrypoint.sh go mod download
+RUN GO111MODULE=on go mod download
 
 # build
 COPY . /go/src/${PACKAGEURL}
-RUN /build_entrypoint.sh make -C /go/src/${PACKAGEURL} build
+RUN make -C /go/src/${PACKAGEURL} build
 
-ENTRYPOINT ["/build_entrypoint.sh"]
 CMD ["/bin/bash"]
 
 
@@ -168,7 +164,7 @@ RUN ldconfig
 RUN mkdir -p /opt/xAppManager \
     && chmod -R 755 /opt/xAppManager
 
-COPY --from=appmgr-build /go/src/${PACKAGEURL}/build/cache/cmd/appmgr /opt/xAppManager/appmgr
+COPY --from=appmgr-build /go/src/${PACKAGEURL}/cache/go/cmd/appmgr /opt/xAppManager/appmgr
 #COPY --from=appmgr-build /go/src/${PACKAGEURL}/config/appmgr.yaml /opt/etc/xAppManager/config-file.yaml
 
 
index 51f53bb..9c29f50 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,19 +24,21 @@ test: go-test
 
 #------------------------------------------------------------------------------
 #
-# Build and test targets
-#
 #------------------------------------------------------------------------------
 ROOT_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
-BUILD_DIR:=$(abspath $(ROOT_DIR)/build)
+CACHE_DIR?=$(abspath $(ROOT_DIR)/cache)
 
+#------------------------------------------------------------------------------
+#
+# Build and test targets
+#
+#------------------------------------------------------------------------------
 
 XAPP_NAME:=appmgr
 XAPP_ROOT:=cmd
 XAPP_TESTENV:="RMR_SEED_RT=config/uta_rtg.rt CFG_FILE=$(ROOT_DIR)helm_chart/uemgr/descriptors/config-file.json"
 include build/make.go.mk 
 
-
 #------------------------------------------------------------------------------
 #
 # DOCKER TARGETS
@@ -48,6 +50,9 @@ DCKR_B_OPTS:=${DCKR_B_OPTS} --build-arg HELMVERSION=${HELMVERSION}
 
 PACKAGEURL:="gerrit.oran-osc.org/r/ric-plt/appmgr"
 
+DCKR_NAME:=appmgr-xapp-base
+include build/make.docker.mk
+
 DCKR_NAME:=appmgr-test_unit
 include build/make.docker.mk
 
@@ -61,5 +66,5 @@ DCKR_NAME:=appmgr
 include build/make.docker.mk
 
 
-docker-test: docker-run_appmgr-test_fmt docker-run_appmgr-test_sanity docker-run-redished_appmgr-test_unit
+docker-test: docker-run-stop_appmgr-test_fmt docker-run-stop_appmgr-test_sanity docker-run-stop_appmgr-test_unit
 
index 92cc418..07390b0 100644 (file)
@@ -2,7 +2,7 @@
   "swagger": "2.0",
   "info": {
     "description": "This is a draft API for RIC appmgr",
-    "version": "0.1.2",
+    "version": "0.1.3",
     "title": "RIC appmgr",
     "license": {
       "name": "Apache 2.0",
     "http"
   ],
   "paths": {
-    "/health": {
+    "/health/alive": {
       "get": {
-        "summary": "Health check of xApp Manager",
+        "summary": "Health check of xApp Manager - Liveness probe",
         "tags": [
           "health"
         ],
-        "operationId": "getHealth",
+        "operationId": "getHealthAlive",
         "responses": {
           "200": {
             "description": "Status of xApp Manager is ok"
         }
       }
     },
+    "/health/ready": {
+      "get": {
+        "summary": "Readiness check of xApp Manager - Readiness probe",
+        "tags": [
+          "health"
+        ],
+        "operationId": "getHealthReady",
+        "responses": {
+          "200": {
+            "description": "xApp Manager is ready for service"
+          },
+          "503": {
+            "description": "xApp Manager is not ready for service"
+          }
+        }
+      }
+    },
     "/xapps": {
       "post": {
         "summary": "Deploy a xapp",
             "schema": {
               "type": "object",
               "required": [
-                "xAppName"
+                "name"
               ],
               "properties": {
-                "xAppName": {
-                  "type":"string",
-                  "description":"Name of the xApp",
+                "name": {
+                  "type": "string",
+                  "description": "Name of the xApp.",
+                  "example": "xapp-dummy"
+                },
+                "configName": {
+                  "type": "string",
+                  "description": "Name of the xApp configmap. Overrides the value given in Helm chart value file.",
+                  "example": "xapp-dummy-configmap"
+                },
+                "namespace": {
+                  "type": "string",
+                  "description": "Name of the namespace to which xApp is deployed. Overrides the value given in Helm chart value file.",
+                  "example": "ricxapps"
+                },
+                "serviceName": {
+                  "type": "string",
+                  "description": "Name of the service xApp is providing. Overrides the value given in Helm chart value file.",
+                  "example": "xapp-dummy-service"
+                },
+                "imageRepo": {
+                  "type": "string",
+                  "description": "Name of the docker repository xApp is located. Overrides the value given in Helm chart value file.",
+                  "example": "xapprepo"
+                },
+                "hostname": {
+                  "type": "string",
+                  "description": "Hostname for the pod. Used by messaging library. Overrides the value given in Helm chart value file.",
                   "example": "xapp-dummy"
                 }
               }
         ],
         "parameters": [
           {
-            "name": "xAppConfig",
+            "name": "XAppConfig",
             "in": "body",
             "description": "xApp config",
             "schema": {
-              "$ref": "#/definitions/xAppConfig"
+              "$ref": "#/definitions/XAppConfig"
             }
           }
         ],
           "201": {
             "description": "xApp config successfully created",
             "schema": {
-              "$ref": "#/definitions/xAppConfig"
+              "$ref": "#/definitions/XAppConfig"
             }
           },
           "400": {
         ],
         "parameters": [
           {
-            "name": "xAppConfig",
+            "name": "XAppConfig",
             "in": "body",
             "description": "xApp config",
             "schema": {
-              "$ref": "#/definitions/xAppConfig"
+              "$ref": "#/definitions/XAppConfig"
             }
           }
         ],
           "200": {
             "description": "xApp config successfully modified",
             "schema": {
-              "$ref": "#/definitions/xAppConfig"
+              "$ref": "#/definitions/XAppConfig"
             }
           },
           "400": {
         "operationId": "deleteXappConfig",
         "parameters": [
           {
-            "name": "xAppConfigInfo",
+            "name": "ConfigMetadata",
             "in": "body",
             "description": "xApp configuration information",
             "schema": {
-              "$ref": "#/definitions/xAppConfigInfo"
+              "$ref": "#/definitions/ConfigMetadata"
             }
           }
         ],
             "in": "path",
             "description": "ID of subscription",
             "required": true,
-            "type": "integer"
+            "type": "string"
           }
         ],
         "responses": {
             "in": "path",
             "description": "ID of subscription",
             "required": true,
-            "type": "integer"
+            "type": "string"
           },
           {
             "in": "body",
             "in": "path",
             "description": "ID of subscription",
             "required": true,
-            "type": "integer"
+            "type": "string"
           }
         ],
         "responses": {
           "type": "integer",
           "example": 32300
         },
-        "txMessages" : {
+        "txMessages": {
           "type": "array",
           "items": {
-            "type" : "string",
-            "example" : "ControlIndication"
+            "type": "string",
+            "example": "ControlIndication"
           }
         },
-        "rxMessages" : {
+        "rxMessages": {
           "type": "array",
           "items": {
-            "type" : "string",
-            "example" : "LoadIndication"
+            "type": "string",
+            "example": "LoadIndication"
           }
         }
       }
     },
-    "xAppConfigInfo": {
+    "ConfigMetadata": {
       "type": "object",
       "required": [
-        "xAppName",
-        "configMapName",
+        "name",
+        "configName",
         "namespace"
       ],
       "properties": {
-        "xAppName": {
-          "type":"string",
-          "description":"Name of the xApp",
+        "name": {
+          "type": "string",
+          "description": "Name of the xApp",
           "example": "xapp-dummy"
         },
-        "configMapName": {
-          "type":"string",
-          "description":"Name of the config map",
+        "configName": {
+          "type": "string",
+          "description": "Name of the config map",
           "example": "xapp-dummy-config-map"
         },
         "namespace": {
-          "type":"string",
-          "description":"Name of the namespace",
+          "type": "string",
+          "description": "Name of the namespace",
           "example": "ricxapp"
         }
       }
     },
-    "xAppConfig": {
+    "XAppConfig": {
       "type": "object",
       "required": [
-        "xAppConfigInfo",
-        "configSchema",
-        "configMap"
+        "metadata",
+        "descriptor",
+        "config"
       ],
       "properties": {
-        "xAppConfigInfo": {
-          "$ref": "#/definitions/xAppConfigInfo"
+        "metadata": {
+          "$ref": "#/definitions/ConfigMetadata"
         },
-        "configSchema": {
-          "type":"object",
-          "description":"Schema of configuration in JSON format"
+        "descriptor": {
+          "type": "object",
+          "description": "Schema of configuration in JSON format"
         },
-        "configMap": {
-          "type":"object",
-          "description":"Configuration in JSON format"
+        "config": {
+          "type": "object",
+          "description": "Configuration in JSON format"
         }
       }
     },
     "AllXappConfig": {
       "type": "array",
       "items": {
-        "$ref": "#/definitions/xAppConfig"
+        "$ref": "#/definitions/XAppConfig"
       }
     },
     "subscriptionRequest": {
index 0a5cf73..afa90f7 100644 (file)
@@ -1,7 +1,7 @@
 swagger: '2.0'
 info:
   description: This is a draft API for RIC appmgr
-  version: 0.1.2
+  version: 0.1.3
   title: RIC appmgr
   license:
     name: Apache 2.0
@@ -12,15 +12,26 @@ schemes:
   - https
   - http
 paths:
-  /health:
-    get:
-      summary: Health check of xApp Manager
-      tags:
+  /health/alive :
+    get :
+      summary     : Health check of xApp Manager - Liveness probe
+      tags        : 
         - health
-      operationId: getHealth
-      responses:
+      operationId : getHealthAlive
+      responses   :
+        '200' :
+          description : Status of xApp Manager is ok
+  /health/ready :
+    get :
+      summary     : Readiness check of xApp Manager - Readiness probe
+      tags        : 
+        - health
+      operationId : getHealthReady
+      responses   :
         '200':
-          description: Status of xApp Manager is ok
+          description : xApp Manager is ready for service
+        '503':
+          description: xApp Manager is not ready for service
   /xapps:
     post:
       summary: Deploy a xapp
@@ -38,11 +49,31 @@ paths:
           schema:
             type: object
             required:
-              - xAppName
+              - name
             properties:
-              xAppName:
+              name:
                 type: string
-                description: Name of the xApp
+                description: Name of the xApp.
+                example: xapp-dummy
+              configName:
+                type: string
+                description: Name of the xApp configmap. Overrides the value given in Helm chart value file.
+                example: xapp-dummy-configmap
+              namespace:
+                type: string
+                description: Name of the namespace to which xApp is deployed. Overrides the value given in Helm chart value file.
+                example: ricxapps
+              serviceName:
+                type: string
+                description: Name of the service xApp is providing. Overrides the value given in Helm chart value file.
+                example: xapp-dummy-service
+              imageRepo:
+                type: string
+                description: Name of the docker repository xApp is located. Overrides the value given in Helm chart value file.
+                example: xapprepo
+              hostname:
+                type: string
+                description: Hostname for the pod. Used by messaging library. Overrides the value given in Helm chart value file.
                 example: xapp-dummy
       responses:
         '201':
@@ -151,16 +182,16 @@ paths:
       produces:
         - application/json
       parameters:
-        - name: xAppConfig
+        - name: XAppConfig
           in: body
           description: xApp config
           schema:
-            $ref: '#/definitions/xAppConfig'
+            $ref: '#/definitions/XAppConfig'
       responses:
         '201':
           description: xApp config successfully created
           schema:
-            $ref: '#/definitions/xAppConfig'
+            $ref: '#/definitions/XAppConfig'
         '400':
           description: Invalid input
         '422':
@@ -177,16 +208,16 @@ paths:
       produces:
         - application/json
       parameters:
-        - name: xAppConfig
+        - name: XAppConfig
           in: body
           description: xApp config
           schema:
-            $ref: '#/definitions/xAppConfig'
+            $ref: '#/definitions/XAppConfig'
       responses:
         '200':
           description: xApp config successfully modified
           schema:
-            $ref: '#/definitions/xAppConfig'
+            $ref: '#/definitions/XAppConfig'
         '400':
           description: Invalid input
         '422':
@@ -213,11 +244,11 @@ paths:
         - xapp
       operationId: deleteXappConfig
       parameters:
-        - name: xAppConfigInfo
+        - name: ConfigMetadata
           in: body
           description: xApp configuration information
           schema:
-            $ref: '#/definitions/xAppConfigInfo'
+            $ref: '#/definitions/ConfigMetadata'
       responses:
         '204':
           description: Successful deletion of xApp
@@ -277,7 +308,7 @@ paths:
           in: path
           description: ID of subscription
           required: true
-          type: integer
+          type: string
       responses:
         '200':
           description: successful operation
@@ -302,7 +333,7 @@ paths:
           in: path
           description: ID of subscription
           required: true
-          type: integer
+          type: string
         - in: body
           name: subscriptionRequest
           description: Modified subscription
@@ -328,7 +359,7 @@ paths:
           in: path
           description: ID of subscription
           required: true
-          type: integer
+          type: string
       responses:
         '204':
           description: Successful deletion of subscription
@@ -399,18 +430,18 @@ definitions:
         items:
           type: string
           example: LoadIndication
-  xAppConfigInfo:
+  ConfigMetadata:
     type: object
     required:
-      - xAppName
-      - configMapName
+      - name
+      - configName
       - namespace
     properties:
-      xAppName:
+      name:
         type: string
         description: Name of the xApp
         example: xapp-dummy
-      configMapName:
+      configName:
         type: string
         description: Name of the config map
         example: xapp-dummy-config-map
@@ -418,25 +449,25 @@ definitions:
         type: string
         description: Name of the namespace
         example: ricxapp
-  xAppConfig:
+  XAppConfig:
     type: object
     required:
-      - xAppConfigInfo
-      - configSchema
-      - configMap
+      - metadata
+      - descriptor
+      - config
     properties:
-      xAppConfigInfo:
-        $ref: '#/definitions/xAppConfigInfo'
-      configSchema:
+      metadata:
+        $ref: '#/definitions/ConfigMetadata'
+      descriptor:
         type: object
         description: Schema of configuration in JSON format
-      configMap:
+      config:
         type: object
         description: Configuration in JSON format
   AllXappConfig:
     type: array
     items:
-      $ref: '#/definitions/xAppConfig'
+      $ref: '#/definitions/XAppConfig'
   subscriptionRequest:
     type: object
     required:
index 8bb75ac..f183be9 100644 (file)
 ifndef MAKE_DOCKER_TARGETS
 MAKE_DOCKER_TARGETS:=1
 
-.PHONY: docker-build docker-clean
+.PHONY: docker-build docker-clean docker-stop FORCE
+
+FORCE:
 
 
 docker-name_%:
        @echo $($*_DCKR_FULLNAME)
 
+
 docker-build_%:
-       @(\
-               test -z "$${SSH_PRIVATE_KEY}" && SSH_PRIVATE_KEY=$$(cat $${HOME}/.ssh/id_rsa);\
-               docker build --target $* $($*_DCKR_B_OPTS) --build-arg SSH_PRIVATE_KEY="$${SSH_PRIVATE_KEY}" -t $($*_DCKR_FULLNAME) -f $($*_DCKR_FILE) . ;\
-       )
-
-docker-irun_%:
-       docker run $($*_DCKR_R_OPTS) $($*_DCKR_FULLNAME) /bin/bash
-
-docker-irun-mounted_%:
-       docker run $($*_DCKR_R_OPTS) -v $(shell pwd):/ws/go/src/${PACKAGEURL} --workdir "/ws/go/src/${PACKAGEURL}" $($*_DCKR_FULLNAME) /bin/bash
-
-docker-run_%:
-       docker run $($*_DCKR_R_OPTS) $($*_DCKR_FULLNAME)
-
-docker-run-redished_%:
-       @( \
-               RETVAL=0;\
-               docker network create --driver bridge $($*_DCKR_FULLNAME)-run_network;\
-               docker run $($*_DCKR_R_OPTS) -d --name $($*_DCKR_FULLNAME)-run_redis --network $($*_DCKR_FULLNAME)-run_network redis;\
-               docker run $($*_DCKR_R_OPTS) --name $($*_DCKR_FULLNAME)-run_xapp --network $($*_DCKR_FULLNAME)-run_network -e DBAAS_SERVICE_HOST=$($*_DCKR_FULLNAME)-run_redis $($*_DCKR_FULLNAME);\
-               RETVAL=$$?;\
-               docker stop $($*_DCKR_FULLNAME)-run_redis;\
-               docker network rm $($*_DCKR_FULLNAME)-run_network;\
-               exit $${RETVAL};\
-       )
-       
-docker-clean_%:
+       docker build --target $* $($*_DCKR_B_OPTS) -t $($*_DCKR_FULLNAME) -f $($*_DCKR_FILE) .
+
+.docker-services-drun_%:
+       docker network create --driver bridge $($*_DCKR_FULLNAME)-running_network
+       docker run $($*_DCKR_R_OPTS) -d --name $($*_DCKR_FULLNAME)-running_redis --network $($*_DCKR_FULLNAME)-running_network redis
+
+docker-irun_%: .docker-services-drun_%
+       docker run $($*_DCKR_R_OPTS) --name $($*_DCKR_FULLNAME)-running_xapp --network $($*_DCKR_FULLNAME)-running_network -e DBAAS_SERVICE_HOST=$($*_DCKR_FULLNAME)-running_redis $($*_DCKR_FULLNAME) /bin/bash
+
+docker-irun-mounted_%: .docker-services-drun_%
+       docker run $($*_DCKR_R_OPTS) -v $(shell pwd):/ws/go/src/${PACKAGEURL} --workdir "/ws/go/src/${PACKAGEURL}" --name $($*_DCKR_FULLNAME)-running_xapp --network $($*_DCKR_FULLNAME)-running_network -e DBAAS_SERVICE_HOST=$($*_DCKR_FULLNAME)-running_redis $($*_DCKR_FULLNAME) /bin/bash
+
+docker-run_%: .docker-services-drun_%
+       docker run $($*_DCKR_R_OPTS) --name $($*_DCKR_FULLNAME)-running_xapp --network $($*_DCKR_FULLNAME)-running_network -e DBAAS_SERVICE_HOST=$($*_DCKR_FULLNAME)-running_redis $($*_DCKR_FULLNAME)
+
+docker-stop_%:
+       docker rm -f $($*_DCKR_FULLNAME)-running_xapp &> /dev/null || true
+       docker rm -f $($*_DCKR_FULLNAME)-running_redis &> /dev/null || true
+       docker network rm $($*_DCKR_FULLNAME)-running_network &> /dev/null || true
+
+docker-irun-stop_%: docker-irun_%
+       docker rm -f $($*_DCKR_FULLNAME)-running_xapp &> /dev/null || true
+       docker rm -f $($*_DCKR_FULLNAME)-running_redis &> /dev/null || true
+       docker network rm $($*_DCKR_FULLNAME)-running_network &> /dev/null || true
+
+docker-irun-mounted-stop_%: docker-irun-mounted_%
+       docker rm -f $($*_DCKR_FULLNAME)-running_xapp &> /dev/null || true
+       docker rm -f $($*_DCKR_FULLNAME)-running_redis &> /dev/null || true
+       docker network rm $($*_DCKR_FULLNAME)-running_network &> /dev/null || true
+
+docker-run-stop_%: docker-run_%
+       docker rm -f $($*_DCKR_FULLNAME)-running_xapp &> /dev/null || true
+       docker rm -f $($*_DCKR_FULLNAME)-running_redis &> /dev/null || true
+       docker network rm $($*_DCKR_FULLNAME)-running_network &> /dev/null || true
+
+docker-clean_%: docker-stop_%
        docker rmi $($*_DCKR_FULLNAME) || true
 
 
@@ -64,6 +76,10 @@ docker-build: $$(DCKR_TARGETS)
 docker-clean: DCKR_TARGETS:=
 docker-clean: $$(DCKR_TARGETS)
 
+.SECONDEXPANSION:
+docker-stop: DCKR_TARGETS:=
+docker-stop: $$(DCKR_TARGETS)
+
 endif
 
 #------------------------------------------------------------------------------
@@ -98,15 +114,11 @@ $(DCKR_NAME)_DCKR_FULLNAME:=$($(DCKR_NAME)_DCKR_B_PREFIX)$(DCKR_NAME)
 $(DCKR_NAME)_DCKR_B_OPTS:=${DCKR_B_OPTS}
 $(DCKR_NAME)_DCKR_B_OPTS:=$($(DCKR_NAME)_DCKR_B_OPTS) --network=host
 
-ifndef PACKAGEURL
+ifdef PACKAGEURL
 $(DCKR_NAME)_DCKR_B_OPTS:=$($(DCKR_NAME)_DCKR_B_OPTS) --build-arg PACKAGEURL=${PACKAGEURL}
 endif
 
-ifndef PACKAGEREPO
-$(DCKR_NAME)_DCKR_B_OPTS:=$($(DCKR_NAME)_DCKR_B_OPTS) --build-arg PACKAGEREPO=${PACKAGEREPO}
-endif
-
-ifndef BUILD_PREFIX
+ifdef BUILD_PREFIX
 $(DCKR_NAME)_DCKR_B_OPTS:=$($(DCKR_NAME)_DCKR_B_OPTS) --build-arg BUILD_PREFIX=${BUILD_PREFIX}
 endif
 
@@ -126,3 +138,5 @@ docker-build: DCKR_TARGETS+=docker-build_$(DCKR_NAME)
 
 docker-clean: DCKR_TARGETS+=docker-clean_$(DCKR_NAME)
 
+docker-stop: DCKR_TARGETS+=docker-stop_$(DCKR_NAME)
+
index 18d5d44..286d9b1 100644 (file)
 #------------------------------------------------------------------------------
 #
 #------------------------------------------------------------------------------
-#ROOT_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
-
 ifndef ROOT_DIR
 $(error ROOT_DIR NOT DEFINED)
 endif
-BUILD_DIR?=$(abspath $(ROOT_DIR)/build)
-CACHE_DIR?=$(abspath $(BUILD_DIR)/cache)
+ifndef CACHE_DIR
+$(error CACHE_DIR NOT DEFINED)
+endif
+
+#------------------------------------------------------------------------------
+#
+#------------------------------------------------------------------------------
 
+GO_CACHE_DIR?=$(abspath $(CACHE_DIR)/go)
 
 #------------------------------------------------------------------------------
 #
-#-------------------------------------------------------------------- ----------
+#------------------------------------------------------------------------------
 ifndef MAKE_GO_TARGETS
 MAKE_GO_TARGETS:=1
 
 
+.PHONY: FORCE go-build go-test go-test-fmt go-fmt go-clean
+FORCE:
+
+
 GOOS=$(shell go env GOOS)
 GOCMD=go
 GOBUILD=$(GOCMD) build -a -installsuffix cgo
@@ -45,18 +54,15 @@ GOFILES:=$(shell find $(ROOT_DIR) -name '*.go' -not -name '*_test.go')
 GOALLFILES:=$(shell find $(ROOT_DIR) -name '*.go')
 GOMODFILES:=go.mod go.sum
 
-.PHONY: FORCE go-build go-test go-test-fmt go-fmt go-clean
-
-FORCE:
-
 
-$(CACHE_DIR)/%: $(GOFILES) $(GOMODFILES)
+.SECONDEXPANSION:
+$(GO_CACHE_DIR)/%: $(GOFILES) $(GOMODFILES) $$(BUILDDEPS)
        @echo "Building:\t$*"
        GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $@ ./$*
 
 
-$(CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES)
+.SECONDEXPANSION:
+$(GO_CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES) $$(BUILDDEPS) FORCE
        @echo "Testing:\t$*"
        GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOTEST) -coverprofile $(COVEROUT) -c -o $@ ./$*
        test -e $@ && (eval $(TESTENV) $@ -test.coverprofile $(COVEROUT) || false) || true
@@ -64,12 +70,12 @@ $(CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES)
 
 
 .SECONDEXPANSION:
-go-build: XAPP_TARGETS:=
-go-build: $$(XAPP_TARGETS)
+go-build: GO_TARGETS:=
+go-build: $$(GO_TARGETS)
 
 .SECONDEXPANSION:
-go-test: XAPP_TARGETS:=
-go-test: go-clean $$(XAPP_TARGETS)
+go-test: GO_TARGETS:=
+go-test: $$(GO_TARGETS)
 
 go-test-fmt: $(GOFILES)
        @(RESULT="$$(gofmt -l $^)"; test -z "$${RESULT}" || (echo -e "gofmt failed:\n$${RESULT}" && false) )
@@ -77,10 +83,16 @@ go-test-fmt: $(GOFILES)
 go-fmt: $(GOFILES)
        gofmt -w -s $^
 
-go-clean: XAPP_TARGETS:=
+go-mod-tidy: FORCE
+       GO111MODULE=on go mod tidy
+
+go-mod-download: FORCE
+       GO111MODULE=on go mod download
+
+go-clean: GO_TARGETS:=
 go-clean:
        @echo "  >  Cleaning build cache"
-       @-rm -rf $(XAPP_TARGETS)* 2> /dev/null
+       @-rm -rf $(GO_TARGETS)* 2> /dev/null
        go clean 2> /dev/null
 
 
@@ -90,11 +102,15 @@ endif
 #
 #-------------------------------------------------------------------- ----------
 
-$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVEROUT:=$(abspath $(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.out)
-$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVERHTML:=$(abspath $(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.html)
-$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: TESTENV:=$(XAPP_TESTENV)
+$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME): BUILDDEPS:=$(XAPP_BUILDDEPS)
+
+
+$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: BUILDDEPS:=$(XAPP_BUILDDEPS)
+$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVEROUT:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.out)
+$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVERHTML:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.html)
+$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: TESTENV:=$(XAPP_TESTENV)
 
-go-build: XAPP_TARGETS+=$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)
-go-test: XAPP_TARGETS+=$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
-go-clean: XAPP_TARGETS+=$(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME) $(CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
+go-build: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)
+go-test: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
+go-clean: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME) $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
 
index 2f55460..ac1d0c8 100755 (executable)
@@ -24,6 +24,7 @@ import (
        "errors"
        "fmt"
        "github.com/spf13/viper"
+       "github.com/valyala/fastjson"
        "github.com/xeipuuv/gojsonschema"
        "io/ioutil"
        "log"
@@ -134,7 +135,7 @@ func (cm *ConfigMap) ApplyConfigMap(r XAppConfig, action string) (err error) {
                Data:       r.Configuration,
        }
 
-       cmJson, err := json.Marshal(c)
+       cmJson, err := json.Marshal(c.Data)
        if err != nil {
                log.Println("Config marshalling failed: ", err)
                return
@@ -158,6 +159,13 @@ func (cm *ConfigMap) ApplyConfigMap(r XAppConfig, action string) (err error) {
        return
 }
 
+func (cm *ConfigMap) GetConfigMap(m XappDeploy, c *interface{}) (err error) {
+       if m.ConfigName == "" {
+               m.ConfigName = m.Name + "-appconfig"
+       }
+       return cm.ReadConfigMap(m.ConfigName, m.Namespace, c)
+}
+
 func (cm *ConfigMap) CreateConfigMap(r XAppConfig) (errList []CMError, err error) {
        if errList, err = cm.Validate(r); err != nil {
                return
@@ -282,5 +290,26 @@ func (cm *ConfigMap) FetchChart(name string) (err error) {
 
 func (cm *ConfigMap) GetMessages(name string) (msgs MessageTypes) {
        log.Println("Fetching tx/rx messages for: ", name)
+
+       args := fmt.Sprintf("get configmap -o jsonpath='{.data.config-file\\.json}' -n ricxapp %s-appconfig", name)
+       out, err := KubectlExec(args)
+       if err != nil {
+               return
+       }
+
+       var p fastjson.Parser
+       v, err := p.Parse(string(out))
+       if err != nil {
+               log.Printf("fastjson.Parser for '%s' failed: %v", name, err)
+               return
+       }
+
+       for _, m := range v.GetArray("rmr", "txMessages") {
+               msgs.TxMessages = append(msgs.TxMessages, strings.Trim(m.String(), `"`))
+       }
+       for _, m := range v.GetArray("rmr", "rxMessages") {
+               msgs.RxMessages = append(msgs.RxMessages, strings.Trim(m.String(), `"`))
+       }
+
        return
 }
index 36b6c72..f553c38 100755 (executable)
@@ -34,6 +34,30 @@ helm-repo/dualco        0.0.1           1.0             Helm Chart for Nokia dua
 helm-repo/reporter      0.0.1           1.0             Helm Chart for Reporting xAPP
 helm-repo/uemgr         0.0.1           1.0             Helm Chart for Nokia uemgr xAPP
 `
+
+var kubectlConfigmapOutput = `
+{
+    "local": {
+        "host": ":8080"
+    },
+    "logger": {
+        "level": 3
+    },
+    "rmr": {
+       "protPort": "tcp:4560",
+       "maxSize": 2072,
+       "numWorkers": 1,
+       "txMessages": ["RIC_X2_LOAD_INFORMATION"],
+       "rxMessages": ["RIC_X2_LOAD_INFORMATION"]
+    },
+    "db": {
+        "namespace": "ricxapp",
+        "host": "dbaas",
+        "port": 6379
+    }
+}
+`
+
 type ConfigSample struct {
        Level   int
        Host    string
@@ -85,10 +109,18 @@ func (cm *MockedConfigMapper) GetMessages(name string) (msgs MessageTypes) {
 // Test cases
 func TestGetMessages(t *testing.T) {
        cm := ConfigMap{}
-       expectedMsgs := MessageTypes{}
+       expectedMsgs := MessageTypes{
+               TxMessages: []string{"RIC_X2_LOAD_INFORMATION"},
+               RxMessages: []string{"RIC_X2_LOAD_INFORMATION"},
+       }
+
+       KubectlExec = func(args string) (out []byte, err error) {
+               return []byte(kubectlConfigmapOutput), nil
+       }
 
-       if !reflect.DeepEqual(cm.GetMessages("dummy-xapp"), expectedMsgs) {
-               t.Errorf("TestGetMessages failed!")
+    result := cm.GetMessages("dummy-xapp")
+       if !reflect.DeepEqual(result, expectedMsgs) {
+               t.Errorf("TestGetMessages failed: expected: %v, got: %v", expectedMsgs, result)
        }
 }
 
index 388fb5c..578dcf0 100755 (executable)
@@ -149,7 +149,9 @@ func (h *Helm) Install(m XappDeploy) (xapp Xapp, err error) {
        }
 
        var cm interface{}
-       if err = h.cm.ReadConfigMap(m.Name, m.Namespace, &cm); err != nil {
+       m.Namespace = getNamespace(m.Namespace)
+
+       if err = h.cm.GetConfigMap(m, &cm); err != nil {
                out, err = h.Run(getInstallArgs(m, false))
                if err != nil {
                        return
@@ -357,23 +359,22 @@ func getNamespace(namespace string) string {
 }
 
 func getInstallArgs(x XappDeploy, cmOverride bool) (args string) {
-       x.Namespace = getNamespace(x.Namespace)
        args = args + " --namespace=" + x.Namespace
 
        if x.ImageRepo != "" {
-               args = args + " --set image.repository=" + x.ImageRepo
+               args = args + " --set global.repository=" + x.ImageRepo
        }
 
        if x.ServiceName != "" {
-               args = args + " --set service.name=" + x.ServiceName
+               args = args + " --set ricapp.service.name=" + x.ServiceName
        }
 
        if x.Hostname != "" {
-               args = args + " --set hostname=" + x.Hostname
+               args = args + " --set ricapp.hostname=" + x.Hostname
        }
 
        if cmOverride == true {
-               args = args + " --set appconfig.override=true"
+               args = args + " --set ricapp.appconfig.override=" + x.Name + "-appconfig"
        }
 
        rname := viper.GetString("helm.repo-name")
index 2e0f547..e32b62f 100755 (executable)
@@ -73,6 +73,7 @@ type XappManager struct {
 
 type ConfigMapper interface {
        UploadConfig() (cfg []XAppConfig)
+       GetConfigMap(m XappDeploy, c *interface{}) (err error)
        CreateConfigMap(r XAppConfig) (errList []CMError, err error)
        UpdateConfigMap(r XAppConfig) (errList []CMError, err error)
        DeleteConfigMap(r XAppConfig) (cm interface{}, err error)
@@ -134,8 +135,8 @@ type SubscriptionDispatcher struct {
 }
 
 type MessageTypes struct {
-       TxMessages []string `yaml:"txMessages"`
-       RxMessages []string `yaml:"rxMessages"`
+       TxMessages []string `json:"txMessages"`
+       RxMessages []string `json:"rxMessages"`
 }
 
 type EventType string
diff --git a/go.mod b/go.mod
index 8c5298a..19c1062 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -10,6 +10,7 @@ require (
        github.com/orcaman/concurrent-map v0.0.0-20190314100340-2693aad1ed75
        github.com/segmentio/ksuid v1.0.2
        github.com/spf13/viper v1.3.2
+       github.com/valyala/fastjson v1.4.1
        github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
        github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
        github.com/xeipuuv/gojsonschema v1.1.0
diff --git a/go.sum b/go.sum
index e1a2985..46361f4 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -54,6 +54,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
 github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
+github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
+github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=