aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-10-07 13:59:01 +0000
committerGerrit Code Review <gerrit@onap.org>2020-10-07 13:59:01 +0000
commitc78b9b566d82c60318ca5a235ce00ca735be430b (patch)
tree3a42864d4a497d783203bc08108e1a06689c2907
parent4c7a4b6c8a137ce3799d8ac00d4d2b4a0031fe1d (diff)
parent7c996cbd1735e4c570bef411c8fbbec0db44faea (diff)
Merge "use timeout interval in minutes for poll duration"
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java16
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java25
2 files changed, 28 insertions, 13 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index c33160d255..a7c47f8f53 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -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;
}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
index 4938bff748..4f7fed7df4 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
@@ -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,6 +140,7 @@ 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"));
@@ -148,6 +148,22 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
}
@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();
stack.setId("id");
@@ -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);