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