2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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.List;
25 import javax.servlet.http.HttpServletResponse;
27 import org.onap.portalsdk.core.restful.domain.EcompUser;
28 import org.oransc.ric.portal.dashboard.DashboardApplication;
29 import org.oransc.ric.portal.dashboard.DashboardConstants;
30 import org.oransc.ric.portal.dashboard.DashboardUserManager;
31 import org.oransc.ric.portal.dashboard.model.ErrorTransport;
32 import org.oransc.ric.portal.dashboard.model.IDashboardResponse;
33 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.beans.factory.annotation.Value;
38 import org.springframework.http.MediaType;
39 import org.springframework.security.access.annotation.Secured;
40 import org.springframework.web.bind.annotation.GetMapping;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.bind.annotation.RequestParam;
43 import org.springframework.web.bind.annotation.RestController;
45 import io.swagger.annotations.ApiOperation;
48 * Answers REST requests for admin services like version, health etc.
51 @RequestMapping(value = AdminController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
52 public class AdminController {
54 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
56 // Publish paths in constants so tests are easy to write
57 public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/admin";
58 public static final String USER_METHOD = "user";
59 public static final String HEALTH_METHOD = "health";
60 public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
61 public static final String XAPPMETRICS_METHOD = "metrics";
63 @Value("${metrics.url.ac}")
64 private String acAppMetricsUrl;
66 @Value("${metrics.url.mc}")
67 private String mcAppMetricsUrl;
70 private DashboardUserManager dashboardUserManager;
72 public AdminController() {
75 @ApiOperation(value = "Gets the Dashboard MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
76 @GetMapping(VERSION_METHOD)
78 public SuccessTransport getVersion() {
79 // These endpoints are invoked repeatedly by K8S
80 logger.trace("getVersion");
81 return new SuccessTransport(200,
82 DashboardApplication.getImplementationVersion(MethodHandles.lookup().lookupClass()));
85 @ApiOperation(value = "Checks the health of the application.", response = SuccessTransport.class)
86 @GetMapping(HEALTH_METHOD)
88 public SuccessTransport getHealth() {
89 // These endpoints are invoked repeatedly by K8S
90 logger.trace("getHealth");
91 return new SuccessTransport(200, "Dashboard is healthy!");
94 @ApiOperation(value = "Gets the list of application users.", response = EcompUser.class, responseContainer = "List")
95 @GetMapping(USER_METHOD)
96 @Secured({ DashboardConstants.ROLE_ADMIN }) // regular users should not see this
97 public List<EcompUser> getUsers() {
98 logger.debug("getUsers");
99 return dashboardUserManager.getUsers();
102 @ApiOperation(value = "Gets the kibana metrics URL for the specified app.", response = SuccessTransport.class)
103 @GetMapping(XAPPMETRICS_METHOD)
105 public IDashboardResponse getAppMetricsUrl(@RequestParam String app, HttpServletResponse response) {
106 String metricsUrl = null;
107 if (DashboardConstants.APP_NAME_AC.equals(app))
108 metricsUrl = acAppMetricsUrl;
109 else if (DashboardConstants.APP_NAME_MC.equals(app))
110 metricsUrl = mcAppMetricsUrl;
111 logger.debug("getAppMetricsUrl: app {} metricsurl {}", app, metricsUrl);
112 if (metricsUrl != null)
113 return new SuccessTransport(200, metricsUrl);
115 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
116 return new ErrorTransport(400, "Client provided app name is invalid as: " + app);