2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 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.oran.dmaapadapter.controllers;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
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.oran.dmaapadapter.r1.ProducerJobInfo;
34 import org.oran.dmaapadapter.repository.InfoTypes;
35 import org.oran.dmaapadapter.repository.Job;
36 import org.oran.dmaapadapter.repository.Jobs;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.MediaType;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.web.bind.annotation.DeleteMapping;
44 import org.springframework.web.bind.annotation.GetMapping;
45 import org.springframework.web.bind.annotation.PathVariable;
46 import org.springframework.web.bind.annotation.PostMapping;
47 import org.springframework.web.bind.annotation.RequestBody;
48 import org.springframework.web.bind.annotation.RestController;
50 @RestController("ConfigurationControllerV2")
51 @Tag(name = ProducerCallbacksController.API_NAME)
52 public class ProducerCallbacksController {
53 private static final Logger logger = LoggerFactory.getLogger(ProducerCallbacksController.class);
55 public static final String API_NAME = "Management of configuration";
56 public static final String API_DESCRIPTION = "";
57 public static final String JOB_URL = "/dmaap_dataproducer/info_job";
58 public static final String SUPERVISION_URL = "/dmaap_dataproducer/health_check";
59 private static Gson gson = new GsonBuilder().create();
60 private final Jobs jobs;
61 private final InfoTypes types;
63 public ProducerCallbacksController(@Autowired Jobs jobs, @Autowired InfoTypes types) {
68 @PostMapping(path = JOB_URL, produces = MediaType.APPLICATION_JSON_VALUE)
69 @Operation(summary = "Callback for Information Job creation/modification",
70 description = "The call is invoked to activate or to modify a data subscription. The endpoint is provided by the Information Producer.")
71 @ApiResponses(value = { //
72 @ApiResponse(responseCode = "200", description = "OK", //
73 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
75 public ResponseEntity<Object> jobCreatedCallback( //
76 @RequestBody String body) {
78 ProducerJobInfo request = gson.fromJson(body, ProducerJobInfo.class);
80 logger.info("Job started callback {}", request.id);
81 Job job = new Job(request.id, request.targetUri, types.getType(request.typeId));
83 return new ResponseEntity<>(HttpStatus.OK);
84 } catch (Exception e) {
85 return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
89 @DeleteMapping(path = JOB_URL + "/{infoJobId}", produces = MediaType.APPLICATION_JSON_VALUE)
90 @Operation(summary = "Callback for Information Job deletion",
91 description = "The call is invoked to terminate a data subscription. The endpoint is provided by the Information Producer.")
92 @ApiResponses(value = { //
93 @ApiResponse(responseCode = "200", description = "OK", //
94 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
96 public ResponseEntity<Object> jobDeletedCallback( //
97 @PathVariable("infoJobId") String infoJobId) {
99 logger.info("Job deleted callback {}", infoJobId);
100 this.jobs.remove(infoJobId);
101 return new ResponseEntity<>(HttpStatus.OK);
104 @GetMapping(path = SUPERVISION_URL, produces = MediaType.APPLICATION_JSON_VALUE)
105 @Operation(summary = "Producer supervision",
106 description = "The endpoint is provided by the Information Producer and is used for supervision of the producer.")
107 @ApiResponses(value = { //
108 @ApiResponse(responseCode = "200", description = "The producer is OK", //
109 content = @Content(schema = @Schema(implementation = String.class))) //
111 public ResponseEntity<Object> producerSupervision() {
112 logger.info("Producer supervision");
113 return new ResponseEntity<>(HttpStatus.OK);