- // http://localhost:8080/rics?managedElementId=kista_1
- @GetMapping("/rics")
- @ApiOperation(value = "Returns defined NearRT RIC:s")
- public ResponseEntity<String> getRics(
- @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
- Vector<RicInfo> result = new Vector<RicInfo>();
- Vector<RicConfig> config = getRicConfigs(managedElementId);
-
- for (RicConfig ricConfig : config) {
- RicInfo ric = ImmutableRicInfo.builder() //
- .managedElementIds(ricConfig.managedElementIds()) //
- .name(ricConfig.name()) //
+ @DeleteMapping("/policy")
+ @ApiOperation(value = "Deletes the policy", response = Object.class)
+ @ApiResponses(value = {@ApiResponse(code = 204, message = "Policy deleted", response = Object.class)})
+ public Mono<ResponseEntity<Void>> deletePolicy( //
+ @RequestParam(name = "instance", required = true) String id) {
+ Policy policy = policies.get(id);
+ if (policy != null && policy.ric().getState() == Ric.RicState.IDLE) {
+ policies.remove(policy);
+ return a1ClientFactory.createA1Client(policy.ric()) //
+ .flatMap(client -> client.deletePolicy(policy)) //
+ .flatMap(notUsed -> {
+ return Mono.just(new ResponseEntity<>(HttpStatus.NO_CONTENT));
+ });
+ } else {
+ return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
+ }
+ }
+
+ @PutMapping(path = "/policy")
+ @ApiOperation(value = "Put a policy", response = String.class)
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Policy created or updated")})
+ public Mono<ResponseEntity<String>> putPolicy( //
+ @RequestParam(name = "type", required = true) String typeName, //
+ @RequestParam(name = "instance", required = true) String instanceId, //
+ @RequestParam(name = "ric", required = true) String ricName, //
+ @RequestParam(name = "service", required = true) String service, //
+ @RequestBody Object jsonBody) {
+
+ String jsonString = gson.toJson(jsonBody);
+
+ Ric ric = rics.get(ricName);
+ PolicyType type = policyTypes.get(typeName);
+ if (ric != null && type != null && ric.getState() == Ric.RicState.IDLE) {
+ Policy policy = ImmutablePolicy.builder() //
+ .id(instanceId) //
+ .json(jsonString) //
+ .type(type) //
+ .ric(ric) //
+ .ownerServiceName(service) //
+ .lastModified(getTimeStampUTC()) //