2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019,2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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;
33 import java.util.UUID;
34 import lombok.RequiredArgsConstructor;
35 import org.apache.commons.lang3.tuple.Pair;
36 import org.onap.policy.models.base.PfModelException;
37 import org.onap.policy.models.pdp.concepts.Pdps;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.GetMapping;
41 import org.springframework.web.bind.annotation.RequestHeader;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RestController;
46 * Class to provide REST end point for PAP component to fetch health status of all PDPs registered with PAP.
48 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
52 @RequestMapping(path = "/policy/pap/v1")
53 @RequiredArgsConstructor
54 public class PdpGroupHealthCheckControllerV1 extends PapRestControllerV1 {
56 private final PdpGroupHealthCheckProvider provider;
59 * Returns health status of all PDPs registered with PAP.
61 * @param requestId request ID used in ONAP logging
65 @GetMapping("pdps/healthcheck")
66 @ApiOperation(value = "Returns health status of all PDPs registered with PAP",
67 notes = "Queries health status of all PDPs, returning all pdps health status",
68 response = Pdps.class,
69 tags = {"Policy Administration (PAP) API"},
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<Pdps> pdpGroupHealthCheck(@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
95 value = REQUEST_ID_NAME) final UUID requestId) throws PfModelException {
96 Pair<HttpStatus, Pdps> pair = provider.fetchPdpGroupHealthStatus();
97 return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId)
98 .body(pair.getRight());