diff options
Diffstat (limited to 'adapters')
23 files changed, 439 insertions, 556 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java index 4eb16d46b2..d7bc22aa7c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java @@ -566,7 +566,7 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { Executions executions = listExecutions.execute(); // If no executions, does this give NOT_FOUND or empty set? - if (executions.getItems().isEmpty()) { + if (executions == null || executions.getItems().isEmpty()) { return new DeploymentInfoBuilder().withId(deployment.getId()) .withDeploymentInputs(deployment.getInputs()).build(); } else { @@ -755,16 +755,19 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint exists: {}", bp.getId()); - return true; + if (bp != null) { + logger.debug("Blueprint exists: {}", bp.getId()); + return true; + } else { + logger.debug("Null blueprint!"); + return false; + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { return false; } else { throw ce; } - } catch (Exception e) { - throw e; } } @@ -803,8 +806,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint {} already exists.", bp.getId()); - return false; + if (bp != null) { + logger.debug("Blueprint {} already exists.", bp.getId()); + return false; + } else { + logger.debug("Null blueprint!"); + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { // This is the expected result. @@ -812,8 +819,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { } else { throw ce; } - } catch (Exception e) { - throw e; } // Create a blueprint ZIP file in memory 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 b5a97f7559..75a8ca0593 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 @@ -89,6 +89,10 @@ import com.woorea.openstack.heat.model.Stacks; @Component public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { + private static final String CREATE_FAILED = "CREATE_FAILED"; + + private static final String DELETE_FAILED = "DELETE_FAILED"; + private static final String CREATE_COMPLETE = "CREATE_COMPLETE"; private static final String DELETE_COMPLETE = "DELETE_COMPLETE"; @@ -133,42 +137,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); - /** - * keep this old method signature here to maintain backwards compatibility. keep others as well. this method does - * not include environment, files, or heatFiles - */ - public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, - String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes) - throws MsoException { - // Just call the new method with the environment & files variable set to null - return this.createStack(cloudSiteId, cloudOwner, tenantId, stackName, null, heatTemplate, stackInputs, - pollForCompletion, timeoutMinutes, null, null, null, true); - } - - // This method has environment, but not files or heatFiles - public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, - String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes, - String environment) throws MsoException { - // Just call the new method with the files/heatFiles variables set to null - return this.createStack(cloudSiteId, cloudOwner, tenantId, stackName, null, heatTemplate, stackInputs, - pollForCompletion, timeoutMinutes, environment, null, null, true); - } - - // This method has environment and files, but not heatFiles. - public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, - String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes, - String environment, Map<String, Object> files) throws MsoException { - return this.createStack(cloudSiteId, cloudOwner, tenantId, stackName, null, heatTemplate, stackInputs, - pollForCompletion, timeoutMinutes, environment, files, null, true); - } - // This method has environment, files, heatfiles - public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, - String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes, - String environment, Map<String, Object> files, Map<String, Object> heatFiles) throws MsoException { - return this.createStack(cloudSiteId, cloudOwner, tenantId, stackName, null, heatTemplate, stackInputs, - pollForCompletion, timeoutMinutes, environment, files, heatFiles, true); - } /** * Create a new Stack in the specified cloud location and tenant. The Heat template and parameter map are passed in @@ -211,20 +180,50 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { @SuppressWarnings("unchecked") public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, VduModelInfo vduModel, String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, - int timeoutMinutes, String environment, Map<String, Object> files, Map<String, Object> heatFiles, - boolean backout) throws MsoException { - + int timeoutMinutes, String environment, Map<String, Object> nestedTemplates, Map<String, Object> heatFiles, + boolean backout, boolean failIfExists) throws MsoException { stripMultiCloudInputs(stackInputs); - CreateStackParam createStack = - createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles); - Stack currentStack = createStack(createStack, cloudSiteId, tenantId); - currentStack.setStackName(stackName); - if (pollForCompletion) { - currentStack = + CreateStackParam createStack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, + environment, nestedTemplates, heatFiles); + Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId); + if (currentStack != null) { + logger.debug("Existing Stack found with Status: {} ", currentStack.getStackStatus()); + if (CREATE_COMPLETE.equals(currentStack.getStackStatus())) { + new StackInfoMapper(currentStack).map(); + } else if (CREATE_IN_PROGRESS.equals(currentStack.getStackStatus())) { + currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, + createStack, true); + } else if (CREATE_FAILED.equals(currentStack.getStackStatus()) + || DELETE_FAILED.equals(currentStack.getStackStatus())) { + try { 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"); + currentStack = createStack(createStack, cloudSiteId, tenantId); + currentStack.setStackName(stackName); + if (pollForCompletion) { + currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, + currentStack, createStack, true); + } else { + currentStack = queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), + cloudSiteId, tenantId); + } + } else { + throw e; + } + } + } } else { - currentStack = - queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), cloudSiteId, tenantId); + currentStack = createStack(createStack, cloudSiteId, tenantId); + currentStack.setStackName(stackName); + if (pollForCompletion) { + currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, + createStack, true); + } else { + currentStack = + queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), cloudSiteId, tenantId); + } } return new StackInfoMapper(currentStack).map(); } @@ -270,7 +269,8 @@ 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); + latestStack = + pollStackForStatus(timeoutMinutes, heatStack, CREATE_IN_PROGRESS, cloudSiteId, tenantId, false); } catch (MsoException me) { logger.error("Exception in Create Stack", me); } @@ -280,47 +280,54 @@ 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 { + boolean stackCreationFailed = false; + boolean stackRollbackFailed = false; if (stack == null) { throw new StackCreationException("Unknown Error in Stack Creation"); - } - - 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 (StackRollbackException se) { - logger.error("Sync Error Deleting Stack during rollback process", se); - errorMessage = errorMessage + se.getMessage(); - } catch (MsoException e) { - logger.error("Sync Error Deleting Stack during rollback", e); - - errorMessage = - errorMessage + " , Rollback of Stack Creation failed with sync error: " + e.getMessage(); + } 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"); + stackCreationFailed = true; + throw new StackCreationException("Stack rollback suppressed, stack not deleted", + stackCreationFailed, stackRollbackFailed); + } else { + logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); + stackCreationFailed = true; + 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) { + stackRollbackFailed = true; + 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, stackCreationFailed, stackRollbackFailed); } - throw new StackCreationException(errorMessage); + } else { + return stack; } - } else { - return stack; } - } protected Stack pollStackForStatus(int timeoutMinutes, Stack stack, String stackStatus, String cloudSiteId, - String tenantId) throws MsoException { + String tenantId, boolean notFoundIsSuccess) throws MsoException { int pollingFrequency = Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT)); int pollingMultiplier = @@ -329,9 +336,10 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); while (true) { Stack latestStack = queryHeatStack(heatClient, stack.getStackName() + "/" + stack.getId()); - if (latestStack != null) { + if (latestStack == null && notFoundIsSuccess) { + return null; + } else if (latestStack != null) { statusHandler.updateStackStatus(latestStack); - logger.debug("Polling: {} ({})", latestStack.getStackStatus(), latestStack.getStackName()); if (stackStatus.equals(latestStack.getStackStatus())) { if (numberOfPollingAttempts <= 0) { logger.error("Polling of stack timed out with Status: {}", latestStack.getStackStatus()); @@ -342,9 +350,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } else { return latestStack; } - } else { - logger.error("latestStack is null"); - return null; } } } @@ -381,17 +386,26 @@ 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())) { - OpenStackRequest<Void> request = getHeatClient(cloudSiteId, tenantId).getStacks() - .deleteByName(stack.getStackName() + "/" + stack.getId()); - executeAndRecordOpenstackRequest(request); - Stack currentStack = pollStackForStatus(timeoutMinutes, stack, DELETE_IN_PROGRESS, cloudSiteId, tenantId); - postProcessStackDelete(currentStack); - return currentStack; + return deleteStack(stack, timeoutMinutes, cloudSiteId, tenantId); } else { throw new StackCreationException("Cannot Find Stack Name or Id"); } } + private Stack deleteStack(Stack stack, int timeoutMinutes, String cloudSiteId, String tenantId) + throws MsoException { + OpenStackRequest<Void> 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) { + return currentStack; + } else { + postProcessStackDelete(currentStack); + } + return currentStack; + } + protected void postProcessStackDelete(Stack stack) throws MsoException { logger.info("Performing post processing on delete stack {}", stack); if (stack != null && !Strings.isNullOrEmpty(stack.getStackStatus())) { @@ -453,7 +467,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { // Query the Stack. // An MsoException will propagate transparently to the caller. Stack heatStack = queryHeatStack(heatClient, stackName); - if (heatStack == null) { // Stack does not exist. Return a StackInfo with status NOTFOUND return new StackInfo(stackName, HeatStatus.NOTFOUND); @@ -484,114 +497,16 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { * @throws MsoCloudSiteNotFound */ public StackInfo deleteStack(String tenantId, String cloudOwner, String cloudSiteId, String stackName, - boolean pollForCompletion) throws MsoException { - Heat heatClient = null; - try { - heatClient = getHeatClient(cloudSiteId, tenantId); - } catch (MsoTenantNotFound e) { - logger.debug("Tenant with id " + tenantId + "not found.", e); - return new StackInfo(stackName, HeatStatus.NOTFOUND); - } catch (MsoException me) { - logger.error("{} {} Openstack Exception on Token request: ", MessageEnum.RA_CONNECTION_EXCEPTION, - ErrorCode.AvailabilityError.getValue(), me); - me.addContext(DELETE_STACK); - throw me; - } - - // OK if stack not found, perform a query first - Stack heatStack = queryHeatStack(heatClient, stackName); - if (heatStack == null || DELETE_COMPLETE.equals(heatStack.getStackStatus())) { - // Not found. Return a StackInfo with status NOTFOUND - return new StackInfo(stackName, HeatStatus.NOTFOUND); - } - - // Use canonical name "<stack name>/<stack-id>" to delete. - // Otherwise, deletion by name returns a 302 redirect. - // NOTE: This is specific to the v1 Orchestration API. - String canonicalName = heatStack.getStackName() + "/" + heatStack.getId(); - - try { - OpenStackRequest<Void> request = null; - if (null != heatClient) { - request = heatClient.getStacks().deleteByName(canonicalName); - } else { - logger.debug("Heat Client is NULL"); - } - executeAndRecordOpenstackRequest(request); - } catch (OpenStackResponseException e) { - if (e.getStatus() == 404) { - // Not found. We are OK with this. Return a StackInfo with status NOTFOUND - return new StackInfo(stackName, HeatStatus.NOTFOUND); - } else { - // Convert the OpenStackResponseException to an MsoOpenstackException - throw heatExceptionToMsoException(e, DELETE_STACK); - } - } catch (OpenStackConnectException e) { - // Error connecting to Openstack instance. Convert to an MsoException - throw heatExceptionToMsoException(e, DELETE_STACK); - } catch (RuntimeException e) { - // Catch-all - throw runtimeExceptionToMsoException(e, DELETE_STACK); - } - - // Requery the stack for current status. - // It will probably still exist with "DELETE_IN_PROGRESS" status. - heatStack = queryHeatStack(heatClient, canonicalName); - statusHandler.updateStackStatus(heatStack); - if (pollForCompletion) { - int pollInterval = Integer - .parseInt(this.environment.getProperty(deletePollIntervalProp, "" + DELETE_POLL_INTERVAL_DEFAULT)); - int pollTimeout = Integer - .parseInt(this.environment.getProperty(deletePollTimeoutProp, "" + DELETE_POLL_INTERVAL_DEFAULT)); - statusHandler.updateStackStatus(heatStack); - // When querying by canonical name, Openstack returns DELETE_COMPLETE status - // instead of "404" (which would result from query by stack name). - while (heatStack != null && !DELETE_COMPLETE.equals(heatStack.getStackStatus())) { - logger.debug("Stack status: {}", heatStack.getStackStatus()); - - if ("DELETE_FAILED".equals(heatStack.getStackStatus())) { - // Throw a 'special case' of MsoOpenstackException to report the Heat status - String error = "Stack delete error (" + heatStack.getStackStatus() + "): " - + heatStack.getStackStatusReason(); - MsoOpenstackException me = new MsoOpenstackException(0, "", error); - me.addContext(DELETE_STACK); - - // Alarm this condition, stack deletion failed - - - throw me; - } - - if (pollTimeout <= 0) { - logger.error("{} Cloud site: {} Tenant: {} Stack: {} Stack status: {} {} Delete Stack Timeout", - MessageEnum.RA_DELETE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, - heatStack.getStackStatus(), ErrorCode.AvailabilityError.getValue()); - - // Throw a 'special case' of MsoOpenstackException to report the Heat status - MsoOpenstackException me = new MsoOpenstackException(0, "", "Stack Deletion Timeout"); - me.addContext(DELETE_STACK); - - // Alarm this condition, stack deletion failed - - - throw me; - } - - sleep(pollInterval * 1000L); - - pollTimeout -= pollInterval; - logger.debug("pollTimeout remaining: {}", pollTimeout); - - heatStack = queryHeatStack(heatClient, canonicalName); - } - - // The stack is gone when this point is reached + boolean pollForCompletion, int timeoutMinutes) throws MsoException { + Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId); + if (currentStack == null || DELETE_COMPLETE.equals(currentStack.getStackStatus())) { return new StackInfo(stackName, HeatStatus.NOTFOUND); + } else { + currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId); + StackInfo stackInfo = new StackInfoMapper(currentStack).map(); + stackInfo.setName(stackName); + return stackInfo; } - // Return the current status (if not polling, the delete may still be in progress) - StackInfo stackInfo = new StackInfoMapper(heatStack).map(); - stackInfo.setName(stackName); - return stackInfo; } /** @@ -734,7 +649,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { if (!inputs.containsKey(key)) { Object obj = otherStackOutputs.get(key); if (obj instanceof String) { - inputs.put(key, (String) otherStackOutputs.get(key)); + inputs.put(key, otherStackOutputs.get(key)); } else if (obj instanceof JsonNode) { // This is a bit of mess - but I think it's the least impacting // let's convert it BACK to a string - then it will get converted back later @@ -1115,11 +1030,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } try { - StackInfo stackInfo = - createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, inputs, true, // poll - // for - // completion - vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure); + StackInfo stackInfo = createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, + inputs, true, // poll + // for + // completion + vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure, false); // Populate a vduInstance from the StackInfo return stackInfoToVduInstance(stackInfo); @@ -1160,7 +1075,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { try { // Delete the Heat stack - StackInfo stackInfo = deleteStack(tenantId, cloudOwner, cloudSiteId, instanceId, true); + StackInfo stackInfo = deleteStack(tenantId, cloudOwner, cloudSiteId, instanceId, true, timeoutMinutes); // Populate a VduInstance based on the deleted Cloudify Deployment object VduInstance vduInstance = stackInfoToVduInstance(stackInfo); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 1701cda98e..3eb3fe188d 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -135,7 +135,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, VduModelInfo vduModel, String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes, String environment, Map<String, Object> files, Map<String, Object> heatFiles, - boolean backout) throws MsoException { + boolean backout, boolean failIfExists) throws MsoException { logger.trace("Started MsoMulticloudUtils.createStack"); @@ -881,11 +881,11 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { } try { - StackInfo stackInfo = - createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, inputs, true, // poll - // for - // completion - vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure); + StackInfo stackInfo = createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, + inputs, true, // poll + // for + // completion + vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure, false); // Populate a vduInstance from the StackInfo return stackInfoToVduInstance(stackInfo); } catch (Exception e) { @@ -957,6 +957,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { /* * Convert the local DeploymentInfo object (Cloudify-specific) to a generic VduInstance object */ + @Override protected VduInstance stackInfoToVduInstance(StackInfo stackInfo) { VduInstance vduInstance = new VduInstance(); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackCreationException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackCreationException.java index e3936e31f7..ab9c8a6dee 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackCreationException.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackCreationException.java @@ -24,8 +24,22 @@ import org.onap.so.openstack.exceptions.MsoException; public class StackCreationException extends MsoException { + /** + * + */ + private static final long serialVersionUID = 6221508301589330950L; + + boolean stackCreationFailed = false; + boolean stackRollbackFailed = false; + public StackCreationException(String error) { super(error); } + public StackCreationException(String error, boolean stackCreationFailed, boolean stackRollbackFailed) { + super(error); + this.stackRollbackFailed = stackRollbackFailed; + this.stackCreationFailed = stackCreationFailed; + } + } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsITTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsITTest.java index 7e783aa7a4..86b1413291 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsITTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsITTest.java @@ -133,7 +133,7 @@ public class MsoHeatUtilsITTest extends BaseTest { @Test public void deleteVduTest() throws Exception { VduInstance expected = new VduInstance(); - expected.setVduInstanceId("instanceId"); + expected.setVduInstanceId("name/stackId"); expected.setVduInstanceName("instanceId"); VduStatus status = new VduStatus(); status.setState(VduStateType.DELETED); @@ -209,8 +209,8 @@ public class MsoHeatUtilsITTest extends BaseTest { StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort); StubOpenStack.mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack_Created.json"); StubOpenStack.mockOpenStackGet(wireMockServer, "TEST-stack/stackId"); - StackInfo stackInfo = heatUtils.createStack(cloudSite.getId(), "CloudOwner", "tenantId", "TEST-stack", - "TEST-heat", new HashMap<>(), false, 1, "TEST-env", new HashMap<>(), new HashMap<>()); + StackInfo stackInfo = heatUtils.createStack(cloudSite.getId(), "CloudOwner", "tenantId", "TEST-stack", null, + "TEST-heat", new HashMap<>(), false, 1, "TEST-env", new HashMap<>(), new HashMap<>(), false, false); assertNotNull(stackInfo); } 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 e68364eab8..92cf96ed16 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 @@ -124,7 +124,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { latestStack.setStackStatusReason("Stack Finished"); doReturn(latestStack).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); + Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false); Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(latestStack); Mockito.verify(heatUtils, times(1)).queryHeatStack(isA(Heat.class), eq("stackName/id")); assertEquals(true, actual != null); @@ -141,7 +141,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); - Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId); + 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); @@ -259,11 +259,12 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { doReturn(stackResource).when(heatClient).getStacks(); doReturn(mockDeleteStack).when(stackResource).deleteByName("stackName/id"); doReturn(deletedStack).when(heatUtils).pollStackForStatus(120, stack, "DELETE_IN_PROGRESS", cloudSiteId, - tenantId); + tenantId, true); 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(1)).pollStackForStatus(120, stack, "DELETE_IN_PROGRESS", cloudSiteId, tenantId, + true); Mockito.verify(heatUtils, times(1)).postProcessStackDelete(deletedStack); } @@ -357,12 +358,13 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { createStackParam.setStackName("stackName"); doReturn(createdStack).when(heatUtils).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, - tenantId); + tenantId, false); doReturn(createdStack).when(heatUtils).postProcessStackCreate(createdStack, true, 120, true, cloudSiteId, tenantId, createStackParam); 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)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, + false); Mockito.verify(heatUtils, times(1)).postProcessStackCreate(createdStack, true, 120, true, cloudSiteId, tenantId, createStackParam); } @@ -387,11 +389,12 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { createStackParam.setStackName("stackName"); doThrow(new StackCreationException("Error")).when(heatUtils).pollStackForStatus(120, stack, - "CREATE_IN_PROGRESS", cloudSiteId, tenantId); + "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false); 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)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, + false); Mockito.verify(heatUtils, times(1)).postProcessStackCreate(stack, true, 120, true, cloudSiteId, tenantId, createStackParam); } @@ -527,12 +530,13 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { createStackParam.setStackName("stackName"); doThrow(new StackCreationException("Error")).when(heatUtils).pollStackForStatus(120, stack, - "CREATE_IN_PROGRESS", cloudSiteId, tenantId); + "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false); exceptionRule.expect(MsoException.class); exceptionRule.expectMessage("Error"); heatUtils.processCreateStack(cloudSiteId, tenantId, 120, false, stack, createStackParam, true); - Mockito.verify(heatUtils, times(1)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId); + Mockito.verify(heatUtils, times(1)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, + false); Mockito.verify(heatUtils, times(0)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java index 995db522e9..44a9bc3e10 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java @@ -24,8 +24,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -95,9 +95,9 @@ public class MsoMulticloudUtilsTest extends BaseTest { wireMockServer.stubFor(get(urlEqualTo(MULTICLOUD_GET_PATH)).inScenario("CREATE").whenScenarioStateIs("UPDATING") .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("MulticloudGetUpdateResponse.json").withStatus(HttpStatus.SC_OK))); - StackInfo result = - multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), - "TEST-heat", new HashMap<>(), true, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); + StackInfo result = multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", + new VduModelInfo(), "TEST-heat", new HashMap<>(), true, 200, "TEST-env", new HashMap<>(), + new HashMap<>(), false, false); wireMockServer.resetScenarios(); assertNotNull(result); assertEquals("TEST-stack", result.getName()); @@ -155,7 +155,8 @@ public class MsoMulticloudUtilsTest extends BaseTest { cloudSite.setIdentityService(new CloudIdentity()); when(cloudConfigMock.getCloudSite("MTN13")).thenReturn(Optional.of(cloudSite)); multicloudUtilsMock.createStack("MNT14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), - "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false, + false); } catch (MsoException e) { assertEquals("0 : Multicloud client could not be initialized", e.toString()); return; @@ -169,7 +170,8 @@ public class MsoMulticloudUtilsTest extends BaseTest { wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).willReturn( aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_BAD_REQUEST))); multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), - "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false, + false); } catch (MsoException e) { assertEquals("0 : Bad Request", e.toString()); return; @@ -181,9 +183,9 @@ public class MsoMulticloudUtilsTest extends BaseTest { public void createStackEmptyResponseEntity() throws MsoException { wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).willReturn( aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_CREATED))); - StackInfo result = - multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), - "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); + StackInfo result = multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", + new VduModelInfo(), "TEST-heat", new HashMap<>(), false, 200, "TEST-env", new HashMap<>(), + new HashMap<>(), false, false); assertNotNull(result); assertEquals("TEST-stack/", result.getName()); } diff --git a/adapters/mso-adapter-utils/src/test/resources/__files/OpenstackResponse_Stack_DeleteComplete.json b/adapters/mso-adapter-utils/src/test/resources/__files/OpenstackResponse_Stack_DeleteComplete.json index a26a551f7d..ea05b64e08 100644 --- a/adapters/mso-adapter-utils/src/test/resources/__files/OpenstackResponse_Stack_DeleteComplete.json +++ b/adapters/mso-adapter-utils/src/test/resources/__files/OpenstackResponse_Stack_DeleteComplete.json @@ -3,7 +3,7 @@ "description": null, "links": null, "stack_status_reason": null, - "stack_name": null, + "stack_name": "name", "updated_time": null, "creation_time": null, "stack_status": "DELETE_COMPLETE", diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java index e1cca8901e..347bce5b17 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java @@ -37,6 +37,7 @@ import org.json.JSONException; import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest; +import org.onap.so.db.catalog.beans.ServiceRecipe; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -52,6 +53,8 @@ public class CatalogDBRestTest extends CatalogDbAdapterBaseTest { private static final String ECOMP_MSO_CATALOG_V2_VF_MODULES = "ecomp/mso/catalog/v2/vfModules"; + private static final String SERVICE_RECIPE = "serviceRecipe"; + private static final String ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES = "ecomp/mso/catalog/v2/serviceAllottedResources"; @@ -839,6 +842,25 @@ public class CatalogDBRestTest extends CatalogDbAdapterBaseTest { } } + @Test + public void testCreateServiceRecipe() throws JSONException { + ServiceRecipe recipe = new ServiceRecipe(); + recipe.setAction("action"); + recipe.setDescription("description"); + recipe.setOrchestrationUri("http://test"); + recipe.setRecipeTimeout(120); + recipe.setServiceModelUUID(serviceUUID); + HttpEntity<ServiceRecipe> entity = new HttpEntity<ServiceRecipe>(recipe, headers); + headers.set("Accept", MediaType.APPLICATION_JSON); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(SERVICE_RECIPE)); + + ResponseEntity<String> response = + restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class); + + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value()); + } + private String createURLWithPort(String uri) { return "http://localhost:" + port + uri; } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java index 013c7f8a84..52b97da61a 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java @@ -24,8 +24,6 @@ package org.onap.so.adapters.network; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,7 +31,6 @@ import java.util.Map; import java.util.Optional; import javax.jws.WebService; import javax.xml.ws.Holder; -import org.onap.so.logger.LoggingAnchor; import org.onap.so.adapters.network.beans.ContrailPolicyRef; import org.onap.so.adapters.network.beans.ContrailPolicyRefSeq; import org.onap.so.adapters.network.beans.ContrailSubnet; @@ -51,6 +48,7 @@ import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; import org.onap.so.db.catalog.utils.MavenLikeVersioning; import org.onap.so.entity.MsoRequest; import org.onap.so.logger.ErrorCode; +import org.onap.so.logger.LoggingAnchor; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; import org.onap.so.openstack.beans.NetworkInfo; @@ -74,6 +72,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; @Component @Transactional @@ -427,7 +427,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { if (backout == null) backout = true; heatStack = heat.createStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName, null, template, - stackParams, true, heatTemplate.getTimeoutMinutes(), null, null, null, backout.booleanValue()); + stackParams, true, heatTemplate.getTimeoutMinutes(), null, null, null, backout.booleanValue(), + failIfExists); } catch (MsoException me) { me.addContext(CREATE_NETWORK_CONTEXT); logger.error("{} {} Exception creating network type {} in {}/{} ", MessageEnum.RA_CREATE_NETWORK_EXC, @@ -1015,13 +1016,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { @Override public void deleteNetwork(String cloudSiteId, String tenantId, String networkType, String modelCustomizationUuid, String networkId, MsoRequest msoRequest, Holder<Boolean> networkDeleted) throws NetworkException { - logger.debug("*** DELETE Network adapter with Network: {} in {}/{}", networkId, cloudSiteId, tenantId); - - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); - - if (commonUtils.isNullOrEmpty(cloudSiteId) || commonUtils.isNullOrEmpty(tenantId) || commonUtils.isNullOrEmpty(networkId)) { String error = "Missing mandatory parameter cloudSiteId, tenantId or networkId"; @@ -1043,20 +1038,15 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { networkResource = nrc.getNetworkResource(); } } + String mode = ""; if (networkResource != null) { - logger.debug(LOG_DEBUG_MSG, networkResource); - + logger.debug(LOG_DEBUG_MSG, networkResource.toString()); mode = networkResource.getOrchestrationMode(); } if (NEUTRON_MODE.equals(mode)) { - - // Use MsoNeutronUtils for all NEUTRON commands - long deleteNetworkStarttime = System.currentTimeMillis(); try { - // The deleteNetwork function in MsoNeutronUtils returns success if the network - // was not found. So don't bother to query first. boolean deleted = neutron.deleteNetwork(networkId, tenantId, cloudSiteId); networkDeleted.value = deleted; } catch (MsoException me) { @@ -1065,21 +1055,10 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { ErrorCode.DataError.getValue(), networkId, cloudSiteId, tenantId, me); throw new NetworkException(me); } - } else { // DEFAULT to ("HEAT".equals (mode)) - long deleteStackStarttime = System.currentTimeMillis(); - + } else { try { - // The deleteStack function in MsoHeatUtils returns NOTFOUND if the stack was not found or if the stack - // was deleted. - // So query first to report back if stack WAS deleted or just NOTOFUND - StackInfo heatStack = null; - heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkId); - if (heatStack != null && heatStack.getStatus() != HeatStatus.NOTFOUND) { - heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true); - networkDeleted.value = true; - } else { - networkDeleted.value = false; - } + heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, 120); + networkDeleted.value = true; } catch (MsoException me) { me.addContext("DeleteNetwork"); logger.error("{} {} Delete Network (heat): {} in {}/{} ", MessageEnum.RA_DELETE_NETWORK_EXC, @@ -1087,10 +1066,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { throw new NetworkException(me); } } - - - // On success, nothing is returned. - return; } /** @@ -1103,9 +1078,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { */ @Override public void rollbackNetwork(NetworkRollback rollback) throws NetworkException { - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); - if (rollback == null) { logger.error("{} {} rollback is null", MessageEnum.RA_ROLLBACK_NULL, ErrorCode.DataError.getValue()); return; @@ -1119,8 +1091,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { String modelCustomizationUuid = rollback.getModelCustomizationUuid(); logger.debug("*** ROLLBACK Network {} in {}/{}", networkId, cloudSiteId, tenantId); - - // Retrieve the Network Resource definition NetworkResource networkResource = null; if (commonUtils.isNullOrEmpty(modelCustomizationUuid)) { @@ -1138,13 +1108,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } if (rollback.getNetworkCreated()) { - // Rolling back a newly created network, so delete it. if (NEUTRON_MODE.equals(mode)) { - // Use MsoNeutronUtils for all NEUTRON commands - long deleteNetworkStarttime = System.currentTimeMillis(); try { - // The deleteNetwork function in MsoNeutronUtils returns success if the network - // was not found. So don't bother to query first. neutron.deleteNetwork(networkId, tenantId, cloudSiteId); } catch (MsoException me) { me.addContext("RollbackNetwork"); @@ -1153,12 +1118,9 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { cloudSiteId, tenantId, me); throw new NetworkException(me); } - } else { // DEFAULT to if ("HEAT".equals (mode)) - long deleteStackStarttime = System.currentTimeMillis(); + } else { try { - // The deleteStack function in MsoHeatUtils returns success if the stack - // was not found. So don't bother to query first. - heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true); + heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, 120); } catch (MsoException me) { me.addContext("RollbackNetwork"); logger.error("{} {} Exception - Rollback Network (heat): {} in {}/{} ", @@ -1168,8 +1130,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } } } - - return; } private String validateNetworkParams(NetworkType neutronNetworkType, String networkName, String physicalNetwork, diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index af2fa24ff9..2c78e593a1 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -36,7 +36,6 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import javax.jws.WebService; import javax.xml.ws.Holder; -import org.onap.so.logger.LoggingAnchor; import org.apache.commons.collections.CollectionUtils; import org.onap.so.adapters.valet.GenericValetResponse; import org.onap.so.adapters.valet.ValetClient; @@ -47,7 +46,6 @@ import org.onap.so.adapters.valet.beans.ValetDeleteResponse; import org.onap.so.adapters.valet.beans.ValetRollbackResponse; import org.onap.so.adapters.valet.beans.ValetStatus; import org.onap.so.adapters.valet.beans.ValetUpdateResponse; -import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists; import org.onap.so.adapters.vnf.exceptions.VnfException; import org.onap.so.adapters.vnf.exceptions.VnfNotFound; import org.onap.so.client.aai.AAIResourcesClient; @@ -68,6 +66,7 @@ import org.onap.so.entity.MsoRequest; import org.onap.so.heatbridge.HeatBridgeApi; import org.onap.so.heatbridge.HeatBridgeImpl; import org.onap.so.logger.ErrorCode; +import org.onap.so.logger.LoggingAnchor; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; import org.onap.so.openstack.beans.StackInfo; @@ -80,6 +79,10 @@ import org.onap.so.openstack.exceptions.MsoHeatNotFoundException; import org.onap.so.openstack.utils.MsoHeatEnvironmentEntry; import org.onap.so.openstack.utils.MsoHeatUtils; import org.onap.so.openstack.utils.MsoHeatUtilsWithUpdate; +import org.openstack4j.model.compute.Flavor; +import org.openstack4j.model.compute.Image; +import org.openstack4j.model.compute.Server; +import org.openstack4j.model.heat.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -89,10 +92,6 @@ import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openstack4j.model.compute.Flavor; -import org.openstack4j.model.compute.Image; -import org.openstack4j.model.compute.Server; -import org.openstack4j.model.heat.Resource; @WebService(serviceName = "VnfAdapter", endpointInterface = "org.onap.so.adapters.vnf.MsoVnfAdapter", targetNamespace = "http://org.onap.so/vnf") @@ -133,7 +132,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { @Autowired private MsoHeatUtilsWithUpdate heatU; @Autowired - private MsoHeatUtils heat; + private MsoHeatUtils msoHeatUtils; @Autowired private ValetClient vci; @@ -264,7 +263,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { StackInfo heatStack; try { - heatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, vnfName); + heatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, vnfName); } catch (MsoException me) { me.addContext("QueryVNF"); // Failed to query the Stack due to an openstack exception. @@ -317,7 +316,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug("Deleting VNF {} in {}", vnfName, cloudSiteId + "/" + tenantId); try { - heat.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true); + msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, 118); } catch (MsoException me) { me.addContext(DELETE_VNF); // Failed to query the Stack due to an openstack exception. @@ -360,7 +359,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. try { - heat.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfId, true); + msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfId, true, 118); } catch (MsoException me) { // Failed to rollback the Stack due to an openstack exception. // Convert to a generic VnfException @@ -638,96 +637,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { callHeatbridge(baseVfHeatStackId); } - StackInfo heatStack = null; - try { - if (heat != null) { - heatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, vfModuleName); - } else { - throw new MsoHeatNotFoundException(); - } - } catch (MsoException me) { - String error = "Create VF Module: Query " + vfModuleName + " in " + cloudOwner + "/" + cloudSiteId + "/" - + tenantId + ": " + me; - logger.error(LoggingAnchor.NINE, MessageEnum.RA_QUERY_VNF_ERR.toString(), vfModuleName, cloudOwner, - cloudSiteId, tenantId, OPENSTACK, QUERY_STACK, ErrorCode.DataError.getValue(), - "Exception - " + QUERY_STACK, me); - logger.debug(error); - // Failed to query the Stack due to an openstack exception. - // Convert to a generic VnfException - me.addContext(CREATE_VFM_MODULE); - throw new VnfException(me); - } - // more precise handling/messaging if the stack already exists - if (heatStack != null && heatStack.getStatus() != HeatStatus.NOTFOUND) { - // INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED - HeatStatus status = heatStack.getStatus(); - if (status == HeatStatus.INIT || status == HeatStatus.BUILDING || status == HeatStatus.DELETING - || status == HeatStatus.UPDATING) { - // fail - it's in progress - return meaningful error - String error = CREATE_VF_STACK + " " + vfModuleName + " already exists and has status " - + status.toString() + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId - + "; please wait for it to complete, or fix manually."; - logger.error(LoggingAnchor.NINE, MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, - cloudSiteId, tenantId, OPENSTACK, QUERY_STACK, ErrorCode.DataError.getValue(), - STACK + " " + vfModuleName + " already exists"); - logger.debug(error); - throw new VnfAlreadyExists(vfModuleName, cloudOwner, cloudSiteId, tenantId, - heatStack.getCanonicalName()); - } - if (status == HeatStatus.FAILED) { - // fail - it exists and is in a FAILED state - String error = CREATE_VF_STACK + " " + vfModuleName + " already exists and is in FAILED state in " - + cloudOwner + "/" + cloudSiteId + "/" + tenantId + "; requires manual intervention."; - logger.error(LoggingAnchor.NINE, MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, - cloudSiteId, tenantId, OPENSTACK, QUERY_STACK, ErrorCode.DataError.getValue(), - STACK + " " + vfModuleName + " already exists and is " + "in FAILED state"); - logger.debug(error); - throw new VnfAlreadyExists(vfModuleName, cloudOwner, cloudSiteId, tenantId, - heatStack.getCanonicalName()); - } - if (status == HeatStatus.UNKNOWN || status == HeatStatus.UPDATED) { - // fail - it exists and is in a FAILED state - String error = CREATE_VF_STACK + " " + vfModuleName + " already exists and has status " - + status.toString() + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId - + "; requires manual intervention."; - logger.error(LoggingAnchor.NINE, MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, - cloudSiteId, tenantId, OPENSTACK, QUERY_STACK, ErrorCode.DataError.getValue(), - STACK + " " + vfModuleName + " already exists and is " + "in UPDATED or UNKNOWN state"); - logger.debug(error); - throw new VnfAlreadyExists(vfModuleName, cloudOwner, cloudSiteId, tenantId, - heatStack.getCanonicalName()); - } - if (status == HeatStatus.CREATED) { - // fail - it exists - if (failIfExists != null && failIfExists) { - String error = CREATE_VF_STACK + " " + vfModuleName + " already exists in " + cloudOwner + "/" - + cloudSiteId + "/" + tenantId; - logger.error(LoggingAnchor.NINE, MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, - cloudOwner, cloudSiteId, tenantId, OPENSTACK, QUERY_STACK, ErrorCode.DataError.getValue(), - STACK + " " + vfModuleName + " already exists"); - logger.debug(error); - throw new VnfAlreadyExists(vfModuleName, cloudOwner, cloudSiteId, tenantId, - heatStack.getCanonicalName()); - } else { - logger.debug("Found Existing stack, status={}", heatStack.getStatus()); - // Populate the outputs from the existing stack. - vnfId.value = heatStack.getCanonicalName(); - outputs.value = copyStringOutputs(heatStack.getOutputs()); - rollback.value = vfRollback; // Default rollback - no updates performed - } - } - return; - - } - // handle a nestedStackId if sent- this one would be for the volume - so applies to both Vf and Vnf StackInfo nestedHeatStack = null; - Map<String, Object> nestedVolumeOutputs = null; if (nestedStackId != null) { try { logger.debug("Querying for nestedStackId = {}", nestedStackId); - nestedHeatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, nestedStackId); + nestedHeatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, nestedStackId); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -761,7 +677,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (nestedBaseStackId != null) { try { logger.debug("Querying for nestedBaseStackId = {}", nestedBaseStackId); - nestedBaseHeatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, nestedBaseStackId); + nestedBaseHeatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, nestedBaseStackId); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -790,7 +706,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } try { - // Retrieve the VF VfModule vf = null; VnfResource vnfResource = null; VfModuleCustomization vfmc = null; @@ -985,7 +900,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug("Contents of nestedTemplates - to be added to files: on stack:"); for (HeatTemplate entry : nestedTemplates) { nestedTemplatesChecked.put(entry.getTemplateName(), entry.getTemplateBody()); - logger.debug(entry.getTemplateName() + " -> " + entry.getTemplateBody()); + logger.debug("Adding Nested Template", entry.getTemplateName()); } } else { logger.debug("No nested templates found - nothing to do here"); @@ -1107,13 +1022,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Step 1 - convert what we got as inputs (Map<String, String>) to a // Map<String, Object> - where the object matches the param type identified in the template // This will also not copy over params that aren't identified in the template - goldenInputs = heat.convertInputMap(inputs, heatTemplate); + goldenInputs = msoHeatUtils.convertInputMap(inputs, heatTemplate); // Step 2 - now simply add the outputs as we received them - no need to convert to string logger.debug("Now add in the base stack outputs if applicable"); - heat.copyBaseOutputsToInputs(goldenInputs, baseStackOutputs, parameterNames, aliasToParam); + msoHeatUtils.copyBaseOutputsToInputs(goldenInputs, baseStackOutputs, parameterNames, aliasToParam); // Step 3 - add the volume inputs if any logger.debug("Now add in the volume stack outputs if applicable"); - heat.copyBaseOutputsToInputs(goldenInputs, nestedVolumeOutputs, parameterNames, aliasToParam); + msoHeatUtils.copyBaseOutputsToInputs(goldenInputs, nestedVolumeOutputs, parameterNames, aliasToParam); for (HeatTemplateParam parm : heatTemplate.getParameters()) { logger.debug("Parameter:'" + parm.getParamName() + "', isRequired=" + parm.isRequired() + ", alias=" @@ -1186,15 +1101,16 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Have the tenant. Now deploy the stack itself // Ignore MsoTenantNotFound and MsoStackAlreadyExists exceptions // because we already checked for those. + + StackInfo heatStack = null; try { if (backout == null) { backout = true; } - if (heat != null) { - - heatStack = heat.createStack(cloudSiteId, cloudOwner, tenantId, vfModuleName, null, template, - goldenInputs, true, heatTemplate.getTimeoutMinutes(), newEnvironmentString, - nestedTemplatesChecked, heatFilesObjects, backout.booleanValue()); + if (msoHeatUtils != null) { + heatStack = msoHeatUtils.createStack(cloudSiteId, cloudOwner, tenantId, vfModuleName, null, + template, goldenInputs, true, heatTemplate.getTimeoutMinutes(), newEnvironmentString, + nestedTemplatesChecked, heatFilesObjects, backout.booleanValue(), failIfExists); } else { throw new MsoHeatNotFoundException(); } @@ -1251,15 +1167,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { @Override public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException { - - logger.debug("Deleting VF {} in ", vnfName, cloudOwner + "/" + cloudSiteId + "/" + tenantId); - // Will capture execution time for metrics - - // 1702 capture the output parameters on a delete - // so we'll need to query first Map<String, Object> stackOutputs; try { - stackOutputs = heat.queryStackForOutputs(cloudSiteId, cloudOwner, tenantId, vnfName); + stackOutputs = msoHeatUtils.queryStackForOutputs(cloudSiteId, cloudOwner, tenantId, vnfName); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -1286,7 +1196,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } try { - heat.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true); + msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, 118); } catch (MsoException me) { me.addContext(DELETE_VNF); // Failed to query the Stack due to an openstack exception. @@ -1321,9 +1231,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.error("Exception encountered while sending Confirm to Valet ", e); } } - - // On success, nothing is returned. - return; } @Override @@ -1417,7 +1324,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { StackInfo heatStack; logger.debug("UpdateVfModule - querying for {}", vfModuleName); try { - heatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, vfModuleName); + heatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, vfModuleName); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -1452,7 +1359,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (nestedStackId != null) { try { logger.debug("Querying for nestedStackId = {}", nestedStackId); - nestedHeatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, nestedStackId); + nestedHeatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, nestedStackId); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -1475,7 +1382,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } else { logger.debug("Found nested heat stack - copying values to inputs *later*"); nestedVolumeOutputs = nestedHeatStack.getOutputs(); - heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); + msoHeatUtils.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); } } // handle a nestedBaseStackId if sent - this is the stack ID of the base. @@ -1484,7 +1391,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (nestedBaseStackId != null) { try { logger.debug("Querying for nestedBaseStackId = {}", nestedBaseStackId); - nestedBaseHeatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, nestedBaseStackId); + nestedBaseHeatStack = msoHeatUtils.queryStack(cloudSiteId, cloudOwner, tenantId, nestedBaseStackId); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException @@ -1507,14 +1414,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } else { logger.debug("Found nested base heat stack - copying values to inputs *later*"); baseStackOutputs = nestedBaseHeatStack.getOutputs(); - heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); + msoHeatUtils.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); } } - // Ready to deploy the new VNF - - - // Retrieve the VF definition VnfResource vnfResource = null; VfModule vf = null; @@ -1924,9 +1827,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { parsedVfModuleName = "unknown"; } sendResponseToValet = this.valetUpdateRequest(cloudSiteId, cloudOwner, tenantId, heatFilesObjects, - nestedTemplatesChecked, parsedVfModuleName, false, heatTemplate, newEnvironmentString, - (HashMap<String, Object>) goldenInputs, msoRequest, inputs, failRequestOnValetFailure, - valetModifiedParamsHolder); + nestedTemplatesChecked, parsedVfModuleName, false, heatTemplate, newEnvironmentString, goldenInputs, + msoRequest, inputs, failRequestOnValetFailure, valetModifiedParamsHolder); if (sendResponseToValet) { goldenInputs = valetModifiedParamsHolder.value; } @@ -2064,7 +1966,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean valetSucceeded = false; String valetErrorMessage = "more detail not available"; try { - String keystoneUrl = heat.getCloudSiteKeystoneUrl(cloudSiteId); + String keystoneUrl = msoHeatUtils.getCloudSiteKeystoneUrl(cloudSiteId); Map<String, Object> files = this.combineGetFilesAndNestedTemplates(heatFilesObjects, nestedTemplatesChecked); HeatRequest heatRequest = new HeatRequest(vfModuleName, backout, heatTemplate.getTimeoutMinutes(), @@ -2126,7 +2028,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean valetSucceeded = false; String valetErrorMessage = "more detail not available"; try { - String keystoneUrl = heat.getCloudSiteKeystoneUrl(cloudSiteId); + String keystoneUrl = msoHeatUtils.getCloudSiteKeystoneUrl(cloudSiteId); Map<String, Object> files = this.combineGetFilesAndNestedTemplates(heatFilesObjects, nestedTemplatesChecked); HeatRequest heatRequest = new HeatRequest(vfModuleName, false, heatTemplate.getTimeoutMinutes(), diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2.java index 77c9b1e2f5..89eb6a161d 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2.java @@ -105,7 +105,6 @@ public class VolumeAdapterRestV2 { @ApiResponse(code = 500, message = "create vnfVolume failed, examine entity object for details")}) public Response createVNFVolumes(@ApiParam(value = "mode", required = true) @QueryParam("mode") String mode, @ApiParam(value = "CreateVolumeGroupRequest", required = true) final CreateVolumeGroupRequest req) { - logger.debug("createVNFVolumes enter: {}", req.toJsonString()); CreateVNFVolumesTask task = new CreateVNFVolumesTask(req, mode); if (req.isSynchronous()) { // This is a synchronous request diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java index 1f4c205e7a..412abeab3b 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java @@ -194,9 +194,7 @@ public class NetworkAdapterRestTest extends BaseRestTestUtils { public void testRollbackNetwork() throws IOException { RollbackNetworkRequest request = new RollbackNetworkRequest(); - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(MSO_REQUEST_ID); msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java index 651e2c9a73..0d972bb4d2 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java @@ -40,7 +40,6 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists; import org.onap.so.adapters.vnf.exceptions.VnfException; import org.onap.so.adapters.vnf.exceptions.VnfNotFound; import org.onap.so.db.catalog.beans.HeatEnvironment; @@ -50,15 +49,15 @@ import org.onap.so.db.catalog.beans.VfModule; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfResource; import org.onap.so.entity.MsoRequest; -import org.onap.so.openstack.beans.HeatStatus; -import org.onap.so.openstack.beans.StackInfo; import org.onap.so.openstack.beans.VnfRollback; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.utils.MsoHeatUtils; import org.springframework.beans.factory.annotation.Autowired; +import com.github.tomakehurst.wiremock.stubbing.Scenario; public class MsoVnfAdapterImplTest extends BaseRestTestUtils { + @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -71,17 +70,7 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"; @Test - @Ignore - public void healthCheckVNFTest() { - MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); - instance.healthCheck(); - } - - @Test public void createVnfTest() throws Exception { - StackInfo info = new StackInfo(); - info.setStatus(HeatStatus.CREATED); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStackVfModule_200(wireMockServer); @@ -90,105 +79,57 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + "VFMOD", null, null, "b4ea86b4-253f-11e7-93ae-92361f002671", map, Boolean.TRUE, Boolean.TRUE, + Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); } @Test - public void createVnfTest_HeatStatusUpdating() throws Exception { - expectedException.expect(VnfAlreadyExists.class); + public void createVnfTest_HeatStatusFailed() throws Exception { mockOpenStackResponseAccess(wireMockServer, wireMockPort); - wireMockServer.stubFor(get( urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Updating_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatStatusUpdated() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + .withBodyFile("OpenstackResponse_Stack_Failed_VfModule.json") + .withStatus(HttpStatus.SC_OK)) + .inScenario("HeatStatusFailure").whenScenarioStateIs(Scenario.STARTED) + .willSetStateTo("HeatStackFailed")); wireMockServer.stubFor(get( urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK))); + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") + .withStatus(HttpStatus.SC_OK)) + .inScenario("HeatStatusFailure").whenScenarioStateIs("HeatStackFailed") + .willSetStateTo("HeatStackSuccess")); MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + "VFMOD", null, null, "b4ea86b4-253f-11e7-93ae-92361f002671", map, Boolean.FALSE, Boolean.TRUE, + Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); } - @Test - public void createVnfTest_HeatStatusFailed() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - wireMockServer.stubFor(get( - urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Failed_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); - } @Test public void createVnfTest_HeatStatusCreated() throws Exception { - expectedException.expect(VnfAlreadyExists.class); mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - MsoRequest msoRequest = getMsoRequest(); - Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + "VFMOD", null, null, "b4ea86b4-253f-11e7-93ae-92361f002671", map, Boolean.TRUE, Boolean.TRUE, + Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); } @Test - public void createVnfTest_ExceptionInGettingHeat() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", - "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), - new Holder<Map<String, String>>(), new Holder<VnfRollback>()); - } - - @Test public void createVnfTest_NestedHeatStatusNotFound() throws Exception { expectedException.expect(VnfException.class); mockOpenStackResponseAccess(wireMockServer, wireMockPort); diff --git a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml index 7cc7697129..20fd812ab9 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml +++ b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml @@ -1,5 +1,3 @@ -# will be used as entry in DB to say SITE OFF/ON for healthcheck -# MSO Properties go here org: onap: so: @@ -41,7 +39,7 @@ org: default_keystone_reg_ex: "/[vV][0-9]" default_tenant_description: ECOMP Tenant default_region_type: single - default_user_role: admin + default_user_role: adminev default_success_status_string: Success default_no_regions_status_string: no regions default_orm_request_path: /v1/orm/customers/ diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/Readme.txt b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/Readme.txt index 66876311db..aaad60320d 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/Readme.txt +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/Readme.txt @@ -1,5 +1,9 @@ The following describes how to configure authentication for the VNFM adapter.
+TLS should always be configured to ensure secure communication between the VNFM-adapter <-> BPMN infra and VNFM-adapter <-> VNFM
+If two-way TLS is configured then there is no need for any further authentication (i.e. no need for token or basic auth).
+If two-way TLS is NOT configured then authentication is REQUIRED. Oauth token based authentication must be used for requests, while for notifications either oauth tokens or basic auth can be used.
+
==========================================
To confgure TLS
@@ -12,8 +16,8 @@ The following parameters can be set to configure the certificate for the VNFM ad server:
ssl:
key-alias: so@so.onap.org
- key--store-password: 'I,re7WWEJR$e]x370wRgx?qE'
- key-store: classpath:org.onap.so.p12
+ key--store-password: 'ywsqCy:EEo#j}HJHM7z^Rk[L'
+ key-store: classpath:so-vnfm-adapter.p12
key-store-type: PKCS12
The values shown above relate to the certificate included in the VNFM adapter jar which has been generated from AAF. If a different certificate is to be used then these values should be changed accordingly.
@@ -21,8 +25,8 @@ The following paramters can be set to configure the trust store for the VNFM ada http:
client:
ssl:
- trust-store: org.onap.so.trust.jks
- trust-store-password: NyRD](z:EJJNIt?},QgM3o7H
+ trust-store: classpath:org.onap.so.trust.jks
+ trust-store-password: ',sx#.C*W)]wVgJC6ccFHI#:H'
The values shown above relate to the trust store included in the VNFM adapter jar which has been generated from AAI. If a different trust store is to be used then these values should be changed accordingly.
Ensure the value for the below parameter uses https instead of http
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java index 948f5fc269..3bdba368b2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java @@ -26,10 +26,13 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest; +import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager; import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmRequestFailureException; +import org.onap.so.rest.exceptions.RestProcessingException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,6 +118,18 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider { try { response = getHttpServiceProvider(vnfm).postHttpRequest(terminateVnfRequest, vnfSelfLink + "/terminate", Void.class); + } catch (final RestProcessingException restProcessingException) { + if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) { + InlineResponse201 vnf = getVnf(vnfm, vnfSelfLink).get(); + if (vnf.getInstantiationState().equals(InstantiationStateEnum.NOT_INSTANTIATED)) { + return JobManager.ALREADY_COMPLETED_OPERATION_ID; + } else { + final String errorMessage = + "Terminate request to " + vnfSelfLink + " resulted in exception" + terminateVnfRequest; + logger.error(errorMessage, restProcessingException); + throw new VnfmRequestFailureException(errorMessage, restProcessingException); + } + } } catch (final Exception exception) { final String errorMessage = "Terminate request to " + vnfSelfLink + " resulted in exception" + terminateVnfRequest; diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java index 68fdb79444..3de94ebe05 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java @@ -29,6 +29,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.rest.exceptions.JobNotFoundException; +import org.onap.so.rest.exceptions.HttpResouceNotFoundException; import org.onap.vnfmadapter.v1.model.OperationEnum; import org.onap.vnfmadapter.v1.model.OperationStateEnum; import org.onap.vnfmadapter.v1.model.OperationStatusRetrievalStatusEnum; @@ -42,6 +43,7 @@ import org.springframework.stereotype.Component; */ @Component public class JobManager { + public static final String ALREADY_COMPLETED_OPERATION_ID = "alreadyCompleted"; private static final String SEPARATOR = "_"; private static Logger logger = getLogger(JobManager.class); private final Map<String, VnfmOperation> mapOfJobIdToVnfmOperation = Maps.newConcurrentMap(); @@ -87,6 +89,11 @@ public class JobManager { throw new JobNotFoundException("No job found with ID: " + jobId); } + if (vnfmOperation.getOperationId().equals(ALREADY_COMPLETED_OPERATION_ID)) { + response.setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + return response.operationState(OperationStateEnum.COMPLETED); + } + if (vnfmOperation.isVnfDeleted()) { response.setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); return response.operationState(getOperationState(vnfmOperation, null)); @@ -116,7 +123,7 @@ public class JobManager { response.setVnfInstanceId(operation.getVnfInstanceId()); return response; - } catch (final Exception exception) { + } catch (final HttpResouceNotFoundException exception) { logger.error("Exception encountered trying to get operation status for operation id " + vnfmOperation.getOperationId(), exception); return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java index 461c15a512..a885721b76 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java @@ -24,6 +24,7 @@ import com.google.common.base.Optional; import java.util.Map; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.Relationship; import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; @@ -207,6 +208,10 @@ public class LifecycleManager { final EsrVnfm vnfm = getAssignedVnfm(genericVnf); final String operationId = sendTerminateRequestToVnfm(vnfm, genericVnf); + + if (operationId.equals(JobManager.ALREADY_COMPLETED_OPERATION_ID)) { + sendDeleteRequestToVnfm(genericVnf); + } final String jobId = jobManager.createJob(vnfm.getVnfmId(), operationId, true); return new DeleteVnfResponse().jobId(jobId); @@ -234,4 +239,27 @@ public class LifecycleManager { } return vnfm; } + + private void sendDeleteRequestToVnfm(final GenericVnf genericVnf) { + + vnfmServiceProvider.deleteVnf(aaiHelper.getAssignedVnfm(genericVnf), genericVnf.getSelflink()); + + final GenericVnf genericVnfPatch = new GenericVnf(); + genericVnfPatch.setVnfId(genericVnf.getVnfId()); + genericVnfPatch.setOrchestrationStatus("Assigned"); + genericVnfPatch.setSelflink(""); + aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); + + for (final Relationship relationship : genericVnf.getRelationshipList().getRelationship()) { + if (relationship.getRelatedTo().equals("vserver")) { + aaiServiceProvider.invokeDeleteVserver( + aaiHelper.getRelationshipData(relationship, "cloud-region.cloud-owner"), + aaiHelper.getRelationshipData(relationship, "cloud-region.cloud-region-id"), + aaiHelper.getRelationshipData(relationship, "tenant.tenant-id"), + aaiHelper.getRelationshipData(relationship, "vserver.vserver-id")); + } + } + + + } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java index 7a6bbfe0d9..63ec4ccc57 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java @@ -145,31 +145,31 @@ public class NotificationHandler implements Runnable { } private void handleVnfTerminateFailed() { - final GenericVnf genericVnf = aaiServiceProvider - .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); - deleteVservers(vnfLcmOperationOccurrenceNotification, genericVnf); - jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId(), false); + try { + final GenericVnf genericVnf = aaiServiceProvider + .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); + deleteVserversFromAai(vnfLcmOperationOccurrenceNotification, genericVnf); + } finally { + jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId(), + false); + } } private void handleVnfTerminateCompleted() { - final GenericVnf genericVnf = aaiServiceProvider - .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); - deleteVservers(vnfLcmOperationOccurrenceNotification, genericVnf); - - boolean deleteSuccessful = false; + GenericVnf genericVnf = null; + boolean vServersDeletedFromAai = false; + boolean identifierDeletedFromVnfm = false; + boolean genericVnfUpdated = false; try { - vnfmServiceProvider.deleteVnf(aaiHelper.getAssignedVnfm(genericVnf), genericVnf.getSelflink()); - deleteSuccessful = true; + genericVnf = aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()) + .getGenericVnf().get(0); + vServersDeletedFromAai = deleteVserversFromAai(vnfLcmOperationOccurrenceNotification, genericVnf); + identifierDeletedFromVnfm = deleteVnfIdentifierOnVnfm(genericVnf); + genericVnfUpdated = patchVnfInAai(genericVnf.getVnfId(), "Assigned", identifierDeletedFromVnfm ? "" : null); } finally { jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId(), - deleteSuccessful); + vServersDeletedFromAai && identifierDeletedFromVnfm && genericVnfUpdated); jobManager.vnfDeleted(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId()); - - final GenericVnf genericVnfPatch = new GenericVnf(); - genericVnfPatch.setVnfId(genericVnf.getVnfId()); - genericVnfPatch.setOrchestrationStatus("Assigned"); - genericVnfPatch.setSelflink(""); - aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); } } @@ -194,19 +194,60 @@ public class NotificationHandler implements Runnable { } } - private void deleteVservers(final VnfLcmOperationOccurrenceNotification notification, final GenericVnf vnf) { - for (final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc : notification.getAffectedVnfcs()) { - if (ChangeTypeEnum.REMOVED.equals(vnfc.getChangeType())) { + private boolean deleteVserversFromAai(final VnfLcmOperationOccurrenceNotification notification, + final GenericVnf vnf) { + try { + for (final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc : notification.getAffectedVnfcs()) { + if (ChangeTypeEnum.REMOVED.equals(vnfc.getChangeType())) { - final Relationship relationshipToVserver = aaiHelper.deleteRelationshipWithDataValue(vnf, "vserver", - "vserver.vserver-id", vnfc.getComputeResource().getResourceId()); + final Relationship relationshipToVserver = aaiHelper.deleteRelationshipWithDataValue(vnf, "vserver", + "vserver.vserver-id", vnfc.getComputeResource().getResourceId()); - aaiServiceProvider.invokeDeleteVserver( - aaiHelper.getRelationshipData(relationshipToVserver, "cloud-region.cloud-owner"), - aaiHelper.getRelationshipData(relationshipToVserver, "cloud-region.cloud-region-id"), - aaiHelper.getRelationshipData(relationshipToVserver, "tenant.tenant-id"), - vnfc.getComputeResource().getResourceId()); + aaiServiceProvider.invokeDeleteVserver( + aaiHelper.getRelationshipData(relationshipToVserver, "cloud-region.cloud-owner"), + aaiHelper.getRelationshipData(relationshipToVserver, "cloud-region.cloud-region-id"), + aaiHelper.getRelationshipData(relationshipToVserver, "tenant.tenant-id"), + vnfc.getComputeResource().getResourceId()); + } } + return true; + } catch (final Exception exception) { + logger.error( + "Error encountered deleting vservers based on received notification, AAI may not be updated correctly " + + vnfLcmOperationOccurrenceNotification, + exception); + return false; + } + } + + private boolean deleteVnfIdentifierOnVnfm(GenericVnf genericVnf) { + try { + vnfmServiceProvider.deleteVnf(aaiHelper.getAssignedVnfm(genericVnf), genericVnf.getSelflink()); + return true; + } catch (Exception exception) { + logger.error("Exception deleting the identifier " + genericVnf.getSelflink() + + " from the VNFM. The VNF has been terminated successfully but the identifier will remain on the VNFM.", + exception); + return false; + } + } + + private boolean patchVnfInAai(final String vnfId, final String orchestrationStatus, final String selfLink) { + try { + final GenericVnf genericVnfPatch = new GenericVnf(); + genericVnfPatch.setVnfId(vnfId); + genericVnfPatch.setOrchestrationStatus(orchestrationStatus); + if (selfLink != null) { + genericVnfPatch.setSelflink(selfLink); + } + aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); + return true; + } catch (final Exception exception) { + logger.error( + "Error encountered setting orchestration status and/or self link based on received notification, AAI may not be updated correctly " + + vnfLcmOperationOccurrenceNotification, + exception); + return false; } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml index 4434d2edd9..951d4a3bb9 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml @@ -23,22 +23,11 @@ spring: http: converters: preferred-json-mapper: gson - -http: - client: - ssl: - trust-store: classpath:org.onap.so.trust.jks - trust-store-password: ',sx#.C*W)]wVgJC6ccFHI#:H' server: port: 9092 tomcat: max-threads: 50 - ssl: - key-alias: so@so.onap.org - key--store-password: 'ywsqCy:EEo#j}HJHM7z^Rk[L' - key-store: classpath:so-vnfm-adapter.p12 - key-store-type: PKCS12 mso: key: 07a7159d3bf51a0e53be7a8f89699be7 @@ -55,7 +44,7 @@ sdc: endpoint: http://sdc.onap/1234A vnfmadapter: - endpoint: https://so-vnfm-adapter.onap:9092 + endpoint: http://so-vnfm-adapter.onap:9092 #Actuator management: diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java index f83e9c94d2..cd92d987d7 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java @@ -73,6 +73,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201L import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.AAIVersion; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java index 297f74433e..e408a326f2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java @@ -57,10 +57,12 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.JSON; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.AAIVersion; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; @@ -322,6 +324,40 @@ public class VnfmAdapterControllerTest { } @Test + public void deleteVnf_VnfAlreadyTerminated_Returns202AndJobId() throws Exception { + final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); + + final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1"); + addSelfLinkToGenericVnf(genericVnf); + addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); + setUpVnfmsInMockAai(); + + mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate")) + .andRespond(withStatus(HttpStatus.CONFLICT).contentType(MediaType.APPLICATION_JSON)); + + final InlineResponse201 reponse = new InlineResponse201(); + reponse.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED); + mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) + .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON)); + + mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")) + .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON)); + + final RequestEntity<Void> request = RequestEntity + .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) + .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") + .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); + final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = + restTemplate.exchange(request, DeleteVnfResponse.class); + assertEquals(202, deleteVnfResponse.getStatusCode().value()); + assertNotNull(deleteVnfResponse.getBody().getJobId()); + + final ResponseEntity<QueryJobResponse> jobQueryResponse = + controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213"); + assertEquals(OperationStateEnum.COMPLETED, jobQueryResponse.getBody().getOperationState()); + } + + @Test public void deleteVnf_GenericVnfNotFound_Returns404() throws Exception { final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); @@ -408,7 +444,8 @@ public class VnfmAdapterControllerTest { private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) { final Relationship relationshipToVnfm = new Relationship(); - relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId); + relationshipToVnfm + .setRelatedLink("/aai/" + AAIVersion.LATEST + "/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId); relationshipToVnfm.setRelatedTo("esr-vnfm"); final RelationshipData relationshipData = new RelationshipData(); relationshipData.setRelationshipKey("esr-vnfm.vnfm-id"); |