- private void increaseReconcileCount(BigInteger nodeId, Boolean reconcileState) {
- InstanceIdentifier<ReconcileCounter> instanceIdentifier = InstanceIdentifier
- .builder(ReconciliationCounter.class).child(ReconcileCounter.class,
- new ReconcileCounterKey(nodeId)).build();
- ReadWriteTransaction tx = broker.newReadWriteTransaction();
- Optional<ReconcileCounter> optional = readReconcileCounterFromDS(tx, instanceIdentifier, nodeId);
- ReconcileCounterBuilder counterBuilder = new ReconcileCounterBuilder()
- .withKey(new ReconcileCounterKey(nodeId)).setNodeId(nodeId)
- .setLastRequestTime(LocalDateTime.now().toString());
- if (reconcileState) {
- counterBuilder.setSuccessCount(startCount);
- if (optional.isPresent()) {
- ReconcileCounter counter = optional.get();
- Long successCount = counter.getSuccessCount();
- counterBuilder.setSuccessCount(++successCount);
- LOG.debug("Reconcile Success count {} for the node: {} ", successCount, nodeId);
- }
- } else {
- counterBuilder.setFailureCount(startCount);
- if (optional.isPresent()) {
- ReconcileCounter counter = optional.get();
- Long failureCount = counter.getFailureCount();
- counterBuilder.setFailureCount(++failureCount);
- LOG.debug("Reconcile Failure count {} for the node: {} ", failureCount, nodeId);
- }
- }
- try {
- tx.merge(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, counterBuilder.build(), true);
- tx.submit().get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Exception while submitting counter {}", nodeId, e);
- }
- }
-
- private Optional<ReconcileCounter> readReconcileCounterFromDS(ReadWriteTransaction tx,
- InstanceIdentifier<ReconcileCounter> instanceIdentifier, BigInteger nodeId) {
- try {
- return tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Exception while reading counter for node: {}", nodeId, e);
- }
- return Optional.absent();