aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java66
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java29
2 files changed, 65 insertions, 30 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 c323bb699d..6db0a58e3f 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
@@ -220,7 +220,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
boolean backout) throws MsoException {
stripMultiCloudInputs(stackInputs);
-
CreateStackParam createStack =
createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles);
Stack currentStack = createStack(createStack, cloudSiteId, tenantId);
@@ -271,20 +270,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
}
}
+
protected Stack processCreateStack(String cloudSiteId, String tenantId, int timeoutMinutes, boolean backout,
Stack heatStack, CreateStackParam stackCreate, boolean keyPairCleanUp) throws MsoException {
- Stack latestStack;
+ Stack latestStack = null;
try {
latestStack = pollStackForStatus(timeoutMinutes, heatStack, CREATE_IN_PROGRESS, cloudSiteId, tenantId);
} catch (MsoException me) {
- if (!backout) {
- logger.info("Exception in Create Stack, stack deletion suppressed", me);
- } else {
- logger.info("Exception in Create Stack, stack deletion will be executed", me);
- handleUnknownCreateStackFailure(heatStack, timeoutMinutes, cloudSiteId, tenantId);
- }
- me.addContext(CREATE_STACK);
- throw me;
+ logger.error("Exception in Create Stack", me);
}
return postProcessStackCreate(latestStack, backout, timeoutMinutes, keyPairCleanUp, cloudSiteId, tenantId,
stackCreate);
@@ -292,26 +285,43 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
protected Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair,
String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException {
- logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair,
- stack);
- if (!CREATE_COMPLETE.equals(stack.getStackStatus())) {
- if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason())
- && isKeyPairFailure(stack.getStackStatusReason())) {
- return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack);
- }
- if (!backout) {
- logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed");
- throw new StackCreationException("Stack rollback suppressed, stack not deleted");
+ if (stack == null) {
+ throw new StackCreationException("Unknown Error in Stack Creation");
+ } else {
+ logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair,
+ stack);
+ if (!CREATE_COMPLETE.equals(stack.getStackStatus())) {
+ if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason())
+ && isKeyPairFailure(stack.getStackStatusReason())) {
+ return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack);
+ }
+ if (!backout) {
+ logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed");
+ throw new StackCreationException("Stack rollback suppressed, stack not deleted");
+ } else {
+ logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed");
+ String errorMessage = "Stack Creation Failed Openstack Status: " + stack.getStackStatus()
+ + " Status Reason: " + stack.getStackStatusReason();
+ try {
+ Stack deletedStack =
+ handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId);
+ errorMessage = errorMessage + " , Rollback of Stack Creation completed with status: "
+ + deletedStack.getStackStatus() + " Status Reason: "
+ + deletedStack.getStackStatusReason();
+ } catch (MsoException e) {
+ logger.error("Sync Error Deleting Stack during rollback", e);
+ if (e instanceof StackRollbackException) {
+ errorMessage = errorMessage + e.getMessage();
+ } else {
+ errorMessage = errorMessage + " , Rollback of Stack Creation failed with sync error: "
+ + e.getMessage();
+ }
+ }
+ throw new StackCreationException(errorMessage);
+ }
} else {
- logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed");
- Stack deletedStack = handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId);
- throw new StackCreationException("Stack Creation Failed Openstack Status: " + stack.getStackStatus()
- + " Status Reason: " + stack.getStackStatusReason()
- + " , Rollback of Stack Creation completed with status: " + deletedStack.getStackStatus()
- + " Status Reason: " + deletedStack.getStackStatusReason());
+ return stack;
}
- } else {
- return stack;
}
}
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 6673e69a09..de55e85ad6 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
@@ -188,6 +188,31 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
}
@Test
+ public final void postProcessStackCreate_Backout_True_Delete_Fail_Test() throws MsoException, IOException {
+ Stack stack = new Stack();
+ stack.setId("id");
+ stack.setStackName("stackName");
+ stack.setStackStatus("CREATE_IN_PROGRESS");
+ stack.setStackStatusReason("Stack Finished");
+
+ Stack deletedStack = new Stack();
+ deletedStack.setId("id");
+ deletedStack.setStackName("stackName");
+ deletedStack.setStackStatus("DELETE_COMPLETE");
+ deletedStack.setStackStatusReason("Stack Deleted");
+
+ CreateStackParam createStackParam = new CreateStackParam();
+ createStackParam.setStackName("stackName");
+ doThrow(new MsoOpenstackException(500, "Error In Delete", "Error In Delete")).when(heatUtils)
+ .handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
+ exceptionRule.expect(MsoException.class);
+ exceptionRule.expectMessage(
+ "Stack Creation Failed Openstack Status: CREATE_IN_PROGRESS Status Reason: Stack Finished , Rollback of Stack Creation failed with sync error: Error In Delete");
+ heatUtils.postProcessStackCreate(stack, true, 120, false, cloudSiteId, tenantId, createStackParam);
+ Mockito.verify(heatUtils, times(1)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
+ }
+
+ @Test
public final void postProcessStackCreate_Keypair_True_Test() throws MsoException, IOException {
Stack stack = new Stack();
stack.setId("id");
@@ -375,12 +400,12 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
doThrow(new StackCreationException("Error")).when(heatUtils).pollStackForStatus(120, stack,
"CREATE_IN_PROGRESS", cloudSiteId, tenantId);
- doReturn(deletedStack).when(heatUtils).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
exceptionRule.expect(MsoException.class);
exceptionRule.expectMessage("Error");
heatUtils.processCreateStack(cloudSiteId, tenantId, 120, true, stack, createStackParam, true);
Mockito.verify(heatUtils, times(1)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId);
- Mockito.verify(heatUtils, times(1)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
+ Mockito.verify(heatUtils, times(1)).postProcessStackCreate(stack, true, 120, true, cloudSiteId, tenantId,
+ createStackParam);
}