Removing AAF references from Cert-Service in OOM repo.
[oom/platform/cert-service.git] / certService / src / main / java / org / onap / oom / certservice / api / ReadinessController.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PROJECT
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.oom.certservice.api;
22
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.oom.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;
33
34 @RestController
35 @Tag(name = "CertificationService")
36 public final class ReadinessController {
37
38     private final CmpServersConfig cmpServersConfig;
39
40     @Autowired
41     public ReadinessController(CmpServersConfig cmpServersConfig) {
42         this.cmpServersConfig = cmpServersConfig;
43     }
44
45     @GetMapping(value = "/ready", produces = "application/json")
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")
49     })
50     @Operation(
51             summary = "Check if CertService application 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);
57         } else {
58             return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE);
59         }
60     }
61 }