From cd4e5b408603a13dabc58f832e4aae4194e81995 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Wed, 25 Mar 2020 16:04:41 -0400 Subject: convert openstack to external tasks Use external tasks to communicate with openstack adapter Will be more resilient to failures Refactored all flows to use external tasks not REST calls Rollback is now an external task Ensured backwards compatibility Issue-ID: SO-2767 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I8afdb89c688d756aed0f25f7d9a7fb898142554d --- .../openstack/utils/MsoHeatEnvironmentEntry.java | 3 +- .../org/onap/so/openstack/utils/MsoHeatUtils.java | 52 +++++++++++++--------- .../onap/so/openstack/utils/MsoHeatUtilsTest.java | 10 ++--- 3 files changed, 37 insertions(+), 28 deletions(-) (limited to 'adapters/mso-adapter-utils') diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java index 47ba076e0e..1f6ff1408c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java @@ -58,7 +58,8 @@ public class MsoHeatEnvironmentEntry { return; byte[] b = this.rawEntry.toString().getBytes(); MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); - StringBuilder sb = null; + this.parameters = yaml.getParameterListFromEnvt(); + StringBuilder sb = this.getResourceRegistryRawEntry(); if (yaml != null) { this.parameters = yaml.getParameterListFromEnvt(); // this.resources = yaml.getResourceListFromEnvt(); 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 97ba7828c0..62d9f068f9 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 @@ -132,7 +132,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); - /** * Create a new Stack in the specified cloud location and tenant. The Heat template and parameter map are passed in * as arguments, along with the cloud access credentials. It is expected that parameters have been validated and @@ -190,7 +189,10 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } else if (CREATE_FAILED.equals(currentStack.getStackStatus()) || DELETE_FAILED.equals(currentStack.getStackStatus())) { try { - processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, createStack, true); + if (pollForCompletion) { + processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, createStack, + true); + } } catch (MsoException e) { if (e instanceof StackCreationException) { logger.warn("Error during Stack will attempt to recreate stack"); @@ -199,9 +201,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { if (pollForCompletion) { currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, createStack, true); - } else { - currentStack = queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), - cloudSiteId, tenantId); } } else { throw e; @@ -214,9 +213,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { if (pollForCompletion) { currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, createStack, true); - } else { - currentStack = - queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), cloudSiteId, tenantId); } operationPerformed = true; } @@ -266,6 +262,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Stack heatStack, CreateStackParam stackCreate, boolean keyPairCleanUp) throws MsoException { Stack latestStack = null; try { + latestStack = pollStackForStatus(timeoutMinutes, heatStack, CREATE_IN_PROGRESS, cloudSiteId, tenantId, false); } catch (MsoException me) { @@ -275,7 +272,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { stackCreate); } - protected Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair, + public Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair, String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException { boolean stackCreationFailed = false; boolean stackRollbackFailed = false; @@ -325,7 +322,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } - protected Stack pollStackForStatus(int timeoutMinutes, Stack stack, String stackStatus, String cloudSiteId, + public Stack pollStackForStatus(int timeoutMinutes, Stack stack, String stackStatus, String cloudSiteId, String tenantId, boolean notFoundIsSuccess) throws MsoException { int pollingFrequency = Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT)); @@ -334,7 +331,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { int numberOfPollingAttempts = Math.floorDiv((timeoutMinutes * pollingMultiplier), pollingFrequency); Heat heatClient = getHeatClient(cloudSiteId, tenantId); while (true) { - Stack latestStack = queryHeatStack(heatClient, stack.getStackName() + "/" + stack.getId()); + String stackName = stack.getStackName() + "/" + stack.getId(); + if (stack.getId() == null) { + stackName = stack.getStackName(); + } + Stack latestStack = queryHeatStack(heatClient, stackName); if (latestStack == null && notFoundIsSuccess) { return null; } else if (latestStack != null) { @@ -385,27 +386,33 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { protected Stack handleUnknownCreateStackFailure(Stack stack, int timeoutMinutes, String cloudSiteId, String tenantId) throws MsoException { if (stack != null && !Strings.isNullOrEmpty(stack.getStackName()) && !Strings.isNullOrEmpty(stack.getId())) { - return deleteStack(stack, timeoutMinutes, cloudSiteId, tenantId); + return deleteStack(stack, timeoutMinutes, cloudSiteId, tenantId, false); } else { throw new StackCreationException("Cannot Find Stack Name or Id"); } } - private Stack deleteStack(Stack stack, int timeoutMinutes, String cloudSiteId, String tenantId) - throws MsoException { + private Stack deleteStack(Stack stack, int timeoutMinutes, String cloudSiteId, String tenantId, + boolean pollForCompletion) throws MsoException { OpenStackRequest request = getHeatClient(cloudSiteId, tenantId).getStacks() .deleteByName(stack.getStackName() + "/" + stack.getId()); executeAndRecordOpenstackRequest(request); - Stack currentStack = pollStackForStatus(timeoutMinutes, stack, DELETE_IN_PROGRESS, cloudSiteId, tenantId, true); - if (currentStack == null) { + logger.debug("Completed Executing executeAndRecordOpenstackRequest"); + if (pollForCompletion == true) { + Stack currentStack = + pollStackForStatus(timeoutMinutes, stack, DELETE_IN_PROGRESS, cloudSiteId, tenantId, true); + if (currentStack == null) { + return currentStack; + } + postProcessStackDelete(currentStack); return currentStack; } else { - postProcessStackDelete(currentStack); + logger.debug("Returning the stack"); + return stack; } - return currentStack; } - protected void postProcessStackDelete(Stack stack) throws MsoException { + public void postProcessStackDelete(Stack stack) throws MsoException { logger.info("Performing post processing on delete stack {}", stack); if (stack != null && !Strings.isNullOrEmpty(stack.getStackStatus())) { if (!DELETE_COMPLETE.equals(stack.getStackStatus())) @@ -503,10 +510,13 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { stackInfo = new StackInfo(stackName, HeatStatus.NOTFOUND); stackInfo.setOperationPerformed(false); } else { - currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId); + currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId, pollForCompletion); stackInfo = new StackInfoMapper(currentStack).map(); stackInfo.setName(stackName); stackInfo.setOperationPerformed(true); + if (currentStack != null) { + stackInfo.setCanonicalName(currentStack.getStackName() + "/" + currentStack.getId()); + } } return stackInfo; } @@ -632,7 +642,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { return queryHeatStack(getHeatClient(cloudSiteId, tenantId), stackName); } - + // TODO enhancement - just have this return the stack then we dont have to query again in deleteStack public Map queryStackForOutputs(String cloudSiteId, String cloudOwner, String tenantId, String stackName) throws MsoException { logger.debug("MsoHeatUtils.queryStackForOutputs)"); 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 0f9f7a273e..4938bff748 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -264,9 +264,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { heatUtils.handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); Mockito.verify(heatUtils, times(1)).executeAndRecordOpenstackRequest(mockDeleteStack); - Mockito.verify(heatUtils, times(1)).pollStackForStatus(120, stack, "DELETE_IN_PROGRESS", cloudSiteId, tenantId, + Mockito.verify(heatUtils, times(0)).pollStackForStatus(120, stack, "DELETE_IN_PROGRESS", cloudSiteId, tenantId, true); - Mockito.verify(heatUtils, times(1)).postProcessStackDelete(deletedStack); + Mockito.verify(heatUtils, times(0)).postProcessStackDelete(deletedStack); } @@ -324,8 +324,6 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { CreateStackParam createStackParam = new CreateStackParam(); createStackParam.setStackName("stackName"); - // doReturn(mockResources).when(heatUtils).queryStackResources(cloudSiteId, tenantId, "stackName", 2); - // doNothing().when(novaClient).deleteKeyPair(cloudSiteId, tenantId, "KeypairName"); doReturn(null).when(heatUtils).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); doReturn(createdStack).when(heatUtils).createStack(createStackParam, cloudSiteId, tenantId); doReturn(createdStack).when(heatUtils).processCreateStack(cloudSiteId, tenantId, 120, true, createdStack, -- cgit 1.2.3-korg