Merge "Add chart for MR subscriber"
authorZhe Huang <zhehuang@research.att.com>
Thu, 5 Sep 2019 20:20:45 +0000 (20:20 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Thu, 5 Sep 2019 20:20:45 +0000 (20:20 +0000)
ric-aux/80-Auxiliary-Functions/bin/install
ric-aux/80-Auxiliary-Functions/bin/uninstall
ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml [new file with mode: 0644]
ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml [new file with mode: 0644]

index 52bf88d..63ed6d1 100755 (executable)
@@ -122,7 +122,7 @@ fi
 
 
 
-RICAUX_COMPONENTS="dashboard ves message-router"
+RICAUX_COMPONENTS="dashboard ves message-router mrsub"
 
 echo "Deploying RIC AUX components [$RICAUX_COMPONENTS]"
 echo "Helm Release Name: $RELEASE_NAME"
index c86e42b..85d3b5c 100755 (executable)
@@ -30,7 +30,7 @@ else
    RELEASE_NAME=$RICAUX_RELEASE_NAME
 fi
 
-RICAUX_COMPONENTS="dashboard message-router ves"
+RICAUX_COMPONENTS="dashboard message-router ves mrsub"
 
 echo "Undeploying RIC AUX components [$RICAUX_COMPONENTS]"
 echo "Helm Release Name: $RELEASE_NAME"
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore b/ric-aux/80-Auxiliary-Functions/helm/mrsub/.helmignore
new file mode 100644 (file)
index 0000000..50af031
--- /dev/null
@@ -0,0 +1,22 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/Chart.yaml
new file mode 100644 (file)
index 0000000..fb316eb
--- /dev/null
@@ -0,0 +1,5 @@
+apiVersion: v1
+appVersion: "1.0"
+description: A Helm chart for Kubernetes
+name: mrsub
+version: 0.1.0
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh b/ric-aux/80-Auxiliary-Functions/helm/mrsub/resources/mrsub.sh
new file mode 100644 (file)
index 0000000..2743951
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+MR_HOSTPORT="$_MR_HOSTPORT"
+MR_TOPIC="$_MR_TOPIC"
+LOGSTASH_URL="$_LOGSTASH_URL"
+
+if ! jq --version > /dev/null 2&>1 ; then
+  apt-get update
+  apt-get install -y jq curl
+fi
+
+echo "IN SCRIPT"
+echo "$MR_HOSTPORT   $MR_TOPIC  $LOGSTASH_URL"
+
+while true; do
+  # if dmaap returns single JSON structure
+  DATA=$(curl -s -H "Accept: application/json" -X GET http://${MR_HOSTPORT}/events/${MR_TOPIC}/elk-plotter/elk-plotter?timeout=60000)
+  DATA=$(echo $DATA| sed -e 's/\\"/"/g' -e 's/"{/{/g' -e 's/}"/}/g')
+  echo "Getting data: $DATA"
+
+  #VESEVENT=$(echo $DATA |jq -r '((.event.commonEventHeader.lastEpochMicrosec)|tostring) + "," + ((.event.measurementsForVfScalingFields.vNicUsageArray[0].receivedTotalPacketsDelta) | tostring)')
+  #curl -i -XPUT 'http://127.0.0.1:8080/onenumber/onenumebr' -d "${VESEVENT}"
+
+  # dmaap returns json array
+  # echo "Reading source: $.event.commonEventHeader.reportingEntityName"
+  source=$(echo $DATA |jq -r '.[] | ((.event.commonEventHeader.reportingEntityName) | tostring)')
+  echo "Source name: $source"
+  if [ "$source" == "GS_LITE MC" ]
+  then
+    DATA=$(echo $DATA |jq -r --arg source "$source"  '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[1].value) | tostring)+ ","+ ((.event.measurementsForVfScalingFields.additionalFields[2].value) | tostring)')
+  #EVENTS=$(echo $DATA |jq -r '.event.measurementFields.additionalFields.SgNBRequestRate')
+  #for EVENT in $EVENTS; do
+  elif [ "$source" == "AC xAPP" ] 
+  then  
+    DATA=$(echo $DATA |jq -r --arg source "$source"  '.[] | $source+","+((.event.measurementsForVfScalingFields.additionalFields[0].value) | tostring)')
+  else
+    DATA="No supportive reporting entity provided"
+  fi
+  echo "Injecting VES event: $DATA"
+  curl -i -XPUT "${LOGSTASH_URL}" -d "${DATA}"
+  #done
+done
+
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/_helpers.tpl
new file mode 100644 (file)
index 0000000..34157e2
--- /dev/null
@@ -0,0 +1,37 @@
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "mrsub.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "mrsub.fullname" -}}
+{{- if .Values.fullnameOverride -}}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- if contains $name .Release.Name -}}
+{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "mrsub.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{- define "mrsub.configmapname" -}}
+  {{- $name := ( include "mrsub.fullname" . ) -}}
+  {{- printf "configmap-%s" $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-bin.yaml
new file mode 100644 (file)
index 0000000..b511a9e
--- /dev/null
@@ -0,0 +1,24 @@
+################################################################################
+#   Copyright (c) 2019 AT&T Intellectual Property.                             #
+#   Copyright (c) 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.                                             #
+################################################################################
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "mrsub.configmapname" . }}-bin
+data:
+  {{- (.Files.Glob "resources/mrsub.sh").AsConfig |nindent 2 }}
+
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/configmap-env.yaml
new file mode 100644 (file)
index 0000000..8f1d4de
--- /dev/null
@@ -0,0 +1,29 @@
+################################################################################
+#   Copyright (c) 2019 AT&T Intellectual Property.                             #
+#   Copyright (c) 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.                                             #
+################################################################################
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "mrsub.configmapname" . }}-env
+data:
+  {{- if .Values.mrsub.appenv }}
+    {{- toYaml .Values.mrsub.appenv | nindent 2 }}
+  {{- end }}
+  _MR_HOSTPORT: "{{ .Values.mrsub.mrhostport }}"
+  _MR_TOPIC: "{{ .Values.mrsub.mrtopic }}"
+  _LOGSTASH_URL: "{{ .Values.mrsub.logstashurl }}"
+
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/templates/deployment.yaml
new file mode 100644 (file)
index 0000000..022350d
--- /dev/null
@@ -0,0 +1,52 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "mrsub.fullname" . }}
+  labels:
+    app.kubernetes.io/name: {{ include "mrsub.name" . }}
+    helm.sh/chart: {{ include "mrsub.chart" . }}
+    app.kubernetes.io/instance: {{ .Release.Name }}
+    app.kubernetes.io/managed-by: {{ .Release.Service }}
+spec:
+  replicas: {{ .Values.replicaCount }}
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: {{ include "mrsub.name" . }}
+      app.kubernetes.io/instance: {{ .Release.Name }}
+  template:
+    metadata:
+      labels:
+        app.kubernetes.io/name: {{ include "mrsub.name" . }}
+        app.kubernetes.io/instance: {{ .Release.Name }}
+    spec:
+      containers:
+        - name: {{ .Chart.Name }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
+          imagePullPolicy: {{ .Values.image.pullPolicy }}
+          command: ["/scripts/mrsub.sh"]
+          #command: ["sleep"]
+          #args: ["3600"]
+          volumeMounts:
+            - mountPath: /scripts
+              name: script
+          envFrom:
+            - configMapRef:
+                name: {{ include "mrsub.configmapname" . }}-env
+      volumes:
+      - name: script
+        configMap:
+          name: {{ include "mrsub.configmapname" . }}-bin
+          defaultMode: 0744
+
+      {{- with .Values.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+    {{- with .Values.affinity }}
+      affinity:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+    {{- with .Values.tolerations }}
+      tolerations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
diff --git a/ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml b/ric-aux/80-Auxiliary-Functions/helm/mrsub/values.yaml
new file mode 100644 (file)
index 0000000..cb05a5c
--- /dev/null
@@ -0,0 +1,17 @@
+# Default values for mrsub.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+replicaCount: 1
+
+image:
+  repository: ubuntu
+  tag: 16.04
+  pullPolicy: IfNotPresent
+
+
+mrsub:
+  mrhostport: "10.1.0.26:30227"
+  mrtopic: "unauthenticated.SEC_MEASUREMENT_OUTPUT"
+  logstashurl: "http://192.168.130.77:8081/ves/ves"
+