Add Logging to specify next retry 68/129768/3
authorDylanB95EST <dylan.byrne@est.tech>
Fri, 1 Jul 2022 15:38:14 +0000 (16:38 +0100)
committerDylanB95EST <dylan.byrne@est.tech>
Fri, 1 Jul 2022 16:18:13 +0000 (17:18 +0100)
Adding logging to specify the next time in minutes
until the retry mechanism will attempt to unlock
the cm handle if it is not yet ready to be unlocked

Issue-ID: CPS-1076
Change-Id: Ic2b011966c779f13ad8380ebfd7d4b4354e6b3e1
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/SyncUtils.java

index 0c3af6a..8c30b59 100644 (file)
@@ -151,18 +151,22 @@ public class SyncUtils {
      * @return if the retry mechanism should be attempted
      */
     public boolean isReadyForRetry(final CompositeState compositeState) {
-        int timeUntilNextAttempt = 1;
+        int timeInMinutesUntilNextAttempt = 1;
         final OffsetDateTime time =
             OffsetDateTime.parse(compositeState.getLastUpdateTime(),
                 DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
         final Matcher matcher = retryAttemptPattern.matcher(compositeState.getLockReason().getDetails());
         if (matcher.find()) {
-            timeUntilNextAttempt = (int) Math.pow(2, Integer.parseInt(matcher.group(1)));
+            timeInMinutesUntilNextAttempt = (int) Math.pow(2, Integer.parseInt(matcher.group(1)));
         } else {
             log.debug("First Attempt: no current attempts found.");
         }
         final int timeSinceLastAttempt = (int) Duration.between(time, OffsetDateTime.now()).toMinutes();
-        return timeSinceLastAttempt > timeUntilNextAttempt;
+        if (timeInMinutesUntilNextAttempt >= timeSinceLastAttempt) {
+            log.info("Time until next attempt is {} minutes: ",
+                timeInMinutesUntilNextAttempt - timeSinceLastAttempt);
+        }
+        return timeSinceLastAttempt > timeInMinutesUntilNextAttempt;
     }
 
     /**