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;
24 import javax.servlet.http.HttpServletResponse;
26 import org.oransc.ric.portal.dashboard.DashboardApplication;
27 import org.oransc.ric.portal.dashboard.DashboardConstants;
28 import org.oransc.ric.portal.dashboard.model.ErrorTransport;
29 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
30 import org.oransc.ric.xappmgr.client.api.HealthApi;
31 import org.oransc.ric.xappmgr.client.api.XappApi;
32 import org.oransc.ric.xappmgr.client.model.AllXapps;
33 import org.oransc.ric.xappmgr.client.model.XAppInfo;
34 import org.oransc.ric.xappmgr.client.model.Xapp;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Configuration;
39 import org.springframework.http.MediaType;
40 import org.springframework.util.Assert;
41 import org.springframework.web.bind.annotation.PathVariable;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestMethod;
45 import org.springframework.web.bind.annotation.RestController;
47 import io.swagger.annotations.ApiOperation;
50 * Mimics the xApp Manager API. These controller methods just proxy calls from
51 * the front-end thru to the real back-end.
56 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xappmgr", produces = MediaType.APPLICATION_JSON_VALUE)
57 public class XappManagerController {
59 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
61 // Populated by the autowired constructor
62 private final HealthApi healthApi;
63 private final XappApi xappApi;
66 public XappManagerController(final HealthApi healthApi, final XappApi xappApi) {
67 Assert.notNull(healthApi, "health API must not be null");
68 Assert.notNull(xappApi, "xapp API must not be null");
69 if (logger.isDebugEnabled())
70 logger.debug("ctor: configured with client types {} and {}", healthApi.getClass().getName(),
71 xappApi.getClass().getName());
72 this.healthApi = healthApi;
73 this.xappApi = xappApi;
76 @ApiOperation(value = "Gets the XApp manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
77 @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
78 public SuccessTransport getVersion() {
79 logger.debug("getVersion enter");
80 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
83 @ApiOperation(value = "Calls the xApp Manager health check.")
84 @RequestMapping(value = "/health", method = RequestMethod.GET)
85 public void getHealth(HttpServletResponse response) {
86 logger.debug("getHealt");
87 healthApi.getHealth();
88 response.setStatus(healthApi.getApiClient().getStatusCode().value());
91 @ApiOperation(value = "Calls the xApp Manager to get the list of xApps.", response = AllXapps.class)
92 @RequestMapping(value = "/xapps", method = RequestMethod.GET)
93 public AllXapps getAllXapps() {
94 if (logger.isDebugEnabled())
95 logger.debug("getAllXapps via {}", xappApi.getApiClient().getBasePath());
96 return xappApi.getAllXapps();
99 @ApiOperation(value = "Calls the xApp Manager to get the named xApp.", response = Xapp.class)
100 @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.GET)
101 public Xapp getXapp(@PathVariable("xAppName") String xAppName) {
102 logger.debug("getXapp {}", xAppName);
103 return xappApi.getXappByName(xAppName);
106 @ApiOperation(value = "Calls the xApp Manager to deploy the specified Xapp.", response = Xapp.class)
107 @RequestMapping(value = "/xapps", method = RequestMethod.POST)
108 public Object deployXapp(@RequestBody XAppInfo xAppInfo, HttpServletResponse response) {
109 logger.debug("deployXapp {}", xAppInfo);
111 return xappApi.deployXapp(xAppInfo);
112 } catch (Exception ex) {
113 logger.error("deployXapp failed", ex);
114 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
115 return new ErrorTransport(500, "deployXapp failed", ex);
119 @ApiOperation(value = "Calls the xApp Manager to undeploy the named Xapp.")
120 @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.DELETE)
121 public void undeployXapp(@PathVariable("xAppName") String xAppName, HttpServletResponse response) {
122 logger.debug("undeployXapp {}", xAppName);
124 xappApi.undeployXapp(xAppName);
125 } catch (Exception ex) {
126 logger.error("deployXapp failed", ex);
127 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);