Revert "Support for XApp configuration update"
[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         ConfigName string         `json:"configName, omitempty"`
43         Namespace  string         `json:"namespace, omitempty"`
44         Status     string         `json:"status"`
45         Version    string         `json:"version"`
46         Instances  []XappInstance `json:"instances"`
47 }
48
49 type XappInstance struct {
50         Name       string   `json:"name"`
51         Status     string   `json:"status"`
52         Ip         string   `json:"ip"`
53         Port       int      `json:"port"`
54         TxMessages []string `json:"txMessages"`
55         RxMessages []string `json:"rxMessages"`
56 }
57
58 type XappManager struct {
59         router *mux.Router
60         helm   Helmer
61         sd     SubscriptionDispatcher
62         opts   CmdOptions
63         ready  bool
64 }
65
66 type Helmer interface {
67         Initialize()
68         Install(m ConfigMetadata) (xapp Xapp, err error)
69         Status(name string) (xapp Xapp, err error)
70         StatusAll() (xapps []Xapp, err error)
71         List() (xapps []string, err error)
72         Delete(name string) (xapp Xapp, err error)
73 }
74
75 type Helm struct {
76         host      string
77         chartPath string
78         initDone  bool
79 }
80
81 type SubscriptionReq struct {
82         Id         string `json:"id"`
83         TargetUrl  string `json:"targetUrl"`
84         EventType  string `json:"eventType"`
85         MaxRetries int    `json:"maxRetries"`
86         RetryTimer int    `json:"retryTimer"`
87 }
88
89 type SubscriptionResp struct {
90         Id        string `json:"id"`
91         Version   int    `json:"version"`
92         EventType string `json:"eventType"`
93 }
94
95 type SubscriptionNotif struct {
96         Id        string `json:"id"`
97         Version   int    `json:"version"`
98         EventType string `json:"eventType"`
99         XappData  []Xapp `json:"xapp"`
100 }
101
102 type Subscription struct {
103         req  SubscriptionReq
104         resp SubscriptionResp
105 }
106
107 type SubscriptionDispatcher struct {
108         client        *http.Client
109         subscriptions cmap.ConcurrentMap
110         db            *DB
111         Seq           int
112 }
113
114 type MessageTypes struct {
115         TxMessages []string `yaml:"txMessages"`
116         RxMessages []string `yaml:"rxMessages"`
117 }
118
119 type EventType string
120
121 const (
122         Created EventType = "created"
123         Updated EventType = "updated"
124         Deleted EventType = "deleted"
125 )
126
127 const (
128         MdclogErr   = 1 //! Error level log entry
129         MdclogWarn  = 2 //! Warning level log entry
130         MdclogInfo  = 3 //! Info level log entry
131         MdclogDebug = 4 //! Debug level log entry
132 )