X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Ftasks%2FRicSynchronizationTask.java;h=a42135ef335e594696c45206ae9e27cf5c758fe2;hb=refs%2Fchanges%2F31%2F2831%2F3;hp=d75999111532c9fd916a3cb76a4884c31b9b9d93;hpb=7c297ddb425a52dae965adc6a83629a14421ea05;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java index d7599911..a42135ef 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java @@ -28,6 +28,7 @@ import org.oransc.policyagent.clients.A1Client; import org.oransc.policyagent.clients.A1ClientFactory; import org.oransc.policyagent.clients.AsyncRestClient; import org.oransc.policyagent.repository.ImmutablePolicyType; +import org.oransc.policyagent.repository.Lock; import org.oransc.policyagent.repository.Lock.LockType; import org.oransc.policyagent.repository.Policies; import org.oransc.policyagent.repository.Policy; @@ -54,6 +55,7 @@ import reactor.core.publisher.Mono; *
* Notify subscribing services
*/
+@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class RicSynchronizationTask {
private static final Logger logger = LoggerFactory.getLogger(RicSynchronizationTask.class);
@@ -71,7 +73,7 @@ public class RicSynchronizationTask {
this.services = services;
}
- @SuppressWarnings("squid:S2629")
+ @SuppressWarnings("squid:S2445") // Blocks should be synchronized on "private final" fields
public void run(Ric ric) {
logger.debug("Handling ric: {}", ric.getConfig().name());
@@ -82,9 +84,10 @@ public class RicSynchronizationTask {
}
ric.setState(RicState.SYNCHRONIZING);
}
- ric.getLock().lockBlocking(LockType.EXCLUSIVE); // Make sure no NBI updates are running
- ric.getLock().unlock();
- this.a1ClientFactory.createA1Client(ric)//
+
+ ric.getLock().lock(LockType.EXCLUSIVE) // Make sure no NBI updates are running
+ .flatMap(Lock::unlock) //
+ .flatMap(lock -> this.a1ClientFactory.createA1Client(ric)) //
.flatMapMany(client -> startSynchronization(ric, client)) //
.subscribe(x -> logger.debug("Synchronize: {}", x), //
throwable -> onSynchronizationError(ric, throwable), //
@@ -99,9 +102,8 @@ public class RicSynchronizationTask {
return Flux.concat(recoverTypes, policiesDeletedInRic, policiesRecreatedInRic);
}
- @SuppressWarnings("squid:S2629")
private void onSynchronizationComplete(Ric ric) {
- logger.debug("Synchronization completed for: {}", ric.name());
+ logger.info("Synchronization completed for: {}", ric.name());
ric.setState(RicState.IDLE);
notifyAllServices("Synchronization completed for:" + ric.name());
}
@@ -122,25 +124,23 @@ public class RicSynchronizationTask {
}
}
- @SuppressWarnings("squid:S2629")
private void onSynchronizationError(Ric ric, Throwable t) {
logger.warn("Synchronization failed for ric: {}, reason: {}", ric.name(), t.getMessage());
- // If recovery fails, try to remove all instances
+ // If synchronization fails, try to remove all instances
deleteAllPoliciesInRepository(ric);
Flux