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.SetupRequest;
31 import org.oransc.ric.portal.dashboard.DashboardApplication;
32 import org.oransc.ric.portal.dashboard.DashboardConstants;
33 import org.oransc.ric.portal.dashboard.model.E2SetupRequestType;
34 import org.oransc.ric.portal.dashboard.model.E2SetupResponse;
35 import org.oransc.ric.portal.dashboard.model.IDashboardResponse;
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.util.Assert;
43 import org.springframework.web.bind.annotation.RequestBody;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.bind.annotation.RequestMethod;
46 import org.springframework.web.bind.annotation.RestController;
48 import io.swagger.annotations.ApiOperation;
51 * Provides methods to contact the E2 Manager.
53 * As of this writing the E2 interface only supports setup connection and check
54 * health actions; it does not support query or close operations on existing
55 * connections. So this class mocks up some of that functionality.
59 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE)
60 public class E2ManagerController {
62 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
64 // Populated by the autowired constructor
65 private final HealthCheckApi e2HealthCheckApi;
66 private final NodebApi e2NodebApi;
68 // Stores the requests and results.
69 // TODO remove when the E2 manager is extended.
70 private Set<E2SetupResponse> responses = new HashSet<>();
73 public E2ManagerController(final HealthCheckApi e2HealthCheckApi, final NodebApi e2NodebApi) {
74 Assert.notNull(e2HealthCheckApi, "API must not be null");
75 Assert.notNull(e2NodebApi, "API must not be null");
76 this.e2HealthCheckApi = e2HealthCheckApi;
77 this.e2NodebApi = e2NodebApi;
80 private void assertNotNull(Object o) {
82 throw new IllegalArgumentException("Null not permitted");
85 private void assertNotEmpty(String s) {
88 throw new IllegalArgumentException("Empty not permitted");
91 @ApiOperation(value = "Gets the E2 manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
92 @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
93 public SuccessTransport getVersion() {
94 logger.debug("getVersion enter");
95 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthCheckApi.class));
98 @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.")
99 @RequestMapping(value = "/health", method = RequestMethod.GET)
100 public void getHealth(HttpServletResponse response) {
101 logger.debug("getHealth");
102 e2HealthCheckApi.healthGet();
103 response.setStatus(e2HealthCheckApi.getApiClient().getStatusCode().value());
106 @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = E2SetupResponse.class, responseContainer = "List")
107 @RequestMapping(value = "/setup", method = RequestMethod.GET)
108 public Iterable<E2SetupResponse> getRequests() {
109 logger.debug("getRequests");
113 @ApiOperation(value = "Sets up an EN-DC RAN connection via the E2 manager.", response = E2SetupResponse.class)
114 @RequestMapping(value = "/endcSetup", method = RequestMethod.POST)
115 public E2SetupResponse endcSetup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) {
116 logger.debug("endcSetup {}", setupRequest);
117 int responseCode = -1;
119 assertNotEmpty(setupRequest.getRanIp());
120 assertNotEmpty(setupRequest.getRanName());
121 assertNotNull(setupRequest.getRanPort());
122 e2NodebApi.endcSetup(setupRequest);
123 responseCode = e2NodebApi.getApiClient().getStatusCode().value();
124 } catch (Exception ex) {
125 logger.warn("endcSetup failed", ex);
126 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
127 responseCode = HttpServletResponse.SC_BAD_REQUEST;
129 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.ENDC, setupRequest, responseCode);
134 @ApiOperation(value = "Sets up an X2 RAN connection via the E2 manager.", response = E2SetupResponse.class)
135 @RequestMapping(value = "/x2Setup", method = RequestMethod.POST)
136 public IDashboardResponse x2Setup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) {
137 logger.debug("x2Setup {}", setupRequest);
138 int responseCode = -1;
140 assertNotEmpty(setupRequest.getRanIp());
141 assertNotEmpty(setupRequest.getRanName());
142 assertNotNull(setupRequest.getRanPort());
143 e2NodebApi.x2Setup(setupRequest);
144 responseCode = e2NodebApi.getApiClient().getStatusCode().value();
145 } catch (Exception ex) {
146 logger.warn("x2Setup failed", ex);
147 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
148 responseCode = HttpServletResponse.SC_BAD_REQUEST;
150 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.X2, setupRequest, responseCode);