Parse message names from xApp configMap
[ric-plt/appmgr.git] / cmd / appmgr / types.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package main
21
22 import (
23         "github.com/gorilla/mux"
24         cmap "github.com/orcaman/concurrent-map"
25         "net/http"
26 )
27
28 type CmdOptions struct {
29         hostAddr      *string
30         helmHost      *string
31         helmChartPath *string
32 }
33
34 type Resource struct {
35         Method      string
36         Url         string
37         HandlerFunc http.HandlerFunc
38 }
39
40 type Xapp struct {
41         Name      string         `json:"name"`
42         Status    string         `json:"status"`
43         Version   string         `json:"version"`
44         Instances []XappInstance `json:"instances"`
45 }
46
47 type XappInstance struct {
48         Name       string   `json:"name"`
49         Status     string   `json:"status"`
50         Ip         string   `json:"ip"`
51         Port       int      `json:"port"`
52         TxMessages []string `json:"txMessages"`
53         RxMessages []string `json:"rxMessages"`
54 }
55
56 type XappDeploy struct {
57         Name        string `json:"name"`
58         ConfigName  string `json:"configName, omitempty"`
59         Namespace   string `json:"namespace, omitempty"`
60         ServiceName string `json:"serviceName, omitempty"`
61         ImageRepo   string `json:"imageRepo, omitempty"`
62         Hostname    string `json:"hostname, omitempty"`
63 }
64
65 type XappManager struct {
66         router *mux.Router
67         helm   Helmer
68         cm     ConfigMapper
69         sd     SubscriptionDispatcher
70         opts   CmdOptions
71         ready  bool
72 }
73
74 type ConfigMapper interface {
75         UploadConfig() (cfg []XAppConfig)
76         GetConfigMap(m XappDeploy, c *interface{}) (err error)
77         CreateConfigMap(r XAppConfig) (errList []CMError, err error)
78         UpdateConfigMap(r XAppConfig) (errList []CMError, err error)
79         DeleteConfigMap(r XAppConfig) (cm interface{}, err error)
80         PurgeConfigMap(m XappDeploy) (cm interface{}, err error)
81         RestoreConfigMap(m XappDeploy, cm interface{}) (err error)
82         ReadConfigMap(name string, ns string, c *interface{}) (err error)
83         ApplyConfigMap(r XAppConfig, action string) (err error)
84         GetMessages(name string) (msgs MessageTypes)
85 }
86
87 type Helmer interface {
88         SetCM(ConfigMapper)
89         Initialize()
90         Install(m XappDeploy) (xapp Xapp, err error)
91         Status(name string) (xapp Xapp, err error)
92         StatusAll() (xapps []Xapp, err error)
93         List() (xapps []string, err error)
94         Delete(name string) (xapp Xapp, err error)
95 }
96
97 type Helm struct {
98         host      string
99         chartPath string
100         initDone  bool
101         cm        ConfigMapper
102 }
103
104 type SubscriptionReq struct {
105         Id         string `json:"id"`
106         TargetUrl  string `json:"targetUrl"`
107         EventType  string `json:"eventType"`
108         MaxRetries int    `json:"maxRetries"`
109         RetryTimer int    `json:"retryTimer"`
110 }
111
112 type SubscriptionResp struct {
113         Id        string `json:"id"`
114         Version   int    `json:"version"`
115         EventType string `json:"eventType"`
116 }
117
118 type SubscriptionNotif struct {
119         Id        string `json:"id"`
120         Version   int    `json:"version"`
121         EventType string `json:"eventType"`
122         XappData  []Xapp `json:"xapp"`
123 }
124
125 type Subscription struct {
126         req  SubscriptionReq
127         resp SubscriptionResp
128 }
129
130 type SubscriptionDispatcher struct {
131         client        *http.Client
132         subscriptions cmap.ConcurrentMap
133         db            *DB
134         Seq           int
135 }
136
137 type MessageTypes struct {
138         TxMessages []string `json:"txMessages"`
139         RxMessages []string `json:"rxMessages"`
140 }
141
142 type EventType string
143
144 const (
145         Created EventType = "created"
146         Updated EventType = "updated"
147         Deleted EventType = "deleted"
148 )
149
150 const (
151         MdclogErr   = 1 //! Error level log entry
152         MdclogWarn  = 2 //! Warning level log entry
153         MdclogInfo  = 3 //! Info level log entry
154         MdclogDebug = 4 //! Debug level log entry
155 )