summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-09-01 18:29:19 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-01 18:29:19 +0000
commit31fe9a139a820dc83d472f69605107d1041341c8 (patch)
tree0eea90127dc1a378b839969f4599bfd5ae5997d6
parent7e7144ddbd512a1d2a2da93c80b9cff2d58bf16d (diff)
parent50daaac12878c4acd2a5d38e8964f293db02f674 (diff)
Merge "Fixing instable test"
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java35
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java14
2 files changed, 35 insertions, 14 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
index 9d9aff45..d42d51e9 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
@@ -115,18 +115,25 @@ public class PolicyController {
value = "The identity of the policy type to get the definition for. When this parameter is given, max one schema will be returned") //
@RequestParam(name = Consts.POLICY_TYPE_ID_PARAM, required = false) String policyTypeId) {
try {
- if (ricId == null && policyTypeId == null) {
+ Ric ric = ricId == null ? null : rics.getRic(ricId);
+ if (ric == null && policyTypeId == null) {
Collection<PolicyType> types = this.policyTypes.getAll();
return new ResponseEntity<>(toPolicyTypeSchemasJson(types), HttpStatus.OK);
- } else if (ricId != null && policyTypeId != null) {
- Collection<PolicyType> types = new ArrayList<>();
- if (rics.getRic(ricId).isSupportingType(policyTypeId)) {
- types.add(policyTypes.getType(policyTypeId));
+ } else if (ric != null && policyTypeId != null) {
+ synchronized (ric) {
+ assertRicStateIdleSync(ric);
+ Collection<PolicyType> types = new ArrayList<>();
+ if (rics.getRic(ricId).isSupportingType(policyTypeId)) {
+ types.add(policyTypes.getType(policyTypeId));
+ }
+ return new ResponseEntity<>(toPolicyTypeSchemasJson(types), HttpStatus.OK);
+ }
+ } else if (ric != null) {
+ synchronized (ric) {
+ assertRicStateIdleSync(ric);
+ Collection<PolicyType> types = rics.getRic(ricId).getSupportedPolicyTypes();
+ return new ResponseEntity<>(toPolicyTypeSchemasJson(types), HttpStatus.OK);
}
- return new ResponseEntity<>(toPolicyTypeSchemasJson(types), HttpStatus.OK);
- } else if (ricId != null) {
- Collection<PolicyType> types = rics.getRic(ricId).getSupportedPolicyTypes();
- return new ResponseEntity<>(toPolicyTypeSchemasJson(types), HttpStatus.OK);
} else {
Collection<PolicyType> types = new ArrayList<>();
types.add(policyTypes.getType(policyTypeId));
@@ -318,13 +325,19 @@ public class PolicyController {
return Mono.just("{}");
}
+ private void assertRicStateIdleSync(Ric ric) throws ServiceException {
+ if (ric.getState() != Ric.RicState.AVAILABLE) {
+ throw new ServiceException("Near-RT RIC: " + ric.id() + " is " + ric.getState());
+ }
+ }
+
private Mono<Object> assertRicStateIdle(Ric ric) {
if (ric.getState() == Ric.RicState.AVAILABLE) {
return Mono.just("{}");
} else {
- logger.debug("Request rejected RIC not IDLE, ric: {}", ric);
+ logger.debug("Request rejected Near-RT RIC not IDLE, ric: {}", ric);
RejectionException e = new RejectionException(
- "Ric is not operational, RIC name: " + ric.id() + ", state: " + ric.getState(), HttpStatus.LOCKED);
+ "Near-RT RIC: is not operational, id: " + ric.id() + ", state: " + ric.getState(), HttpStatus.LOCKED);
return Mono.error(e);
}
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
index 5ef70aa9..243ded43 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
@@ -253,9 +253,9 @@ class ApplicationTest {
supervision.checkAllRics(); // The created policy should be put in the RIC
// Wait until synch is completed
- await().untilAsserted(() -> RicState.SYNCHRONIZING.equals(rics.getRic(ric1Name).getState()));
- await().untilAsserted(() -> RicState.AVAILABLE.equals(rics.getRic(ric1Name).getState()));
- await().untilAsserted(() -> RicState.AVAILABLE.equals(rics.getRic("ric2").getState()));
+ waitForRicState(ric1Name, RicState.SYNCHRONIZING);
+ waitForRicState(ric1Name, RicState.AVAILABLE);
+ waitForRicState("ric2", RicState.AVAILABLE);
Policies ricPolicies = getA1Client(ric1Name).getPolicies();
assertThat(ricPolicies.size()).isEqualTo(1);
@@ -466,6 +466,9 @@ class ApplicationTest {
addPolicyType("type1", "ric1");
addPolicyType("type2", "ric2");
+ waitForRicState("ric1", RicState.AVAILABLE);
+ waitForRicState("ric2", RicState.AVAILABLE);
+
String url = "/policy-schemas";
String rsp = this.restClient().get(url).block();
assertThat(rsp).contains("type1") //
@@ -804,6 +807,11 @@ class ApplicationTest {
.verify();
}
+ private void waitForRicState(String ricId, RicState state) throws ServiceException {
+ Ric ric = rics.getRic(ricId);
+ await().untilAsserted(() -> state.equals(ric.getState()));
+ }
+
private boolean checkWebClientError(Throwable throwable, HttpStatus expStatus, String responseContains,
boolean expectApplicationProblemJsonMediaType) {
assertTrue(throwable instanceof WebClientResponseException);