42ab7cb8ee98c7ba5ccfa29fcd1f4cc2791143e4
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / controllers / StatusController.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2020 Nordix Foundation
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.oransc.enrichment.controllers;
22
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.google.gson.annotations.SerializedName;
25
26 import io.swagger.annotations.Api;
27 import io.swagger.annotations.ApiModel;
28 import io.swagger.annotations.ApiModelProperty;
29 import io.swagger.annotations.ApiOperation;
30 import io.swagger.annotations.ApiResponse;
31 import io.swagger.annotations.ApiResponses;
32
33 import org.immutables.gson.Gson;
34 import org.oransc.enrichment.repository.EiJobs;
35 import org.oransc.enrichment.repository.EiProducers;
36 import org.oransc.enrichment.repository.EiTypes;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.MediaType;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.RestController;
43 import reactor.core.publisher.Mono;
44
45 @RestController("StatusController")
46 @Api(tags = "Service status")
47 public class StatusController {
48
49     @Autowired
50     private EiJobs eiJobs;
51
52     @Autowired
53     private EiTypes eiTypes;
54
55     @Autowired
56     private EiProducers eiProducers;
57
58     @Gson.TypeAdapters
59     @ApiModel(value = "status_info")
60     public static class StatusInfo {
61         @ApiModelProperty(value = "status text")
62         @SerializedName("status")
63         @JsonProperty(value = "status", required = true)
64         public final String status;
65
66         @ApiModelProperty(value = "Number of EI producers")
67         @SerializedName("no_of_producers")
68         @JsonProperty(value = "no_of_producers", required = true)
69         public final int noOfProducers;
70
71         @ApiModelProperty(value = "Number of EI types")
72         @SerializedName("no_of_types")
73         @JsonProperty(value = "no_of_types", required = true)
74         public final int noOfTypes;
75
76         @ApiModelProperty(value = "Number of EI jobs")
77         @SerializedName("no_of_jobs")
78         @JsonProperty(value = "no_of_jobs", required = true)
79         public final int noOfJobs;
80
81         public StatusInfo(String status, EiProducers producers, EiTypes types, EiJobs jobs) {
82             this.status = status;
83             this.noOfJobs = jobs.size();
84             this.noOfProducers = producers.size();
85             this.noOfTypes = types.size();
86         }
87     }
88
89     @GetMapping(path = "/status", produces = MediaType.APPLICATION_JSON_VALUE)
90     @ApiOperation(value = "Returns status and statistics of this service")
91     @ApiResponses(
92         value = { //
93             @ApiResponse(code = 200, message = "Service is living", response = StatusInfo.class) //
94         })
95     public Mono<ResponseEntity<Object>> getStatus() {
96         StatusInfo info = new StatusInfo("hunky dory", this.eiProducers, this.eiTypes, this.eiJobs);
97         return Mono.just(new ResponseEntity<>(info, HttpStatus.OK));
98     }
99
100 }