2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 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===================================
20 package org.oransc.policyagent.controllers;
22 import com.google.gson.Gson;
23 import com.google.gson.GsonBuilder;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
29 import java.util.Vector;
31 import org.oransc.policyagent.configuration.ApplicationConfig;
32 import org.oransc.policyagent.configuration.RicConfig;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.GetMapping;
37 import org.springframework.web.bind.annotation.RequestParam;
38 import org.springframework.web.bind.annotation.RestController;
39 import reactor.core.publisher.Mono;
42 public class PolicyController {
44 private final ApplicationConfig appConfig;
45 private static Gson gson = new GsonBuilder() //
50 PolicyController(ApplicationConfig config) {
51 this.appConfig = config;
54 // http://localhost:8080/policy?type=type3&instance=xxx
55 @GetMapping("/policy")
56 public String getPolicy(@RequestParam(name = "type", required = false, defaultValue = "type1") String typeName,
57 @RequestParam(name = "instance", required = false, defaultValue = "new") String instanceId) {
58 System.out.println("**** getPolicy " + typeName);
60 return "policy" + typeName + instanceId;
63 public String getHello() {
67 @GetMapping("/status")
68 @ApiOperation(value = "Returns status and statistics of the service")
71 @ApiResponse(code = 200, message = "DATAFILE service is living"),
72 @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
73 @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
74 @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") //
76 public Mono<ResponseEntity<String>> getStatus() {
77 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>("hunky dory", HttpStatus.OK));
81 // http://localhost:8080/rics?managedElementId=kista_1
83 @ApiOperation(value = "Returns defined NearRT RIC:s")
84 public ResponseEntity<String> getRics(
85 @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
86 Vector<RicInfo> result = new Vector<RicInfo>();
87 Vector<RicConfig> config = getRicConfigs(managedElementId);
89 for (RicConfig ricConfig : config) {
90 RicInfo ric = ImmutableRicInfo.builder() //
91 .managedElementIds(ricConfig.managedElementIds()) //
92 .name(ricConfig.name()) //
97 return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
100 private Vector<RicConfig> getRicConfigs(String managedElementId) {
101 if (managedElementId.equals("")) {
102 return this.appConfig.getRicConfigs();
105 Vector<RicConfig> result = new Vector<RicConfig>(1);
106 appConfig.getRicConfig(managedElementId).ifPresent((config) -> {