2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. 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.
18 * ============LICENSE_END=========================================================
21 package org.onap.aaf.certservice.api;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.responses.ApiResponse;
25 import io.swagger.v3.oas.annotations.responses.ApiResponses;
26 import io.swagger.v3.oas.annotations.tags.Tag;
27 import org.onap.aaf.certservice.certification.configuration.CmpServersConfig;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.web.bind.annotation.GetMapping;
32 import org.springframework.web.bind.annotation.RestController;
35 @Tag(name = "CertificationService")
36 public final class ReadinessController {
38 private final CmpServersConfig cmpServersConfig;
41 public ReadinessController(CmpServersConfig cmpServersConfig) {
42 this.cmpServersConfig = cmpServersConfig;
45 @GetMapping(value = "/ready", produces = "application/json; charset=utf-8")
46 @ApiResponses(value = {
47 @ApiResponse(responseCode = "200", description = "configuration is loaded and service is ready to use"),
48 @ApiResponse(responseCode = "503", description = "configuration loading failed and service is unavailable")
51 summary = "check is container is ready",
52 description = "Web endpoint for checking if service is ready to be used.",
53 tags = {"CertificationService"})
54 public ResponseEntity<String> checkReady() {
55 if (cmpServersConfig.isReady()) {
56 return new ResponseEntity<>(HttpStatus.OK);
58 return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE);