diff options
44 files changed, 480 insertions, 201 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java index 567f849b36..b0c2d9430a 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java @@ -76,7 +76,7 @@ public class CinderClientImpl extends MsoCommonUtils { // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Volumes> request = cinderClient.volumes().list(false).queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Cinder Client", e); throw new CinderClientException("Error building Cinder Client", e); @@ -90,7 +90,7 @@ public class CinderClientImpl extends MsoCommonUtils { Cinder cinderClient = getCinderClient(cloudSiteId, tenantId); // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Volume> request = cinderClient.volumes().show(volumeId); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Cinder Client", e); throw new CinderClientException("Error building Cinder Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java index 57faaac717..698b605be3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java @@ -74,7 +74,7 @@ public class GlanceClientImpl extends MsoCommonUtils { // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Images> request = glanceClient.images().list(false).queryParam("visibility", visibility) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Glance Client", e); throw new GlanceClientException("Error building Glance Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java index 4ea205a8e1..576784ae3e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java @@ -98,19 +98,23 @@ public class MsoCommonUtils { */ protected <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request) { + return executeAndRecordOpenstackRequest(request, true); + } - String requestType; - if (request.getClass().getEnclosingClass() != null) { - requestType = - request.getClass().getEnclosingClass().getSimpleName() + "." + request.getClass().getSimpleName(); - } else { - requestType = request.getClass().getSimpleName(); - } + /* + * Method to execute an Openstack command and track its execution time. For the metrics log, a category of + * "Openstack" is used along with a sub-category that identifies the specific call (using the real + * openstack-java-sdk classname of the OpenStackRequest<T> parameter). boolean isNoRetry - true if No retry; and + * false if Retry. + */ + protected <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request, boolean shouldRetry) { int retryDelay = poConfig.getRetryDelay(); int retryCount = poConfig.getRetryCount(); String retryCodes = poConfig.getRetryCodes(); - + if (!shouldRetry) { + retryCodes = null; + } // Run the actual command. All exceptions will be propagated while (true) { try { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index c323bb699d..7174bc0e31 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -220,7 +220,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { boolean backout) throws MsoException { stripMultiCloudInputs(stackInputs); - CreateStackParam createStack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles); Stack currentStack = createStack(createStack, cloudSiteId, tenantId); @@ -271,20 +270,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } + protected Stack processCreateStack(String cloudSiteId, String tenantId, int timeoutMinutes, boolean backout, Stack heatStack, CreateStackParam stackCreate, boolean keyPairCleanUp) throws MsoException { - Stack latestStack; + Stack latestStack = null; try { latestStack = pollStackForStatus(timeoutMinutes, heatStack, CREATE_IN_PROGRESS, cloudSiteId, tenantId); } catch (MsoException me) { - if (!backout) { - logger.info("Exception in Create Stack, stack deletion suppressed", me); - } else { - logger.info("Exception in Create Stack, stack deletion will be executed", me); - handleUnknownCreateStackFailure(heatStack, timeoutMinutes, cloudSiteId, tenantId); - } - me.addContext(CREATE_STACK); - throw me; + logger.error("Exception in Create Stack", me); } return postProcessStackCreate(latestStack, backout, timeoutMinutes, keyPairCleanUp, cloudSiteId, tenantId, stackCreate); @@ -292,26 +285,43 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { protected Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair, String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException { - logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair, - stack); - if (!CREATE_COMPLETE.equals(stack.getStackStatus())) { - if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason()) - && isKeyPairFailure(stack.getStackStatusReason())) { - return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack); - } - if (!backout) { - logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed"); - throw new StackCreationException("Stack rollback suppressed, stack not deleted"); + if (stack == null) { + throw new StackCreationException("Unknown Error in Stack Creation"); + } else { + logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair, + stack); + if (!CREATE_COMPLETE.equals(stack.getStackStatus())) { + if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason()) + && isKeyPairFailure(stack.getStackStatusReason())) { + return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack); + } + if (!backout) { + logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed"); + throw new StackCreationException("Stack rollback suppressed, stack not deleted"); + } else { + logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); + String errorMessage = "Stack Creation Failed Openstack Status: " + stack.getStackStatus() + + " Status Reason: " + stack.getStackStatusReason(); + try { + Stack deletedStack = + handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId); + errorMessage = errorMessage + " , Rollback of Stack Creation completed with status: " + + deletedStack.getStackStatus() + " Status Reason: " + + deletedStack.getStackStatusReason(); + } catch (MsoException e) { + logger.error("Sync Error Deleting Stack during rollback", e); + if (e instanceof StackRollbackException) { + errorMessage = errorMessage + e.getMessage(); + } else { + errorMessage = errorMessage + " , Rollback of Stack Creation failed with sync error: " + + e.getMessage(); + } + } + throw new StackCreationException(errorMessage); + } } else { - logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); - Stack deletedStack = handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId); - throw new StackCreationException("Stack Creation Failed Openstack Status: " + stack.getStackStatus() - + " Status Reason: " + stack.getStackStatusReason() - + " , Rollback of Stack Creation completed with status: " + deletedStack.getStackStatus() - + " Status Reason: " + deletedStack.getStackStatusReason()); + return stack; } - } else { - return stack; } } @@ -1239,7 +1249,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<Resources> request = heatClient.getResources().listResources(stackName).queryParam("nested_depth", nestedDepth); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public Events queryStackEvents(String cloudSiteId, String tenantId, String stackName, String stackId, @@ -1247,7 +1257,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<Events> request = heatClient.getEvents().listEvents(stackName, stackId).queryParam("nested_depth", nestedDepth); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public Stacks queryStacks(String cloudSiteId, String tenantId, int limit, String marker) @@ -1261,14 +1271,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } OpenStackRequest<Stacks> request = heatClient.getStacks().list().queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public <R> R executeHeatClientRequest(String url, String cloudSiteId, String tenantId, Class<R> returnType) throws MsoException { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<R> request = heatClient.get(url, returnType); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } protected void sleep(long time) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java index 6f08afc55f..069c6c7c5b 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java @@ -382,7 +382,7 @@ public class MsoNeutronUtils extends MsoCommonUtils { Authentication credentials = authenticationMethodFactory.getAuthenticationFor(cloudIdentity); OpenStackRequest<Access> request = keystoneTenantClient.tokens().authenticate(credentials).withTenantId(tenantId); - access = executeAndRecordOpenstackRequest(request); + access = executeAndRecordOpenstackRequest(request, true); try { @@ -499,7 +499,7 @@ public class MsoNeutronUtils extends MsoCommonUtils { try { OpenStackRequest<Port> request = neutronClient.ports().show(neutronPortId); - Port port = executeAndRecordOpenstackRequest(request); + Port port = executeAndRecordOpenstackRequest(request, false); return port; } catch (OpenStackResponseException e) { if (e.getStatus() == 404) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java index 93745de54a..938a888bbd 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java @@ -75,7 +75,7 @@ public class NeutronClientImpl extends MsoCommonUtils { Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId); OpenStackRequest<Networks> request = neutronClient.networks().list().queryParam("id", id) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Neutron Client", e); throw new NeutronClientException("Error building Neutron Client", e); @@ -103,7 +103,7 @@ public class NeutronClientImpl extends MsoCommonUtils { Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId); OpenStackRequest<Subnets> request = neutronClient.subnets().list().queryParam("id", id) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Neutron Client", e); throw new NeutronClientException("Error building Neutron Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java index 6cd79de476..99e8b589b1 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java @@ -78,7 +78,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavors> request = novaClient.flavors().list(false).queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -103,7 +103,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavor> request = novaClient.flavors().show(id); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -128,7 +128,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregates> request = novaClient.aggregates().list().queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -152,7 +152,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregate> request = novaClient.aggregates().showAggregate(id); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -176,7 +176,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<QuotaSet> request = novaClient.quotaSets().showQuota(tenantId); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -198,7 +198,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> request = novaClient.keyPairs().delete(keyPairName); - executeAndRecordOpenstackRequest(request); + executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java index 5cf7c86522..622ad4f94f 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java @@ -69,6 +69,7 @@ public class MsoCommonUtilsTest extends BaseTest { Mockito.when(openstackRequest.path()).thenReturn("/test"); // TODO:Must try a real connection assertNull(commonUtils.executeAndRecordOpenstackRequest(openstackRequest)); + assertNull(commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true)); } @Test @@ -78,6 +79,7 @@ public class MsoCommonUtilsTest extends BaseTest { doThrow(OpenStackResponseException.class).when(openstackRequest).execute(); commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true); } @Test @@ -86,7 +88,7 @@ public class MsoCommonUtilsTest extends BaseTest { doThrow(OpenStackConnectException.class).when(openstackRequest).execute(); - commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true); } @Test diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java index 6673e69a09..de55e85ad6 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java @@ -188,6 +188,31 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { } @Test + public final void postProcessStackCreate_Backout_True_Delete_Fail_Test() throws MsoException, IOException { + Stack stack = new Stack(); + stack.setId("id"); + stack.setStackName("stackName"); + stack.setStackStatus("CREATE_IN_PROGRESS"); + stack.setStackStatusReason("Stack Finished"); + + Stack deletedStack = new Stack(); + deletedStack.setId("id"); + deletedStack.setStackName("stackName"); + deletedStack.setStackStatus("DELETE_COMPLETE"); + deletedStack.setStackStatusReason("Stack Deleted"); + + CreateStackParam createStackParam = new CreateStackParam(); + createStackParam.setStackName("stackName"); + doThrow(new MsoOpenstackException(500, "Error In Delete", "Error In Delete")).when(heatUtils) + .handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); + exceptionRule.expect(MsoException.class); + exceptionRule.expectMessage( + "Stack Creation Failed Openstack Status: CREATE_IN_PROGRESS Status Reason: Stack Finished , Rollback of Stack Creation failed with sync error: Error In Delete"); + heatUtils.postProcessStackCreate(stack, true, 120, false, cloudSiteId, tenantId, createStackParam); + Mockito.verify(heatUtils, times(1)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); + } + + @Test public final void postProcessStackCreate_Keypair_True_Test() throws MsoException, IOException { Stack stack = new Stack(); stack.setId("id"); @@ -375,12 +400,12 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { doThrow(new StackCreationException("Error")).when(heatUtils).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId); - doReturn(deletedStack).when(heatUtils).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); exceptionRule.expect(MsoException.class); exceptionRule.expectMessage("Error"); heatUtils.processCreateStack(cloudSiteId, tenantId, 120, true, stack, createStackParam, true); Mockito.verify(heatUtils, times(1)).pollStackForStatus(120, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId); - Mockito.verify(heatUtils, times(1)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); + Mockito.verify(heatUtils, times(1)).postProcessStackCreate(stack, true, 120, true, cloudSiteId, tenantId, + createStackParam); } diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.10__Add_Column_IS_DATA_INTERNAL.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.10__Add_Column_IS_DATA_INTERNAL.sql new file mode 100644 index 0000000000..2196d11e07 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.10__Add_Column_IS_DATA_INTERNAL.sql @@ -0,0 +1,3 @@ +use requestdb; + +ALTER TABLE request_processing_data ADD COLUMN IF NOT EXISTS IS_DATA_INTERNAL TINYINT NOT NULL DEFAULT '0';
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/DuplicateNameException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/DuplicateNameException.java new file mode 100644 index 0000000000..2f2a116526 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/DuplicateNameException.java @@ -0,0 +1,18 @@ +package org.onap.so.bpmn.servicedecomposition.tasks.exceptions; + +public class DuplicateNameException extends Exception { + + private static final long serialVersionUID = -2850043981787600326L; + + public DuplicateNameException() { + super(); + } + + public DuplicateNameException(String message) { + super(message); + } + + public DuplicateNameException(String objectType, String name) { + super(objectType + " with name " + name + " already exists. The name must be unique."); + } +} diff --git a/bpmn/pom.xml b/bpmn/pom.xml index f09cfaa38c..65af2fd8d5 100644 --- a/bpmn/pom.xml +++ b/bpmn/pom.xml @@ -24,7 +24,7 @@ <xmlunit.version>2.4.0</xmlunit.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <sdnc.northbound.version>1.5.2-SNAPSHOT</sdnc.northbound.version> + <sdnc.northbound.version>1.5.2</sdnc.northbound.version> <appc.client.version>1.6.0-SNAPSHOT</appc.client.version> </properties> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 28d5363ad2..524098bcb7 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -50,6 +50,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -76,6 +77,7 @@ public class AAICreateTasks { private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class); private static final String networkTypeProvider = "PROVIDER"; + private static final String A_LA_CARTE = "aLaCarte"; private static String NETWORK_COLLECTION_NAME = "networkCollectionName"; private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList"; private static String HEAT_STACK_ID = "heatStackId"; @@ -193,7 +195,11 @@ public class AAICreateTasks { public void createVnf(BuildingBlockExecution execution) { try { + Boolean alaCarte = execution.getVariable(A_LA_CARTE); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + if (Boolean.TRUE.equals(alaCarte) && aaiVnfResources.checkNameInUse(vnf.getVnfName())) { + throw new DuplicateNameException("generic-vnf", vnf.getVnfName()); + } ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); execution.setVariable("homing", Boolean.TRUE.equals(vnf.isCallHoming())); @@ -252,6 +258,10 @@ public class AAICreateTasks { GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID); CloudRegion cloudRegion = gBBInput.getCloudRegion(); + Boolean alaCarte = execution.getVariable(A_LA_CARTE); + if (Boolean.TRUE.equals(alaCarte) && aaiVolumeGroupResources.checkNameInUse(volumeGroup)) { + throw new DuplicateNameException("volume-group", volumeGroup.getVolumeGroupName()); + } aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion); aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion); aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion); @@ -264,6 +274,10 @@ public class AAICreateTasks { try { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + Boolean alaCarte = execution.getVariable(A_LA_CARTE); + if (Boolean.TRUE.equals(alaCarte) && aaiVfModuleResources.checkNameInUse(vfModule)) { + throw new DuplicateNameException("vf-module", vfModule.getVfModuleName()); + } int moduleIndex = 0; if (vfModule.getModelInfoVfModule() != null && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTasks.java index 32276891c7..e4dd35503e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTasks.java @@ -22,6 +22,8 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; @@ -46,6 +48,7 @@ import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -62,7 +65,8 @@ public class SDNCActivateTasks { private SDNCNetworkResources sdncNetworkResources; @Autowired private SDNCVfModuleResources sdncVfModuleResources; - + @Autowired + private Environment env; public void activateVnf(BuildingBlockExecution execution) { try { @@ -122,9 +126,12 @@ public class SDNCActivateTasks { vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); Customer customer = gBBInput.getCustomer(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); - GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.activateVfModule(vfModule, vnf, - serviceInstance, customer, cloudRegion, requestContext); SDNCRequest sdncRequest = new SDNCRequest(); + UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint")) + .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue()); + URI uri = builder.build(); + GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.activateVfModule(vfModule, vnf, + serviceInstance, customer, cloudRegion, requestContext, uri); sdncRequest.setSDNCPayload(req); sdncRequest.setTopology(SDNCTopology.VFMODULE); execution.setVariable(SDNC_REQUEST, sdncRequest); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java index 111f008159..c100cd6cee 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java @@ -22,6 +22,8 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; @@ -49,6 +51,7 @@ import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -67,6 +70,8 @@ public class SDNCAssignTasks { private ExtractPojosForBB extractPojosForBB; @Autowired private SDNCNetworkResources sdncNetworkResources; + @Autowired + private Environment env; public void assignServiceInstance(BuildingBlockExecution execution) { try { @@ -122,9 +127,12 @@ public class SDNCAssignTasks { } Customer customer = gBBInput.getCustomer(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); - GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.assignVfModule(vfModule, - volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext); SDNCRequest sdncRequest = new SDNCRequest(); + UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint")) + .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue()); + URI uri = builder.build(); + GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.assignVfModule(vfModule, + volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext, uri); sdncRequest.setSDNCPayload(req); sdncRequest.setTopology(SDNCTopology.VFMODULE); execution.setVariable(SDNC_REQUEST, sdncRequest); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasks.java index 4ffb397707..acf48acdda 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasks.java @@ -20,6 +20,8 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; @@ -43,6 +45,7 @@ import org.onap.so.client.orchestration.SDNCVnfResources; import org.onap.so.client.sdnc.beans.SDNCRequest; import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -60,6 +63,8 @@ public class SDNCChangeAssignTasks { private ExceptionBuilder exceptionUtil; @Autowired private SDNCVfModuleResources sdncVfModuleResources; + @Autowired + private Environment env; public void changeModelServiceInstance(BuildingBlockExecution execution) { try { @@ -121,9 +126,12 @@ public class SDNCChangeAssignTasks { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); Customer customer = gBBInput.getCustomer(); - GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule, - vnf, serviceInstance, customer, cloudRegion, requestContext); SDNCRequest sdncRequest = new SDNCRequest(); + UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint")) + .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue()); + URI uri = builder.build(); + GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule, + vnf, serviceInstance, customer, cloudRegion, requestContext, uri); sdncRequest.setSDNCPayload(req); sdncRequest.setTopology(SDNCTopology.VFMODULE); execution.setVariable(SDNC_REQUEST, sdncRequest); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTasks.java index e587830c74..3fc25196e1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTasks.java @@ -22,6 +22,8 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; @@ -47,6 +49,7 @@ import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -65,6 +68,8 @@ public class SDNCDeactivateTasks { private ExceptionBuilder exceptionUtil; @Autowired private ExtractPojosForBB extractPojosForBB; + @Autowired + private Environment env; public void deactivateVfModule(BuildingBlockExecution execution) { try { @@ -76,9 +81,12 @@ public class SDNCDeactivateTasks { VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); Customer customer = gBBInput.getCustomer(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); - GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.deactivateVfModule(vfModule, vnf, - serviceInstance, customer, cloudRegion, requestContext); SDNCRequest sdncRequest = new SDNCRequest(); + UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint")) + .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue()); + URI uri = builder.build(); + GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.deactivateVfModule(vfModule, vnf, + serviceInstance, customer, cloudRegion, requestContext, uri); sdncRequest.setSDNCPayload(req); sdncRequest.setTopology(SDNCTopology.VFMODULE); execution.setVariable(SDNC_REQUEST, sdncRequest); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeleteTasks.java deleted file mode 100644 index 6d81cba41d..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeleteTasks.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.sdnc.tasks; - -import org.springframework.stereotype.Component; - -@Component -public class SDNCDeleteTasks { - -} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java index f32ffd72c3..cb761f4110 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -21,8 +21,13 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import java.io.StringReader; +import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -98,12 +103,18 @@ public class SDNCRequestTasks { Document doc = db.parse(new InputSource(new StringReader(asyncRequest))); String finalMessageIndicator = getXmlElement(doc, "/input/ack-final-indicator"); + boolean isCallbackCompleted = convertIndicatorToBoolean(finalMessageIndicator); execution.setVariable(IS_CALLBACK_COMPLETED, isCallbackCompleted); if (isCallbackCompleted) { String responseCode = getXmlElement(doc, "/input/response-code"); - String responseMessage = getXmlElement(doc, "/input/response-message"); if (!SDNC_SUCCESS.equalsIgnoreCase(responseCode)) { + String responseMessage; + try { + responseMessage = getXmlElement(doc, "/input/response-message"); + } catch (Exception e) { + responseMessage = "Unknown Error in SDNC"; + } throw new SDNCErrorResponseException(responseMessage); } } @@ -126,8 +137,17 @@ public class SDNCRequestTasks { } protected String getXmlElement(Document doc, String exp) throws Exception { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(doc), new StreamResult(writer)); + logger.debug(writer.getBuffer().toString()); XPath xPath = XPathFactory.newInstance().newXPath(); - return xPath.evaluate(exp, doc); + String result = xPath.evaluate(exp, doc); + if (result == null || result.isEmpty()) { + throw new Exception("XPath Failed to find element expression: " + exp); + } + return result; } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java index fba189fcfc..7d5591af0f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasks.java @@ -22,6 +22,8 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; @@ -47,6 +49,7 @@ import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -65,6 +68,8 @@ public class SDNCUnassignTasks { private ExtractPojosForBB extractPojosForBB; @Autowired private SDNCNetworkResources sdncNetworkResources; + @Autowired + private Environment env; public void unassignServiceInstance(BuildingBlockExecution execution) { try { @@ -90,9 +95,12 @@ public class SDNCUnassignTasks { extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - GenericResourceApiVfModuleOperationInformation req = - sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance); SDNCRequest sdncRequest = new SDNCRequest(); + UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint")) + .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue()); + URI uri = builder.build(); + GenericResourceApiVfModuleOperationInformation req = + sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance, uri); sdncRequest.setSDNCPayload(req); sdncRequest.setTopology(SDNCTopology.VFMODULE); execution.setVariable(SDNC_REQUEST, sdncRequest); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java index 514f48ffc8..4d1a6dce38 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java @@ -23,12 +23,15 @@ package org.onap.so.client.orchestration; import java.util.Optional; +import org.onap.aai.domain.yang.VfModules; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; @@ -108,4 +111,19 @@ public class AAIVfModuleResources { cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()); injectionHelper.getAaiClient().connect(vfModuleURI, volumeGroupURI); } + + public boolean checkNameInUse(VfModule vfModule) { + boolean nameInUse = false; + AAIResourceUri vfModuleUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE) + .queryParam("vf-module-name", vfModule.getVfModuleName()); + AAIResourceUri vfModuleUriWithCustomization = vfModuleUri.clone().queryParam("model-customization-id", + vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + if (injectionHelper.getAaiClient().exists(vfModuleUriWithCustomization)) { + // assume it's a resume case and return false + nameInUse = false; + } else { + nameInUse = injectionHelper.getAaiClient().exists(vfModuleUri); + } + return nameInUse; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java index eb66f6bef5..a9635d1e34 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java @@ -30,8 +30,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIValidatorImpl; +import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; @@ -152,4 +154,10 @@ public class AAIVnfResources { return aaiValidatorImpl.isPhysicalServerLocked(vnf.getVnfId()); } + + public boolean checkNameInUse(String vnfName) { + AAIResourceUri vnfUri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName); + return injectionHelper.getAaiClient().exists(vnfUri); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVolumeGroupResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVolumeGroupResources.java index f4c285fdb3..b9e4aeb888 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVolumeGroupResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVolumeGroupResources.java @@ -26,6 +26,7 @@ import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -93,4 +94,10 @@ public class AAIVolumeGroupResources { copiedVolumeGroup.setHeatStackId(volumeGroup.getHeatStackId()); injectionHelper.getAaiClient().update(uri, aaiObjectMapper.mapVolumeGroup(copiedVolumeGroup)); } + + public boolean checkNameInUse(VolumeGroup volumeGroup) { + AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", volumeGroup.getVolumeGroupName()); + return injectionHelper.getAaiClient().exists(volumeGroupUri); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCVfModuleResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCVfModuleResources.java index 60cad78f5d..b83a4d5628 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCVfModuleResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCVfModuleResources.java @@ -22,6 +22,7 @@ package org.onap.so.client.orchestration; +import java.net.URI; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; @@ -53,22 +54,22 @@ public class SDNCVfModuleResources { public GenericResourceApiVfModuleOperationInformation assignVfModule(VfModule vfModule, VolumeGroup volumeGroup, GenericVnf vnf, ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, - RequestContext requestContext) throws MapperException { + RequestContext requestContext, URI callbackURI) throws MapperException { return sdncRM.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, - volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext, null); + volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext, null, callbackURI); } public GenericResourceApiVfModuleOperationInformation unassignVfModule(VfModule vfModule, GenericVnf vnf, - ServiceInstance serviceInstance) throws MapperException { + ServiceInstance serviceInstance, URI callbackURI) throws MapperException { return sdncRM.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, - vnf, serviceInstance, null, null, null, null); + vnf, serviceInstance, null, null, null, null, callbackURI); } public GenericResourceApiVfModuleOperationInformation deactivateVfModule(VfModule vfModule, GenericVnf vnf, - ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext) - throws MapperException { + ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext, + URI callbackURI) throws MapperException { return sdncRM.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, vfModule, null, - vnf, serviceInstance, customer, cloudRegion, requestContext, null); + vnf, serviceInstance, customer, cloudRegion, requestContext, null, callbackURI); } public String queryVfModule(VfModule vfModule) throws MapperException, BadResponseException { @@ -77,16 +78,16 @@ public class SDNCVfModuleResources { } public GenericResourceApiVfModuleOperationInformation activateVfModule(VfModule vfModule, GenericVnf vnf, - ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext) - throws MapperException { + ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext, + URI callbackURI) throws MapperException { return sdncRM.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ACTIVATE, vfModule, null, - vnf, serviceInstance, customer, cloudRegion, requestContext, null); + vnf, serviceInstance, customer, cloudRegion, requestContext, null, callbackURI); } public GenericResourceApiVfModuleOperationInformation changeAssignVfModule(VfModule vfModule, GenericVnf vnf, - ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext) - throws MapperException { + ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext, + URI callbackURI) throws MapperException { return sdncRM.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, vfModule, - null, vnf, serviceInstance, customer, cloudRegion, requestContext, null); + null, vnf, serviceInstance, customer, cloudRegion, requestContext, null, callbackURI); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java index 0cfe6fbc8d..6ddb292a6c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java @@ -22,6 +22,7 @@ package org.onap.so.client.sdnc.mapper; +import java.net.URI; import java.util.Map; import java.util.UUID; import org.onap.so.logger.LoggingAnchor; @@ -65,7 +66,7 @@ public class VfModuleTopologyOperationRequestMapper { public GenericResourceApiVfModuleOperationInformation reqMapper(SDNCSvcOperation svcOperation, SDNCSvcAction svcAction, VfModule vfModule, VolumeGroup volumeGroup, GenericVnf vnf, ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext, - String sdncAssignResponse) throws MapperException { + String sdncAssignResponse, URI callbackURL) throws MapperException { GenericResourceApiVfModuleOperationInformation req = new GenericResourceApiVfModuleOperationInformation(); boolean includeModelInformation = false; @@ -114,7 +115,7 @@ public class VfModuleTopologyOperationRequestMapper { GenericResourceApiVfmodulerequestinputVfModuleRequestInput vfModuleRequestInput = buildVfModuleRequestInput(vfModule, volumeGroup, cloudRegion, requestContext); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = - buildVfModuleSdncRequestHeader(sdncReqId, genericResourceApiSvcAction); + buildVfModuleSdncRequestHeader(sdncReqId, genericResourceApiSvcAction, callbackURL); req.setRequestInformation(requestInformation); req.setSdncRequestHeader(sdncRequestHeader); @@ -170,13 +171,12 @@ public class VfModuleTopologyOperationRequestMapper { } private GenericResourceApiSdncrequestheaderSdncRequestHeader buildVfModuleSdncRequestHeader(String sdncReqId, - GenericResourceApiSvcActionEnumeration svcAction) { + GenericResourceApiSvcActionEnumeration svcAction, URI callbackUrl) { GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = new GenericResourceApiSdncrequestheaderSdncRequestHeader(); - sdncRequestHeader.setSvcRequestId(sdncReqId); sdncRequestHeader.setSvcAction(svcAction); - + sdncRequestHeader.setSvcNotificationUrl(callbackUrl.toString()); return sdncRequestHeader; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index b054cc17bb..d5159975a9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -60,6 +60,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.onap.so.client.aai.entities.uri.AAIResourceUri; @@ -140,7 +141,7 @@ public class AAICreateTasksTest extends BaseTaskTest { @Test public void createVolumeGroupTest() throws Exception { volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); - + execution.setVariable("aLaCarte", Boolean.FALSE); doNothing().when(aaiVolumeGroupResources).createVolumeGroup(volumeGroup, cloudRegion); doNothing().when(aaiVolumeGroupResources).connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion); @@ -152,6 +153,14 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test + public void createVolumeGroupDuplicateNameTest() throws Exception { + expectedException.expect(BpmnError.class); + execution.setVariable("aLaCarte", Boolean.TRUE); + doReturn(true).when(aaiVolumeGroupResources).checkNameInUse(volumeGroup); + aaiCreateTasks.createVolumeGroup(execution); + } + + @Test public void createVolumeGroupExceptionTest() throws Exception { expectedException.expect(BpmnError.class); @@ -325,11 +334,20 @@ public class AAICreateTasksTest extends BaseTaskTest { @Test public void createVnfTest() throws Exception { doNothing().when(aaiVnfResources).createVnfandConnectServiceInstance(genericVnf, serviceInstance); + execution.setVariable("aLaCarte", Boolean.FALSE); aaiCreateTasks.createVnf(execution); verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance); } @Test + public void createVnfDuplicateNameTest() throws Exception { + expectedException.expect(BpmnError.class); + doReturn(true).when(aaiVnfResources).checkNameInUse(genericVnf.getVnfName()); + execution.setVariable("aLaCarte", Boolean.TRUE); + aaiCreateTasks.createVnf(execution); + } + + @Test public void createVnfExceptionTest() throws Exception { expectedException.expect(BpmnError.class); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "notfound"); @@ -352,12 +370,21 @@ public class AAICreateTasksTest extends BaseTaskTest { .thenReturn(newVfModule); assertEquals(null, newVfModule.getModuleIndex()); + execution.setVariable("aLaCarte", Boolean.FALSE); aaiCreateTasks.createVfModule(execution); assertEquals(1, newVfModule.getModuleIndex().intValue()); verify(aaiVfModuleResources, times(1)).createVfModule(newVfModule, genericVnf); } @Test + public void createVfModuleDuplicateNameTest() throws Exception { + expectedException.expect(BpmnError.class); + execution.setVariable("aLaCarte", Boolean.TRUE); + doReturn(true).when(aaiVfModuleResources).checkNameInUse(vfModule); + aaiCreateTasks.createVfModule(execution); + } + + @Test public void createServiceSubscriptionTest() { doNothing().when(aaiServiceInstanceResources).createServiceSubscription(customer); aaiCreateTasks.createServiceSubscription(execution); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java index 4eb1432bbf..ffd4f74b63 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.net.URI; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -85,7 +86,10 @@ public class SDNCActivateTaskTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); + when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090"); } @Test @@ -129,11 +133,12 @@ public class SDNCActivateTaskTest extends BaseTaskTest { @Test public void activateVfModuleTest() throws Exception { - doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources) - .activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).activateVfModule( + eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), + any(URI.class)); sdncActivateTasks.activateVfModule(execution); - verify(sdncVfModuleResources, times(1)).activateVfModule(vfModule, genericVnf, serviceInstance, customer, - cloudRegion, requestContext); + verify(sdncVfModuleResources, times(1)).activateVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance), + eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); SDNCRequest sdncRequest = execution.getVariable("SDNCRequest"); assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology()); } @@ -141,8 +146,8 @@ public class SDNCActivateTaskTest extends BaseTaskTest { @Test public void activateVfModuleTestException() throws Exception { expectedException.expect(BpmnError.class); - doThrow(RuntimeException.class).when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf, - serviceInstance, customer, cloudRegion, requestContext); + doThrow(RuntimeException.class).when(sdncVfModuleResources).activateVfModule(eq(vfModule), eq(genericVnf), + eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); sdncActivateTasks.activateVfModule(execution); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java index 7d8e94d1e9..982868dcbc 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.net.URI; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -89,6 +90,7 @@ public class SDNCAssignTasksTest extends BaseTaskTest { .thenReturn(serviceInstance); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))) .thenReturn(volumeGroup); + when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090"); } @Test @@ -132,10 +134,11 @@ public class SDNCAssignTasksTest extends BaseTaskTest { @Test public void assignVfModuleTest() throws Exception { doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).assignVfModule( - vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + eq(vfModule), eq(volumeGroup), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), + eq(requestContext), any(URI.class)); sdncAssignTasks.assignVfModule(execution); - verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, - customer, cloudRegion, requestContext); + verify(sdncVfModuleResources, times(1)).assignVfModule(eq(vfModule), eq(volumeGroup), eq(genericVnf), + eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); SDNCRequest sdncRequest = execution.getVariable("SDNCRequest"); assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology()); } @@ -143,8 +146,8 @@ public class SDNCAssignTasksTest extends BaseTaskTest { @Test public void assignVfModuleExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, - serviceInstance, customer, cloudRegion, requestContext); + doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(eq(vfModule), eq(volumeGroup), + eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); sdncAssignTasks.assignVfModule(execution); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java index 1c1616a472..8c25bea801 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.net.URI; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -74,6 +75,7 @@ public class SDNCChangeAssignTasksTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); + when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090"); } @Test @@ -97,11 +99,12 @@ public class SDNCChangeAssignTasksTest extends BaseTaskTest { @Test public void changeAssignModelVfModuleTest() throws Exception { - doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources) - .changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).changeAssignVfModule( + eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), + any(URI.class)); sdncChangeAssignTasks.changeAssignModelVfModule(execution); - verify(sdncVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, - cloudRegion, requestContext); + verify(sdncVfModuleResources, times(1)).changeAssignVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance), + eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); SDNCRequest sdncRequest = execution.getVariable("SDNCRequest"); assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology()); } @@ -109,8 +112,8 @@ public class SDNCChangeAssignTasksTest extends BaseTaskTest { @Test public void changeAssignModelVfModuleExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - doThrow(RuntimeException.class).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, - serviceInstance, customer, cloudRegion, requestContext); + doThrow(RuntimeException.class).when(sdncVfModuleResources).changeAssignVfModule(eq(vfModule), eq(genericVnf), + eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); sdncChangeAssignTasks.changeAssignModelVfModule(execution); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java index 08d4d196da..d8a1b0182e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.net.URI; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -81,16 +82,17 @@ public class SDNCDeactivateTaskTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); - + when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090"); } @Test public void deactivateVfModuleTest() throws Exception { - doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources) - .deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).deactivateVfModule( + eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), + any(URI.class)); sdncDeactivateTasks.deactivateVfModule(execution); - verify(sdncVfModuleResources, times(1)).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, - cloudRegion, requestContext); + verify(sdncVfModuleResources, times(1)).deactivateVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance), + eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); SDNCRequest sdncRequest = execution.getVariable("SDNCRequest"); assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology()); } @@ -98,8 +100,8 @@ public class SDNCDeactivateTaskTest extends BaseTaskTest { @Test public void deactivateVfModuleExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - doThrow(RuntimeException.class).when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf, - serviceInstance, customer, cloudRegion, requestContext); + doThrow(RuntimeException.class).when(sdncVfModuleResources).deactivateVfModule(eq(vfModule), eq(genericVnf), + eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class)); sdncDeactivateTasks.deactivateVfModule(execution); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java index b5d34ea4c9..6a94b357e0 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -23,8 +23,6 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import java.io.IOException; import java.io.StringReader; import java.nio.file.Files; @@ -39,7 +37,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; @@ -69,6 +66,7 @@ public class SDNCRequestTasksTest extends SDNCRequestTasks { @Mock SDNCClient sdncClient; + @Spy private ExceptionBuilder exceptionBuilder; @@ -151,7 +149,7 @@ public class SDNCRequestTasksTest extends SDNCRequestTasks { db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(sdncResponse))); - String finalMessageIndicator = getXmlElement(doc, "/input/ack-final-indicator"); + String finalMessageIndicator = getXmlElement(doc, "//*:ack-final-indicator"); String responseCode = getXmlElement(doc, "/input/response-code"); String responseMessage = getXmlElement(doc, "/input/response-message"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java index 968723c628..10c034dc36 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.net.URI; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -81,6 +82,7 @@ public class SDNCUnassignTasksTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); + when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090"); } @Test @@ -105,9 +107,10 @@ public class SDNCUnassignTasksTest extends BaseTaskTest { @Test public void unassignVfModuleTest() throws Exception { doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources) - .unassignVfModule(vfModule, genericVnf, serviceInstance); + .unassignVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance), any(URI.class)); sdncUnassignTasks.unassignVfModule(execution); - verify(sdncVfModuleResources, times(1)).unassignVfModule(vfModule, genericVnf, serviceInstance); + verify(sdncVfModuleResources, times(1)).unassignVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance), + any(URI.class)); SDNCRequest sdncRequest = execution.getVariable("SDNCRequest"); assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology()); } @@ -115,8 +118,8 @@ public class SDNCUnassignTasksTest extends BaseTaskTest { @Test public void unassignVfModuleExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - doThrow(RuntimeException.class).when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, - serviceInstance); + doThrow(RuntimeException.class).when(sdncVfModuleResources).unassignVfModule(eq(vfModule), eq(genericVnf), + eq(serviceInstance), any(URI.class)); sdncUnassignTasks.unassignVfModule(execution); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java index ae3ebeddbd..9e3bc4f552 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java @@ -21,7 +21,10 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -41,8 +44,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -154,4 +159,39 @@ public class AAIVfModuleResourcesTest extends TestDataSetup { assertEquals("testContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn()); } + + @Test + public void checkNameInUseTrueTest() throws Exception { + AAIResourceUri vfModuleUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE) + .queryParam("vf-module-name", vfModule.getVfModuleName()); + AAIResourceUri vfModuleUriWithCustomization = vfModuleUri.clone().queryParam("model-customization-id", + vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(vfModuleUriWithCustomization)); + doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(vfModuleUri)); + boolean nameInUse = aaiVfModuleResources.checkNameInUse(vfModule); + assertTrue(nameInUse); + } + + @Test + public void checkNameInUseFalseIsResumeTest() throws Exception { + AAIResourceUri vfModuleUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE) + .queryParam("vf-module-name", vfModule.getVfModuleName()); + AAIResourceUri vfModuleUriWithCustomization = vfModuleUri.clone().queryParam("model-customization-id", + vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(vfModuleUriWithCustomization)); + boolean nameInUse = aaiVfModuleResources.checkNameInUse(vfModule); + assertFalse(nameInUse); + } + + @Test + public void checkNameInUseFalseTest() throws Exception { + AAIResourceUri vfModuleUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE) + .queryParam("vf-module-name", vfModule.getVfModuleName()); + AAIResourceUri vfModuleUriWithCustomization = vfModuleUri.clone().queryParam("model-customization-id", + vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(vfModuleUriWithCustomization)); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(vfModuleUri)); + boolean nameInUse = aaiVfModuleResources.checkNameInUse(vfModule); + assertFalse(nameInUse); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java index cdc601c1e4..0d48a29ca9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -21,6 +21,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -45,9 +46,11 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.AAIValidatorImpl; +import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; @@ -227,4 +230,23 @@ public class AAIVnfResourcesTest extends TestDataSetup { verify(MOCK_aaiValidatorImpl, times(1)).isPhysicalServerLocked(isA(String.class)); assertTrue(isVnfPserversLockedFlag); } + + + @Test + public void checkNameInUseTrueTest() { + AAIResourceUri vnfUri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "vnfName"); + doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(vnfUri)); + boolean nameInUse = aaiVnfResources.checkNameInUse("vnfName"); + assertTrue(nameInUse); + } + + @Test + public void checkNameInUseFalseTest() { + AAIResourceUri vnfUri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "vnfName"); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(vnfUri)); + boolean nameInUse = aaiVnfResources.checkNameInUse("vnfName"); + assertFalse(nameInUse); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java index 2bdcf30a4c..5772cab995 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java @@ -21,7 +21,10 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -39,8 +42,11 @@ import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -146,4 +152,22 @@ public class AAIVolumeGroupResourcesTest extends TestDataSetup { assertEquals("testVolumeHeatStackId", volumeGroup.getHeatStackId()); } + + @Test + public void checkNameInUseTrueTest() { + AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", "testVolumeGroupName1"); + doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(volumeGroupUri)); + boolean nameInUse = aaiVolumeGroupResources.checkNameInUse(volumeGroup); + assertTrue(nameInUse); + } + + @Test + public void checkNameInUseFalseTest() { + AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", "testVolumeGroupName1"); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(volumeGroupUri)); + boolean nameInUse = aaiVolumeGroupResources.checkNameInUse(volumeGroup); + assertFalse(nameInUse); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java index 2b45a3302c..57d6496a4f 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java @@ -23,6 +23,8 @@ package org.onap.so.client.orchestration; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.net.URI; +import java.net.URISyntaxException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,6 +64,8 @@ public class SDNCVfModuleResourcesTest extends TestDataSetup { private RequestContext requestContext; private GenericResourceApiVfModuleOperationInformation sdncReq; + private URI testURI; + @Before public void before() { vfModule = buildVfModule(); @@ -72,60 +76,67 @@ public class SDNCVfModuleResourcesTest extends TestDataSetup { cloudRegion = buildCloudRegion(); requestContext = buildRequestContext(); sdncReq = new GenericResourceApiVfModuleOperationInformation(); + try { + testURI = new URI("http://localhost:9800"); + } catch (URISyntaxException e) { + + } } @Test public void assignVfModuleTest() throws MapperException { doReturn(sdncReq).when(vfModuleTopologyMapper).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, - requestContext, null); + requestContext, null, testURI); sdncVfModuleResources.assignVfModule(vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, - requestContext); + requestContext, testURI); verify(vfModuleTopologyMapper, times(1)).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, - requestContext, null); + requestContext, null, testURI); } @Test public void unassignVfModuleTest() throws MapperException { doReturn(sdncReq).when(vfModuleTopologyMapper).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, - SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, null, null, null); - sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance); + SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, null, null, null, testURI); + sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance, testURI); verify(vfModuleTopologyMapper, times(1)).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, - SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, null, null, null); + SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, null, null, null, testURI); } @Test public void activateVfModuleTest() throws MapperException { doReturn(sdncReq).when(vfModuleTopologyMapper).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ACTIVATE, vfModule, null, vnf, serviceInstance, customer, cloudRegion, requestContext, - null); - sdncVfModuleResources.activateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext); + null, testURI); + sdncVfModuleResources.activateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext, + testURI); verify(vfModuleTopologyMapper, times(1)).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ACTIVATE, vfModule, null, vnf, serviceInstance, customer, cloudRegion, requestContext, - null); + null, testURI); } @Test public void deactivateVfModuleTest() throws MapperException { doReturn(sdncReq).when(vfModuleTopologyMapper).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, vfModule, null, vnf, serviceInstance, customer, cloudRegion, requestContext, - null); - sdncVfModuleResources.deactivateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext); + null, testURI); + sdncVfModuleResources.deactivateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext, + testURI); verify(vfModuleTopologyMapper, times(1)).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, vfModule, null, vnf, serviceInstance, customer, cloudRegion, requestContext, - null); + null, testURI); } @Test public void changeAssignVfModuleTest() throws MapperException, BadResponseException { doReturn(sdncReq).when(vfModuleTopologyMapper).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, vfModule, null, vnf, serviceInstance, customer, cloudRegion, - requestContext, null); + requestContext, null, testURI); sdncVfModuleResources.changeAssignVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, - requestContext); + requestContext, testURI); verify(vfModuleTopologyMapper, times(1)).reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, vfModule, null, vnf, serviceInstance, customer, cloudRegion, - requestContext, null); + requestContext, null, testURI); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java index 275e9f7dbb..b71ddba63b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -25,6 +25,7 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -38,6 +39,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -53,7 +55,6 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.beans.SDNCSvcAction; import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(MockitoJUnitRunner.class) @@ -134,9 +135,9 @@ public class VfModuleTopologyOperationRequestMapperTest { CloudRegion cloudRegion = new CloudRegion(); - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, - volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext, null); + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); String jsonToCompare = new String(Files.readAllBytes( Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationAssign.json"))); @@ -145,7 +146,7 @@ public class VfModuleTopologyOperationRequestMapperTest { GenericResourceApiVfModuleOperationInformation reqMapper1 = omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); - assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") + assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @@ -174,7 +175,7 @@ public class VfModuleTopologyOperationRequestMapperTest { GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, - vnf, serviceInstance, null, null, requestContext, null); + vnf, serviceInstance, null, null, requestContext, null, new URI("http://localhost:8080")); String jsonToCompare = new String(Files.readAllBytes( Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationUnassign.json"))); @@ -183,7 +184,7 @@ public class VfModuleTopologyOperationRequestMapperTest { GenericResourceApiVfModuleOperationInformation reqMapper1 = omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); - assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") + assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @@ -211,7 +212,7 @@ public class VfModuleTopologyOperationRequestMapperTest { GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, - vnf, serviceInstance, null, null, requestContext, null); + vnf, serviceInstance, null, null, requestContext, null, new URI("http://localhost:8080")); assertNotNull(vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @@ -271,9 +272,9 @@ public class VfModuleTopologyOperationRequestMapperTest { CloudRegion cloudRegion = new CloudRegion(); - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, - vnf, serviceInstance, customer, cloudRegion, requestContext, null); + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); assertNull(vfModuleSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); assertEquals("vnfModelCustomizationUuid", @@ -330,7 +331,7 @@ public class VfModuleTopologyOperationRequestMapperTest { expectedException.expectMessage(ERRORMESSAGE); mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, - serviceInstance, customer, cloudRegion, requestContext, null); + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); } } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationAssign.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationAssign.json index 777f3444d2..53c1997126 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationAssign.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationAssign.json @@ -43,7 +43,7 @@ }, "sdnc-request-header" : { "svc-request-id" : "svcRequestId", - "svc-notification-url" : null, + "svc-notification-url" : "http://localhost:8080", "svc-action" : "assign" }, "vf-module-information" : { diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationUnassign.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationUnassign.json index c28b0fa689..9f93c0df1f 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationUnassign.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/genericResourceApiVfModuleOperationInformationUnassign.json @@ -17,7 +17,7 @@ }, "sdnc-request-header" : { "svc-request-id" : "svcRequestId", - "svc-notification-url" : null, + "svc-notification-url" : "http://localhost:8080", "svc-action" : "unassign" }, "vf-module-information" : { diff --git a/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java b/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java index 86d4aa7413..48c2d1495d 100644 --- a/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java +++ b/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java @@ -49,12 +49,12 @@ public abstract class DmaapClient { this.msoProperties = dmaapProperties.getProperties(); this.properties = new Properties(); this.properties.load(resource.getInputStream()); - try { - this.properties.put("auth", CryptoUtils.decrypt(this.getAuth(), this.getKey()).getBytes()); - } catch (GeneralSecurityException e) { - logger.error(e.getMessage(), e); + if (this.getAuth() != null && this.getKey() != null) { + this.properties.put("auth", this.getAuth()); + this.properties.put("key", this.getKey()); + } else { + logger.error("Dmaap auth or key is null"); } - this.properties.put("key", this.getKey()); this.properties.put("topic", this.getTopic()); Optional<String> host = this.getHost(); if (host.isPresent()) { diff --git a/common/src/main/java/org/onap/so/client/graphinventory/Format.java b/common/src/main/java/org/onap/so/client/graphinventory/Format.java index c3cb4b9eaf..078b35aaf4 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/Format.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/Format.java @@ -29,7 +29,8 @@ public enum Format { CONSOLE("console"), PATHED("pathed"), GRAPHSON("graphson"), - ID("id"); + ID("id"), + COUNT("count"); private final String name; diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java index 2a76dab107..c7cdb2ff58 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java @@ -32,9 +32,7 @@ import org.onap.so.client.RestClient; import org.onap.so.client.RestProperties; import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel; import org.onap.so.client.graphinventory.entities.GraphInventoryResultWrapper; -import org.onap.so.client.graphinventory.entities.uri.Depth; import org.onap.so.client.graphinventory.entities.uri.GraphInventoryResourceUri; -import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri; public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInventoryResourceUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { @@ -74,7 +72,9 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven * @return */ public boolean exists(Uri uri) { - GraphInventoryUri forceMinimal = this.addParams(Optional.of(Depth.ZERO), true, uri); + GraphInventoryResourceUri forceMinimal = uri.clone(); + forceMinimal.format(Format.COUNT); + forceMinimal.limit(1); try { RestClient giRC = client.createClient(forceMinimal); @@ -314,18 +314,6 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven */ public abstract SingleTransactionClient beginSingleTransaction(); - private GraphInventoryUri addParams(Optional<Depth> depth, boolean nodesOnly, GraphInventoryUri uri) { - GraphInventoryUri clone = uri.clone(); - if (depth.isPresent()) { - clone.depth(depth.get()); - } - if (nodesOnly) { - clone.nodesOnly(nodesOnly); - } - - return clone; - } - public <T extends RestProperties> T getRestProperties() { return client.getRestProperties(); } diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java index d6d3e5eaa2..6b48ad44ef 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java @@ -22,7 +22,6 @@ package org.onap.so.client.graphinventory.entities.uri; import java.net.URI; import java.util.Map; -import org.onap.so.client.graphinventory.entities.uri.Depth; import org.onap.so.client.graphinventory.GraphInventoryObjectType; public interface GraphInventoryUri { diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java index 2a75c24c46..3c81555b99 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -86,6 +86,9 @@ public class RequestProcessingData implements Serializable { @Temporal(TemporalType.TIMESTAMP) private Date created = null; + @Column(name = "IS_DATA_INTERNAL") + private Boolean isDataInternal = true; + @Override public boolean equals(final Object other) { if (!(other instanceof RequestProcessingData)) { @@ -105,7 +108,7 @@ public class RequestProcessingData implements Serializable { public String toString() { return new ToStringBuilder(this).append("id", id).append("soRequestId", soRequestId) .append("groupingId", groupingId).append("name", name).append("value", value).append("tag", tag) - .toString(); + .append("isDataInternal", isDataInternal).toString(); } @PrePersist @@ -164,4 +167,12 @@ public class RequestProcessingData implements Serializable { public Date getCreated() { return created; } + + public Boolean getIsDataInternal() { + return isDataInternal; + } + + public void setIsDataInternal(Boolean isDataInternal) { + this.isDataInternal = isDataInternal; + } } |