2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
23 package org.onap.clamp.clds.service;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
28 import java.util.Date;
30 import org.onap.clamp.clds.dao.CldsDao;
31 import org.onap.clamp.clds.model.CldsHealthCheck;
32 import org.onap.clamp.clds.util.LoggingUtils;
33 import org.onap.clamp.clds.util.ONAPLogConstants;
34 import org.slf4j.event.Level;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.stereotype.Component;
41 * Service to retrieve the Health Check of the clds application.
45 public class CldsHealthcheckService {
48 private CldsDao cldsDao;
50 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsHealthcheckService.class);
53 * REST service that retrieves clds healthcheck information.
55 * @return CldsHealthCheck class containing healthcheck info
57 public ResponseEntity<CldsHealthCheck> gethealthcheck() {
58 CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
59 Date startTime = new Date();
60 LoggingUtils util = new LoggingUtils(logger);
61 LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
62 LoggingUtils.setTimeContext(startTime, new Date());
63 boolean healthcheckFailed = false;
65 cldsDao.doHealthCheck();
66 cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
67 cldsHealthCheck.setHealthCheckStatus("UP");
68 cldsHealthCheck.setDescription("OK");
69 LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
70 } catch (Exception e) {
71 healthcheckFailed = true;
72 logger.error("CLAMP application Heath check failed", e);
73 LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
74 cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
75 cldsHealthCheck.setHealthCheckStatus("DOWN");
76 cldsHealthCheck.setDescription("NOT-OK");
79 LoggingUtils.setTimeContext(startTime, new Date());
80 if (healthcheckFailed) {
81 util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Healthcheck failed", Level.INFO,
82 ONAPLogConstants.ResponseStatus.ERROR);
83 return new ResponseEntity<>(cldsHealthCheck, HttpStatus.INTERNAL_SERVER_ERROR);
85 util.exiting("200", "Healthcheck failed", Level.INFO,
86 ONAPLogConstants.ResponseStatus.COMPLETED);
87 return new ResponseEntity<>(cldsHealthCheck, HttpStatus.OK);