2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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.HashSet;
26 import javax.servlet.http.HttpServletResponse;
28 import org.oransc.ric.e2mgr.client.api.HealthCheckApi;
29 import org.oransc.ric.e2mgr.client.api.NodebApi;
30 import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
31 import org.oransc.ric.e2mgr.client.model.SetupRequest;
32 import org.oransc.ric.portal.dashboard.DashboardApplication;
33 import org.oransc.ric.portal.dashboard.DashboardConstants;
34 import org.oransc.ric.portal.dashboard.model.E2SetupRequestType;
35 import org.oransc.ric.portal.dashboard.model.E2SetupResponse;
36 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
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.util.Assert;
44 import org.springframework.web.bind.annotation.PathVariable;
45 import org.springframework.web.bind.annotation.RequestBody;
46 import org.springframework.web.bind.annotation.RequestMapping;
47 import org.springframework.web.bind.annotation.RequestMethod;
48 import org.springframework.web.bind.annotation.RestController;
49 import org.springframework.web.client.HttpStatusCodeException;
51 import io.swagger.annotations.ApiOperation;
54 * Proxies calls from the front end to the E2 Manager API. All methods answer
55 * 502 on failure: <blockquote>HTTP server received an invalid response from a
56 * server it consulted when acting as a proxy or gateway.</blockquote>
58 * As of this writing the E2 interface does not support get-all, so this class
59 * mocks up some of that functionality.
63 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE)
64 public class E2ManagerController {
66 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
69 private static final String PP_RANNAME = "ranName";
71 // Populated by the autowired constructor
72 private final HealthCheckApi e2HealthCheckApi;
73 private final NodebApi e2NodebApi;
75 // Stores the requests and results.
76 // TODO remove when the E2 manager is extended.
77 private Set<E2SetupResponse> responses = new HashSet<>();
80 public E2ManagerController(final HealthCheckApi e2HealthCheckApi, final NodebApi e2NodebApi) {
81 Assert.notNull(e2HealthCheckApi, "API must not be null");
82 Assert.notNull(e2NodebApi, "API must not be null");
83 this.e2HealthCheckApi = e2HealthCheckApi;
84 this.e2NodebApi = e2NodebApi;
87 private void assertNotNull(Object o) {
89 throw new IllegalArgumentException("Null not permitted");
92 private void assertNotEmpty(String s) {
95 throw new IllegalArgumentException("Empty not permitted");
98 @ApiOperation(value = "Gets the E2 manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
99 @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
100 public SuccessTransport getE2ManagerClientVersion() {
101 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthCheckApi.class));
104 @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.")
105 @RequestMapping(value = "/health", method = RequestMethod.GET)
106 public Object healthGet(HttpServletResponse response) {
107 logger.debug("healthGet");
109 e2HealthCheckApi.healthGet();
110 response.setStatus(e2HealthCheckApi.getApiClient().getStatusCode().value());
112 } catch (HttpStatusCodeException ex) {
113 logger.warn("healthGet failed: {}", ex.toString());
114 return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString());
118 // TODO replace with actual functionality
119 @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = E2SetupResponse.class, responseContainer = "List")
120 @RequestMapping(value = "/setup", method = RequestMethod.GET)
121 public Iterable<E2SetupResponse> getRequests() {
122 logger.debug("getRequests");
126 @ApiOperation(value = "Get RAN by name.", response = GetNodebResponse.class)
127 @RequestMapping(value = "/nodeb/{" + PP_RANNAME + "}", method = RequestMethod.GET)
128 public Object getNb(@PathVariable(PP_RANNAME) String ranName) {
129 logger.debug("getNb {}", ranName);
131 return e2NodebApi.getNb(ranName);
132 } catch (HttpStatusCodeException ex) {
133 logger.warn("getNb failed: {}", ex.toString());
134 return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString());
138 // TODO replace with actual functionality
139 @ApiOperation(value = "Disconnect all RAN Connections.")
140 @RequestMapping(value = "/disconnectAllRAN", method = RequestMethod.DELETE)
141 public void disconnectAllRANConnections() {
142 logger.debug("disconnectAllRANConnections");
146 @ApiOperation(value = "Sets up an EN-DC RAN connection via the E2 manager.", response = E2SetupResponse.class)
147 @RequestMapping(value = "/endcSetup", method = RequestMethod.POST)
148 public Object endcSetup(@RequestBody SetupRequest setupRequest) {
149 logger.debug("endcSetup {}", setupRequest);
151 assertNotEmpty(setupRequest.getRanIp());
152 assertNotEmpty(setupRequest.getRanName());
153 assertNotNull(setupRequest.getRanPort());
154 } catch (Exception ex) {
155 return new E2SetupResponse(E2SetupRequestType.ENDC, setupRequest, HttpServletResponse.SC_BAD_REQUEST);
158 e2NodebApi.endcSetup(setupRequest);
159 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.ENDC, setupRequest,
160 e2NodebApi.getApiClient().getStatusCode().value());
163 } catch (HttpStatusCodeException ex) {
164 logger.warn("endcSetup failed: {}", ex.toString());
165 return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString());
169 @ApiOperation(value = "Sets up an X2 RAN connection via the E2 manager.", response = E2SetupResponse.class)
170 @RequestMapping(value = "/x2Setup", method = RequestMethod.POST)
171 public Object x2Setup(@RequestBody SetupRequest setupRequest) {
172 logger.debug("x2Setup {}", setupRequest);
174 assertNotEmpty(setupRequest.getRanIp());
175 assertNotEmpty(setupRequest.getRanName());
176 assertNotNull(setupRequest.getRanPort());
177 } catch (Exception ex) {
178 return new E2SetupResponse(E2SetupRequestType.ENDC, setupRequest, HttpServletResponse.SC_BAD_REQUEST);
181 e2NodebApi.x2Setup(setupRequest);
182 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.X2, setupRequest,
183 e2NodebApi.getApiClient().getStatusCode().value());
186 } catch (HttpStatusCodeException ex) {
187 logger.warn("x2Setup failed: {}", ex.toString());
188 return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString());