diff options
12 files changed, 244 insertions, 105 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index e4c95f6290..ef1e5128de 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -48,6 +48,7 @@ import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery.TopologyTemplateQueryBuilder; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.*; @@ -629,7 +630,7 @@ public class ToscaResourceInstaller { protected void processNetworks(ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException { - List<IEntityDetails> vlEntityList = getEntityDetails(toscaResourceStruct, SdcTypes.VL, SdcTypes.SERVICE); + List<IEntityDetails> vlEntityList = getEntityDetails(toscaResourceStruct, SdcTypes.VL, SdcTypes.SERVICE, false); if (vlEntityList != null) { for (IEntityDetails vlEntity : vlEntityList) { @@ -1432,10 +1433,10 @@ public class ToscaResourceInstaller { return configCustomizationResource; } - protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, + protected ConfigurationResource createFabricConfiguration(IEntityDetails fabricEntity, ToscaResourceStructure toscaResourceStructure) { - Metadata fabricMetadata = nodeTemplate.getMetaData(); + Metadata fabricMetadata = fabricEntity.getMetadata(); ConfigurationResource configResource = new ConfigurationResource(); @@ -1444,7 +1445,7 @@ public class ToscaResourceInstaller { configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - configResource.setToscaNodeType(nodeTemplate.getType()); + configResource.setToscaNodeType(fabricEntity.getToscaType()); return configResource; } @@ -1475,7 +1476,6 @@ public class ToscaResourceInstaller { if (vnfcCustomization == null) vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID); - // vnfcCustomization = new VnfcCustomization(); return vnfcCustomization; } @@ -1979,16 +1979,16 @@ public class ToscaResourceInstaller { } // Extract CVFC lists - List<NodeTemplate> cvfcList = - toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC); + List<IEntityDetails> cvnfcEntityList = + getEntityDetails(toscaResourceStructure, SdcTypes.CVFC, SdcTypes.VF, false); - for (NodeTemplate cvfcTemplate : cvfcList) { + for (IEntityDetails cvfcEntity : cvnfcEntityList) { boolean cvnfcVfModuleNameMatch = false; for (NodeTemplate node : groupMembers) { vfModuleMemberName = node.getName(); - if (vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())) { + if (vfModuleMemberName.equalsIgnoreCase(cvfcEntity.getName())) { cvnfcVfModuleNameMatch = true; break; } @@ -1997,16 +1997,18 @@ public class ToscaResourceInstaller { if (vfModuleMemberName != null && cvnfcVfModuleNameMatch) { // Extract associated VFC - Should always be just one - List<NodeTemplate> vfcList = - toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); + List<IEntityDetails> vfcEntityList = getEntityDetails(toscaResourceStructure, SdcTypes.VFC, + TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID( + cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)), + false); - for (NodeTemplate vfcTemplate : vfcList) { + for (IEntityDetails vfcEntity : vfcEntityList) { VnfcCustomization vnfcCustomization = new VnfcCustomization(); VnfcCustomization existingVnfcCustomization = null; existingVnfcCustomization = findExistingVfc(existingVnfcSet, - vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); if (existingVnfcCustomization == null) { vnfcCustomization = new VnfcCustomization(); @@ -2015,23 +2017,24 @@ public class ToscaResourceInstaller { } // Only Add Abstract VNFC's to our DB, ignore all others - if (existingVnfcCustomization == null && vfcTemplate.getMetaData() + if (existingVnfcCustomization == null && vfcEntity.getMetadata() .getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")) { + vnfcCustomization.setModelCustomizationUUID( - vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - vnfcCustomization.setModelInstanceName(vfcTemplate.getName()); + vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vnfcCustomization.setModelInstanceName(vfcEntity.getName()); vnfcCustomization.setModelInvariantUUID( - vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); vnfcCustomization - .setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + .setModelName(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); vnfcCustomization - .setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + .setModelUUID(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); vnfcCustomization.setModelVersion( - testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - vnfcCustomization.setDescription(testNull( - vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType())); + testNull(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + vnfcCustomization.setDescription( + testNull(vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + vnfcCustomization.setToscaNodeType(testNull(vfcEntity.getToscaType())); vnfcCustomizations.add(vnfcCustomization); existingVnfcSet.add(vnfcCustomization); @@ -2043,20 +2046,20 @@ public class ToscaResourceInstaller { if (vnfcCustomization.getModelCustomizationUUID() != null) { CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); cvnfcCustomization.setModelCustomizationUUID( - cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName()); + cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + cvnfcCustomization.setModelInstanceName(cvfcEntity.getName()); cvnfcCustomization.setModelInvariantUUID( - cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); cvnfcCustomization - .setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + .setModelName(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); cvnfcCustomization - .setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + .setModelUUID(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); cvnfcCustomization.setModelVersion( - testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + testNull(cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); cvnfcCustomization.setDescription(testNull( - cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType())); + cvfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + cvnfcCustomization.setToscaNodeType(testNull(cvfcEntity.getToscaType())); if (existingVnfcCustomization != null) { cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization); @@ -2064,38 +2067,35 @@ public class ToscaResourceInstaller { cvnfcCustomization.setVnfcCustomization(vnfcCustomization); } - cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function")); - cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code")); - cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); - + cvnfcCustomization.setNfcFunction(getLeafPropertyValue(cvfcEntity, "nfc_function")); + cvnfcCustomization.setNfcNamingCode(getLeafPropertyValue(cvfcEntity, "nfc_naming_code")); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); // ***************************************************************************************************************************************** // * Extract Fabric Configuration // ***************************************************************************************************************************************** - List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION); + List<IEntityDetails> fabricEntityList = + getEntityDetails(toscaResourceStructure, SdcTypes.CONFIGURATION, SdcTypes.VF, false); - for (NodeTemplate fabricTemplate : fabricConfigList) { + for (IEntityDetails fabricEntity : fabricEntityList) { ConfigurationResource fabricConfig = null; ConfigurationResource existingConfig = findExistingConfiguration(existingCvnfcConfigurationCustom, - fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + fabricEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); if (existingConfig == null) { - fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure); + fabricConfig = createFabricConfiguration(fabricEntity, toscaResourceStructure); } else { fabricConfig = existingConfig; } CvnfcConfigurationCustomization cvnfcConfigurationCustomization = - createCvnfcConfigurationCustomization(fabricTemplate, toscaResourceStructure, + createCvnfcConfigurationCustomization(fabricEntity, toscaResourceStructure, vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, vfModuleMemberName); @@ -2119,12 +2119,12 @@ public class ToscaResourceInstaller { return vfModuleCustomization; } - protected CvnfcConfigurationCustomization createCvnfcConfigurationCustomization(NodeTemplate fabricTemplate, + protected CvnfcConfigurationCustomization createCvnfcConfigurationCustomization(IEntityDetails fabricEntity, ToscaResourceStructure toscaResourceStruct, VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization, ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) { - Metadata fabricMetadata = fabricTemplate.getMetaData(); + Metadata fabricMetadata = fabricEntity.getMetadata(); CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization(); @@ -2134,34 +2134,31 @@ public class ToscaResourceInstaller { cvnfcConfigurationCustomization .setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - cvnfcConfigurationCustomization.setModelInstanceName(fabricTemplate.getName()); + cvnfcConfigurationCustomization.setModelInstanceName(fabricEntity.getName()); - List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper() - .getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External"); + List<IEntityDetails> policyList = + getEntityDetails(toscaResourceStruct, "org.openecomp.policies.External", SdcTypes.VF, true); if (policyList != null) { - for (Policy policy : policyList) { + for (IEntityDetails policyEntity : policyList) { - for (String policyCvfcTarget : policy.getTargets()) { + for (String policyCvfcTarget : policyEntity.getTargets()) { if (policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)) { - Map<String, Object> propMap = policy.getPolicyProperties(); + String policyType = getLeafPropertyValue(policyEntity, "type"); - if (propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")) { - cvnfcConfigurationCustomization.setPolicyName(propMap.get("name").toString()); + if (policyType != null && policyType.equalsIgnoreCase("Fabric Policy")) { + cvnfcConfigurationCustomization.setPolicyName(getLeafPropertyValue(policyEntity, "name")); } } } } } - cvnfcConfigurationCustomization.setConfigurationFunction( - toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function")); - cvnfcConfigurationCustomization.setConfigurationRole( - toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role")); - cvnfcConfigurationCustomization.setConfigurationType( - toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type")); + cvnfcConfigurationCustomization.setConfigurationFunction(getLeafPropertyValue(fabricEntity, "function")); + cvnfcConfigurationCustomization.setConfigurationRole(getLeafPropertyValue(fabricEntity, "role")); + cvnfcConfigurationCustomization.setConfigurationType(getLeafPropertyValue(fabricEntity, "type")); return cvnfcConfigurationCustomization; } @@ -2680,24 +2677,36 @@ public class ToscaResourceInstaller { } protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, SdcTypes entityType, - SdcTypes topologyTemplate) { + SdcTypes topologyTemplate, boolean nestedSearch) { EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build(); TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(topologyTemplate).build(); List<IEntityDetails> entityDetails = - toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, false); + toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch); return entityDetails; } protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, String entityType, - SdcTypes topologyTemplate) { + SdcTypes topologyTemplate, boolean nestedSearch) { EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build(); TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(topologyTemplate).build(); List<IEntityDetails> entityDetails = - toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, true); + toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch); + + return entityDetails; + + } + + protected List<IEntityDetails> getEntityDetails(ToscaResourceStructure toscaResourceStruct, SdcTypes entityType, + TopologyTemplateQueryBuilder topologyTemplateBuilder, boolean nestedSearch) { + + EntityQuery entityQuery = EntityQuery.newBuilder(entityType).build(); + TopologyTemplateQuery topologyTemplateQuery = topologyTemplateBuilder.build(); + List<IEntityDetails> entityDetails = + toscaResourceStruct.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, nestedSearch); return entityDetails; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java index 9828d11186..c05557a317 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java @@ -78,8 +78,24 @@ public class ApplicationControllerAction { appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress, controllerType); break; case Snapshot: + if (vmIdList.isEmpty()) { + logger.warn("vmIdList is Empty in AppCClient"); + break; + } String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds"); + if (vmIds == null) { + logger.warn("vmIds null in AppCClient"); + break; + } + if (vserverIdList.isEmpty()) { + logger.warn("vserverIdList is empty in AppCClient"); + break; + } String vserverIds = JsonUtils.getJsonValue(vserverIdList, "vserverIds"); + if (vserverIds == null) { + logger.warn("vserverIds null in AppCClient"); + break; + } String vmId = ""; String vserverId = ""; ObjectMapper mapper = new ObjectMapper(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java index 32db3a7bf6..48c6995715 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java @@ -481,4 +481,100 @@ public class ApplicationControllerActionTest extends BaseTest { assertEquals(expectedErrorCode, appCAction.getErrorCode()); } + @Test + public void runAppCCommand_Snapshot_vmIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", "identityUrl"); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vmId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + + JSONObject vmIdListJson = new JSONObject(); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId1"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + JSONObject vserverIdListJson = new JSONObject(); + payloadInfo.put("vserverIdList", vserverIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/aai/bulkprocess/test-request.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/aai/bulkprocess/test-request.json deleted file mode 100644 index f5ffe38285..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/aai/bulkprocess/test-request.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "transactions" : [ { - "put" : [ { - "uri" : "/network/generic-vnfs/generic-vnf/test1/relationship-list/relationship", - "body" : { - "related-link" : "/cloud-infrastructure/pservers/pserver/test2" - } - }, { - "uri" : "/network/generic-vnfs/generic-vnf/test3/relationship-list/relationship", - "body" : { - "related-link" : "/cloud-infrastructure/pservers/pserver/test4" - } - } ] - }, { - "put" : [ { - "uri" : "/network/generic-vnfs/generic-vnf/test5/relationship-list/relationship", - "body" : { - "related-link" : "/cloud-infrastructure/pservers/pserver/test6" - } - } ] - } ] -}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java b/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java index 1370bb3fa3..3f9715bdef 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java @@ -116,17 +116,23 @@ public class AAISingleTransactionClient } @Override - public void put(String uri, Object body) { + protected void put(String uri, Object body) { request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uri).withBody(body)); } @Override - public void delete(String uri, Object body) { - request.getOperations().add(new OperationBodyRequest().withAction("delete").withUri(uri).withBody(body)); + protected void delete(String uri) { + request.getOperations() + .add(new OperationBodyRequest().withAction("delete").withUri(uri).withBody(new Object())); } @Override - public void patch(String uri, Object body) { + protected void delete(String uri, Object obj) { + request.getOperations().add(new OperationBodyRequest().withAction("delete").withUri(uri).withBody(obj)); + } + + @Override + protected void patch(String uri, Object body) { request.getOperations().add(new OperationBodyRequest().withAction("patch").withUri(uri).withBody(body)); } diff --git a/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java b/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java index 11e458a3da..e621566e5a 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java @@ -169,18 +169,22 @@ public class AAITransactionalClient } @Override - public void put(String uri, Object body) { + protected void put(String uri, Object body) { currentTransaction.getPut().add(new OperationBody().withUri(uri).withBody(body)); } @Override - public void delete(String uri, Object body) { - currentTransaction.getDelete().add(new OperationBody().withUri(uri).withBody(body)); + protected void delete(String uri) { + currentTransaction.getDelete().add(new OperationBody().withUri(uri).withBody(null)); + } + @Override + protected void delete(String uri, Object obj) { + currentTransaction.getDelete().add(new OperationBody().withUri(uri).withBody(obj)); } @Override - public void patch(String uri, Object body) { + protected void patch(String uri, Object body) { currentTransaction.getPatch().add(new OperationBody().withUri(uri).withBody(body)); } diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperProvider.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperProvider.java index 72b01c268e..a4f9496d17 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperProvider.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperProvider.java @@ -40,6 +40,7 @@ public class GraphInventoryCommonObjectMapperProvider extends CommonObjectMapper mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); mapper.enable(MapperFeature.USE_ANNOTATIONS); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector aiJaxb = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java index 5fc8726427..45ac1f741d 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java @@ -33,8 +33,7 @@ import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInventoryResourceUri, EdgeLabel extends GraphInventoryEdgeLabel> - implements TransactionBuilder { +public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInventoryResourceUri, EdgeLabel extends GraphInventoryEdgeLabel> { protected static Logger logger = LoggerFactory.getLogger(GraphInventoryTransactionClient.class); @@ -181,7 +180,7 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv Map<String, Object> result = this.get(new GenericType<Map<String, Object>>() {}, (Uri) uri.clone()) .orElseThrow(() -> new NotFoundException(uri.build() + " does not exist in " + this.getGraphDBName())); String resourceVersion = (String) result.get("resource-version"); - this.delete(uri.resourceVersion(resourceVersion).build().toString(), ""); + this.delete(uri.resourceVersion(resourceVersion).build().toString()); incrementActionAmount(); return (Self) this; } @@ -192,6 +191,14 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv protected abstract String getGraphDBName(); + protected abstract void put(String uri, Object body); + + protected abstract void delete(String uri); + + protected abstract void delete(String uri, Object obj); + + protected abstract void patch(String uri, Object body); + /** * @param obj - can be any object which will marshal into a valid A&AI payload * @param uri diff --git a/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java index 1c49c11382..b07d893adb 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java @@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -32,12 +33,14 @@ import static org.mockito.Mockito.verify; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; +import javax.ws.rs.core.GenericType; import org.json.JSONException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Pserver; @@ -46,7 +49,6 @@ import org.onap.so.client.aai.entities.singletransaction.SingleTransactionReques import org.onap.so.client.aai.entities.singletransaction.SingleTransactionResponse; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; -import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; @@ -60,11 +62,13 @@ public class AAISingleTransactionClientTest { private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/singletransaction/"; AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "pserver-hostname"); AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex"); + AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex2"); ObjectMapper mapper; public AAIClient client = new AAIClient(); + @Spy public AAIResourcesClient aaiClient = new AAIResourcesClient(); @Before @@ -82,9 +86,11 @@ public class AAISingleTransactionClientTest { pserver2.setFqdn("patched-fqdn"); Complex complex = new Complex(); complex.setCity("my-city"); - AAISingleTransactionClient singleTransaction = - aaiClient.beginSingleTransaction().create(uriA, pserver).update(uriA, pserver2).create(uriB, complex); - + Map<String, Object> map = new HashMap<>(); + map.put("resource-version", "1234"); + doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriC)); + AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction().create(uriA, pserver) + .update(uriA, pserver2).create(uriB, complex).delete(uriC); SingleTransactionRequest actual = singleTransaction.getRequest(); diff --git a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java index adbdbb419f..305cdf59cc 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java @@ -22,6 +22,7 @@ package org.onap.so.client.aai; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -31,19 +32,19 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import javax.ws.rs.core.GenericType; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Relationship; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; -import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; @@ -61,11 +62,13 @@ public class AAITransactionalClientTest { AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4"); AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5"); AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6"); + AAIResourceUri uriG = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test7"); ObjectMapper mapper; public AAIClient client = new AAIClient(); + @Spy public AAIResourcesClient aaiClient = new AAIResourcesClient(); @Before @@ -95,9 +98,12 @@ public class AAITransactionalClientTest { List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>(); uris.add(uriB); + Map<String, Object> map = new HashMap<>(); + map.put("resource-version", "1234"); + doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriG)); AAIResourceUri uriAClone = uriA.clone(); AAITransactionalClient transactions = aaiClient.beginTransaction().connect(uriA, uris).connect(uriC, uriD) - .beginNewTransaction().connect(uriE, uriF); + .beginNewTransaction().connect(uriE, uriF).beginNewTransaction().delete(uriG); String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); Map<String, Object> actual = diff --git a/common/src/test/resources/__files/aai/bulkprocess/test-request.json b/common/src/test/resources/__files/aai/bulkprocess/test-request.json index f5ffe38285..5a2953c632 100644 --- a/common/src/test/resources/__files/aai/bulkprocess/test-request.json +++ b/common/src/test/resources/__files/aai/bulkprocess/test-request.json @@ -18,5 +18,9 @@ "related-link" : "/cloud-infrastructure/pservers/pserver/test6" } } ] - } ] + }, { + "delete" : [ { + "uri" : "/network/generic-vnfs/generic-vnf/test7?resource-version=1234" + } ] + }] }
\ No newline at end of file diff --git a/common/src/test/resources/__files/aai/singletransaction/sample-request.json b/common/src/test/resources/__files/aai/singletransaction/sample-request.json index f0761a07b6..69024dca83 100644 --- a/common/src/test/resources/__files/aai/singletransaction/sample-request.json +++ b/common/src/test/resources/__files/aai/singletransaction/sample-request.json @@ -21,6 +21,12 @@ "body": { "city": "my-city" } + }, + { + "action": "delete", + "uri": "/cloud-infrastructure/complexes/complex/my-complex2?resource-version=1234", + "body" : { + } } ] }
\ No newline at end of file |