2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019,2021 Nordix Foundation.
4 * Modifications Copyright (C) 2020 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 io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiParam;
27 import io.swagger.annotations.ApiResponse;
28 import io.swagger.annotations.ApiResponses;
29 import io.swagger.annotations.Authorization;
30 import io.swagger.annotations.Extension;
31 import io.swagger.annotations.ExtensionProperty;
32 import io.swagger.annotations.ResponseHeader;
34 import java.util.UUID;
35 import lombok.RequiredArgsConstructor;
36 import org.apache.commons.lang3.tuple.Pair;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.GetMapping;
40 import org.springframework.web.bind.annotation.RequestHeader;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.bind.annotation.RestController;
45 * Class to provide REST end point for PAP component to fetch all policy components, including PAP,
46 * API, Distribution, and PDPs.
48 * @author Yehui Wang (yehui.wang@est.tech)
51 @RequestMapping(path = "/policy/pap/v1")
52 @RequiredArgsConstructor
53 public class PolicyComponentsHealthCheckControllerV1 extends PapRestControllerV1 {
55 private final PolicyComponentsHealthCheckProvider provider;
59 * Returns health status of all Policy components, including PAP, API, Distribution, and PDPs.
61 * @param requestId request ID used in ONAP logging
65 @GetMapping("components/healthcheck")
66 @ApiOperation(value = "Returns health status of all policy components, including PAP, API, Distribution, and PDPs",
67 notes = "Queries health status of all policy components, returning all policy components health status",
69 tags = {"Consolidated Healthcheck"},
70 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
72 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
73 response = String.class),
74 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
75 response = String.class),
76 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
77 response = String.class),
78 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
79 response = UUID.class)},
81 @Extension(name = EXTENSION_NAME,
83 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
84 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
87 @ApiResponses(value = {
88 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
89 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
90 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
93 public ResponseEntity<Map<String, Object>> policyComponentsHealthCheck(
94 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
96 value = REQUEST_ID_NAME) final UUID requestId) {
97 final Pair<HttpStatus, Map<String, Object>> pair = provider.fetchPolicyComponentsHealthStatus();
98 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId)
99 .body(pair.getRight());