use timeout interval in minutes for poll duration 80/113080/2
authorMnushkin, Dmitry <dmitry.mnushkin@att.com>
Wed, 23 Sep 2020 20:26:31 +0000 (16:26 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Thu, 1 Oct 2020 15:56:16 +0000 (11:56 -0400)
use timeout interval in minutes for poll duration
do not ignore retry test with 1 min delay
rename variable and debug info for clarity

Issue-ID: SO-3264
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Ia3c6d789b0e93df909476e92764ccbb32d7472e7

adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java

index c33160d..a7c47f8 100644 (file)
@@ -24,6 +24,7 @@
 package org.onap.so.openstack.utils;
 
 import java.io.IOException;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -124,10 +125,8 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
 
     // Properties names and variables (with default values)
     protected String createPollIntervalProp = "org.onap.so.adapters.po.pollInterval";
-    private String pollingMultiplierProp = "org.onap.so.adapters.po.pollMultiplier";
 
     protected static final String CREATE_POLL_INTERVAL_DEFAULT = "15";
-    private static final String POLLING_MULTIPLIER_DEFAULT = "60";
 
     private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
 
@@ -348,9 +347,12 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
             String tenantId, boolean notFoundIsSuccess) throws MsoException {
         int pollingFrequency =
                 Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT));
-        int pollingMultiplier =
-                Integer.parseInt(this.environment.getProperty(pollingMultiplierProp, POLLING_MULTIPLIER_DEFAULT));
-        int numberOfPollingAttempts = Math.floorDiv((timeoutMinutes * pollingMultiplier), pollingFrequency);
+        LocalDateTime stopPolling = LocalDateTime.now().plusMinutes(timeoutMinutes);
+        if (pollingFrequency > timeoutMinutes * 60) {
+            logger.debug("Will not poll. Poll interval {} sec is greater then timeout {} sec", pollingFrequency,
+                    timeoutMinutes * 60);
+            stopPolling = LocalDateTime.now().minusMinutes(1);
+        }
         Heat heatClient = getHeatClient(cloudSiteId, tenantId);
         while (true) {
             String stackName = stack.getStackName() + "/" + stack.getId();
@@ -363,12 +365,12 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
             } else if (latestStack != null) {
                 statusHandler.updateStackStatus(latestStack);
                 if (stackStatus.equals(latestStack.getStackStatus())) {
-                    if (numberOfPollingAttempts <= 0) {
+                    if (LocalDateTime.now().isAfter(stopPolling)) {
                         logger.error("Polling of stack timed out with Status: {}", latestStack.getStackStatus());
                         return latestStack;
                     }
+                    logger.debug("Will poll again until {}", stopPolling);
                     sleep(pollingFrequency * 1000L);
-                    numberOfPollingAttempts -= 1;
                 } else {
                     return latestStack;
                 }
index 4938bff..4f7fed7 100644 (file)
@@ -36,6 +36,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -106,7 +107,6 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
     @Before
     public void setup() {
         doReturn("15").when(env).getProperty("org.onap.so.adapters.po.pollInterval", "15");
-        doReturn("1").when(env).getProperty("org.onap.so.adapters.po.pollMultiplier", "60");
     }
 
     @Test
@@ -130,9 +130,8 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         assertEquals(true, actual != null);
     }
 
-
     @Test
-    public final void pollStackForStatus_Polling_Exhausted_Test() throws MsoException, IOException {
+    public final void pollStackForStatus_No_Polling_Test() throws MsoException, IOException {
         Stack stack = new Stack();
         stack.setId("id");
         stack.setStackName("stackName");
@@ -141,12 +140,29 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         doNothing().when(stackStatusHandler).updateStackStatus(stack);
         doReturn(stack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
+        doReturn("61").when(env).getProperty("org.onap.so.adapters.po.pollInterval", "15");
         Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
         Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(stack);
         Mockito.verify(heatUtils, times(1)).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         assertEquals(true, actual != null);
     }
 
+    @Test
+    public final void pollStackForStatus_Polling_Exhausted_Test() throws MsoException, IOException {
+        Stack stack = new Stack();
+        stack.setId("id");
+        stack.setStackName("stackName");
+        stack.setStackStatus("CREATE_IN_PROGRESS");
+        stack.setStackStatusReason("Stack Finished");
+        doNothing().when(stackStatusHandler).updateStackStatus(stack);
+        doReturn(stack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
+        doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
+        Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
+        Mockito.verify(stackStatusHandler, times(5)).updateStackStatus(stack);
+        Mockito.verify(heatUtils, times(5)).queryHeatStack(isA(Heat.class), eq("stackName/id"));
+        assertEquals(true, actual != null);
+    }
+
     @Test
     public final void postProcessStackCreate_CREATE_IN_PROGRESS_Test() throws MsoException, IOException {
         Stack stack = new Stack();
@@ -255,12 +271,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         CreateStackParam createStackParam = new CreateStackParam();
         createStackParam.setStackName("stackName");
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
-        doNothing().when(heatUtils).postProcessStackDelete(deletedStack);
         doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(mockDeleteStack);
         doReturn(stackResource).when(heatClient).getStacks();
         doReturn(mockDeleteStack).when(stackResource).deleteByName("stackName/id");
-        doReturn(deletedStack).when(heatUtils).pollStackForStatus(120, stack, "DELETE_IN_PROGRESS", cloudSiteId,
-                tenantId, true);
 
         heatUtils.handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
         Mockito.verify(heatUtils, times(1)).executeAndRecordOpenstackRequest(mockDeleteStack);