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.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.media.Content;
28 import io.swagger.v3.oas.annotations.media.Schema;
29 import io.swagger.v3.oas.annotations.responses.ApiResponse;
30 import io.swagger.v3.oas.annotations.responses.ApiResponses;
31 import io.swagger.v3.oas.annotations.tags.Tag;
33 import org.immutables.gson.Gson;
34 import org.oransc.enrichment.repository.InfoJobs;
35 import org.oransc.enrichment.repository.InfoProducers;
36 import org.oransc.enrichment.repository.InfoTypes;
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 @Tag(name = StatusController.API_NAME)
47 public class StatusController {
49 public static final String API_NAME = "Service status";
50 public static final String API_DESCRIPTION = "API for monitoring of the service";
53 private InfoJobs infoJobs;
56 private InfoTypes infoTypes;
59 private InfoProducers infoProducers;
62 @Schema(name = "service_status_info")
63 public static class StatusInfo {
64 @Schema(name = "status", description = "status text")
65 @SerializedName("status")
66 @JsonProperty(value = "status", required = true)
67 public final String status;
69 @Schema(name = "no_of_producers", description = "Number of Information Producers")
70 @SerializedName("no_of_producers")
71 @JsonProperty(value = "no_of_producers", required = true)
72 public final int noOfProducers;
74 @Schema(name = "no_of_types", description = "Number of Information Types")
75 @SerializedName("no_of_types")
76 @JsonProperty(value = "no_of_types", required = true)
77 public final int noOfTypes;
79 @Schema(name = "no_of_jobs", description = "Number of Information Jobs")
80 @SerializedName("no_of_jobs")
81 @JsonProperty(value = "no_of_jobs", required = true)
82 public final int noOfJobs;
84 public StatusInfo(String status, InfoProducers producers, InfoTypes types, InfoJobs jobs) {
86 this.noOfJobs = jobs.size();
87 this.noOfProducers = producers.size();
88 this.noOfTypes = types.size();
92 @GetMapping(path = "/status", produces = MediaType.APPLICATION_JSON_VALUE)
93 @Operation(summary = "Returns status and statistics of this service")
98 description = "Service is living", //
99 content = @Content(schema = @Schema(implementation = StatusInfo.class))) //
101 public Mono<ResponseEntity<Object>> getStatus() {
102 StatusInfo info = new StatusInfo("hunky dory", this.infoProducers, this.infoTypes, this.infoJobs);
103 return Mono.just(new ResponseEntity<>(info, HttpStatus.OK));