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.controller;
23 import org.openecomp.portalsdk.core.controller.UnRestrictedBaseController;
24 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.openecomp.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.
119 * @throws InterruptedException the interrupted exception
121 @RequestMapping(value="/healthCheck",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
122 public HealthStatus gethealthCheckStatusforIDNS() throws IOException, InterruptedException {
124 String driver = SystemProperties.getProperty("db.driver");
125 String URL = SystemProperties.getProperty("db.connectionURL");
126 String username = SystemProperties.getProperty("db.userName");
127 String password = SystemProperties.getProperty("db.password");
129 LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
130 LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
131 LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
132 LOGGER.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
135 HealthStatus healthStatus = null;
137 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
138 int count=getProfileCount(driver,URL,username,password);
139 LOGGER.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
140 healthStatus = new HealthStatus(200, "health check succeeded");
141 } catch (Exception ex) {
143 LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
144 healthStatus = new HealthStatus(500, "health check failed: " + ex.toString());
150 * Obtain the HealthCheck Status from the System.Properties file.
152 * @return ResponseEntity The response entity
153 * @throws IOException Signals that an I/O exception has occurred.
154 * @throws InterruptedException the interrupted exception
157 @RequestMapping(value="rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
158 public HealthStatus getHealthCheck(
159 @PathVariable("User-Agent") String UserAgent,
160 @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) throws IOException, InterruptedException {
162 String driver = SystemProperties.getProperty("db.driver");
163 String URL = SystemProperties.getProperty("db.connectionURL");
164 String username = SystemProperties.getProperty("db.userName");
165 String password = SystemProperties.getProperty("db.password");
167 LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver);
168 LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL);
169 LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username);
170 LOGGER.debug(EELFLoggerDelegate.debugLogger,"password::" + password);
173 HealthStatus healthStatus = null;
175 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
176 LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent" + UserAgent);
177 LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID" + ECOMPRequestID);
180 int count=getProfileCount(driver,URL,username,password);
182 LOGGER.debug(EELFLoggerDelegate.debugLogger,"count:::"+count);
183 healthStatus = new HealthStatus(200,dateFormat.format(new Date()) ,"health check succeeded");
184 } catch (Exception ex) {
186 LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
187 healthStatus = new HealthStatus(500,dateFormat.format(new Date()),"health check failed: " + ex.toString());