Update RMR version v4.4.6
[ric-plt/vespamgr.git] / cmd / vespamgr / types.go
1 /*
2  *  Copyright (c) 2019 AT&T Intellectual Property.
3  *  Copyright (c) 2018-2019 Nokia.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18  *  platform project (RICP).
19  *
20  */
21
22 package main
23
24 import (
25         "time"
26 )
27
28 type VespaMgr struct {
29         rmrReady             bool
30         vesAgent             *CommandRunner
31         chVesagent           chan error
32         appmgrHost           string
33         appmgrUrl            string
34         appmgrNotifUrl       string
35         appmgrSubsUrl        string
36         appmgrRetry          int
37         hbInterval           string
38         measInterval         string
39         prometheusAddr       string
40         alertManagerBindAddr string
41         subscriptionId       string
42         pltFileCreated       bool
43 }
44
45 // Structs are copied from https://github.com/nokia/ONAP-VESPA/tree/master/ves-agent/config
46 // and from https://github.com/nokia/ONAP-VESPA/blob/master/govel/config.go
47 // Using tag v0.3.0
48
49 // HeartbeatConfiguration parameters
50 type HeartbeatConfiguration struct {
51         DefaultInterval time.Duration `yaml:"defaultInterval"`
52 }
53
54 // Label represents a VES field by it's name, with an expression
55 // for getting its value
56 type Label struct {
57         Name string `yaml:"name"`
58         Expr string `yaml:"expr"`
59 }
60
61 // MetricRule defines how to retrieve metrics and map them
62 // into a list of evel.EventMeasurement struct
63 type MetricRule struct {
64         Target         string  `yaml:"target"`          // Target VES event field
65         Expr           string  `yaml:"expr"`            // Prometheus query expression
66         VMIDLabel      string  `yaml:"vmId"`            // Metric label holding the VNF ID
67         Labels         []Label `yaml:"labels"`          // Set of VES fields to map to values of given label
68         ObjectName     string  `yaml:"object_name"`     // JSON Object Name
69         ObjectInstance string  `yaml:"object_instance"` // JSON Object instance
70         ObjectKeys     []Label `yaml:"object_keys"`     // JSON Object keys
71 }
72
73 // MetricRules defines a list of rules, and defaults values for them
74 type MetricRules struct {
75         DefaultValues *MetricRule  `yaml:"defaults"` // Default rules to apply (except for expr), labels are merged
76         Metrics       []MetricRule `yaml:"metrics"`  // List of query and mapping of rules
77 }
78
79 // PrometheusConfig parameters
80 type PrometheusConfig struct {
81         Address   string        `yaml:"address"`   // Base URL to prometheus API
82         Timeout   time.Duration `yaml:"timeout"`   // API request timeout
83         KeepAlive time.Duration `yaml:"keepalive"` // HTTP Keep-Alive
84         Rules     MetricRules   `yaml:"rules"`     // Querying rules
85 }
86
87 // MeasurementConfiguration parameters
88 type MeasurementConfiguration struct {
89         DomainAbbreviation   string           `yaml:"domainAbbreviation"`   // "Measurement" or "Mfvs"
90         DefaultInterval      time.Duration    `yaml:"defaultInterval"`      // Default measurement interval
91         MaxBufferingDuration time.Duration    `yaml:"maxBufferingDuration"` // Maximum timeframe size of buffering
92         Prometheus           PrometheusConfig `yaml:"prometheus"`           // Prometheus configuration
93 }
94
95 // CollectorConfiguration parameters
96 type CollectorConfiguration struct {
97         ServerRoot string `yaml:"serverRoot"`
98         FQDN       string `yaml:"fqdn"`
99         Port       int    `yaml:"port"`
100         Secure     bool   `yaml:"secure"`
101         Topic      string `yaml:"topic"`
102         User       string `yaml:"user"`
103         Password   string `yaml:"password"`
104         PassPhrase string `yaml:"passphrase,omitempty"` // passPhrase used to encrypt collector password in file
105 }
106
107 //NfcNamingCode mapping bettween NfcNamingCode (oam or etl) and Vnfcs
108 type NfcNamingCode struct {
109         Type  string   `yaml:"type"`
110         Vnfcs []string `yaml:"vnfcs"`
111 }
112
113 // EventConfiguration parameters
114 type EventConfiguration struct {
115         VNFName             string          `yaml:"vnfName"`             // Name of this VNF, eg: dpa2bhsxp5001v
116         ReportingEntityName string          `yaml:"reportingEntityName"` // Value of reporting entity field. Usually local VM (VNFC) name
117         ReportingEntityID   string          `yaml:"reportingEntityID"`   // Value of reporting entity UUID. Usually local VM (VNFC) UUID
118         MaxSize             int             `yaml:"maxSize"`
119         NfNamingCode        string          `yaml:"nfNamingCode,omitempty"` // "hspx"
120         NfcNamingCodes      []NfcNamingCode `yaml:"nfcNamingCodes,omitempty"`
121         RetryInterval       time.Duration   `yaml:"retryInterval,omitempty"`
122         MaxMissed           int             `yaml:"maxMissed,omitempty"`
123 }
124
125 // VESAgentConfiguration parameters
126 type VESAgentConfiguration struct {
127         PrimaryCollector CollectorConfiguration   `yaml:"primaryCollector"`
128         Heartbeat        HeartbeatConfiguration   `yaml:"heartbeat,omitempty"`
129         Measurement      MeasurementConfiguration `yaml:"measurement,omitempty"`
130         Event            EventConfiguration       `yaml:"event,omitempty"`
131         Debug            bool                     `yaml:"debug,omitempty"`
132         CaCert           string                   `yaml:"caCert,omitempty"` // Root certificate content
133         DataDir          string                   `yaml:"datadir"`          // Path to directory containing data
134 }
135
136 // AppMetricsStruct contains xapplication metrics definition
137 type AppMetricsStruct struct {
138         MoId           string
139         MeasType       string
140         MeasId         string
141         MeasInterval   string
142         ObjectName     string
143         ObjectInstance string
144         CounterId      string
145 }
146
147 // AppMetrics contains metrics definitions for all Xapps
148 type AppMetrics map[string]AppMetricsStruct
149
150 var Version string
151 var Hash string