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 err := c.RemoveAllSubscriptionsFromSdl()
52 xapp.Logger.Error("RemoveAllSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error())
54 err = c.RemoveAllRESTSubscriptionsFromSdl()
56 xapp.Logger.Error("RemoveAllRESTSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error())
61 // This is meant to cause submgr's restart in testing
63 xapp.Logger.Debug("os.Exit(1) called")
67 xapp.Logger.Debug("Unsupported rest command received %s", s)
70 //-------------------------------------------------------------------
72 //-------------------------------------------------------------------
73 func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) {
75 // Get all REST Subscriptions in subscription manager
76 xapp.Logger.Debug("GetAllRestSubscriptions() called")
77 _, err := w.Write(c.registry.GetAllRestSubscriptionsJson())
79 xapp.Logger.Error("GetAllRestSubscriptions() w.Write failure: %s", err.Error())
83 func (c *Control) GetAllE2Nodes(w http.ResponseWriter, r *http.Request) {
85 // Get all E2Nodes in subscription manager
86 xapp.Logger.Debug("GetAllE2Nodes() called")
87 w.Write(c.e2IfState.GetE2NodesJson())
90 func (c *Control) GetAllE2NodeRestSubscriptions(w http.ResponseWriter, r *http.Request) {
91 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() called: Req= %v", r.URL.Path)
93 // Get all REST Subscriptions of a E2Node
94 pathParams := mux.Vars(r)
95 ranName := pathParams["ranName"]
96 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() ranName=%s", ranName)
98 _, err := w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName))
100 xapp.Logger.Error("GetAllE2NodeRestSubscriptions() w.Write failure: %s", err.Error())
103 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() Invalid path %s", ranName)
104 w.WriteHeader(400) // Bad request
108 func (c *Control) GetAllXapps(w http.ResponseWriter, r *http.Request) {
110 // Get all xApps in subscription manager
111 xapp.Logger.Debug("GetAllXapps() called: Req= %v", r.URL.Path)
112 _, err := w.Write(c.registry.GetAllXappsJson())
114 xapp.Logger.Error("GetAllXapps() w.Write failure: %s", err.Error())
118 func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Request) {
119 xapp.Logger.Debug("GetAllXappRestSubscriptions() called")
121 // Get all REST Subscriptions of a xApp
122 pathParams := mux.Vars(r)
123 xappServiceName := pathParams["xappServiceName"]
124 xapp.Logger.Debug("GetAllXappRestSubscriptions() xappServiceName=%s", xappServiceName)
125 if xappServiceName != "" {
126 _, err := w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName))
128 xapp.Logger.Error("GetAllXappRestSubscriptions() w.Write failure: %s", err.Error())
131 xapp.Logger.Debug("GetAllXappRestSubscriptions() Invalid path %s", xappServiceName)
132 w.WriteHeader(400) // Bad request
136 func (c *Control) DeleteAllE2nodeSubscriptions(w http.ResponseWriter, r *http.Request) {
137 xapp.Logger.Debug("DeleteAllE2nodeSubscriptions() called: Req= %v", r.URL.Path)
139 // Delete all REST Subscriptions of a E2Node
140 pathParams := mux.Vars(r)
141 ranName := pathParams["ranName"]
142 xapp.Logger.Debug("DeleteE2nodeSubscriptions() ranName=%s", ranName)
144 w.WriteHeader(400) // Bad request
146 nbIds := c.e2IfState.GetAllE2Nodes()
147 ranName, ok := nbIds[ranName]
149 restSubscriptions := c.registry.GetAllE2NodeRestSubscriptions(ranName)
150 for restSubsId, _ := range restSubscriptions {
151 c.RESTSubscriptionDeleteHandler(restSubsId)
155 w.WriteHeader(404) // Not found
159 func (c *Control) DeleteAllXappSubscriptions(w http.ResponseWriter, r *http.Request) {
160 xapp.Logger.Debug("DeleteAllXappSubscriptions() called: Req= %v", r.URL.Path)
162 // Delete all REST Subscriptions of a xApp
163 pathParams := mux.Vars(r)
164 xappServiceName := pathParams["xappServiceName"]
165 xapp.Logger.Debug("DeleteAllXappSubscriptions() ranName=%s", xappServiceName)
166 if xappServiceName == "" {
167 w.WriteHeader(400) // Bad request
169 xapps := c.registry.GetAllXapps()
170 _, ok := xapps[xappServiceName]
172 XappRestSubscriptions := c.registry.GetAllXappRestSubscriptions(xappServiceName)
173 for restSubsId, _ := range XappRestSubscriptions {
174 c.RESTSubscriptionDeleteHandler(restSubsId)
178 w.WriteHeader(404) // Not found
180 w.WriteHeader(200) // OK
183 func (c *Control) GetE2Subscriptions(w http.ResponseWriter, r *http.Request) {
184 xapp.Logger.Debug("GetE2Subscriptions() called: Req= %v", r.URL.Path)
186 // Get all E2 subscriptions of a REST Subscription
187 pathParams := mux.Vars(r)
188 restId := pathParams["restId"]
189 xapp.Logger.Debug("GetE2Subscriptions(): restId=%s", restId)
191 w.WriteHeader(400) // Bad request
194 e2Subscriptions, err := c.registry.GetE2SubscriptionsJson(restId)
196 w.WriteHeader(404) // Not found
198 _, err := w.Write(e2Subscriptions)
200 xapp.Logger.Error("GetE2Subscriptions() w.Write failure: %s", err.Error())