From 364295fa6c8aa7b0aec4efe8ae8ce8241d03966c Mon Sep 17 00:00:00 2001 From: Roni Riska Date: Mon, 30 Sep 2019 09:39:12 +0300 Subject: [PATCH] Fix NfNamingCode and remove NfcNamingCodes NFNamingCode is read from environment variable VESMGR_NFNAMINGCODE. If not set, the default value is "ricp". NfcNamingCodes is an empty list. Also add vesmgr version information log at vesmgr startup. The version information is generated at compile time from the container-tag.yaml file (if exists) and from the git hash of the last commit. Change-Id: If524e679dbba2ee56217b2e03b1daf18eb2c46fb Signed-off-by: Roni Riska --- Dockerfile | 12 +----------- README.md | 33 +++++++++++++++++++++------------ build_vesmgr.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ cmd/vesmgr/config.go | 22 +++++++++++----------- cmd/vesmgr/config_test.go | 6 ++++++ cmd/vesmgr/vesmgr.go | 9 +++++++++ container-tag.yaml | 2 +- 7 files changed, 91 insertions(+), 35 deletions(-) create mode 100755 build_vesmgr.sh diff --git a/Dockerfile b/Dockerfile index de491db..9c8a43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,17 +38,7 @@ WORKDIR $GOPATH/src/vesmgr # Copy vesmgr to the Working Directory COPY $HOME/ . -RUN GO111MODULE=on go mod download - -# Run vesmgr UT -RUN export GOPATH=$HOME/go && \ - export PATH=$GOPATH/bin:$GOROOT/bin:$PATH && \ - go test ./... - -# Install vesmgr -RUN export GOPATH=$HOME/go && \ - export PATH=$GOPATH/bin:$GOROOT/bin:$PATH && \ - go install -v ./cmd/vesmgr +RUN ./build_vesmgr.sh ################# # diff --git a/README.md b/README.md index 06b2cca..f8c3cbf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -# RIC VESPA manager +RIC VESPA manager +================= -The VESPA manager uses the VES Agent (https://github.com/nokia/ONAP-VESPA) -to adapt near-RT RIC internal statistics' collection using Prometheus +The VESPA manager uses the VES Agent [https://github.com/nokia/ONAP-VESPA](https://github.com/nokia/ONAP-VESPA) +to adapt near-RT RIC internal statistics' collection using Prometheus (xApps and platform containers) to ONAP's VES (VNF event streaming). The vesmgr container runs two processes: the VESPA manager and the VES @@ -9,13 +10,13 @@ Agent (i.s. VESPA). The VESPA manager starts and configures the VES Agent. -The VES Agent is a service acting as a bridge between Prometheus and +The VES Agent is a service acting as a bridge between Prometheus and ONAP's VES Collector. # Application metrics definition The application metrics are defined in the application descriptor. -For each counter, the following fields are required in the "metrics" +For each counter, the following fields are required in the "metrics" section of the descriptor: * name - Prometheus name of the counter @@ -23,7 +24,7 @@ section of the descriptor: * objectInstance - object instance in VE The VESPA manager receives the application metrics configuration from the -application manager. It subscribes the app notification messages from the +application manager. It subscribes the app notification messages from the application manager, and after having received one, requests the latest application configuration, creates the VES Agent configuration based on it, and restarts the VES Agent. @@ -37,8 +38,8 @@ The VES Agent reads the ricComponentName from Prometheus label # VES Collector event format -The VES Agent transmits events to the VES Collector in the -VES Common Event Format v5.4.1. +The VES Agent transmits events to the VES Collector in the +VES Common Event Format v5.4.1. The Common Event Format is expressed in JSON schema v28.4.1. VES Event Listener 5.4.1: @@ -52,11 +53,11 @@ JSON schema v28.4.1: The VESPA manager container requires the following environment variables: * VESMGR_VNFNAME - VNF name as a string. Default: Vespa. +* VESMGR_NFNAMINGCODE - NF naming code as a string. Default: ricp. * VESMGR_HB_INTERVAL - VES heartbeat interval as a string. For example: 30s. * VESMGR_MEAS_INTERVAL - Measurement interval as a string. For example: 60s. * VESMGR_PROMETHEUS_ADDR - Prometheus address. For example: http://127.0.0.1:123 - * VESMGR_PRICOLLECTOR_ADDR - Primary collector FQDN as a string. For example: ricaux-entry. * VESMGR_PRICOLLECTOR_PORT - Primary collector port id as an integer. Default: 8443. * VESMGR_PRICOLLECTOR_SERVERROOT - Path before the /eventListener part of the POST URL as a string. @@ -66,21 +67,29 @@ The VESPA manager container requires the following environment variables: * VESMGR_PRICOLLECTOR_PASSWORD - Password as a string. * VESMGR_PRICOLLECTOR_PASSPHASE - Passphrase as a string. - * VESMGR_APPMGRDOMAIN - Application manager domain. This is for testing purposes, only. Default: service-ricplt-appmgr-http.ricplt.svc.cluster.local. # Liveness probe The VESPA manager replies to liveness HTTP GET at path /supervision. +# Errors + +The VESPA manager exits in the following error cases: + +* The VES Agent exits +* An unrecoverable system error during the initialization, for example + * Creation of the VES Agent configuration file fails + * Creation of a HTTP request message fails + # Unit Tests In order to run the VESPA manager unit tests, give the following command: -``` +```shell go test ./... -v ``` # License -See [LICENSES.txt](LICENSES.txt) file. +See [LICENSES.txt](./LICENSES.txt) file. diff --git a/build_vesmgr.sh b/build_vesmgr.sh new file mode 100755 index 0000000..61a63fe --- /dev/null +++ b/build_vesmgr.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2018-2019 Nokia. +# +# 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. +# + +set -e +set -x +# Load modules +GO111MODULE=on go mod download +export GOPATH=$HOME/go +export PATH=$GOPATH/bin:$GOROOT/bin:$PATH + +# Run vesmgr UT +go test ./... + +# setup version tag +if [ -f container-tag.yaml ] +then + tag=$(grep "tag:" container-tag.yaml | awk '{print $2}') +else + tag="-" +fi + +hash=$(git rev-parse --short HEAD || true) + +# Install vesmgr +go install -ldflags "-X main.Version=$tag -X main.Hash=$hash" -v ./cmd/vesmgr + + diff --git a/cmd/vesmgr/config.go b/cmd/vesmgr/config.go index 77b4ca8..0df132b 100644 --- a/cmd/vesmgr/config.go +++ b/cmd/vesmgr/config.go @@ -31,6 +31,7 @@ import ( const defaultReportingEntityID = "00000000-0000-0000-0000-000000000000" const defaultVNFName = "Vespa" +const defaultNFNamingCode = "ricp" func readSystemUUID() string { data, err := ioutil.ReadFile("/sys/class/dmi/id/product_uuid") @@ -48,6 +49,14 @@ func getVNFName() string { return VNFName } +func getNFNamingCode() string { + NFNamingCode := os.Getenv("VESMGR_NFNAMINGCODE") + if NFNamingCode == "" { + return defaultNFNamingCode + } + return NFNamingCode +} + func basicVespaConf() VESAgentConfiguration { var vespaconf = VESAgentConfiguration{ DataDir: "/tmp/data", @@ -57,17 +66,8 @@ func basicVespaConf() VESAgentConfiguration { ReportingEntityName: "Vespa", ReportingEntityID: readSystemUUID(), MaxSize: 2000000, - NfNamingCode: "hsxp", - NfcNamingCodes: []NfcNamingCode{ - NfcNamingCode{ - Type: "oam", - Vnfcs: []string{"lr-ope-0", "lr-ope-1", "lr-ope-2"}, - }, - NfcNamingCode{ - Type: "etl", - Vnfcs: []string{"lr-pro-0", "lr-pro-1"}, - }, - }, + NfNamingCode: getNFNamingCode(), + NfcNamingCodes: []NfcNamingCode{}, RetryInterval: time.Second * 5, MaxMissed: 2, }, diff --git a/cmd/vesmgr/config_test.go b/cmd/vesmgr/config_test.go index 7a07e38..328e253 100644 --- a/cmd/vesmgr/config_test.go +++ b/cmd/vesmgr/config_test.go @@ -35,6 +35,7 @@ func testBaseConf(t *testing.T, vesconf VESAgentConfiguration) { assert.Equal(t, vesconf.Event.RetryInterval, time.Second*5) assert.Equal(t, vesconf.Measurement.Prometheus.KeepAlive, time.Second*30) assert.Equal(t, vesconf.Event.VNFName, defaultVNFName) + assert.Equal(t, vesconf.Event.NfNamingCode, defaultNFNamingCode) assert.Equal(t, vesconf.Event.ReportingEntityName, "Vespa") // depending on the credentials with which this test is run, // root or non-root, the code either reads the UUID from the file or @@ -50,13 +51,17 @@ func TestBasicConfigContainsCorrectValues(t *testing.T) { func TestBasicConfigContainsCorrectVNFName(t *testing.T) { os.Setenv("VESMGR_VNFNAME", "VNF-111") + os.Setenv("VESMGR_NFNAMINGCODE", "code55") vesconf := basicVespaConf() assert.Equal(t, vesconf.Event.VNFName, "VNF-111") + assert.Equal(t, vesconf.Event.NfNamingCode, "code55") os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") } func TestCollectorConfiguration(t *testing.T) { os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") os.Setenv("VESMGR_PRICOLLECTOR_USER", "user123") os.Setenv("VESMGR_PRICOLLECTOR_PASSWORD", "pass123") os.Setenv("VESMGR_PRICOLLECTOR_PASSPHRASE", "phrase123") @@ -81,6 +86,7 @@ func TestCollectorConfiguration(t *testing.T) { func TestCollectorConfigurationWhenEnvironmentVariablesAreNotDefined(t *testing.T) { os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") os.Unsetenv("VESMGR_PRICOLLECTOR_USER") os.Unsetenv("VESMGR_PRICOLLECTOR_PASSWORD") os.Unsetenv("VESMGR_PRICOLLECTOR_PASSPHRASE") diff --git a/cmd/vesmgr/vesmgr.go b/cmd/vesmgr/vesmgr.go index aeebb15..ca6695e 100755 --- a/cmd/vesmgr/vesmgr.go +++ b/cmd/vesmgr/vesmgr.go @@ -52,6 +52,13 @@ type subscriptionNotification struct { var logger *mdcloggo.MdcLogger +// Version information, which is filled during compilation +// Version tag of vesmgr container +var Version string + +// Hash of the git commit used in building +var Hash string + const vesmgrXappNotifPort = "8080" const vesmgrXappNotifPath = "/vesmgr_xappnotif/" const timeoutPostXAppSubscriptions = 5 @@ -101,6 +108,8 @@ func (vesmgr *VesMgr) subscribeXAppNotifications() { // Init initializes the vesmgr func (vesmgr *VesMgr) Init(listenPort string) *VesMgr { logger.Info("vesmgrInit") + logger.Info("version %s (%s)", Version, Hash) + var err error if vesmgr.myIPAddress, err = getMyIP(); err != nil || vesmgr.myIPAddress == "" { logger.Error("Cannot get myIPAddress: IP %s, err %s", vesmgr.myIPAddress, err.Error()) diff --git a/container-tag.yaml b/container-tag.yaml index 81c78cb..0b53be2 100644 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -1,4 +1,4 @@ # The Jenkins job uses this string for the tag in the image name # for example nexus3.o-ran-sc.org:10004/my-image-name:0.0.1 --- -tag: 0.0.6 +tag: 0.0.7 -- 2.16.6