diff options
2 files changed, 45 insertions, 11 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java index faef863e..e84c9838 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java @@ -219,12 +219,16 @@ public class RefreshConfigTask { private Mono<Ric> trySyncronizeSupportedTypes(Ric ric) { logger.debug("Synchronizing policy types for new RIC: {}", ric.id()); // Synchronize the policy types + ric.setState(RicState.SYNCHRONIZING); return this.a1ClientFactory.createA1Client(ric) // .flatMapMany(client -> synchronizationTask().synchronizePolicyTypes(ric, client)) // .collectList() // .flatMap(list -> Mono.just(ric)) // - .doOnError(t -> logger.warn("Failed to synchronize types in new RIC: {}, reason: {}", ric.id(), - t.getMessage())) // + .doOnNext(notUsed -> ric.setState(RicState.AVAILABLE)) // + .doOnError(t -> { + logger.warn("Failed to synchronize types in new RIC: {}, reason: {}", ric.id(), t.getMessage()); + ric.setState(RicState.UNAVAILABLE); // + }) // .onErrorResume(t -> Mono.just(ric)); } @@ -238,7 +242,6 @@ public class RefreshConfigTask { return trySyncronizeSupportedTypes(new Ric(updatedInfo.getRicConfig())) // .flatMap(this::addRic) // .flatMap(this::notifyServicesRicAvailable) // - .doOnNext(ric -> ric.setState(RicState.AVAILABLE)) // .flatMap(notUsed -> Mono.just(event)); } else if (event == RicConfigUpdate.Type.REMOVED) { logger.debug("RIC removed {}", ricId); @@ -270,10 +273,14 @@ public class RefreshConfigTask { } private Mono<Ric> notifyServicesRicAvailable(Ric ric) { - ServiceCallbacks callbacks = new ServiceCallbacks(this.restClientFactory); - return callbacks.notifyServicesRicAvailable(ric, services) // - .collectList() // - .flatMap(list -> Mono.just(ric)); + if (ric.getState() == RicState.AVAILABLE) { + ServiceCallbacks callbacks = new ServiceCallbacks(this.restClientFactory); + return callbacks.notifyServicesRicAvailable(ric, services) // + .collectList() // + .flatMap(list -> Mono.just(ric)); + } else { + return Mono.just(ric); + } } /** 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 84bc47ad..91eb6333 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 @@ -50,6 +50,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient; import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig; +import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig; @@ -263,10 +264,9 @@ class ApplicationTest { putService("service"); - RicConfig config = ricConfig(RIC, "me1"); - ApplicationConfig.RicConfigUpdate update = - new ApplicationConfig.RicConfigUpdate(config, ApplicationConfig.RicConfigUpdate.Type.ADDED); - refreshConfigTask.handleUpdatedRicConfig(update).block(); + refreshConfigTask.handleUpdatedRicConfig( // + new RicConfigUpdate(ricConfig(RIC, "me1"), RicConfigUpdate.Type.ADDED)) // + .block(); waitForRicState(RIC, RicState.AVAILABLE); // Test that the type has been synched @@ -283,6 +283,33 @@ class ApplicationTest { } @Test + void testAddingRicFromConfiguration_nonRespondingRic() throws ServiceException { + putService("service"); + + final String RIC = "NonRespondingRic"; + MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client(RIC); + WebClientResponseException a1Exception = new WebClientResponseException(404, "", null, null, null); + doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyTypeIdentities(); + + refreshConfigTask.handleUpdatedRicConfig( // + new RicConfigUpdate(ricConfig(RIC, "me1"), RicConfigUpdate.Type.ADDED)) // + .block(); + + waitForRicState(RIC, RicState.UNAVAILABLE); + + // Check that no service callback for the UNAVAILABLE RIC is invoked + RappSimulatorController.TestResults receivedCallbacks = rAppSimulator.getTestResults(); + assertThat(receivedCallbacks.getReceivedInfo().size()).isEqualTo(0); + + // Run a synch and check that the AVAILABLE notificationis received + a1ClientFactory.reset(); + supervision.checkAllRics(); + waitForRicState(RIC, RicState.AVAILABLE); + receivedCallbacks = rAppSimulator.getTestResults(); + assertThat(receivedCallbacks.getReceivedInfo().size()).isEqualTo(1); + } + + @Test void testGetRics() throws Exception { addRic("ric1"); this.addPolicyType("type1", "ric1"); |