2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * Modifications Copyright (C) 2021 Bell Canada. 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.rest;
25 import org.onap.policy.common.endpoints.report.HealthCheckReport;
26 import org.onap.policy.common.utils.network.NetworkUtil;
27 import org.onap.policy.common.utils.services.Registry;
28 import org.onap.policy.pap.main.PapConstants;
29 import org.onap.policy.pap.main.startstop.PapActivator;
30 import org.springframework.stereotype.Service;
33 * Class to fetch health check of PAP service.
35 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
38 public class HealthCheckProvider {
40 private static final String NOT_ALIVE = "not alive";
41 private static final String ALIVE = "alive";
42 private static final String URL = NetworkUtil.getHostname();
43 private static final String NAME = "Policy PAP";
46 * Performs the health check of PAP service.
48 * @return Report containing health check status
50 public HealthCheckReport performHealthCheck() {
51 final var report = new HealthCheckReport();
55 boolean alive = Registry.get(PapConstants.REG_PAP_ACTIVATOR, PapActivator.class).isAlive();
57 report.setHealthy(alive);
58 report.setCode(alive ? 200 : 500);
59 report.setMessage(alive ? ALIVE : NOT_ALIVE);