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.RicInstanceList;
34 import org.oransc.ric.portal.dashboard.model.RicInstanceKeyName;
35 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.http.MediaType;
41 import org.springframework.security.access.annotation.Secured;
42 import org.springframework.web.bind.annotation.GetMapping;
43 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestParam;
45 import org.springframework.web.bind.annotation.RestController;
47 import io.swagger.annotations.ApiOperation;
50 * Answers REST requests for admin services like version, health etc.
53 @RequestMapping(value = AdminController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
54 public class AdminController {
56 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
58 // Publish paths in constants so tests are easy to write
59 public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/admin";
60 public static final String HEALTH_METHOD = "health";
61 public static final String INSTANCE_METHOD = "instance";
62 public static final String USER_METHOD = "user";
63 public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
64 public static final String XAPPMETRICS_METHOD = "metrics";
66 @Value("${metrics.url.ac}")
67 private String acAppMetricsUrl;
69 @Value("${metrics.url.mc}")
70 private String mcAppMetricsUrl;
73 private DashboardUserManager dashboardUserManager;
76 private RicInstanceList instanceConfig;
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 = EcompUser.class, responseContainer = "List")
98 @GetMapping(USER_METHOD)
99 @Secured({ DashboardConstants.ROLE_ADMIN }) // regular users should not see this
100 public List<EcompUser> getUsers() {
101 logger.debug("getUsers");
102 return dashboardUserManager.getUsers();
105 @ApiOperation(value = "Gets the list of RIC instances.", response = RicInstanceKeyName.class, responseContainer = "List")
106 @GetMapping(INSTANCE_METHOD)
107 @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
108 public List<RicInstanceKeyName> getInstances() {
109 logger.debug("getInstances");
110 return instanceConfig.getKeyNameList();
113 @ApiOperation(value = "Gets the kibana metrics URL for the specified app.", response = SuccessTransport.class)
114 @GetMapping(XAPPMETRICS_METHOD)
115 @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
116 public IDashboardResponse getAppMetricsUrl(@RequestParam String app, HttpServletResponse response) {
117 String metricsUrl = null;
118 if (DashboardConstants.APP_NAME_AC.equals(app))
119 metricsUrl = acAppMetricsUrl;
120 else if (DashboardConstants.APP_NAME_MC.equals(app))
121 metricsUrl = mcAppMetricsUrl;
122 logger.debug("getAppMetricsUrl: app {} metricsurl {}", app, metricsUrl);
123 if (metricsUrl != null)
124 return new SuccessTransport(200, metricsUrl);
126 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
127 return new ErrorTransport(400, "Client provided app name is invalid as: " + app);