From: PatrikBuhr Date: Thu, 9 Apr 2020 11:46:21 +0000 (+0200) Subject: Added check in PUT policy X-Git-Tag: 2.0.0~81^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=6f609c727d66ad20b5b31eae472fcde5e4acd569;p=nonrtric.git Added check in PUT policy For PUT policy, added ad check that the RIC actually supports the given type. Previously it was only check that the type existed. Change-Id: I0e4772c46686aab44ed335e9026043f4f5febce6 Issue-ID: NONRTRIC-164 Signed-off-by: PatrikBuhr --- diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java index 3240cdd1..e8c75ec9 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@ -226,13 +226,14 @@ public class PolicyController { final boolean isCreate = this.policies.get(policy.id()) == null; return ric.getLock().lock(LockType.SHARED) // - .flatMap(p -> assertRicStateIdle(ric)) // - .flatMap(p -> validateModifiedPolicy(policy)) // + .flatMap(notUsed -> assertRicStateIdle(ric)) // + .flatMap(notUsed -> checkSupportedType(ric, type)) // + .flatMap(notUsed -> validateModifiedPolicy(policy)) // .flatMap(notUsed -> a1ClientFactory.createA1Client(ric)) // .flatMap(client -> client.putPolicy(policy)) // .doOnNext(notUsed -> policies.put(policy)) // .doOnNext(notUsed -> ric.getLock().unlockBlocking()) // - .doOnError(t -> ric.getLock().unlockBlocking()) // + .doOnError(trowable -> ric.getLock().unlockBlocking()) // .flatMap(notUsed -> Mono.just(new ResponseEntity<>(isCreate ? HttpStatus.CREATED : HttpStatus.OK))) // .onErrorResume(this::handleException); } @@ -267,6 +268,15 @@ public class PolicyController { return Mono.just("OK"); } + private Mono checkSupportedType(Ric ric, PolicyType type) { + if (!ric.isSupportingType(type.name())) { + RejectionException e = new RejectionException( + "Type: " + type.name() + " not supported by RIC: " + ric.name(), HttpStatus.NOT_FOUND); + return Mono.error(e); + } + return Mono.just("OK"); + } + private Mono assertRicStateIdle(Ric ric) { if (ric.getState() == Ric.RicState.AVAILABLE) { return Mono.just("OK"); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 19e0425b..7ad2dc86 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -355,6 +355,7 @@ public class ApplicationTest { this.addRic("ric1"); this.addRic("ricXXX"); this.addPolicy("instance1", "type1", "service1", "ric1"); + this.addPolicy("instance2", "type1", "service1", "ricXXX"); // Try change ric1 -> ricXXX String urlWrongRic = putPolicyUrl("service1", "ricXXX", "type1", "instance1"); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java index 21808567..79c8b11d 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java @@ -20,7 +20,6 @@ package org.oransc.policyagent.clients; - import java.util.Arrays; import java.util.Vector;