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;
// 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();
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();
} 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;
}
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;
@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
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");
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();
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);