2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
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.oransc.enrichment.controllers;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.google.gson.annotations.SerializedName;
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;
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;
45 @RestController("StatusController")
46 @Api(tags = "Service status")
47 public class StatusController {
50 private EiJobs eiJobs;
53 private EiTypes eiTypes;
56 private EiProducers eiProducers;
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;
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;
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;
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;
81 public StatusInfo(String status, EiProducers producers, EiTypes types, EiJobs jobs) {
83 this.noOfJobs = jobs.size();
84 this.noOfProducers = producers.size();
85 this.noOfTypes = types.size();
89 @GetMapping(path = "/status", produces = MediaType.APPLICATION_JSON_VALUE)
90 @ApiOperation(value = "Returns status and statistics of this service")
93 @ApiResponse(code = 200, message = "Service is living", response = StatusInfo.class) //
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));