X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fcontrollers%2FPolicyController.java;h=6d3f59456f8349764c6f0de87c5ed16d76d557a6;hb=73a8d2b71f8b683865d96ad78576d0f7ab654ba6;hp=3240cdd113c9a199d9dafc2d26a0b9dbbc23b506;hpb=222a0318c0551eaa4b827a19c7eb5e380a68faf6;p=nonrtric.git 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..6d3f5945 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 @@ -28,6 +28,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -46,6 +47,8 @@ import org.oransc.policyagent.repository.Ric; import org.oransc.policyagent.repository.Rics; import org.oransc.policyagent.repository.Service; import org.oransc.policyagent.repository.Services; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -84,6 +87,7 @@ public class PolicyController { @Autowired private Services services; + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static Gson gson = new GsonBuilder() // .serializeNulls() // .create(); // @@ -226,13 +230,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 +272,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"); @@ -389,7 +403,7 @@ public class PolicyController { policyInfo.service = p.ownerServiceName(); policyInfo.lastModified = p.lastModified(); if (!policyInfo.validate()) { - throw new NullPointerException("BUG, all fields must be set"); + logger.error("BUG, all fields must be set"); } v.add(policyInfo); }