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 err := c.RemoveSubscriptionFromSdl(uint32(subId))
44 xapp.Logger.Error("c.RemoveSubscriptionFromSdl failure: %s", err.Error())
50 // This can be used to remove all subscriptions db from
52 xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called")
53 err := c.RemoveAllSubscriptionsFromSdl()
55 xapp.Logger.Error("RemoveAllSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error())
57 err = c.RemoveAllRESTSubscriptionsFromSdl()
59 xapp.Logger.Error("RemoveAllRESTSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error())
64 // This is meant to cause submgr's restart in testing
66 xapp.Logger.Debug("os.Exit(1) called")
70 xapp.Logger.Debug("Unsupported rest command received %s", s)
73 //-------------------------------------------------------------------
75 //-------------------------------------------------------------------
76 func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) {
78 // Get all REST Subscriptions in subscription manager
79 xapp.Logger.Debug("GetAllRestSubscriptions() called")
80 _, err := w.Write(c.registry.GetAllRestSubscriptionsJson())
82 xapp.Logger.Error("GetAllRestSubscriptions() w.Write failure: %s", err.Error())
86 func (c *Control) GetAllE2Nodes(w http.ResponseWriter, r *http.Request) {
88 // Get all E2Nodes in subscription manager
89 xapp.Logger.Debug("GetAllE2Nodes() called")
90 _, err := w.Write(c.e2IfState.GetE2NodesJson())
92 xapp.Logger.Error("w.Write failure: %s", err.Error())
96 func (c *Control) GetAllE2NodeRestSubscriptions(w http.ResponseWriter, r *http.Request) {
97 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() called: Req= %v", r.URL.Path)
99 // Get all REST Subscriptions of a E2Node
100 pathParams := mux.Vars(r)
101 ranName := pathParams["ranName"]
102 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() ranName=%s", ranName)
104 _, err := w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName))
106 xapp.Logger.Error("GetAllE2NodeRestSubscriptions() w.Write failure: %s", err.Error())
109 xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() Invalid path %s", ranName)
110 w.WriteHeader(400) // Bad request
114 func (c *Control) GetAllXapps(w http.ResponseWriter, r *http.Request) {
116 // Get all xApps in subscription manager
117 xapp.Logger.Debug("GetAllXapps() called: Req= %v", r.URL.Path)
118 _, err := w.Write(c.registry.GetAllXappsJson())
120 xapp.Logger.Error("GetAllXapps() w.Write failure: %s", err.Error())
124 func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Request) {
125 xapp.Logger.Debug("GetAllXappRestSubscriptions() called")
127 // Get all REST Subscriptions of a xApp
128 pathParams := mux.Vars(r)
129 xappServiceName := pathParams["xappServiceName"]
130 xapp.Logger.Debug("GetAllXappRestSubscriptions() xappServiceName=%s", xappServiceName)
131 if xappServiceName != "" {
132 _, err := w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName))
134 xapp.Logger.Error("GetAllXappRestSubscriptions() w.Write failure: %s", err.Error())
137 xapp.Logger.Debug("GetAllXappRestSubscriptions() Invalid path %s", xappServiceName)
138 w.WriteHeader(400) // Bad request
142 func (c *Control) DeleteAllE2nodeSubscriptions(w http.ResponseWriter, r *http.Request) {
143 xapp.Logger.Debug("DeleteAllE2nodeSubscriptions() called: Req= %v", r.URL.Path)
145 // Delete all REST Subscriptions of a E2Node
146 pathParams := mux.Vars(r)
147 ranName := pathParams["ranName"]
148 xapp.Logger.Debug("DeleteE2nodeSubscriptions() ranName=%s", ranName)
150 w.WriteHeader(400) // Bad request
152 nbIds := c.e2IfState.GetAllE2Nodes()
153 ranName, ok := nbIds[ranName]
155 restSubscriptions := c.registry.GetAllE2NodeRestSubscriptions(ranName)
156 for restSubsId, _ := range restSubscriptions {
157 c.RESTSubscriptionDeleteHandler(restSubsId)
161 w.WriteHeader(404) // Not found
165 func (c *Control) DeleteAllXappSubscriptions(w http.ResponseWriter, r *http.Request) {
166 xapp.Logger.Debug("DeleteAllXappSubscriptions() called: Req= %v", r.URL.Path)
168 // Delete all REST Subscriptions of a xApp
169 pathParams := mux.Vars(r)
170 xappServiceName := pathParams["xappServiceName"]
171 xapp.Logger.Debug("DeleteAllXappSubscriptions() ranName=%s", xappServiceName)
172 if xappServiceName == "" {
173 w.WriteHeader(400) // Bad request
175 xapps := c.registry.GetAllXapps()
176 _, ok := xapps[xappServiceName]
178 XappRestSubscriptions := c.registry.GetAllXappRestSubscriptions(xappServiceName)
179 for restSubsId, _ := range XappRestSubscriptions {
180 c.RESTSubscriptionDeleteHandler(restSubsId)
184 w.WriteHeader(404) // Not found
186 w.WriteHeader(200) // OK
189 func (c *Control) GetE2Subscriptions(w http.ResponseWriter, r *http.Request) {
190 xapp.Logger.Debug("GetE2Subscriptions() called: Req= %v", r.URL.Path)
192 // Get all E2 subscriptions of a REST Subscription
193 pathParams := mux.Vars(r)
194 restId := pathParams["restId"]
195 xapp.Logger.Debug("GetE2Subscriptions(): restId=%s", restId)
197 w.WriteHeader(400) // Bad request
200 e2Subscriptions, err := c.registry.GetE2SubscriptionsJson(restId)
202 w.WriteHeader(404) // Not found
204 _, err := w.Write(e2Subscriptions)
206 xapp.Logger.Error("GetE2Subscriptions() w.Write failure: %s", err.Error())