2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
24 "github.com/gorilla/mux"
31 func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) {
32 xapp.Logger.Debug("RESTTestRestHandler() called")
34 pathParams := mux.Vars(r)
35 s := pathParams["testId"]
37 // This can be used to delete single subscription from db
38 if contains := strings.Contains(s, "deletesubid="); contains == true {
39 var splits = strings.Split(s, "=")
40 if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil {
41 xapp.Logger.Debug("RemoveSubscriptionFromSdl() called. subId = %v", subId)
42 c.RemoveSubscriptionFromSdl(uint32(subId))
47 // This can be used to remove all subscriptions db from
49 xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called")
50 c.RemoveAllSubscriptionsFromSdl()
51 c.RemoveAllRESTSubscriptionsFromSdl()
55 // This is meant to cause submgr's restart in testing
57 xapp.Logger.Debug("os.Exit(1) called")
61 xapp.Logger.Debug("Unsupported rest command received %s", s)
64 //-------------------------------------------------------------------
66 //-------------------------------------------------------------------
67 func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) {
69 // Get all REST Subscriptions in subscription manager
70 xapp.Logger.Debug("GetAllRestSubscriptions() called")
71 w.Write(c.registry.GetAllRestSubscriptionsJson())
74 func (c *Control) GetAllE2Nodes(w http.ResponseWriter, r *http.Request) {
76 // Get all E2Nodes in subscription manager
77 xapp.Logger.Debug("GetAllE2Nodes() called")
78 w.Write(c.e2IfState.GetE2NodesJson())
81 func (c *Control) GetAllE2NodeRestSubscriptions(w http.ResponseWriter, r *http.Request) {
82 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() called: Req= %v", r.URL.Path)
84 // Get all REST Subscriptions of a E2Node
85 pathParams := mux.Vars(r)
86 ranName := pathParams["ranName"]
87 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() ranName=%s", ranName)
89 w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName))
91 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() Invalid path %s", ranName)
92 w.WriteHeader(400) // Bad request
96 func (c *Control) GetAllXapps(w http.ResponseWriter, r *http.Request) {
98 // Get all xApps in subscription manager
99 xapp.Logger.Debug("GetAllXapps() called: Req= %v", r.URL.Path)
100 w.Write(c.registry.GetAllXappsJson())
103 func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Request) {
104 xapp.Logger.Debug("GetAllXappRestSubscriptions() called")
106 // Get all REST Subscriptions of a xApp
107 pathParams := mux.Vars(r)
108 xappServiceName := pathParams["xappServiceName"]
109 xapp.Logger.Debug("GetAllXappRestSubscriptions() xappServiceName=%s", xappServiceName)
110 if xappServiceName != "" {
111 w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName))
113 xapp.Logger.Debug("GetAllXappRestSubscriptions() Invalid path %s", xappServiceName)
114 w.WriteHeader(400) // Bad request
118 func (c *Control) DeleteAllE2nodeSubscriptions(w http.ResponseWriter, r *http.Request) {
119 xapp.Logger.Debug("DeleteAllE2nodeSubscriptions() called: Req= %v", r.URL.Path)
121 // Delete all REST Subscriptions of a E2Node
122 pathParams := mux.Vars(r)
123 ranName := pathParams["ranName"]
124 xapp.Logger.Debug("DeleteE2nodeSubscriptions() ranName=%s", ranName)
126 w.WriteHeader(400) // Bad request
128 nbIds := c.e2IfState.GetAllE2Nodes()
129 ranName, ok := nbIds[ranName]
131 restSubscriptions := c.registry.GetAllE2NodeRestSubscriptions(ranName)
132 for restSubsId, _ := range restSubscriptions {
133 c.RESTSubscriptionDeleteHandler(restSubsId)
137 w.WriteHeader(404) // Not found
141 func (c *Control) DeleteAllXappSubscriptions(w http.ResponseWriter, r *http.Request) {
142 xapp.Logger.Debug("DeleteAllXappSubscriptions() called: Req= %v", r.URL.Path)
144 // Delete all REST Subscriptions of a xApp
145 pathParams := mux.Vars(r)
146 xappServiceName := pathParams["xappServiceName"]
147 xapp.Logger.Debug("DeleteAllXappSubscriptions() ranName=%s", xappServiceName)
148 if xappServiceName == "" {
149 w.WriteHeader(400) // Bad request
151 xapps := c.registry.GetAllXapps()
152 _, ok := xapps[xappServiceName]
154 XappRestSubscriptions := c.registry.GetAllXappRestSubscriptions(xappServiceName)
155 for restSubsId, _ := range XappRestSubscriptions {
156 c.RESTSubscriptionDeleteHandler(restSubsId)
160 w.WriteHeader(404) // Not found
162 w.WriteHeader(200) // OK
165 func (c *Control) GetE2Subscriptions(w http.ResponseWriter, r *http.Request) {
166 xapp.Logger.Debug("GetE2Subscriptions() called: Req= %v", r.URL.Path)
168 // Get all E2 subscriptions of a REST Subscription
169 pathParams := mux.Vars(r)
170 restId := pathParams["restId"]
171 xapp.Logger.Debug("GetE2Subscriptions(): restId=%s", restId)
173 w.WriteHeader(400) // Bad request
176 e2Subscriptions, err := c.registry.GetE2SubscriptionsJson(restId)
178 w.WriteHeader(404) // Not found
180 w.Write(e2Subscriptions)