2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
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=========================================================
21 package org.onap.vid.controllers;
23 import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.portalsdk.core.util.SystemProperties;
26 import org.onap.vid.dao.FnAppDoaImpl;
27 import org.springframework.http.MediaType;
28 import org.springframework.web.bind.annotation.PathVariable;
29 import org.springframework.web.bind.annotation.RequestMapping;
30 import org.springframework.web.bind.annotation.RequestMethod;
31 import org.springframework.web.bind.annotation.RestController;
33 import java.io.IOException;
34 import java.text.DateFormat;
35 import java.text.SimpleDateFormat;
36 import java.util.Date;
39 * Controller for user profile view. The view is restricted to authenticated
40 * users. The view name resolves to page user_profile.jsp which uses Angular.
45 public class HealthCheckController extends UnRestrictedBaseController {
49 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(HealthCheckController.class);
51 /** The Constant dateFormat. */
52 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
54 private static final String HEALTH_CHECK_PATH = "/healthCheck";
57 * Model for JSON response with health-check results.
59 public class HealthStatus {
61 public int statusCode;
63 // Additional detail in case of error, empty in case of success.
64 public String message;
68 public HealthStatus(int code, String msg) {
69 this.statusCode = code;
73 public HealthStatus(int code,String date, String msg) {
74 this.statusCode = code;
79 public int getStatusCode() {
83 public void setStatusCode(int code) {
84 this.statusCode = code;
87 public String getMessage() {
91 public void setMessage(String msg) {
95 public String getDate() {
99 public void setDate(String date) {
105 @SuppressWarnings("unchecked")
106 public int getProfileCount(String driver, String URL, String username, String password) {
107 FnAppDoaImpl doa= new FnAppDoaImpl();
108 int count= doa.getProfileCount(driver,URL,username,password);
115 * Obtain the HealthCheck Status from the System.Properties file.
116 * Used by IDNS for redundancy
117 * @return ResponseEntity The response entity
118 * @throws IOException Signals that an I/O exception has occurred.
120 @RequestMapping(value="/healthCheck",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
121 public HealthStatus gethealthCheckStatusforIDNS() {
123 String driver = SystemProperties.getProperty("db.driver");
124 String URL = SystemProperties.getProperty("db.connectionURL");
125 String username = SystemProperties.getProperty("db.userName");
126 String password = SystemProperties.getProperty("db.password");
128 LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
129 LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
130 LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
131 LOGGER.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
134 HealthStatus healthStatus = null;
136 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
137 int count=getProfileCount(driver,URL,username,password);
138 LOGGER.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
139 healthStatus = new HealthStatus(200, "health check succeeded");
140 } catch (Exception ex) {
142 LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
143 healthStatus = new HealthStatus(500, "health check failed: " + ex.toString());
149 * Obtain the HealthCheck Status from the System.Properties file.
151 * @return ResponseEntity The response entity
152 * @throws IOException Signals that an I/O exception has occurred.
155 @RequestMapping(value="rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
156 public HealthStatus getHealthCheck(
157 @PathVariable("User-Agent") String UserAgent,
158 @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) {
160 String driver = SystemProperties.getProperty("db.driver");
161 String URL = SystemProperties.getProperty("db.connectionURL");
162 String username = SystemProperties.getProperty("db.userName");
163 String password = SystemProperties.getProperty("db.password");
165 LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
166 LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
167 LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
168 LOGGER.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
171 HealthStatus healthStatus = null;
173 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
174 LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent" + UserAgent);
175 LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID" + ECOMPRequestID);
178 int count=getProfileCount(driver,URL,username,password);
180 LOGGER.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
181 healthStatus = new HealthStatus(200,dateFormat.format(new Date()) ,"health check succeeded");
182 } catch (Exception ex) {
184 LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
185 healthStatus = new HealthStatus(500,dateFormat.format(new Date()),"health check failed: " + ex.toString());