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