2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
20 package org.oransc.ric.portal.dashboard.controller;
22 import java.lang.invoke.MethodHandles;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.oransc.ric.portal.dashboard.DashboardApplication;
27 import org.oransc.ric.portal.dashboard.DashboardConstants;
28 import org.oransc.ric.portal.dashboard.config.E2ManagerApiBuilder;
29 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
30 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
31 import org.oransc.ricplt.e2mgr.client.api.HealthCheckApi;
32 import org.oransc.ricplt.e2mgr.client.api.NodebApi;
33 import org.oransc.ricplt.e2mgr.client.model.GetNodebResponse;
34 import org.oransc.ricplt.e2mgr.client.model.NodebIdentity;
35 import org.oransc.ricplt.e2mgr.client.model.ResetRequest;
36 import org.oransc.ricplt.e2mgr.client.model.SetupRequest;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.Configuration;
41 import org.springframework.http.MediaType;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.security.access.annotation.Secured;
44 import org.springframework.util.Assert;
45 import org.springframework.web.bind.annotation.GetMapping;
46 import org.springframework.web.bind.annotation.PathVariable;
47 import org.springframework.web.bind.annotation.PostMapping;
48 import org.springframework.web.bind.annotation.PutMapping;
49 import org.springframework.web.bind.annotation.RequestBody;
50 import org.springframework.web.bind.annotation.RequestMapping;
51 import org.springframework.web.bind.annotation.RestController;
52 import org.springframework.web.client.HttpStatusCodeException;
54 import io.swagger.annotations.ApiOperation;
57 * Proxies calls from the front end to the E2 Manager API.
59 * If a method throws RestClientResponseException, it is handled by
60 * {@link CustomResponseEntityExceptionHandler#handleProxyMethodException(Exception, org.springframework.web.context.request.WebRequest)}
61 * which returns status 502. All other exceptions are handled by Spring which
66 @RequestMapping(value = E2ManagerController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
67 public class E2ManagerController {
69 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
71 // Publish paths in constants for tests
72 public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr";
74 public static final String HEALTH_METHOD = "health";
75 // Keep these consistent with the E2M implementation
76 /* package */ static final String NODEB_PREFIX = "nodeb";
77 public static final String RAN_METHOD = NODEB_PREFIX + "/ran";
78 public static final String NODEB_SHUTDOWN_METHOD = NODEB_PREFIX + "/shutdown";
79 public static final String NODEB_LIST_METHOD = NODEB_PREFIX + "/ids";
80 public static final String ENDC_SETUP_METHOD = NODEB_PREFIX + "/endc-setup";
81 public static final String X2_SETUP_METHOD = NODEB_PREFIX + "/x2-setup";
82 // Reset uses prefix, adds a path parameter below
83 public static final String RESET_METHOD = "reset";
85 private static final String PP_RANNAME = "ranName";
87 // Populated by the autowired constructor
88 private final E2ManagerApiBuilder e2ManagerApiBuilder;
91 public E2ManagerController(final E2ManagerApiBuilder e2ManagerApiBuilder) {
92 Assert.notNull(e2ManagerApiBuilder, "builder must not be null");
93 this.e2ManagerApiBuilder = e2ManagerApiBuilder;
94 if (logger.isDebugEnabled())
95 logger.debug("ctor: configured with builder type {}", e2ManagerApiBuilder.getClass().getName());
98 @ApiOperation(value = "Gets the E2 manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
99 @GetMapping(DashboardConstants.VERSION_METHOD)
101 public SuccessTransport getClientVersion() {
102 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthCheckApi.class));
105 @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.")
106 @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + HEALTH_METHOD)
108 public ResponseEntity<String> healthGet(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey) {
109 logger.debug("healthGet instance {}", instanceKey);
110 HealthCheckApi api = e2ManagerApiBuilder.getHealthCheckApi(instanceKey);
112 return ResponseEntity.status(api.getApiClient().getStatusCode().value()).body(null);
115 // This calls other methods to simplify the task of the front-end.
116 @ApiOperation(value = "Gets all RAN identities and statuses from the E2 manager.", response = RanDetailsTransport.class, responseContainer = "List")
117 @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + RAN_METHOD)
118 @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
119 public List<RanDetailsTransport> getRanDetails(
120 @PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey) {
121 logger.debug("getRanDetails instance {}", instanceKey);
122 NodebApi api = e2ManagerApiBuilder.getNodebApi(instanceKey);
123 List<NodebIdentity> nodebIdList = api.getNodebIdList();
124 logger.debug("getRanDetails: nodebIdList {}", nodebIdList);
125 List<RanDetailsTransport> details = new ArrayList<>();
126 for (NodebIdentity nbid : nodebIdList) {
127 GetNodebResponse nbResp = null;
129 // Catch exceptions to keep looping despite failures
130 nbResp = api.getNb(nbid.getInventoryName());
131 } catch (HttpStatusCodeException ex) {
132 logger.warn("E2 getNb failed for name {}: {}", nbid.getInventoryName(), ex.toString());
133 nbResp = new GetNodebResponse().connectionStatus("UNKNOWN").ip("UNKNOWN").port(-1)
134 .ranName(nbid.getInventoryName());
136 details.add(new RanDetailsTransport(nbid, nbResp));
141 @ApiOperation(value = "Get RAN identities list.", response = NodebIdentity.class, responseContainer = "List")
142 @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/"
144 @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
145 public List<NodebIdentity> getNodebIdList(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey) {
146 logger.debug("getNodebIdList instance {}", instanceKey);
147 return e2ManagerApiBuilder.getNodebApi(instanceKey).getNodebIdList();
150 @ApiOperation(value = "Get RAN by name.", response = GetNodebResponse.class)
151 @GetMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + NODEB_PREFIX
152 + "/{" + PP_RANNAME + "}")
153 @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
154 public GetNodebResponse getNb(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
155 @PathVariable(PP_RANNAME) String ranName) {
156 logger.debug("getNb instance {} name {}", instanceKey, ranName);
157 return e2ManagerApiBuilder.getNodebApi(instanceKey).getNb(ranName);
160 @ApiOperation(value = "Sets up an EN-DC RAN connection via the E2 manager.")
161 @PostMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/"
163 @Secured({ DashboardConstants.ROLE_ADMIN })
164 public ResponseEntity<String> endcSetup(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
165 @RequestBody SetupRequest setupRequest) {
166 logger.debug("endcSetup instance {} request {}", instanceKey, setupRequest);
167 NodebApi api = e2ManagerApiBuilder.getNodebApi(instanceKey);
168 api.endcSetup(setupRequest);
169 return ResponseEntity.status(api.getApiClient().getStatusCode().value()).body(null);
172 @ApiOperation(value = "Sets up an X2 RAN connection via the E2 manager.")
173 @PostMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/"
175 @Secured({ DashboardConstants.ROLE_ADMIN })
176 public ResponseEntity<String> x2Setup(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
177 @RequestBody SetupRequest setupRequest) {
178 logger.debug("x2Setup instance {} request {}", instanceKey, setupRequest);
179 NodebApi api = e2ManagerApiBuilder.getNodebApi(instanceKey);
180 api.x2Setup(setupRequest);
181 return ResponseEntity.status(api.getApiClient().getStatusCode().value()).body(null);
184 @ApiOperation(value = "Close all connections to the RANs and delete the data from the nodeb-rnib DB.")
185 @PutMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/"
186 + NODEB_SHUTDOWN_METHOD)
187 @Secured({ DashboardConstants.ROLE_ADMIN })
188 public ResponseEntity<String> nodebShutdownPut(
189 @PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey) {
190 logger.debug("nodebShutdownPut instance {}", instanceKey);
191 NodebApi api = e2ManagerApiBuilder.getNodebApi(instanceKey);
192 api.nodebShutdownPut();
193 return ResponseEntity.status(api.getApiClient().getStatusCode().value()).body(null);
197 @ApiOperation(value = "Abort any other ongoing procedures over X2 between the RIC and the RAN.")
198 @PutMapping(DashboardConstants.RIC_INSTANCE_KEY + "/{" + DashboardConstants.RIC_INSTANCE_KEY + "}/" + NODEB_PREFIX
199 + "/{" + PP_RANNAME + "}/" + RESET_METHOD)
200 @Secured({ DashboardConstants.ROLE_ADMIN })
201 public ResponseEntity<String> reset(@PathVariable(DashboardConstants.RIC_INSTANCE_KEY) String instanceKey,
202 @PathVariable(PP_RANNAME) String ranName, @RequestBody ResetRequest resetRequest) {
203 logger.debug("reset instance {} name {}", instanceKey, ranName);
204 NodebApi api = e2ManagerApiBuilder.getNodebApi(instanceKey);
205 api.reset(ranName, resetRequest);
206 return ResponseEntity.status(api.getApiClient().getStatusCode().value()).body(null);