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.DashboardUser;
29 import org.oransc.ric.portal.dashboard.model.ErrorTransport;
30 import org.oransc.ric.portal.dashboard.model.IDashboardResponse;
31 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.http.MediaType;
35 import org.springframework.security.access.annotation.Secured;
36 import org.springframework.web.bind.annotation.GetMapping;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RestController;
39 import org.springframework.web.bind.annotation.RequestParam;
40 import org.springframework.beans.factory.annotation.Value;
42 import io.swagger.annotations.ApiOperation;
45 * Answers REST requests for admin services like version, health etc.
48 @RequestMapping(value = AdminController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
49 public class AdminController {
51 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
53 // Publish paths in constants so tests are easy to write
54 public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/admin";
55 public static final String USER_METHOD = "user";
56 public static final String HEALTH_METHOD = "health";
57 public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
58 public static final String XAPPMETRICS_METHOD = "metrics";
60 private final DashboardUser[] users;
62 private static final String ACTIVE = "Active";
63 private static final String INACTIVE = "Inactive";
65 @Value("${metrics.url.ac}")
66 private String acAppMetricsUrl;
68 public AdminController() {
70 users = new DashboardUser[] { //
71 new DashboardUser(1, "John", "Doe", ACTIVE), //
72 new DashboardUser(2, "Alice", "Nolan", ACTIVE), //
73 new DashboardUser(3, "Pierce", "King", INACTIVE), //
74 new DashboardUser(4, "Paul", "Smith", INACTIVE), //
75 new DashboardUser(5, "Jack", "Reacher", ACTIVE) };
78 @ApiOperation(value = "Gets the Dashboard MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
79 @GetMapping(VERSION_METHOD)
81 public SuccessTransport getVersion() {
82 // These endpoints are invoked repeatedly by K8S
83 logger.trace("getVersion");
84 return new SuccessTransport(200,
85 DashboardApplication.getImplementationVersion(MethodHandles.lookup().lookupClass()));
88 @ApiOperation(value = "Checks the health of the application.", response = SuccessTransport.class)
89 @GetMapping(HEALTH_METHOD)
91 public SuccessTransport getHealth() {
92 // These endpoints are invoked repeatedly by K8S
93 logger.trace("getHealth");
94 return new SuccessTransport(200, "Dashboard is healthy!");
97 @ApiOperation(value = "Gets the list of application users.", response = DashboardUser.class, responseContainer = "List")
98 @GetMapping(USER_METHOD)
99 @Secured({ DashboardConstants.ROLE_ADMIN })
100 public DashboardUser[] getUsers() {
101 logger.debug("getUsers");
105 @ApiOperation(value = "Gets the kibana metrics URL for the specified app.", response = SuccessTransport.class)
106 @GetMapping(XAPPMETRICS_METHOD)
107 public IDashboardResponse getAppMetricsUrl(@RequestParam String app, HttpServletResponse response) {
108 if (DashboardConstants.APP_NAME_AC.equals(app)) {
109 logger.debug("getAppMetricsUrl: acAppMetricsUrl {}", acAppMetricsUrl);
110 return new SuccessTransport(200, acAppMetricsUrl);
112 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
113 return new ErrorTransport(400, "Client provided app name is invalid as: " + app);