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.E2ManagerApi;
29 import org.oransc.ric.e2mgr.client.model.SetupRequest;
30 import org.oransc.ric.portal.dashboard.DashboardConstants;
31 import org.oransc.ric.portal.dashboard.model.E2SetupRequestType;
32 import org.oransc.ric.portal.dashboard.model.E2SetupResponse;
33 import org.oransc.ric.portal.dashboard.model.IDashboardResponse;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.Configuration;
38 import org.springframework.http.MediaType;
39 import org.springframework.util.Assert;
40 import org.springframework.web.bind.annotation.RequestBody;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.bind.annotation.RequestMethod;
43 import org.springframework.web.bind.annotation.RestController;
45 import io.swagger.annotations.ApiOperation;
48 * Provides methods to contact the E2 Manager.
50 * As of this writing the E2 interface only supports setup connection and check
51 * health actions; it does not support query or close operations on existing
52 * connections. So this class mocks up some of that functionality.
56 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE)
57 public class E2ManagerController {
59 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
61 // Populated by the autowired constructor
62 private final E2ManagerApi e2ManagerApi;
64 // Stores the requests and results.
65 // TODO remove when the E2 manager is extended.
66 private Set<E2SetupResponse> responses = new HashSet<>();
69 public E2ManagerController(final E2ManagerApi e2ManagerApi) {
70 Assert.notNull(e2ManagerApi, "API must not be null");
71 this.e2ManagerApi = e2ManagerApi;
74 private void assertNotNull(Object o) {
76 throw new IllegalArgumentException("Null not permitted");
79 private void assertNotEmpty(String s) {
82 throw new IllegalArgumentException("Empty not permitted");
85 @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.")
86 @RequestMapping(value = "/health", method = RequestMethod.GET)
87 public void getHealth(HttpServletResponse response) {
88 logger.debug("getHealth");
89 e2ManagerApi.healthCheck();
90 response.setStatus(e2ManagerApi.getApiClient().getStatusCode().value());
93 @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = E2SetupResponse.class, responseContainer = "List")
94 @RequestMapping(value = "/setup", method = RequestMethod.GET)
95 public Iterable<E2SetupResponse> getRequests() {
96 logger.debug("getRequests");
100 @ApiOperation(value = "Sets up an EN-DC RAN connection via the E2 manager.", response = E2SetupResponse.class)
101 @RequestMapping(value = "/endcSetup", method = RequestMethod.POST)
102 public E2SetupResponse endcSetup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) {
103 logger.debug("endcSetup {}", setupRequest);
104 int responseCode = -1;
106 assertNotEmpty(setupRequest.getRanIp());
107 assertNotEmpty(setupRequest.getRanName());
108 assertNotNull(setupRequest.getRanPort());
109 e2ManagerApi.endcSetup(setupRequest);
110 responseCode = e2ManagerApi.getApiClient().getStatusCode().value();
111 } catch (Exception ex) {
112 logger.warn("endcSetup failed", ex);
113 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
114 responseCode = HttpServletResponse.SC_BAD_REQUEST;
116 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.ENDC, setupRequest, responseCode);
121 @ApiOperation(value = "Sets up an X2 RAN connection via the E2 manager.", response = E2SetupResponse.class)
122 @RequestMapping(value = "/x2Setup", method = RequestMethod.POST)
123 public IDashboardResponse x2Setup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) {
124 logger.debug("x2Setup {}", setupRequest);
125 int responseCode = -1;
127 assertNotEmpty(setupRequest.getRanIp());
128 assertNotEmpty(setupRequest.getRanName());
129 assertNotNull(setupRequest.getRanPort());
130 e2ManagerApi.setup(setupRequest);
131 responseCode = e2ManagerApi.getApiClient().getStatusCode().value();
132 } catch (Exception ex) {
133 logger.warn("x2Setup failed", ex);
134 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
135 responseCode = HttpServletResponse.SC_BAD_REQUEST;
137 E2SetupResponse r = new E2SetupResponse(E2SetupRequestType.X2, setupRequest, responseCode);