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 java.util.Date;
26 import org.onap.clamp.clds.model.CldsHealthCheck;
27 import org.onap.clamp.clds.util.LoggingUtils;
28 import org.onap.clamp.clds.util.OnapLogConstants;
29 import org.onap.clamp.loop.LoopController;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.slf4j.event.Level;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.stereotype.Component;
38 * Service to retrieve the Health Check of the clds application.
42 public class CldsHealthcheckService {
45 private LoopController loopController;
47 protected static final Logger logger = LoggerFactory.getLogger(CldsHealthcheckService.class);
50 * REST service that retrieves clds healthcheck information.
52 * @return CldsHealthCheck class containing healthcheck info
54 public CldsHealthCheck gethealthcheck() {
55 CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
56 Date startTime = new Date();
57 LoggingUtils util = new LoggingUtils(logger);
58 LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
59 LoggingUtils.setTimeContext(startTime, new Date());
61 loopController.getLoopNames();
62 cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
63 cldsHealthCheck.setHealthCheckStatus("UP");
64 cldsHealthCheck.setDescription("OK");
65 LoggingUtils.setResponseContext("0", "Get healthcheck success",
66 this.getClass().getName());
67 util.exiting(HttpStatus.OK.value(), "Healthcheck success", Level.INFO,
68 OnapLogConstants.ResponseStatus.COMPLETE);
69 } catch (Exception e) {
70 logger.error("CLAMP application Heath check failed", e);
71 LoggingUtils.setResponseContext("999", "Get healthcheck failed",
72 this.getClass().getName());
73 cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
74 cldsHealthCheck.setHealthCheckStatus("DOWN");
75 cldsHealthCheck.setDescription("NOT-OK");
76 util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Healthcheck failed", Level.INFO,
77 OnapLogConstants.ResponseStatus.ERROR);
79 return cldsHealthCheck;