2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.controller;
\r
23 import java.io.IOException;
\r
24 import java.sql.Connection;
\r
25 import java.sql.DriverManager;
\r
26 import java.sql.SQLException;
\r
27 import java.text.DateFormat;
\r
28 import java.text.SimpleDateFormat;
\r
29 import java.util.Date;
\r
31 import org.springframework.http.MediaType;
\r
32 import org.springframework.web.bind.annotation.PathVariable;
\r
33 import org.springframework.web.bind.annotation.RequestMapping;
\r
34 import org.springframework.web.bind.annotation.RequestMethod;
\r
35 import org.springframework.web.bind.annotation.RestController;
\r
37 import org.openecomp.portalsdk.core.controller.UnRestrictedBaseController;
\r
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
39 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
40 import org.openecomp.vid.dao.FnAppDoaImpl;
\r
43 * Controller for user profile view. The view is restricted to authenticated
\r
44 * users. The view name resolves to page user_profile.jsp which uses Angular.
\r
48 @RequestMapping("/")
\r
49 public class HealthCheckController extends UnRestrictedBaseController {
\r
53 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HealthCheckController.class);
\r
55 /** The Constant dateFormat. */
\r
56 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
58 private static final String HEALTH_CHECK_PATH = "/healthCheck";
\r
61 * Model for JSON response with health-check results.
\r
63 public class HealthStatus {
\r
64 // Either 200 or 500
\r
65 public int statusCode;
\r
67 // Additional detail in case of error, empty in case of success.
\r
68 public String message;
\r
72 public HealthStatus(int code, String msg) {
\r
73 this.statusCode = code;
\r
77 public HealthStatus(int code,String date, String msg) {
\r
78 this.statusCode = code;
\r
83 public int getStatusCode() {
\r
87 public void setStatusCode(int code) {
\r
88 this.statusCode = code;
\r
91 public String getMessage() {
\r
95 public void setMessage(String msg) {
\r
99 public String getDate() {
\r
103 public void setDate(String date) {
\r
109 @SuppressWarnings("unchecked")
\r
110 public int getProfileCount(String driver, String URL, String username, String password) {
\r
111 FnAppDoaImpl doa= new FnAppDoaImpl();
\r
112 int count= doa.getProfileCount(driver,URL,username,password);
\r
119 * Obtain the HealthCheck Status from the System.Properties file.
\r
120 * Used by IDNS for redundancy
\r
121 * @return ResponseEntity The response entity
\r
122 * @throws IOException Signals that an I/O exception has occurred.
\r
123 * @throws InterruptedException the interrupted exception
\r
125 @RequestMapping(value="/healthCheck",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
126 public HealthStatus gethealthCheckStatusforIDNS() throws IOException, InterruptedException {
\r
128 String driver = SystemProperties.getProperty("db.driver");
\r
129 String URL = SystemProperties.getProperty("db.connectionURL");
\r
130 String username = SystemProperties.getProperty("db.userName");
\r
131 String password = SystemProperties.getProperty("db.password");
\r
133 logger.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
\r
134 logger.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
\r
135 logger.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
\r
136 logger.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
\r
139 HealthStatus healthStatus = null;
\r
141 logger.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
\r
142 int count=getProfileCount(driver,URL,username,password);
\r
143 logger.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
\r
144 healthStatus = new HealthStatus(200, "health check succeeded");
\r
145 } catch (Exception ex) {
\r
147 logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
\r
148 healthStatus = new HealthStatus(500, "health check failed: " + ex.toString());
\r
150 return healthStatus;
\r
154 * Obtain the HealthCheck Status from the System.Properties file.
\r
156 * @return ResponseEntity The response entity
\r
157 * @throws IOException Signals that an I/O exception has occurred.
\r
158 * @throws InterruptedException the interrupted exception
\r
161 @RequestMapping(value="rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
162 public HealthStatus getHealthCheck(
\r
163 @PathVariable("User-Agent") String UserAgent,
\r
164 @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) throws IOException, InterruptedException {
\r
166 String driver = SystemProperties.getProperty("db.driver");
\r
167 String URL = SystemProperties.getProperty("db.connectionURL");
\r
168 String username = SystemProperties.getProperty("db.userName");
\r
169 String password = SystemProperties.getProperty("db.password");
\r
171 logger.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
\r
172 logger.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
\r
173 logger.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
\r
174 logger.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
\r
177 HealthStatus healthStatus = null;
\r
179 logger.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
\r
180 logger.debug(EELFLoggerDelegate.debugLogger, "User-Agent" + UserAgent);
\r
181 logger.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID" + ECOMPRequestID);
\r
184 int count=getProfileCount(driver,URL,username,password);
\r
186 logger.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
\r
187 healthStatus = new HealthStatus(200,dateFormat.format(new Date()) ,"health check succeeded");
\r
188 } catch (Exception ex) {
\r
190 logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
\r
191 healthStatus = new HealthStatus(500,dateFormat.format(new Date()),"health check failed: " + ex.toString());
\r
193 return healthStatus;
\r