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.oranosc.ric.portal.dash.controller;
22 import java.lang.invoke.MethodHandles;
23 import java.util.HashSet;
26 import javax.servlet.http.HttpServletResponse;
28 import org.oranosc.ric.e2mgr.client.api.DefaultApi;
29 import org.oranosc.ric.e2mgr.client.model.RanSetupRequest;
30 import org.oranosc.ric.portal.dash.DashboardConstants;
31 import org.oranosc.ric.portal.dash.model.SuccessTransport;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Configuration;
36 import org.springframework.http.MediaType;
37 import org.springframework.web.bind.annotation.RequestBody;
38 import org.springframework.web.bind.annotation.RequestMapping;
39 import org.springframework.web.bind.annotation.RequestMethod;
40 import org.springframework.web.bind.annotation.RestController;
42 import io.swagger.annotations.ApiOperation;
45 * Provides methods to contact the E2 Manager.
47 * As of this writing the E2 interface only supports setup connection and check
48 * health actions; it does not support query or close operations on existing
49 * connections. So this class mocks up some of that needed functionality.
53 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE)
54 public class E2ManagerController {
56 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
59 private DefaultApi e2ManagerClient;
61 // Tracks the requests previously submitted.
62 // TODO remove when the E2 manager is extended.
63 private Set<RanSetupRequest> requests = new HashSet<>();
65 private void assertNotNull(Object o) {
67 throw new IllegalArgumentException("Null not permitted");
70 private void assertNotEmpty(String s) {
73 throw new IllegalArgumentException("Empty not permitted");
76 @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.", response = String.class)
77 @RequestMapping(value = "/health", method = RequestMethod.GET)
78 public SuccessTransport getHealth() {
79 logger.debug("getHealth");
80 return new SuccessTransport();
83 @ApiOperation(value = "Gets the unique requests submitted to the E2 manager.", response = RanSetupRequest.class, responseContainer = "List")
84 @RequestMapping(value = "/setup", method = RequestMethod.GET)
85 public Iterable<RanSetupRequest> getRequests() {
86 logger.debug("getRequests");
90 @ApiOperation(value = "Sets up a RAN connection via the E2 manager.")
91 @RequestMapping(value = "/setup", method = RequestMethod.POST)
92 public void setup(@RequestBody RanSetupRequest rsr, HttpServletResponse response) {
93 logger.debug("setup {}", rsr);
95 assertNotEmpty(rsr.getRanIp());
96 assertNotEmpty(rsr.getRanName());
97 assertNotNull(rsr.getRanPort());
98 } catch (Exception ex) {
99 logger.error("Bad request", ex);
100 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
104 e2ManagerClient.setupRan(rsr);
105 } catch (Exception ex) {
106 logger.error("Failed", ex);
107 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);