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;
* <p>
* Notify subscribing services
*/
+@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class RicSynchronizationTask {
private static final Logger logger = LoggerFactory.getLogger(RicSynchronizationTask.class);
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());
}
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), //
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());
}
}
}
- @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<PolicyType> recoverTypes = this.a1ClientFactory.createA1Client(ric) //
.flatMapMany(a1Client -> synchronizePolicyTypes(ric, a1Client));
Flux<?> deletePoliciesInRic = this.a1ClientFactory.createA1Client(ric) //
- .flatMapMany(a1Client -> a1Client.deleteAllPolicies()) //
+ .flatMapMany(A1Client::deleteAllPolicies) //
.doOnComplete(() -> deleteAllPoliciesInRepository(ric));
Flux.concat(recoverTypes, deletePoliciesInRic) //
- .subscribe(x -> logger.debug("Brute recover: " + x), //
+ .subscribe(x -> logger.debug("Brute recover: {}", x), //
throwable -> onRecoveryError(ric, throwable), //
() -> onSynchronizationComplete(ric));
}
- @SuppressWarnings("squid:S2629")
private void onRecoveryError(Ric ric, Throwable t) {
logger.warn("Synchronization failure recovery failed for ric: {}, reason: {}", ric.name(), t.getMessage());
ric.setState(RicState.UNDEFINED);