diff options
60 files changed, 2188 insertions, 361 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CvnfcCatalogDbQueryTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CvnfcCatalogDbQueryTest.java new file mode 100644 index 0000000000..aeee279002 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CvnfcCatalogDbQueryTest.java @@ -0,0 +1,198 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.adapters.catalogdb.catalogrest; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.catalogdb.CatalogDBApplication; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfResource; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; +import org.onap.so.db.catalog.beans.VnfcCustomization; +import org.onap.so.db.catalog.client.CatalogDbClientPortChanger; +import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import org.springframework.beans.BeanUtils; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class CvnfcCatalogDbQueryTest { + + @Autowired + private CvnfcCustomizationRepository cvnfcCustomizationRepository; + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CvnfcCatalogDbQueryTest.class); + + @LocalServerPort + private int port; + boolean isInitialized; + + @Autowired + CatalogDbClientPortChanger client; + + @Before + public void initialize(){ + client.wiremockPort= String.valueOf(port); + } + + @Test + public void cVnfcTest() { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93"); + + List<CvnfcCustomization> foundCvnfcCustomization = client.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671","cb82ffd8-252a-11e7-93ae-92361f002671"); + assertNotNull(foundCvnfcCustomization); + assertTrue(foundCvnfcCustomization.size() > 0); + CvnfcCustomization found = foundCvnfcCustomization.get(0); + + CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization(); + BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization"); + + assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization) + .ignoring("id") + .ignoring("created") + .ignoring("vnfVfmoduleCvnfcConfigurationCustomization") + .ignoring("vnfResourceCusteModelCustomizationUUID")); + } + + @Test + public void getLinkedVnfVfmoduleCvnfcConfigurationCustomizationTest() { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("0c042562-2bac-11e9-b210-d663bd873d93"); + + VnfcCustomization vnfcCustomization = setUpVnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459"); + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + configurationResource.setModelInvariantUUID("modelInvariantUUID"); + configurationResource.setModelUUID("modelUUID"); + configurationResource.setModelName("modelName"); + configurationResource.setModelVersion("modelVersion"); + configurationResource.setDescription("description"); + configurationResource.setToscaNodeType("toscaNodeTypeFC"); + + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUUID("6f19c5fa-2b19-11e9-b210-d663bd873d93"); + vnfResource.setModelVersion("modelVersion"); + vnfResource.setOrchestrationMode("orchestrationMode"); + + VfModule vfModule = new VfModule(); + vfModule.setModelUUID("98aa2a6e-2b18-11e9-b210-d663bd873d93"); + vfModule.setModelInvariantUUID("9fe57860-2b18-11e9-b210-d663bd873d93"); + vfModule.setIsBase(true); + vfModule.setModelName("modelName"); + vfModule.setModelVersion("modelVersion"); + vfModule.setVnfResources(vnfResource); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("bdbf984a-2b16-11e9-b210-d663bd873d93"); + vfModuleCustomization.setVfModule(vfModule); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID("6912dd02-2b16-11e9-b210-d663bd873d93"); + vnfResourceCustomization.setModelInstanceName("testModelInstanceName"); + vnfResourceCustomization.setVnfResources(vnfResource); + cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = new VnfVfmoduleCvnfcConfigurationCustomization(); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationFunction("configurationFunction"); + vnfVfmoduleCvnfcConfigurationCustomization.setModelCustomizationUUID("64627fec-2b1b-11e9-b210-d663bd873d93"); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + vnfVfmoduleCvnfcConfigurationCustomization.setCvnfcCustomization(cvnfcCustomization); + vnfVfmoduleCvnfcConfigurationCustomization.setModelInstanceName("modelInstanceName"); + vnfVfmoduleCvnfcConfigurationCustomization.setVfModuleCustomization(vfModuleCustomization); + vnfVfmoduleCvnfcConfigurationCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizationSet = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); + vnfVfmoduleCvnfcConfigurationCustomizationSet.add(vnfVfmoduleCvnfcConfigurationCustomization); + cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizationSet); + + vnfVfmoduleCvnfcConfigurationCustomization.setCvnfcCustomization(cvnfcCustomization); + + cvnfcCustomizationRepository.save(cvnfcCustomization); + + List<CvnfcCustomization> foundCvnfcCustomization = client.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("6912dd02-2b16-11e9-b210-d663bd873d93","bdbf984a-2b16-11e9-b210-d663bd873d93"); + assertNotNull(foundCvnfcCustomization); + assertTrue(foundCvnfcCustomization.size() > 0); + CvnfcCustomization found = foundCvnfcCustomization.get(0); + + Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = found.getVnfVfmoduleCvnfcConfigurationCustomization(); + if (vnfVfmoduleCvnfcConfigurationCustomizations.size() > 0){ + for(VnfVfmoduleCvnfcConfigurationCustomization customization : vnfVfmoduleCvnfcConfigurationCustomizations) { + Assert.assertTrue(customization.getConfigurationResource().getToscaNodeType().equalsIgnoreCase("toscaNodeTypeFC")); + } + } else { + Assert.fail("No linked VnfVfmoduleCvnfcConfigurationCustomization found for CvnfcCustomization"); + } + } + + protected CvnfcCustomization setUpCvnfcCustomization(String id){ + CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID(id); + cvnfcCustomization.setModelInstanceName("testModelInstanceName"); + cvnfcCustomization.setModelUUID("b25735fe-9b37-11e8-98d0-529269fb1459"); + cvnfcCustomization.setModelInvariantUUID("ba7e6ef0-9b37-11e8-98d0-529269fb1459"); + cvnfcCustomization.setModelVersion("testModelVersion"); + cvnfcCustomization.setModelName("testModelName"); + cvnfcCustomization.setToscaNodeType("testToscaNodeType"); + cvnfcCustomization.setDescription("testCvnfcCustomzationDescription"); + cvnfcCustomization.setNfcFunction("testNfcFunction"); + cvnfcCustomization.setNfcNamingCode("testNfcNamingCode"); + return cvnfcCustomization; + } + + protected VnfcCustomization setUpVnfcCustomization(){ + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + vnfcCustomization.setModelInstanceName("testVnfcCustomizationModelInstanceName"); + vnfcCustomization.setModelUUID("321228a4-9f15-11e8-98d0-529269fb1459"); + vnfcCustomization.setModelInvariantUUID("c0659136-9f15-11e8-98d0-529269fb1459"); + vnfcCustomization.setModelVersion("testModelVersion"); + vnfcCustomization.setModelName("testModelName"); + vnfcCustomization.setToscaNodeType("testToscaModelType"); + vnfcCustomization.setDescription("testVnfcCustomizationDescription"); + return vnfcCustomization; + } +} diff --git a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql index 3e92b5d7ba..1223080e59 100644 --- a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql +++ b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql @@ -241,3 +241,55 @@ INSERT INTO northbound_request_ref_lookup(MACRO_ACTION, ACTION, REQUEST_SCOPE, I INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, FLOW_VERSION, NB_REQ_REF_LOOKUP_ID) VALUES ('Service-Create', '1', 'AssignServiceInstanceBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Service-Create' and CLOUD_OWNER = 'my-custom-cloud-owner' and SERVICE_TYPE = 'TRANSPORT')); + +INSERT INTO `vnfc_customization` + (`model_customization_uuid`, + `model_instance_name`, + `model_uuid`, + `model_invariant_uuid`, + `model_version`, + `model_name`, + `tosca_node_type`, + `description`, + `creation_timestamp`) +VALUES ( '9bcce658-9b37-11e8-98d0-529269fb1459', + 'testModelInstanceName', + 'b25735fe-9b37-11e8-98d0-529269fb1459', + 'ba7e6ef0-9b37-11e8-98d0-529269fb1459', + 'testModelVersion', + 'testModelName', + 'toscaNodeType', + 'testVnfcCustomizationDescription', + '2018-07-17 14:05:08'); + +INSERT INTO `cvnfc_customization` + (`id`, + `model_customization_uuid`, + `model_instance_name`, + `model_uuid`, + `model_invariant_uuid`, + `model_version`, + `model_name`, + `tosca_node_type`, + `description`, + `nfc_function`, + `nfc_naming_code`, + `creation_timestamp`, + `vnf_resource_cust_model_customization_uuid`, + `vf_module_cust_model_customization_uuid`, + `vnfc_cust_model_customization_uuid`) +VALUES ( '1', + 'dadc2c8c-2bab-11e9-b210-d663bd873d93', + 'testModelInstanceName', + 'b25735fe-9b37-11e8-98d0-529269fb1459', + 'ba7e6ef0-9b37-11e8-98d0-529269fb1459', + 'testModelVersion', + 'testModelName', + 'testToscaNodeType', + 'testCvnfcCustomzationDescription', + 'testNfcFunction', + 'testNfcNamingCode', + '2018-07-17 14:05:08', + '68dc9a92-214c-11e7-93ae-92361f002671', + 'cb82ffd8-252a-11e7-93ae-92361f002671', + '9bcce658-9b37-11e8-98d0-529269fb1459'); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java index 7bba136da2..974315374a 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java @@ -162,7 +162,8 @@ public class HeatStackAudit { auditVserver.setLInterfaces(new LInterfaces()); auditVserver.setVserverId(novaResource.getPhysicalResourceId()); Stream<Resource> filteredNeutronNetworks = resources.getList().stream() - .filter(network -> network.getRequiredBy().contains(novaResource.getLogicalResourceId())); + .filter(resource -> resource.getRequiredBy().contains(novaResource.getLogicalResourceId())) + .filter(resource -> "OS::Neutron::Port".equals(resource.getType())); filteredNeutronNetworks.forEach(network -> { LInterface lInterface = new LInterface(); lInterface.setInterfaceId(network.getPhysicalResourceId()); diff --git a/adapters/mso-openstack-adapters/src/test/resources/GetResources.json b/adapters/mso-openstack-adapters/src/test/resources/GetResources.json index 6e2bad38a4..22e66d41bb 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/GetResources.json +++ b/adapters/mso-openstack-adapters/src/test/resources/GetResources.json @@ -1,5 +1,27 @@ { "resources": [ + { + "links": [ + { + "href": "https://orchestration.com:8004/v1/99cecb7b19dc4690960761abd0fe2413/stacks/zdyh3brlba05_addon/03840be2-7ce6-4e38-a748-dbd59a798732/resources/vlbagent_eph_aff_id", + "rel": "self" + }, + { + "href": "https://orchestration.com:8004/v1/99cecb7b19dc4690960761abd0fe2413/stacks/zdyh3brlba05_addon/03840be2-7ce6-4e38-a748-dbd59a798732", + "rel": "stack" + } + ], + "logical_resource_id": "vlbagent_eph_aff_id", + "physical_resource_id": "zdyh3brlba05_addon-vlbagent_eph_aff_id-euhxoicxsgso", + "required_by": [ + "ssc_server_1" + ], + "resource_name": "vlbagent_eph_aff_id", + "resource_status": "CREATE_COMPLETE", + "resource_status_reason": "state changed", + "resource_type": "OS::Heat::RandomString", + "updated_time": "2019-02-07T22:56:12Z" + }, { "resource_name": "ssc_1_trusted_port_0", "links": [ @@ -203,4 +225,4 @@ "resource_type": "OS::Heat::ResourceGroup" } ] -}
\ No newline at end of file +} 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 2f4d5ea6a1..90b705c019 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 @@ -554,8 +554,14 @@ public class ToscaResourceInstaller { for (RequirementAssignment requirement : requirementsList) { if (requirement.getNodeTemplateName().equals(spNode.getName())) { ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy); - - configurationResourceList.add(configurationResource); + + Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream() + .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID())) + .findFirst(); + if(!matchingObject.isPresent()){ + configurationResourceList.add(configurationResource); + } + break; } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index ca0a78a3f2..fbff0620a3 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -406,17 +406,16 @@ public class BBInputSetup implements JavaDelegate { if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null && vfModuleTemp.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) { vfModule = vfModuleTemp; - String vfModuleCustId = bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId(); - modelInfo.setModelCustomizationId(vfModuleCustId); - break; } + String vfModuleCustId = bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModuleTemp.getVfModuleId()).getModelCustomizationId(); + ModelInfo modelInfoVfModule = new ModelInfo(); + modelInfoVfModule.setModelCustomizationId(vfModuleCustId); + mapCatalogVfModule(vfModuleTemp, modelInfoVfModule, service, vnfModelCustomizationUUID); } if (vfModule == null && bbName.equalsIgnoreCase(AssignFlows.VF_MODULE.toString())) { vfModule = createVfModule(lookupKeyMap, resourceId, instanceName, instanceParams); vnf.getVfModules().add(vfModule); - } - if(vfModule != null) { mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID); } } else { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java index b210b5ed2f..ee7999f995 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java @@ -55,6 +55,7 @@ public class ExecuteBuildingBlockRainyDay { private Environment environment; protected String retryDurationPath = "mso.rainyDay.retryDurationMultiplier"; protected String defaultCode = "mso.rainyDay.defaultCode"; + protected String maxRetries = "mso.rainyDay.maxRetries"; public void setRetryTimer(DelegateExecution execution) { try { @@ -172,10 +173,17 @@ public class ExecuteBuildingBlockRainyDay { msoLogger.debug("RainyDayHandler Status Code is: " + handlingCode); execution.setVariable(HANDLING_CODE, handlingCode); } catch (Exception e) { - msoLogger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = Abort", e); String code = this.environment.getProperty(defaultCode); + msoLogger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = "+ code, e); execution.setVariable(HANDLING_CODE, code); } + try{ + int envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries)); + execution.setVariable("maxRetries", envMaxRetries); + } catch (Exception ex) { + msoLogger.error("Could not read maxRetries from config file. Setting max to 5 retries"); + execution.setVariable("maxRetries", 5); + } } public void setHandlingStatusSuccess(DelegateExecution execution) { diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy index 55f68f665e..dac038fab3 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy @@ -97,7 +97,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ @Test void testCreateGenericVnf(){ when(mockExecution.getVariable("CAAIVfMod_vnfName")).thenReturn("vnfName") - Mockito.doNothing().when(client).create(any(AAIResourceUri.class),anyObject()) + Mockito.doNothing().when(client).create(any(AAIResourceUri.class) as AAIResourceUri,anyObject()) createAAIVfModule.createGenericVnf(mockExecution) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createGenericVnfResponseCode", 201) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createGenericVnfResponse","Vnf Created") @@ -112,7 +112,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ when(mockExecution.getVariable("CAAIVfMod_personaId")).thenReturn("model1") when(mockExecution.getVariable("CAAIVfMod_moduleName")).thenReturn("vfModuleName") - Mockito.doNothing().when(client).create(any(AAIResourceUri.class),anyObject()) + Mockito.doNothing().when(client).create(any(AAIResourceUri.class) as AAIResourceUri,anyObject()) createAAIVfModule.createVfModule(mockExecution,false) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createVfModuleResponseCode", 201) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createVfModuleResponse","Vf Module Created") @@ -173,7 +173,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ Optional<GenericVnf> genericVnf = getAAIObjectFromJson(GenericVnf.class,"__files/aai/GenericVnfVfModule.json"); when(mockExecution.getVariable("CAAIVfMod_queryGenericVnfResponse")).thenReturn(genericVnf.get()) when(mockExecution.getVariable("CAAIVfMod_moduleName")).thenReturn("vfModuleName") - Mockito.doNothing().when(client).create(any(AAIResourceUri.class),anyObject()) + Mockito.doNothing().when(client).create(any(AAIResourceUri.class) as AAIResourceUri,anyObject()) createAAIVfModule.createVfModule(mockExecution,true) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createVfModuleResponseCode", 201) Mockito.verify(mockExecution).setVariable("CAAIVfMod_createVfModuleResponse","Vf Module Created") diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy index 4b6f8aa918..2a872511e7 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy @@ -92,7 +92,7 @@ class DeleteAAIVfModuleTest extends MsoGroovyTest{ void testDeleteGenericVnf() { ExecutionEntity mockExecution = setupMock() when(mockExecution.getVariable("DAAIVfMod_vnfId")).thenReturn("vnfId1") - doNothing().when(client).delete(isA(AAIResourceUri.class)) + doNothing().when(client).delete(isA(AAIResourceUri.class) as AAIResourceUri) deleteAAIVfModule.deleteGenericVnf(mockExecution) Mockito.verify(mockExecution).setVariable(prefix + "deleteGenericVnfResponseCode", 200) } @@ -169,7 +169,7 @@ class DeleteAAIVfModuleTest extends MsoGroovyTest{ ExecutionEntity mockExecution = setupMock() when(mockExecution.getVariable("DAAIVfMod_vnfId")).thenReturn("vnfId1") try { - doThrow(new NotFoundException("Vnf Not Found")).when(client).delete(isA(AAIResourceUri.class)) + doThrow(new NotFoundException("Vnf Not Found")).when(client).delete(isA(AAIResourceUri.class) as AAIResourceUri) deleteAAIVfModule.deleteGenericVnf(mockExecution) } catch (Exception ex) { println " Test End - Handle catch-throw BpmnError()! " @@ -186,7 +186,7 @@ class DeleteAAIVfModuleTest extends MsoGroovyTest{ ExecutionEntity mockExecution = setupMock() when(mockExecution.getVariable("DAAIVfMod_vnfId")).thenReturn("vnfId1") when(mockExecution.getVariable("DAAIVfMod_vfModuleId")).thenReturn("vfModuleId1") - doNothing().when(client).delete(isA(AAIResourceUri.class)) + doNothing().when(client).delete(isA(AAIResourceUri.class) as AAIResourceUri) deleteAAIVfModule.deleteVfModule(mockExecution) Mockito.verify(mockExecution).setVariable(prefix + "deleteVfModuleResponseCode", 200) } @@ -197,7 +197,7 @@ class DeleteAAIVfModuleTest extends MsoGroovyTest{ when(mockExecution.getVariable("DAAIVfMod_vnfId")).thenReturn("vnfId1") when(mockExecution.getVariable("DAAIVfMod_vfModuleId")).thenReturn("vfModuleId1") try { - doThrow(new NotFoundException("Vnf Not Found")).when(client).delete(isA(AAIResourceUri.class)) + doThrow(new NotFoundException("Vnf Not Found")).when(client).delete(isA(AAIResourceUri.class) as AAIResourceUri) deleteAAIVfModule.deleteVfModule(mockExecution) } catch (Exception ex) { println " Test End - Handle catch-throw BpmnError()! " diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy index 2d2f58b415..72bcfcf359 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy @@ -111,7 +111,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { vfModule.setVfModuleId("supercool") vfModule.setResourceVersion("12345") when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule) - doNothing().when(client).update(isA(AAIResourceUri.class), anyObject()) + doNothing().when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject()) updateAAIVfModule.updateVfModule(mockExecution) verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 200) } @@ -126,7 +126,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { vfModule.setVfModuleId("supercool") vfModule.setResourceVersion("12345") when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule) - doThrow(new NotFoundException("Vf Module not found")).when(client).update(isA(AAIResourceUri.class), anyObject()) + doThrow(new NotFoundException("Vf Module not found")).when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject()) thrown.expect(BpmnError.class) updateAAIVfModule.updateVfModule(mockExecution) verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 404) @@ -143,7 +143,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { vfModule.setVfModuleId("supercool") vfModule.setResourceVersion("12345") when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule) - doThrow(new IllegalStateException("Error in AAI client")).when(client).update(isA(AAIResourceUri.class), anyObject()) + doThrow(new IllegalStateException("Error in AAI client")).when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject()) thrown.expect(BpmnError.class) updateAAIVfModule.updateVfModule(mockExecution) verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 500) diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index 35a7005751..56875d315b 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -2551,6 +2551,12 @@ public class BBInputSetupTest { volumeGroup.setVolumeGroupId(volumeGroupId); vnf.getVolumeGroups().add(volumeGroup); serviceInstance.getVnfs().add(vnf); + VfModule vfModule1 = new VfModule(); + vfModule1.setVfModuleId("vfModuleId1"); + VfModule vfModule2 = new VfModule(); + vfModule2.setVfModuleId("vfModuleId2"); + vnf.getVfModules().add(vfModule1); + vnf.getVfModules().add(vfModule2); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId); String resourceId = vfModuleId; @@ -2563,16 +2569,20 @@ public class BBInputSetupTest { vnfAAI.setModelCustomizationId("vnfModelCustId"); org.onap.aai.domain.yang.VolumeGroup volumeGroupAAI = new org.onap.aai.domain.yang.VolumeGroup(); volumeGroupAAI.setModelCustomizationId(vfModuleCustomizationId); + org.onap.aai.domain.yang.VfModule vfModuleAAI = new org.onap.aai.domain.yang.VfModule(); + vfModuleAAI.setModelCustomizationId(vfModuleCustomizationId); doReturn(vnfAAI).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId()); doReturn(volumeGroupAAI).when(SPY_bbInputSetupUtils).getAAIVolumeGroup(CLOUD_OWNER, cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()); + doReturn(vfModuleAAI).when(SPY_bbInputSetupUtils).getAAIVfModule(isA(String.class), isA(String.class)); doNothing().when(SPY_bbInputSetup).mapCatalogVnf(isA(GenericVnf.class), isA(ModelInfo.class), isA(Service.class)); doNothing().when(SPY_bbInputSetup).mapCatalogVfModule(isA(VfModule.class), isA(ModelInfo.class), isA(Service.class), isA(String.class)); SPY_bbInputSetup.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId, relatedInstanceList, instanceName, instanceParams, cloudConfiguration); + verify(SPY_bbInputSetup, times(3)).mapCatalogVfModule(isA(VfModule.class), isA(ModelInfo.class), isA(Service.class), isA(String.class)); assertEquals("Lookup Key Map populated with VfModule Id", vfModuleId, lookupKeyMap.get(ResourceKey.VF_MODULE_ID)); assertEquals("Lookup Key Map populated with VolumeGroup Id", volumeGroupId, lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID)); } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java index 868aabf6a9..6344a3f1a6 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java @@ -131,6 +131,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution,true); assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); + assertEquals(5,delegateExecution.getVariable("maxRetries")); } @Test diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/dmaapproperties/DmaapPropertiesClientTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/dmaapproperties/DmaapPropertiesClientTest.java index 95b86524a3..c50a6db178 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/dmaapproperties/DmaapPropertiesClientTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/dmaapproperties/DmaapPropertiesClientTest.java @@ -75,7 +75,7 @@ public class DmaapPropertiesClientTest extends BaseTest{ @Test public void testDmaapPublishRequest() throws JsonProcessingException, MapperException { - stubFor(post(urlEqualTo("/events/com.att.mso.asyncStatusUpdate?timeout=20000")) + stubFor(post(urlEqualTo("/events/com.att.mso.asyncStatusUpdate?timeout=60000")) .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED))); dmaapPropertiesClient.dmaapPublishRequest(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope, diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn index 943ce12a8a..5189f8b48a 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.7.1"> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.8.2"> <bpmn:process id="ExecuteBuildingBlock" name="ExecuteBuildingBlock" isExecutable="true"> <bpmn:startEvent id="Start_ExecuteBuildingBlock" name="start"> <bpmn:outgoing>SequenceFlow_0rq4c5r</bpmn:outgoing> @@ -73,7 +73,7 @@ <bpmn:sequenceFlow id="SequenceFlow_0ndt8ft" sourceRef="Task_SetRetryTimer" targetRef="IntermediateCatchEvent_RetryTimer" /> <bpmn:sequenceFlow id="SequenceFlow_07a1ytc" sourceRef="IntermediateCatchEvent_RetryTimer" targetRef="EndEvent_1sez2lh" /> <bpmn:sequenceFlow id="SequenceFlow_1wbevp0" name="yes" sourceRef="ExclusiveGateway_0ey4zpt" targetRef="Task_SetRetryTimer"> - <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[${execution.getVariable("retryCount")<5}]]></bpmn:conditionExpression> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[${execution.getVariable("retryCount")<execution.getVariable("maxRetries")}]]></bpmn:conditionExpression> </bpmn:sequenceFlow> <bpmn:endEvent id="EndEvent_0mvmk3i"> <bpmn:incoming>SequenceFlow_0h8v45y</bpmn:incoming> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java index d919c53c9c..fec7e8456f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.adapter.network.tasks; import java.io.StringReader; @@ -15,6 +35,9 @@ import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkError; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkError; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.NetworkAdapterResources; import org.slf4j.Logger; @@ -95,6 +118,14 @@ public class NetworkAdapterRestV1 { DeleteNetworkResponse deleteNetworkResponse = (DeleteNetworkResponse) unmarshalXml(callback, DeleteNetworkResponse.class); execution.setVariable("deleteNetworkResponse", deleteNetworkResponse); } + } else if (networkAdapterRequest instanceof UpdateNetworkRequest) { + if (callback.contains("updateNetworkError")) { + UpdateNetworkError updateNetworkError = (UpdateNetworkError) unmarshalXml(callback, UpdateNetworkError.class); + throw new Exception(updateNetworkError.getMessage()); + } else { + UpdateNetworkResponse updateNetworkResponse = (UpdateNetworkResponse) unmarshalXml(callback, UpdateNetworkResponse.class); + execution.setVariable("updateNetworkResponse", updateNetworkResponse); + } } } } catch (Exception e) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java index 32c852b0e1..f2fb37e182 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.flowspecific.tasks; import org.onap.so.bpmn.common.BuildingBlockExecution; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 0c0e1464b2..0082545fa1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -68,6 +68,8 @@ import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.Networks; +import org.onap.so.serviceinstancebeans.RelatedInstance; +import org.onap.so.serviceinstancebeans.RelatedInstanceList; import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -198,7 +200,7 @@ public class WorkflowAction { if (orchFlows == null || orchFlows.isEmpty()) { orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType); } - orchFlows = filterOrchFlows(orchFlows, resourceType, execution); + orchFlows = filterOrchFlows(sIRequest, orchFlows, resourceType, execution); String key = ""; ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo(); if(modelInfo.getModelType().equals(ModelType.service)) { @@ -1103,10 +1105,22 @@ public class WorkflowAction { return listToExecute; } - protected List<OrchestrationFlow> filterOrchFlows(List<OrchestrationFlow> orchFlows, WorkflowType resourceType, DelegateExecution execution) { + protected List<OrchestrationFlow> filterOrchFlows(ServiceInstancesRequest sIRequest, List<OrchestrationFlow> orchFlows, WorkflowType resourceType, DelegateExecution execution) { List<OrchestrationFlow> result = new ArrayList<>(orchFlows); + String vnfCustomizationUUID = ""; + String vfModuleCustomizationUUID = sIRequest.getRequestDetails().getModelInfo().getModelCustomizationUuid(); + RelatedInstanceList[] relatedInstanceList = sIRequest.getRequestDetails().getRelatedInstanceList(); + if (relatedInstanceList != null) { + for (RelatedInstanceList relatedInstList : relatedInstanceList) { + RelatedInstance relatedInstance = relatedInstList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) { + vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid(); + } + } + } + if (resourceType.equals(WorkflowType.VFMODULE)) { - List<String> fabricCustomizations = traverseCatalogDbForConfiguration((String)execution.getVariable("vnfId"), (String)execution.getVariable("vfModuleId")); + List<String> fabricCustomizations = traverseCatalogDbForConfiguration(vnfCustomizationUUID, vfModuleCustomizationUUID); if (fabricCustomizations.isEmpty()) { result = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList()); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java index 2ba8cb4b57..516c9480ad 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -1,11 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.adapter.network.tasks; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; + import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import javax.xml.bind.JAXBException; import org.junit.Test; import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; public class NetworkAdapterRestV1Test { @@ -16,4 +42,17 @@ public class NetworkAdapterRestV1Test { String returnedXml = response.toXmlString(); System.out.println(returnedXml); } + + @Test + public void testUnmarshalXmlUpdate() throws IOException, JAXBException { + UpdateNetworkResponse expectedResponse = new UpdateNetworkResponse(); + expectedResponse.setMessageId("ec100bcc-2659-4aa4-b4d8-3255715c2a51"); + expectedResponse.setNetworkId("80de31e3-cc78-4111-a9d3-5b92bf0a39eb"); + Map<String,String>subnetMap = new HashMap<String,String>(); + subnetMap.put("95cd8437-25f1-4238-8720-cbfe7fa81476", "d8d16606-5d01-4822-b160-9a0d257303e0"); + expectedResponse.setSubnetMap(subnetMap); + String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><updateNetworkResponse><messageId>ec100bcc-2659-4aa4-b4d8-3255715c2a51</messageId><networkId>80de31e3-cc78-4111-a9d3-5b92bf0a39eb</networkId><subnetMap><entry><key>95cd8437-25f1-4238-8720-cbfe7fa81476</key><value>d8d16606-5d01-4822-b160-9a0d257303e0</value></entry></subnetMap></updateNetworkResponse>"; + UpdateNetworkResponse response = (UpdateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, UpdateNetworkResponse.class); + assertThat(expectedResponse, sameBeanAs(response)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java index 57e463c0f8..d1d167e561 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.flowspecific.tasks; import static org.junit.Assert.*; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java index 4ace2727be..03b39f57e5 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.workflow.tasks; import static org.hamcrest.CoreMatchers.equalTo; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 7b348c8cb3..24b87277c4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -37,9 +37,11 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.Set; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -70,6 +72,8 @@ import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResource; import org.onap.so.db.catalog.beans.CollectionResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.HeatEnvironment; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.InstanceGroup; @@ -77,6 +81,7 @@ import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.serviceinstancebeans.RequestDetails; @@ -854,6 +859,63 @@ public class WorkflowActionTest extends BaseTaskTest { ,"DeleteNetworkCollectionBB"); } + @Test + public void selectExecutionListALaCarteVfModuleNoFabricCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "VfModule"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,true,"my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEqualsBulkFlowName(ebbs,"AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB"); + } + + @Test + public void selectExecutionListALaCarteVfModuleFabricCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "VfModule"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + List<CvnfcCustomization> cvnfcCustomizations = new ArrayList<CvnfcCustomization>(); + CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); + VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = new VnfVfmoduleCvnfcConfigurationCustomization(); + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + Set<VnfVfmoduleCvnfcConfigurationCustomization> custSet = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); + custSet.add(vnfVfmoduleCvnfcConfigurationCustomization); + cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(custSet); + cvnfcCustomizations.add(cvnfcCustomization); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,true,"my-custom-cloud-owner")).thenReturn(northBoundRequest); + when(catalogDbClient.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("fc25201d-36d6-43a3-8d39-fdae88e526ae", "9a6d01fd-19a7-490a-9800-460830a12e0b")).thenReturn(cvnfcCustomizations); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEqualsBulkFlowName(ebbs,"AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + } + /** * WorkflowActionBB Tests */ diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java index 297d75a104..2dd4033aa2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java @@ -57,6 +57,10 @@ import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RelatedInstance; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @RunWith(MockitoJUnitRunner.class) public class WorkflowActionUnitTest { @@ -87,9 +91,16 @@ public class WorkflowActionUnitTest { "flow y", "ActivateFabricConfigurationBB", "flow z"); - doReturn(Arrays.asList("yes", "yes")).when(workflowAction).traverseCatalogDbForConfiguration(ArgumentMatchers.isNull(), ArgumentMatchers.isNull()); + doReturn(Arrays.asList("yes", "yes")).when(workflowAction).traverseCatalogDbForConfiguration(ArgumentMatchers.any(String.class), ArgumentMatchers.isNull()); - List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); + ServiceInstancesRequest sIRequest = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + ModelInfo modelInfo = new ModelInfo(); + requestDetails.setModelInfo(modelInfo); + RelatedInstance relatedInstance = new RelatedInstance(); + sIRequest.setRequestDetails(requestDetails); + + List<OrchestrationFlow> result = workflowAction.filterOrchFlows(sIRequest, flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); assertThat(result, is(flows)); } @@ -103,7 +114,14 @@ public class WorkflowActionUnitTest { "ActivateFabricConfigurationBB", "flow z"); - List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); + ServiceInstancesRequest sIRequest = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationUuid(""); + requestDetails.setModelInfo(modelInfo); + sIRequest.setRequestDetails(requestDetails); + + List<OrchestrationFlow> result = workflowAction.filterOrchFlows(sIRequest, flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); List<OrchestrationFlow> expected = createFlowList( "flow x", "flow y", @@ -147,7 +165,7 @@ public class WorkflowActionUnitTest { doReturn(Arrays.asList(flow)).when(workflowAction).queryNorthBoundRequestCatalogDb(any(), any(), any(), anyBoolean(), any(), any()); workflowAction.selectExecutionList(execution); - verify(workflowAction, times(1)).filterOrchFlows(eq(flows), any(), any()); + verify(workflowAction, times(1)).filterOrchFlows(any(), eq(flows), any(), any()); flow = new OrchestrationFlow(); flow.setFlowName("flow y"); @@ -155,7 +173,7 @@ public class WorkflowActionUnitTest { when(execution.getVariable(eq("aLaCarte"))).thenReturn(false); workflowAction.selectExecutionList(execution); - verify(workflowAction, never()).filterOrchFlows(eq(flows), any(), any()); + verify(workflowAction, never()).filterOrchFlows(any(), eq(flows), any(), any()); } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json new file mode 100644 index 0000000000..332ad4500c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json @@ -0,0 +1,65 @@ +{ + "requestDetails": { + "modelInfo": { + "modelCustomizationName": "model-cust-name", + "modelInvariantId": "db86e4a6-c027-452e-a559-3a23b3128367", + "modelType": "vfModule", + "modelName": "test-model-name", + "modelVersion": "1", + "modelCustomizationUuid": "9a6d01fd-19a7-490a-9800-460830a12e0b", + "modelVersionId": "14c8f313-fb0f-4cf6-8caf-c7cce8137b60", + "modelCustomizationId": "9a6d01fd-19a7-490a-9800-460830a12e0b", + "modelUuid": "14c8f313-fb0f-4cf6-8caf-c7cce8137b60", + "modelInvariantUuid": "db86e4a6-c027-452e-a559-3a23b3128367", + "modelInstanceName": "test-model-instance-name" + }, + "requestInfo": { + "source": "VID", + "instanceName": "instanceName", + "suppressRollback": false, + "requestorId": "user" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "f647e3ef-6d2e-4cd3-bff4-8df4634208de", + "modelInfo": { + "modelInvariantId": "86adb376-5303-441a-b50e-96c0cd643b0f", + "modelType": "service", + "modelName": "model-name", + "modelVersion": "1.0", + "modelVersionId": "599e21ed-803d-4d1f-83df-20005339b83f", + "modelUuid": "599e21ed-803d-4d1f-83df-20005339b83f", + "modelInvariantUuid": "86adb376-5303-441a-b50e-96c0cd643b0f" + } + } + }, + { + "relatedInstance": { + "instanceId": "b80b16a5-f80d-4ffa-91c8-bd47c7438a3d", + "modelInfo": { + "modelCustomizationName": "modle-cust-name", + "modelInvariantId": "5cca9285-4ed4-4e11-a609-921ed3344811", + "modelType": "vnf", + "modelName": "modle-name", + "modelVersion": "1.0", + "modelCustomizationUuid": "fc25201d-36d6-43a3-8d39-fdae88e526ae", + "modelVersionId": "7cae703a-b20d-481a-863a-b862236c00f7", + "modelCustomizationId": "fc25201d-36d6-43a3-8d39-fdae88e526ae", + "modelUuid": "7cae703a-b20d-481a-863a-b862236c00f7", + "modelInvariantUuid": "5cca9285-4ed4-4e11-a609-921ed3344811", + "modelInstanceName": "model-inst-name" + } + } + } + ], + "cloudConfiguration": { + "tenantId": "872f331350c54e59991a8de2cbffb40c", + "cloudOwner": "my-custom-cloud-owner", + "lcpCloudRegionId": "cloud-region" + }, + "requestParameters": { + "usePreload": true + } + } +}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperPatchProvider.java b/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperPatchProvider.java index 33c9769400..9c8345d4b6 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperPatchProvider.java +++ b/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperPatchProvider.java @@ -20,16 +20,12 @@ package org.onap.so.client.aai; -import com.fasterxml.jackson.databind.module.SimpleModule; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperPatchProvider; -public class AAICommonObjectMapperPatchProvider extends AAICommonObjectMapperProvider { +public class AAICommonObjectMapperPatchProvider extends GraphInventoryCommonObjectMapperPatchProvider { public AAICommonObjectMapperPatchProvider() { super(); - EmptyStringToNullSerializer sp = new EmptyStringToNullSerializer(); - SimpleModule emptyStringModule = new SimpleModule(); - emptyStringModule.addSerializer(String.class, sp); - mapper.registerModule(emptyStringModule); } } diff --git a/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperProvider.java b/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperProvider.java index 0e2071842f..15bc2ea8ef 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperProvider.java +++ b/common/src/main/java/org/onap/so/client/aai/AAICommonObjectMapperProvider.java @@ -20,33 +20,12 @@ package org.onap.so.client.aai; -import org.onap.so.client.policy.CommonObjectMapperProvider; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.databind.AnnotationIntrospector; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; -import com.fasterxml.jackson.databind.type.TypeFactory; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; - -public class AAICommonObjectMapperProvider extends CommonObjectMapperProvider { +public class AAICommonObjectMapperProvider extends GraphInventoryCommonObjectMapperProvider { public AAICommonObjectMapperProvider() { - mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - mapper.enable(MapperFeature.USE_ANNOTATIONS); - mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - AnnotationIntrospector aiJaxb = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); - AnnotationIntrospector aiJackson = new JacksonAnnotationIntrospector(); - // first Jaxb, second Jackson annotations - mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(aiJaxb, aiJackson)); + super(); } } diff --git a/common/src/main/java/org/onap/so/client/aai/AAIDSLQuery.java b/common/src/main/java/org/onap/so/client/aai/AAIDSLQuery.java new file mode 100644 index 0000000000..52bae20ff3 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/AAIDSLQuery.java @@ -0,0 +1,83 @@ +/*- + * ============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.client.aai; + +import java.util.Optional; + +import org.onap.so.client.RestClient; +import org.onap.so.client.aai.entities.DSLQuery; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.graphinventory.Format; +import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri; + +public class AAIDSLQuery extends AAIClient { + + private Optional<String> depth = Optional.empty(); + private boolean nodesOnly = false; + private Optional<AAISubgraphType> subgraph = Optional.empty(); + + public AAIDSLQuery() { + super(); + } + + public AAIDSLQuery(AAIVersion version) { + super(); + this.version = version; + } + + public String query(Format format, DSLQuery query) { + return this.createClient(AAIUriFactory.createResourceUri(AAIObjectType.DSL).queryParam("format", format.toString())) + .put(query, String.class); + } + + public AAIDSLQuery depth (String depth) { + this.depth = Optional.of(depth); + return this; + } + public AAIDSLQuery nodesOnly() { + this.nodesOnly = true; + return this; + } + public AAIDSLQuery subgraph(AAISubgraphType type){ + + subgraph = Optional.of(type); + + return this; + } + + protected GraphInventoryUri setupQueryParams(GraphInventoryUri uri) { + GraphInventoryUri clone = uri.clone(); + if (this.depth.isPresent()) { + clone.queryParam("depth", depth.get()); + } + if (this.nodesOnly) { + clone.queryParam("nodesOnly", ""); + } + if (this.subgraph.isPresent()) { + clone.queryParam("subgraph", this.subgraph.get().toString()); + } + return clone; + } + @Override + protected RestClient createClient(GraphInventoryUri uri) { + return super.createClient(setupQueryParams(uri)); + } +} diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java index 66ff59d94f..14d7f43911 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java @@ -134,6 +134,7 @@ public class AAIObjectType implements GraphInventoryObjectType, Serializable { public static final AAIObjectType AGGREGATE_ROUTE = new AAIObjectType(AAINamespaceConstants.NETWORK, AggregateRoute.class); public static final AAIObjectType L_INTERFACE = new AAIObjectType(AAIObjectType.VSERVER.uriTemplate(), LInterface.class); public static final AAIObjectType UNKNOWN = new AAIObjectType("", "", "unknown"); + public static final AAIObjectType DSL = new AAIObjectType("/dsl", "", "dsl"); private final String uriTemplate; private final String parentUri; diff --git a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java index 87951d516b..288ac9bc7f 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java @@ -36,9 +36,10 @@ import org.onap.so.client.aai.entities.AAIEdgeLabel; 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.AAIUri; +import org.onap.so.client.graphinventory.GraphInventoryResourcesClient; import org.onap.so.client.graphinventory.entities.uri.Depth; -public class AAIResourcesClient extends AAIClient { +public class AAIResourcesClient extends AAIClient implements GraphInventoryResourcesClient<AAIResourcesClient, AAIResourceUri, AAIEdgeLabel, AAIResultWrapper, AAITransactionalClient, AAISingleTransactionClient> { public AAIResourcesClient() { super(); @@ -49,37 +50,30 @@ public class AAIResourcesClient extends AAIClient { this.version = version; } - /** - * creates a new object in A&AI - * - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#create(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public void create(AAIResourceUri uri, Object obj) { RestClient aaiRC = this.createClient(uri); aaiRC.put(obj); return; } - /** - * creates a new object in A&AI with no payload body - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#createEmpty(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public void createEmpty(AAIResourceUri uri) { RestClient aaiRC = this.createClient(uri); aaiRC.put(""); return; } - /** - * returns false if the object does not exist in A&AI - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#exists(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public boolean exists(AAIResourceUri uri) { AAIUri forceMinimal = this.addParams(Optional.of(Depth.ZERO), true, uri); try { @@ -91,12 +85,10 @@ public class AAIResourcesClient extends AAIClient { } } - /** - * Adds a relationship between two objects in A&AI - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public void connect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); @@ -104,14 +96,10 @@ public class AAIResourcesClient extends AAIClient { return; } - /** - * Adds a relationship between two objects in A&AI - * with a given edge label - * @param uriA - * @param uriB - * @param edge label - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.AAIEdgeLabel) */ + @Override public void connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) { AAIResourceUri uriAClone = uriA.clone(); RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); @@ -119,13 +107,10 @@ public class AAIResourcesClient extends AAIClient { return; } - /** - * Removes relationship from two objects in A&AI - * - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#disconnect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public void disconnect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); @@ -133,12 +118,10 @@ public class AAIResourcesClient extends AAIClient { return; } - /** - * Deletes object from A&AI. Automatically handles resource-version. - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#delete(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public void delete(AAIResourceUri uri) { AAIResourceUri clone = uri.clone(); RestClient aaiRC = this.createClient(clone); @@ -150,23 +133,20 @@ public class AAIResourcesClient extends AAIClient { return; } - /** - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#update(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public void update(AAIResourceUri uri, Object obj) { RestClient aaiRC = this.createClient(uri); aaiRC.patch(obj); return; } - /** - * Retrieves an object from A&AI and unmarshalls it into the Class specified - * @param clazz - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#get(java.lang.Class, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public <T> Optional<T> get(Class<T> clazz, AAIResourceUri uri) { try { return this.createClient(uri).get(clazz); @@ -179,11 +159,10 @@ public class AAIResourcesClient extends AAIClient { } } - /** - * Retrieves an object from A&AI and returns complete response - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#getFullResponse(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public Response getFullResponse(AAIResourceUri uri) { try { return this.createClient(uri).get(); @@ -196,12 +175,10 @@ public class AAIResourcesClient extends AAIClient { } } - /** - * Retrieves an object from A&AI and automatically unmarshalls it into a Map or List - * @param resultClass - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#get(javax.ws.rs.core.GenericType, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public <T> Optional<T> get(GenericType<T> resultClass, AAIResourceUri uri) { try { return this.createClient(uri).get(resultClass); @@ -214,12 +191,10 @@ public class AAIResourcesClient extends AAIClient { } } - /** - * Retrieves an object from A&AI wrapped in a helper class which offer additional features - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#get(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAIResultWrapper get(AAIResourceUri uri) { String json; try { @@ -234,13 +209,10 @@ public class AAIResourcesClient extends AAIClient { return new AAIResultWrapper(json); } - /** - * Retrieves an object from A&AI wrapped in a helper class which offer additional features - * If the object cannot be found in A&AI the method will throw the runtime exception - * included as an argument - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#get(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Class) */ + @Override public AAIResultWrapper get(AAIResourceUri uri, Class<? extends RuntimeException> c) { String json; try { @@ -285,13 +257,10 @@ public class AAIResourcesClient extends AAIClient { return result; } - /** - * Will automatically create the object if it does not exist - * - * @param obj - Optional object which serializes to a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#createIfNotExists(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.Optional) */ + @Override public AAIResourcesClient createIfNotExists(AAIResourceUri uri, Optional<Object> obj) { if(!this.exists(uri)){ if (obj.isPresent()) { @@ -304,20 +273,18 @@ public class AAIResourcesClient extends AAIClient { return this; } - /** - * Starts a transaction which encloses multiple A&AI mutations - * - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#beginTransaction() */ + @Override public AAITransactionalClient beginTransaction() { return new AAITransactionalClient(this.getVersion()); } - /** - * Starts a transaction groups multiple A&AI mutations - * - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#beginSingleTransaction() */ + @Override public AAISingleTransactionClient beginSingleTransaction() { return new AAISingleTransactionClient(this.getVersion()); } @@ -333,6 +300,9 @@ public class AAIResourcesClient extends AAIClient { return clone; } + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryResourcesClient#getRestProperties() + */ @Override public <T extends RestProperties> T getRestProperties() { return super.getRestProperties(); diff --git a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java index 4f235c35f1..a2651195ee 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java @@ -28,6 +28,7 @@ import javax.ws.rs.core.Response; import org.onap.so.client.ResponseExceptionMapper; import org.onap.so.client.RestClientSSL; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.onap.so.client.policy.CommonObjectMapperProvider; import org.onap.so.utils.TargetEntity; @@ -36,7 +37,7 @@ public class AAIRestClient extends RestClientSSL { private final AAIProperties aaiProperties; private static final AAICommonObjectMapperProvider standardProvider = new AAICommonObjectMapperProvider(); - private final AAIPatchConverter patchConverter = new AAIPatchConverter(); + private final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter(); protected AAIRestClient(AAIProperties props, URI uri) { super(props, Optional.of(uri)); @@ -81,7 +82,7 @@ public class AAIRestClient extends RestClientSSL { return super.patch(convertToPatchFormat(obj), resultClass); } - protected AAIPatchConverter getPatchConverter() { + protected GraphInventoryPatchConverter getPatchConverter() { return this.patchConverter; } 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 2ecdb7c480..ba65ac3f15 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 @@ -43,19 +43,21 @@ import org.onap.so.client.aai.entities.singletransaction.SingleTransactionRespon import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; +import org.onap.so.client.graphinventory.GraphInventorySingleTransactionClient; import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; -public class AAISingleTransactionClient extends AAIClient { +public class AAISingleTransactionClient extends AAIClient implements GraphInventorySingleTransactionClient<AAISingleTransactionClient, AAIResourceUri, AAIEdgeLabel> { private final SingleTransactionRequest request; private final AAIVersion version; private int actionCount = 0; - private final AAIPatchConverter patchConverter = new AAIPatchConverter(); + private final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter(); protected AAISingleTransactionClient(AAIVersion version) { super(); @@ -63,37 +65,30 @@ public class AAISingleTransactionClient extends AAIClient { this.request = new SingleTransactionRequest(); } - /** - * creates a new object in A&AI - * - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#create(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public AAISingleTransactionClient create(AAIResourceUri uri, Object obj) { request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uri.build().toString()).withBody(obj)); incrementActionAmount(); return this; } - /** - * creates a new object in A&AI with no payload body - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#createEmpty(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAISingleTransactionClient createEmpty(AAIResourceUri uri) { request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uri.build().toString()).withBody(new HashMap<String, String>())); incrementActionAmount(); return this; } - /** - * Adds a relationship between two objects in A&AI - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAISingleTransactionClient connect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB))); @@ -101,13 +96,10 @@ public class AAISingleTransactionClient extends AAIClient { return this; } - /** - * relationship between multiple objects in A&AI - connects A to all objects specified in list - * - * @param uriA - * @param uris - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List) */ + @Override public AAISingleTransactionClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris) { for (AAIResourceUri uri : uris) { this.connect(uriA, uri); @@ -115,6 +107,10 @@ public class AAISingleTransactionClient extends AAIClient { return this; } + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.AAIEdgeLabel) + */ + @Override public AAISingleTransactionClient connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) { AAIResourceUri uriAClone = uriA.clone(); RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); @@ -122,6 +118,10 @@ public class AAISingleTransactionClient extends AAIClient { return this; } + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List, org.onap.so.client.aai.entities.AAIEdgeLabel) + */ + @Override public AAISingleTransactionClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris, AAIEdgeLabel label) { for (AAIResourceUri uri : uris) { this.connect(uriA, uri, label); @@ -129,13 +129,10 @@ public class AAISingleTransactionClient extends AAIClient { return this; } - /** - * Removes relationship from two objects in A&AI - * - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#disconnect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAISingleTransactionClient disconnect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); request.getOperations().add(new OperationBodyRequest().withAction("delete").withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB))); @@ -143,24 +140,20 @@ public class AAISingleTransactionClient extends AAIClient { return this; } - /** - * Removes relationship from multiple objects - disconnects A from all objects specified in list - * @param uriA - * @param uris - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#disconnect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List) */ + @Override public AAISingleTransactionClient disconnect(AAIResourceUri uriA, List<AAIResourceUri> uris) { for (AAIResourceUri uri : uris) { this.disconnect(uriA, uri); } return this; } - /** - * Deletes object from A&AI. Automatically handles resource-version. - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#delete(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAISingleTransactionClient delete(AAIResourceUri uri) { AAIResourcesClient client = new AAIResourcesClient(); AAIResourceUri clone = uri.clone(); @@ -172,11 +165,10 @@ public class AAISingleTransactionClient extends AAIClient { return this; } - /** - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#update(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public AAISingleTransactionClient update(AAIResourceUri uri, Object obj) { final String payload = getPatchConverter().convertPatchFormat(obj); @@ -188,10 +180,10 @@ public class AAISingleTransactionClient extends AAIClient { private void incrementActionAmount() { actionCount++; } - /** - * Executes all created transactions in A&AI - * @throws BulkProcessFailed + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionClient#execute() */ + @Override public void execute() throws BulkProcessFailed { RestClient client = this.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION)); try { @@ -261,7 +253,7 @@ public class AAISingleTransactionClient extends AAIClient { return this.request; } - protected AAIPatchConverter getPatchConverter() { + protected GraphInventoryPatchConverter getPatchConverter() { return this.patchConverter; } } 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 118a3edf1c..dd4cb2f591 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 @@ -20,8 +20,6 @@ package org.onap.so.client.aai; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -42,8 +40,9 @@ import org.onap.so.client.aai.entities.bulkprocess.OperationBody; import org.onap.so.client.aai.entities.bulkprocess.Transaction; import org.onap.so.client.aai.entities.bulkprocess.Transactions; import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.client.aai.entities.uri.AAIUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; +import org.onap.so.client.graphinventory.GraphInventoryTransactionalClient; import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; import org.onap.so.jsonpath.JsonPathUtil; @@ -51,14 +50,14 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; -public class AAITransactionalClient extends AAIClient { +public class AAITransactionalClient extends AAIClient implements GraphInventoryTransactionalClient<AAITransactionalClient, AAIResourceUri, AAIEdgeLabel> { private final Transactions transactions; private Transaction currentTransaction; private final AAIVersion version; private int actionCount = 0; - private final AAIPatchConverter patchConverter = new AAIPatchConverter(); + private final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter(); protected AAITransactionalClient(AAIVersion version) { super(); @@ -73,47 +72,39 @@ public class AAITransactionalClient extends AAIClient { currentTransaction = transaction; } - /** - * adds an additional transaction and closes the previous transaction - * - * @return AAITransactionalClient + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#beginNewTransaction() */ + @Override public AAITransactionalClient beginNewTransaction() { startTransaction(); return this; } - /** - * creates a new object in A&AI - * - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#create(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public AAITransactionalClient create(AAIResourceUri uri, Object obj) { currentTransaction.getPut().add(new OperationBody().withUri(uri.build().toString()).withBody(obj)); incrementActionAmount(); return this; } - /** - * creates a new object in A&AI with no payload body - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#createEmpty(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAITransactionalClient createEmpty(AAIResourceUri uri) { currentTransaction.getPut().add(new OperationBody().withUri(uri.build().toString()).withBody(new HashMap<String, String>())); incrementActionAmount(); return this; } - /** - * Adds a relationship between two objects in A&AI - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAITransactionalClient connect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); currentTransaction.getPut().add(new OperationBody().withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB))); @@ -121,13 +112,10 @@ public class AAITransactionalClient extends AAIClient { return this; } - /** - * relationship between multiple objects in A&AI - connects A to all objects specified in list - * - * @param uriA - * @param uris - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List) */ + @Override public AAITransactionalClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris) { for (AAIResourceUri uri : uris) { this.connect(uriA, uri); @@ -135,6 +123,10 @@ public class AAITransactionalClient extends AAIClient { return this; } + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.AAIEdgeLabel) + */ + @Override public AAITransactionalClient connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) { AAIResourceUri uriAClone = uriA.clone(); RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); @@ -142,6 +134,10 @@ public class AAITransactionalClient extends AAIClient { return this; } + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#connect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List, org.onap.so.client.aai.entities.AAIEdgeLabel) + */ + @Override public AAITransactionalClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris, AAIEdgeLabel label) { for (AAIResourceUri uri : uris) { this.connect(uriA, uri, label); @@ -149,13 +145,10 @@ public class AAITransactionalClient extends AAIClient { return this; } - /** - * Removes relationship from two objects in A&AI - * - * @param uriA - * @param uriB - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#disconnect(org.onap.so.client.aai.entities.uri.AAIResourceUri, org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAITransactionalClient disconnect(AAIResourceUri uriA, AAIResourceUri uriB) { AAIResourceUri uriAClone = uriA.clone(); currentTransaction.getDelete().add(new OperationBody().withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB))); @@ -163,24 +156,20 @@ public class AAITransactionalClient extends AAIClient { return this; } - /** - * Removes relationship from multiple objects - disconnects A from all objects specified in list - * @param uriA - * @param uris - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#disconnect(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.util.List) */ + @Override public AAITransactionalClient disconnect(AAIResourceUri uriA, List<AAIResourceUri> uris) { for (AAIResourceUri uri : uris) { this.disconnect(uriA, uri); } return this; } - /** - * Deletes object from A&AI. Automatically handles resource-version. - * - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#delete(org.onap.so.client.aai.entities.uri.AAIResourceUri) */ + @Override public AAITransactionalClient delete(AAIResourceUri uri) { AAIResourcesClient client = new AAIResourcesClient(); AAIResourceUri clone = uri.clone(); @@ -192,11 +181,10 @@ public class AAITransactionalClient extends AAIClient { return this; } - /** - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#update(org.onap.so.client.aai.entities.uri.AAIResourceUri, java.lang.Object) */ + @Override public AAITransactionalClient update(AAIResourceUri uri, Object obj) { final String payload = getPatchConverter().convertPatchFormat(obj); currentTransaction.getPatch().add(new OperationBody().withUri(uri.build().toString()).withBody(payload)); @@ -207,10 +195,10 @@ public class AAITransactionalClient extends AAIClient { private void incrementActionAmount() { actionCount++; } - /** - * Executes all created transactions in A&AI - * @throws BulkProcessFailed + /* (non-Javadoc) + * @see org.onap.so.client.aai.GraphInventoryTransactionalClient#execute() */ + @Override public void execute() throws BulkProcessFailed { RestClient client = this.createClient(AAIUriFactory.createResourceUri(AAIObjectType.BULK_PROCESS)); try { @@ -293,7 +281,7 @@ public class AAITransactionalClient extends AAIClient { return this.transactions; } - protected AAIPatchConverter getPatchConverter() { + protected GraphInventoryPatchConverter getPatchConverter() { return this.patchConverter; } } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java index 77ea9bcdfe..9b3f98baa4 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java @@ -20,96 +20,22 @@ package org.onap.so.client.aai.entities; -import java.io.IOException; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.onap.so.client.aai.AAICommonObjectMapperProvider; -import org.onap.so.jsonpath.JsonPathUtil; +import org.onap.so.client.graphinventory.entities.GraphInventoryResultWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class AAIResultWrapper implements Serializable { +public class AAIResultWrapper extends GraphInventoryResultWrapper implements Serializable { private static final long serialVersionUID = 5895841925807816737L; - private final String jsonBody; - private final ObjectMapper mapper; - private final transient Logger logger = LoggerFactory.getLogger(AAIResultWrapper.class); + private final static transient Logger logger = LoggerFactory.getLogger(AAIResultWrapper.class); public AAIResultWrapper(String json) { - this.jsonBody = json; - this.mapper = new AAICommonObjectMapperProvider().getMapper(); + super(json, logger); } public AAIResultWrapper(Object aaiObject) { - this.mapper = new AAICommonObjectMapperProvider().getMapper(); - this.jsonBody = mapObjectToString(aaiObject); - } - - protected String mapObjectToString(Object aaiObject) { - try { - return mapper.writeValueAsString(aaiObject); - } catch (JsonProcessingException e) { - logger.warn("could not parse object into json - defaulting to {}"); - return "{}"; - } + super(aaiObject, logger); } - public Optional<Relationships> getRelationships() { - final String path = "$.relationship-list"; - if (isEmpty()) { - return Optional.empty(); - } - Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody, path); - if (result.isPresent()) { - return Optional.of(new Relationships(result.get())); - } else { - return Optional.empty(); - } - } - - public String getJson() { - if(jsonBody == null) { - return "{}"; - } else { - return jsonBody; - } - } - - public Map<String, Object> asMap() { - if (isEmpty()) { - return new HashMap<>(); - } - try { - return mapper.readValue(this.jsonBody, new TypeReference<Map<String, Object>>(){}); - } catch (IOException e) { - return new HashMap<>(); - } - } - - public <T> Optional<T> asBean(Class<T> clazz) { - if (isEmpty()) { - return Optional.empty(); - } - try { - return Optional.of(mapper.readValue(this.jsonBody, clazz)); - } catch (IOException e) { - return Optional.empty(); - } - } - - public boolean isEmpty() { - return jsonBody == null; - } - @Override - public String toString() { - return this.getJson(); - } - } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/DSLNode.java b/common/src/main/java/org/onap/so/client/aai/entities/DSLNode.java new file mode 100644 index 0000000000..f94c28c5b7 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/DSLNode.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.onap.so.client.graphinventory.GraphInventoryObjectName; + +public class DSLNode implements QueryStep { + + private final String nodeName; + private final List<DSLNodeKey> nodeKeys; + private final StringBuilder query = new StringBuilder(); + private boolean output = false; + + public DSLNode() { + this.nodeName = ""; + this.nodeKeys = new ArrayList<>(); + + } + public DSLNode(GraphInventoryObjectName name) { + this.nodeName = name.typeName(); + this.nodeKeys = new ArrayList<>(); + query.append(nodeName); + } + public DSLNode(GraphInventoryObjectName name, DSLNodeKey... key) { + this.nodeName = name.typeName(); + this.nodeKeys = Arrays.asList(key); + query.append(nodeName); + } + + public DSLNode output() { + this.output = true; + + return this; + } + + public DSLNode and(DSLNodeKey... key) { + this.nodeKeys.addAll(Arrays.asList(key)); + + return this; + } + + @Override + public String build() { + if (output) { + query.append("*"); + } + for (DSLNodeKey key : nodeKeys) { + query.append(key.build()); + } + + return query.toString(); + } +} diff --git a/common/src/main/java/org/onap/so/client/aai/entities/DSLNodeKey.java b/common/src/main/java/org/onap/so/client/aai/entities/DSLNodeKey.java new file mode 100644 index 0000000000..a9795d1cc3 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/DSLNodeKey.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.google.common.base.Joiner; + + +public class DSLNodeKey implements QueryStep { + + private boolean not = false; + private final StringBuilder query = new StringBuilder(); + private final String keyName; + private final List<String> values; + public DSLNodeKey(String keyName, String... value) { + + this.keyName = keyName; + this.values = Arrays.asList(value); + } + + public DSLNodeKey not() { + + this.not = true; + return this; + } + + @Override + public String build() { + + if (not) { + query.append(" !"); + } + query.append("('").append(keyName).append("', "); + List<String> temp = new ArrayList<>(); + for (String item : values) { + if (item.equals("null")) { + temp.add(String.format("' %s '", item)); + } else if (item.equals("")){ + temp.add("' '"); + } else { + temp.add(String.format("'%s'", item)); + } + } + query.append(Joiner.on(", ").join(temp)).append(")"); + + return query.toString(); + } +} diff --git a/common/src/main/java/org/onap/so/client/aai/entities/DSLQuery.java b/common/src/main/java/org/onap/so/client/aai/entities/DSLQuery.java new file mode 100644 index 0000000000..0f4095177a --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/DSLQuery.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DSLQuery { + + private String dsl; + + public DSLQuery() { + + } + + public DSLQuery(String dsl) { + this.dsl = dsl; + } + + public String getDsl() { + return dsl; + } + + public void setDsl(String dsl) { + this.dsl = dsl; + } + + +} diff --git a/common/src/main/java/org/onap/so/client/aai/entities/DSLQueryBuilder.java b/common/src/main/java/org/onap/so/client/aai/entities/DSLQueryBuilder.java new file mode 100644 index 0000000000..9f1dbeda8f --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/DSLQueryBuilder.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import com.google.common.base.Joiner; + + +public class DSLQueryBuilder<S, E> implements QueryStep { + + private List<QueryStep> steps = new ArrayList<>(); + + + public DSLQueryBuilder() { + + } + public DSLQueryBuilder(DSLNode node) { + steps.add(node); + } + + public DSLQueryBuilder<S, DSLNode> node(DSLNode node) { + steps.add(node); + + return (DSLQueryBuilder<S, DSLNode>) this; + } + public DSLQueryBuilder<S, E> output() { + if (steps.get(steps.size() -1) instanceof DSLNode) { + ((DSLNode)steps.get(steps.size() -1)).output(); + } + return this; + } + + public <E2> DSLQueryBuilder<S, E2> union(final DSLQueryBuilder<?, E2>... union) { + + List<DSLQueryBuilder<?, ?>> unions = Arrays.asList(union); + steps.add(() -> { + StringBuilder query = new StringBuilder(); + + query.append("> [ ").append( + Joiner.on(", ").join( + unions.stream().map(item -> item.build()).collect(Collectors.toList()))) + .append(" ]"); + return query.toString(); + }); + + return (DSLQueryBuilder<S, E2>) this; + } + + public DSLQueryBuilder<S, E> where(DSLQueryBuilder<?, ?> where) { + + steps.add(() -> { + StringBuilder query = new StringBuilder(); + query.append(where.build()).append(")"); + String result = query.toString(); + if (!result.startsWith(">")) { + result = "> " + result; + } + return "(" + result; + }); + return this; + } + + public DSLQueryBuilder<S, E> to(DSLQueryBuilder<?, ?> to) { + steps.add(() -> { + StringBuilder query = new StringBuilder(); + + query.append("> ").append(to.build()); + return query.toString(); + }); + return this; + } + + public String limit(int limit) { + return compile() + " LIMIT " + limit; + } + + @Override + public String build() { + return compile(); + } + + private String compile() { + return Joiner.on(" ").join(steps.stream().map(item -> item.build()).collect(Collectors.toList())); + } + + protected QueryStep getFirst() { + return steps.get(0); + } +} diff --git a/common/src/main/java/org/onap/so/client/aai/entities/QueryStep.java b/common/src/main/java/org/onap/so/client/aai/entities/QueryStep.java new file mode 100644 index 0000000000..b056fd0e40 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/QueryStep.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +@FunctionalInterface +public interface QueryStep { + + + public String build(); +} diff --git a/common/src/main/java/org/onap/so/client/aai/entities/__.java b/common/src/main/java/org/onap/so/client/aai/entities/__.java new file mode 100644 index 0000000000..16d6f9b27e --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/__.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities; + +import org.onap.so.client.graphinventory.GraphInventoryObjectName; + +public class __ { + + protected __() { + + } + + public static <A> DSLQueryBuilder<A, A> identity() { + return new DSLQueryBuilder<>(); + } + public static <A> DSLQueryBuilder<A, A> start(DSLNode node) { + return new DSLQueryBuilder<>(node); + } + public static DSLQueryBuilder<DSLNode, DSLNode> node(GraphInventoryObjectName name) { + + return __.<DSLNode>start(new DSLNode(name)); + } + + public static DSLQueryBuilder<DSLNode, DSLNode> node(GraphInventoryObjectName name, DSLNodeKey... key) { + return __.<DSLNode>start(new DSLNode(name, key)); + } + + public static DSLNodeKey key(String keyName, String... value) { + return new DSLNodeKey(keyName, value); + } + + public static <A, B> DSLQueryBuilder<A, B> union(final DSLQueryBuilder<?, B>... traversal) { + + return __.<A>identity().union(traversal); + } + +public static <A> DSLQueryBuilder<A, A> where(DSLQueryBuilder<A, A> traversal) { + + return __.<A>identity().where(traversal); + } +} diff --git a/common/src/main/java/org/onap/so/client/aai/EmptyStringToNullSerializer.java b/common/src/main/java/org/onap/so/client/graphinventory/EmptyStringToNullSerializer.java index 1120ebe0b9..e21386f809 100644 --- a/common/src/main/java/org/onap/so/client/aai/EmptyStringToNullSerializer.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/EmptyStringToNullSerializer.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.client.aai; +package org.onap.so.client.graphinventory; import java.io.IOException; diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperPatchProvider.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperPatchProvider.java new file mode 100644 index 0000000000..47c9e77b84 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperPatchProvider.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.client.graphinventory; + +import com.fasterxml.jackson.databind.module.SimpleModule; + +public class GraphInventoryCommonObjectMapperPatchProvider extends GraphInventoryCommonObjectMapperProvider { + + + public GraphInventoryCommonObjectMapperPatchProvider() { + super(); + EmptyStringToNullSerializer sp = new EmptyStringToNullSerializer(); + SimpleModule emptyStringModule = new SimpleModule(); + emptyStringModule.addSerializer(String.class, sp); + mapper.registerModule(emptyStringModule); + } +} 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 new file mode 100644 index 0000000000..f9857424a2 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryCommonObjectMapperProvider.java @@ -0,0 +1,52 @@ +/*- + * ============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.client.graphinventory; + +import org.onap.so.client.policy.CommonObjectMapperProvider; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; + +public class GraphInventoryCommonObjectMapperProvider extends CommonObjectMapperProvider { + + public GraphInventoryCommonObjectMapperProvider() { + mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + mapper.enable(MapperFeature.USE_ANNOTATIONS); + mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); + mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + AnnotationIntrospector aiJaxb = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); + AnnotationIntrospector aiJackson = new JacksonAnnotationIntrospector(); + // first Jaxb, second Jackson annotations + mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(aiJaxb, aiJackson)); + } + +} diff --git a/common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverter.java index 6ccb592409..00e597b189 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverter.java @@ -18,29 +18,31 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.client.aai; +package org.onap.so.client.graphinventory; import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import org.onap.so.client.aai.AAICommonObjectMapperPatchProvider; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException; import org.onap.so.jsonpath.JsonPathUtil; import com.fasterxml.jackson.core.JsonProcessingException; -public class AAIPatchConverter { +public class GraphInventoryPatchConverter { private static final AAICommonObjectMapperProvider standardProvider = new AAICommonObjectMapperProvider(); private static final AAICommonObjectMapperPatchProvider patchProvider = new AAICommonObjectMapperPatchProvider(); private static final Pattern LOCATE_COMPLEX_OBJECT = Pattern.compile("^((?!relationship-list).)+?\\['[^\\[\\]]+?'\\]$"); - protected String convertPatchFormat(Object obj) { + public String convertPatchFormat(Object obj) { return validatePatchObject(marshallObjectToPatchFormat(obj)); } - protected String validatePatchObject(String payload) { + public String validatePatchObject(String payload) { if (hasComplexObject(payload)) { throw new GraphInventoryPatchDepthExceededException(payload); } 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 new file mode 100644 index 0000000000..7fbe286b98 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java @@ -0,0 +1,147 @@ +package org.onap.so.client.graphinventory; + +import java.util.Optional; + +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; + +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.GraphInventoryUri; + +public interface GraphInventoryResourcesClient<Self, Uri extends GraphInventoryUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { + + /** + * creates a new object in GraphInventory + * + * @param obj - can be any object which will marshal into a valid GraphInventory payload + * @param uri + * @return + */ + void create(Uri uri, Object obj); + + /** + * creates a new object in GraphInventory with no payload body + * + * @param uri + * @return + */ + void createEmpty(Uri uri); + + /** + * returns false if the object does not exist in GraphInventory + * + * @param uri + * @return + */ + boolean exists(Uri uri); + + /** + * Adds a relationship between two objects in GraphInventory + * @param uriA + * @param uriB + * @return + */ + void connect(Uri uriA, Uri uriB); + + /** + * Adds a relationship between two objects in GraphInventory + * with a given edge label + * @param uriA + * @param uriB + * @param edge label + * @return + */ + void connect(Uri uriA, Uri uriB, EdgeLabel label); + + /** + * Removes relationship from two objects in GraphInventory + * + * @param uriA + * @param uriB + * @return + */ + void disconnect(Uri uriA, Uri uriB); + + /** + * Deletes object from GraphInventory. Automatically handles resource-version. + * + * @param uri + * @return + */ + void delete(Uri uri); + + /** + * @param obj - can be any object which will marshal into a valid GraphInventory payload + * @param uri + * @return + */ + void update(Uri uri, Object obj); + + /** + * Retrieves an object from GraphInventory and unmarshalls it into the Class specified + * @param clazz + * @param uri + * @return + */ + <T> Optional<T> get(Class<T> clazz, Uri uri); + + /** + * Retrieves an object from GraphInventory and returns complete response + * @param uri + * @return + */ + Response getFullResponse(Uri uri); + + /** + * Retrieves an object from GraphInventory and automatically unmarshalls it into a Map or List + * @param resultClass + * @param uri + * @return + */ + <T> Optional<T> get(GenericType<T> resultClass, Uri uri); + + /** + * Retrieves an object from GraphInventory wrapped in a helper class which offer additional features + * + * @param uri + * @return + */ + Wrapper get(Uri uri); + + /** + * Retrieves an object from GraphInventory wrapped in a helper class which offer additional features + * If the object cannot be found in GraphInventory the method will throw the runtime exception + * included as an argument + * @param uri + * @return + */ + Wrapper get(Uri uri, Class<? extends RuntimeException> c); + + /** + * Will automatically create the object if it does not exist + * + * @param obj - Optional object which serializes to a valid GraphInventory payload + * @param uri + * @return + */ + Self createIfNotExists(Uri uri, Optional<Object> obj); + + /** + * Starts a transaction which encloses multiple GraphInventory mutations + * + * @return + */ + TransactionalClient beginTransaction(); + + /** + * Starts a transaction groups multiple GraphInventory mutations + * + * @return + */ + SingleTransactionClient beginSingleTransaction(); + + <T extends RestProperties> T getRestProperties(); + +}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventorySingleTransactionClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventorySingleTransactionClient.java new file mode 100644 index 0000000000..e1aa2252d9 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventorySingleTransactionClient.java @@ -0,0 +1,87 @@ +package org.onap.so.client.graphinventory; + +import java.util.List; + +import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel; +import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri; +import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; + +public interface GraphInventorySingleTransactionClient<Self, Uri extends GraphInventoryUri, EdgeLabel extends GraphInventoryEdgeLabel> { + + /** + * creates a new object in A&AI + * + * @param obj - can be any object which will marshal into a valid A&AI payload + * @param uri + * @return + */ + Self create(Uri uri, Object obj); + + /** + * creates a new object in A&AI with no payload body + * + * @param uri + * @return + */ + Self createEmpty(Uri uri); + + /** + * Adds a relationship between two objects in A&AI + * @param uriA + * @param uriB + * @return + */ + Self connect(Uri uriA, Uri uriB); + + /** + * relationship between multiple objects in A&AI - connects A to all objects specified in list + * + * @param uriA + * @param uris + * @return + */ + Self connect(Uri uriA, List<Uri> uris); + + Self connect(Uri uriA, Uri uriB, EdgeLabel label); + + Self connect(Uri uriA, List<Uri> uris, EdgeLabel label); + + /** + * Removes relationship from two objects in A&AI + * + * @param uriA + * @param uriB + * @return + */ + Self disconnect(Uri uriA, Uri uriB); + + /** + * Removes relationship from multiple objects - disconnects A from all objects specified in list + * @param uriA + * @param uris + * @return + */ + Self disconnect(Uri uriA, List<Uri> uris); + + /** + * Deletes object from A&AI. Automatically handles resource-version. + * + * @param uri + * @return + */ + Self delete(Uri uri); + + /** + * @param obj - can be any object which will marshal into a valid A&AI payload + * @param uri + * @return + */ + Self update(Uri uri, Object obj); + + /** + * Executes all created transactions in A&AI + * @throws BulkProcessFailed + */ + void execute() throws BulkProcessFailed; + +}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionalClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionalClient.java new file mode 100644 index 0000000000..a7362c85da --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionalClient.java @@ -0,0 +1,94 @@ +package org.onap.so.client.graphinventory; + +import java.util.List; + +import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel; +import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri; +import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; + +public interface GraphInventoryTransactionalClient<Self, Uri extends GraphInventoryUri, EdgeLabel extends GraphInventoryEdgeLabel> { + + /** + * adds an additional transaction and closes the previous transaction + * + * @return Self + */ + Self beginNewTransaction(); + + /** + * creates a new object in A&AI + * + * @param obj - can be any object which will marshal into a valid A&AI payload + * @param uri + * @return + */ + Self create(Uri uri, Object obj); + + /** + * creates a new object in A&AI with no payload body + * + * @param uri + * @return + */ + Self createEmpty(Uri uri); + + /** + * Adds a relationship between two objects in A&AI + * @param uriA + * @param uriB + * @return + */ + Self connect(Uri uriA, Uri uriB); + + /** + * relationship between multiple objects in A&AI - connects A to all objects specified in list + * + * @param uriA + * @param uris + * @return + */ + Self connect(Uri uriA, List<Uri> uris); + + Self connect(Uri uriA, Uri uriB, EdgeLabel label); + + Self connect(Uri uriA, List<Uri> uris, EdgeLabel label); + + /** + * Removes relationship from two objects in A&AI + * + * @param uriA + * @param uriB + * @return + */ + Self disconnect(Uri uriA, Uri uriB); + + /** + * Removes relationship from multiple objects - disconnects A from all objects specified in list + * @param uriA + * @param uris + * @return + */ + Self disconnect(Uri uriA, List<Uri> uris); + + /** + * Deletes object from A&AI. Automatically handles resource-version. + * + * @param uri + * @return + */ + Self delete(Uri uri); + + /** + * @param obj - can be any object which will marshal into a valid A&AI payload + * @param uri + * @return + */ + Self update(Uri uri, Object obj); + + /** + * Executes all created transactions in A&AI + * @throws BulkProcessFailed + */ + void execute() throws BulkProcessFailed; + +}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java new file mode 100644 index 0000000000..cc1ce0063b --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java @@ -0,0 +1,117 @@ +/*- + * ============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.client.graphinventory.entities; + +import java.io.IOException; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.jsonpath.JsonPathUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class GraphInventoryResultWrapper implements Serializable { + + private static final long serialVersionUID = 5895841925807816727L; + protected final String jsonBody; + protected final ObjectMapper mapper; + private final transient Logger logger; + + protected GraphInventoryResultWrapper(String json, Logger logger) { + this.jsonBody = json; + this.mapper = new AAICommonObjectMapperProvider().getMapper(); + this.logger = logger; + } + + protected GraphInventoryResultWrapper(Object aaiObject, Logger logger) { + this.mapper = new AAICommonObjectMapperProvider().getMapper(); + this.jsonBody = mapObjectToString(aaiObject); + this.logger = logger; + } + + protected String mapObjectToString(Object aaiObject) { + try { + return mapper.writeValueAsString(aaiObject); + } catch (JsonProcessingException e) { + logger.warn("could not parse object into json - defaulting to {}"); + return "{}"; + } + } + public Optional<Relationships> getRelationships() { + final String path = "$.relationship-list"; + if (isEmpty()) { + return Optional.empty(); + } + Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody, path); + if (result.isPresent()) { + return Optional.of(new Relationships(result.get())); + } else { + return Optional.empty(); + } + } + + public String getJson() { + if(jsonBody == null) { + return "{}"; + } else { + return jsonBody; + } + } + + public Map<String, Object> asMap() { + if (isEmpty()) { + return new HashMap<>(); + } + try { + return mapper.readValue(this.jsonBody, new TypeReference<Map<String, Object>>(){}); + } catch (IOException e) { + return new HashMap<>(); + } + } + + public <T> Optional<T> asBean(Class<T> clazz) { + if (isEmpty()) { + return Optional.empty(); + } + try { + return Optional.of(mapper.readValue(this.jsonBody, clazz)); + } catch (IOException e) { + return Optional.empty(); + } + } + + public boolean isEmpty() { + return jsonBody == null; + } + @Override + public String toString() { + return this.getJson(); + } + +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java index c94e561274..121708fc46 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.graphinventory.exceptions; public class IncorrectNumberOfUriKeys extends RuntimeException { diff --git a/common/src/main/resources/dmaap/default-consumer.properties b/common/src/main/resources/dmaap/default-consumer.properties index f19b64242d..3f492e1d33 100644 --- a/common/src/main/resources/dmaap/default-consumer.properties +++ b/common/src/main/resources/dmaap/default-consumer.properties @@ -16,6 +16,7 @@ maxBatchSize=100 maxAgeMs=250 group=MSO id=dev +timeout=60000 AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler AFT_DME2_REQ_TRACE_ON=true diff --git a/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java index ad15417b71..95b30f934b 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java @@ -41,6 +41,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.client.RestClientSSL; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -68,7 +69,7 @@ public class AAIRestClientTest { public void verifyPatchValidation() throws URISyntaxException { AAIRestClient client = new AAIRestClient(props, new URI("")); AAIRestClient spy = spy(client); - AAIPatchConverter patchValidatorMock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class); doReturn(patchValidatorMock).when(spy).getPatchConverter(); String payload = "{}"; doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any()); 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 428fa276db..27637126c6 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 @@ -45,6 +45,7 @@ import org.onap.so.client.aai.entities.singletransaction.SingleTransactionRespon 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; @@ -117,7 +118,7 @@ public class AAISingleTransactionClientTest { @Test public void confirmPatchFormat() { AAISingleTransactionClient singleTransaction = spy(new AAISingleTransactionClient(AAIVersion.LATEST)); - AAIPatchConverter mock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class); doReturn(mock).when(singleTransaction).getPatchConverter(); singleTransaction.update(uriA, "{}"); verify(mock, times(1)).convertPatchFormat(any()); 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 621375882b..342e3b1aa4 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 @@ -43,6 +43,7 @@ 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; @@ -143,7 +144,7 @@ public class AAITransactionalClientTest { @Test public void confirmPatchFormat() { AAITransactionalClient client = spy(new AAITransactionalClient(AAIVersion.LATEST)); - AAIPatchConverter mock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class); doReturn(mock).when(client).getPatchConverter(); client.update(uriA, "{}"); verify(mock, times(1)).convertPatchFormat(any()); diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java new file mode 100644 index 0000000000..e66f43fa5f --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.client.aai.entities.DSLNode; +import org.onap.so.client.aai.entities.DSLQueryBuilder; +import org.onap.so.client.aai.entities.__; + +public class DSLQueryBuilderTest { + + + @Test + public void whereTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "att-nc"), + __.key("cloud-region-id", "test"))); + + builder.to(__.node(AAIObjectType.VLAN_TAG)).where( + __.node(AAIObjectType.OWNING_ENTITY, + __.key("owning-entity-name", "name") + ) + ).to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output()); + + assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > " + + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + + "vlan-tag*('vlan-id-outer', '108')", builder.build()); + } + + @Test + public void unionTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, + __.key("vnf-id", "vnfId")).output()); + + builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), + __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()))); + + assertEquals("generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + + "vserver > pserver* > complex* ]", builder.build()); + } + + @Test + public void whereUnionTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, + __.key("vnf-id", "vnfId")).output()); + + builder.where( + __.union( + __.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")), + __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1"))))); + + assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), " + + "vserver > pserver('hostname', 'hostname1') ])", builder.build()); + } + + @Test + public void notNullTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "", "null").not()).output()); + + assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java index 729f0e50e9..e84326e95f 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.entities.uri; import static org.hamcrest.CoreMatchers.equalTo; diff --git a/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java b/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java index b964e905de..3979902962 100644 --- a/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java +++ b/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.client.aai.objects; import org.onap.so.client.aai.AAINamespaceConstants; diff --git a/common/src/test/java/org/onap/so/client/aai/AAIPatchConverterTest.java b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java index 0d4490f51d..d24b3ff147 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIPatchConverterTest.java +++ b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.client.aai; +package org.onap.so.client.graphinventory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -35,6 +35,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -42,13 +44,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(MockitoJUnitRunner.class) -public class AAIPatchConverterTest { +public class GraphInventoryPatchConverterTest { private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper(); @Test public void convertObjectToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); GenericVnf vnf = new GenericVnf(); vnf.setIpv4Loopback0Address(""); String result = validator.marshallObjectToPatchFormat(vnf); @@ -60,7 +62,7 @@ public class AAIPatchConverterTest { @Test public void convertStringToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\":\"\"}"; String result = validator.marshallObjectToPatchFormat(payload); @@ -69,7 +71,7 @@ public class AAIPatchConverterTest { @Test public void convertStringToPatchFormatNull_Test() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\": null}"; String result = validator.marshallObjectToPatchFormat(payload); System.out.println(result); @@ -78,7 +80,7 @@ public class AAIPatchConverterTest { @Test public void convertMapToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); HashMap<String, String> map = new HashMap<>(); map.put("ipv4-loopback0-address", ""); map.put("ipv4-loopback1-address", "192.168.1.1"); @@ -89,7 +91,7 @@ public class AAIPatchConverterTest { @Test public void hasComplexObjectTest() { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String hasNesting = "{ \"hello\" : \"world\", \"nested\" : { \"key\" : \"value\" } }"; String noNesting = "{ \"hello\" : \"world\" }"; String arrayCase = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"nestedComplex\" : [{\"key\" : \"value\"}]}"; diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CvnfcCustomization.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CvnfcCustomization.java index c02b1e3030..b1ad0de5ca 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CvnfcCustomization.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CvnfcCustomization.java @@ -107,7 +107,7 @@ public class CvnfcCustomization implements Serializable { @JoinColumn(name = "VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID") private VnfResourceCustomization vnfResourceCustomization; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "modelCustomizationUUID") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "cvnfcCustomization") private Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomization; @Override diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfVfmoduleCvnfcConfigurationCustomization.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfVfmoduleCvnfcConfigurationCustomization.java index 8ef797f8fa..f5e9b5f560 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfVfmoduleCvnfcConfigurationCustomization.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfVfmoduleCvnfcConfigurationCustomization.java @@ -44,6 +44,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonFormat; import com.openpojo.business.annotation.BusinessKey; +import uk.co.blackpepper.bowman.annotation.LinkedResource; + @Entity @Table(name = "vnf_vfmodule_cvnfc_configuration_customization") public class VnfVfmoduleCvnfcConfigurationCustomization implements Serializable { @@ -202,6 +204,7 @@ public class VnfVfmoduleCvnfcConfigurationCustomization implements Serializable this.created = created; } + @LinkedResource public ConfigurationResource getConfigurationResource() { return configurationResource; } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index 828b2ff920..ac123b280d 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -223,7 +223,7 @@ public class CatalogDbClient { private final Client<CloudifyManager> cloudifyManagerClient; - private Client<CvnfcCustomization> cvnfcCustomizationClient; + private final Client<CvnfcCustomization> cvnfcCustomizationClient; private final Client<ControllerSelectionReference> controllerSelectionReferenceClient; @@ -695,18 +695,11 @@ public class CatalogDbClient { } public List<CvnfcCustomization> getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID(String vnfCustomizationUUID, String vfModuleCustomizationUUID){ - return this.getMultipleVnfcCustomizations( - UriBuilder.fromUri(endpoint + "/vnfcCustomization/search/findByVnfCustomizationUUIDAndVfModuleCustomizationUUID") - .queryParam("VNF_CUSTOMIZATION_UUID", vnfCustomizationUUID) - .queryParam("VFMODULE_CUSTOMIZATION_UUID", vfModuleCustomizationUUID).build()); - } - - private List<CvnfcCustomization> getMultipleVnfcCustomizations(URI uri) { - Iterable<CvnfcCustomization> vnfcIterator = cvnfcCustomizationClient.getAll(uri); - List<CvnfcCustomization> vnfcList = new ArrayList<>(); - Iterator<CvnfcCustomization> it = vnfcIterator.iterator(); - it.forEachRemaining(vnfcList::add); - return vnfcList; + + return this.getMultipleResources(cvnfcCustomizationClient,getUri(UriBuilder + .fromUri(endpoint + "/cvnfcCustomization/search/findByVnfResourceCustomizationAndVfModuleCustomization") + .queryParam("VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID", vnfCustomizationUUID) + .queryParam("VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID", vfModuleCustomizationUUID).build().toString())); } } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepository.java index 0c82b84c0f..059d0da498 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepository.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepository.java @@ -24,13 +24,15 @@ import java.util.List; import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "cvnfcCustomization", path = "cvnfcCustomization") -public interface CvnfcCustomizationRepository extends JpaRepository<CvnfcCustomization, String> { +public interface CvnfcCustomizationRepository extends JpaRepository<CvnfcCustomization, Integer> { CvnfcCustomization findOneByModelCustomizationUUID(String modelCustomizationUuid); List<CvnfcCustomization> findByModelCustomizationUUID(String modelCustomizationUUID); - List<CvnfcCustomization> findByVnfResourceCustomizationAndVfModuleCustomization (@Param("VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID") String vnfResourceCustomization, - @Param("VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID") String vfModuleCustomization); + + @Query(value = "SELECT * FROM cvnfc_customization WHERE VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID = ?1 AND VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID = ?2", nativeQuery = true) + List<CvnfcCustomization> findByVnfResourceCustomizationAndVfModuleCustomization (@Param("VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID") String vnfResourceCustomization,@Param("VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID") String vfModuleCustomization); }
\ No newline at end of file diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepositoryTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepositoryTest.java index ae3c49ec7d..8de5366ff3 100644 --- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepositoryTest.java +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CvnfcCustomizationRepositoryTest.java @@ -24,16 +24,20 @@ import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.Assert; import org.junit.Test; import org.onap.so.db.catalog.BaseTest; +import org.onap.so.db.catalog.beans.ConfigurationResource; import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.VfModule; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfResource; import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.VnfcCustomization; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -51,7 +55,7 @@ public class CvnfcCustomizationRepositoryTest extends BaseTest { @Test @Transactional - public void createAndGetTest() throws Exception { + public void createAndGetAllTest() throws Exception { CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization(); cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); @@ -100,4 +104,235 @@ public class CvnfcCustomizationRepositoryTest extends BaseTest { } Assert.assertTrue(matchFound); } + + @Test + @Transactional + public void createAndGetCvnfcCustomizationListTest() throws Exception { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModule vFModule = setUpVfModule(); + VnfResource vnfResource = setUpVnfResource(); + + vFModule.setVnfResources(vnfResource); + vfModuleCustomization.setVfModule(vFModule); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + vnfResourceCustomization.setModelInstanceName("testModelInstanceName"); + + List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList(); + vnfResourceCustomizations.add(vnfResourceCustomization); + vnfResource.setVnfResourceCustomizations(vnfResourceCustomizations); + vnfResourceCustomization.setVnfResources(vnfResource); + + cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + VnfcCustomization vnfcCustomization = setUpVnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459"); + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + + + + cvnfcCustomizationRepository.save(cvnfcCustomization); + + List<CvnfcCustomization> cvnfcCustomizationList = cvnfcCustomizationRepository.findByModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + boolean matchFound = false; + for (CvnfcCustomization foundCvnfcCustomization : cvnfcCustomizationList) { + if (foundCvnfcCustomization.getDescription().equalsIgnoreCase(cvnfcCustomization.getDescription())) { + + assertThat(cvnfcCustomization, sameBeanAs(foundCvnfcCustomization) + .ignoring("id") + .ignoring("created") + .ignoring("vnfVfmoduleCvnfcConfigurationCustomization") + .ignoring("vnfResourceCusteModelCustomizationUUID")); + + matchFound = true; + break; + } + } + Assert.assertTrue(matchFound); + } + + + @Test + @Transactional + public void createAndGetCvnfcCustomizationTest() throws Exception { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModule vFModule = setUpVfModule(); + VnfResource vnfResource = setUpVnfResource(); + + vFModule.setVnfResources(vnfResource); + vfModuleCustomization.setVfModule(vFModule); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + vnfResourceCustomization.setModelInstanceName("testModelInstanceName"); + + List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList(); + vnfResourceCustomizations.add(vnfResourceCustomization); + vnfResource.setVnfResourceCustomizations(vnfResourceCustomizations); + vnfResourceCustomization.setVnfResources(vnfResource); + + cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + VnfcCustomization vnfcCustomization = setUpVnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459"); + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + + cvnfcCustomizationRepository.save(cvnfcCustomization); + + CvnfcCustomization cvnfcCustomizationList = cvnfcCustomizationRepository.findOneByModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + assertThat(cvnfcCustomization, sameBeanAs(cvnfcCustomizationList) + .ignoring("id") + .ignoring("created") + .ignoring("vnfVfmoduleCvnfcConfigurationCustomization") + .ignoring("vnfResourceCusteModelCustomizationUUID")); + + } + + @Test + @Transactional + public void createAndGetCvnfcCustomizationsTest() throws Exception { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModule vFModule = setUpVfModule(); + VnfResource vnfResource = setUpVnfResource(); + + vFModule.setVnfResources(vnfResource); + vfModuleCustomization.setVfModule(vFModule); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + vnfResourceCustomization.setModelInstanceName("testModelInstanceName"); + + List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList(); + vnfResourceCustomizations.add(vnfResourceCustomization); + vnfResource.setVnfResourceCustomizations(vnfResourceCustomizations); + vnfResourceCustomization.setVnfResources(vnfResource); + + cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + VnfcCustomization vnfcCustomization = setUpVnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459"); + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + + cvnfcCustomizationRepository.save(cvnfcCustomization); + + List<CvnfcCustomization> cvnfcCustomizationList = cvnfcCustomizationRepository.findByVnfResourceCustomizationAndVfModuleCustomization("cf9f6efc-9f14-11e8-98d0-529269fb1459","cf9f6efc-9f14-11e8-98d0-529269fb1459"); + boolean matchFound = false; + for (CvnfcCustomization foundCvnfcCustomization : cvnfcCustomizationList) { + if (foundCvnfcCustomization.getDescription().equalsIgnoreCase(cvnfcCustomization.getDescription())) { + + assertThat(cvnfcCustomization, sameBeanAs(foundCvnfcCustomization) + .ignoring("id") + .ignoring("created") + .ignoring("vnfVfmoduleCvnfcConfigurationCustomization") + .ignoring("vnfResourceCusteModelCustomizationUUID")); + + matchFound = true; + break; + } + } + Assert.assertTrue(matchFound); + } + + @Test + @Transactional + public void createAndGetCvnfcCustomizationsExtractToscaModelTest() throws Exception { + + CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + + VfModule vFModule = setUpVfModule(); + VnfResource vnfResource = setUpVnfResource(); + + vFModule.setVnfResources(vnfResource); + vfModuleCustomization.setVfModule(vFModule); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); + vnfResourceCustomization.setModelInstanceName("testModelInstanceName"); + + List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList(); + vnfResourceCustomizations.add(vnfResourceCustomization); + vnfResource.setVnfResourceCustomizations(vnfResourceCustomizations); + vnfResourceCustomization.setVnfResources(vnfResource); + + cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + VnfcCustomization vnfcCustomization = setUpVnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459"); + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + configurationResource.setModelInvariantUUID("modelInvariantUUID"); + configurationResource.setModelUUID("modelUUID"); + configurationResource.setModelName("modelName"); + configurationResource.setModelVersion("modelVersion"); + configurationResource.setDescription("description"); + configurationResource.setToscaNodeType("toscaNodeType"); + + VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = new VnfVfmoduleCvnfcConfigurationCustomization(); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationFunction("configurationFunction"); + vnfVfmoduleCvnfcConfigurationCustomization.setModelCustomizationUUID("modelCustomizationUUID"); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + vnfVfmoduleCvnfcConfigurationCustomization.setCvnfcCustomization(cvnfcCustomization); + vnfVfmoduleCvnfcConfigurationCustomization.setModelInstanceName("modelInstanceName"); + vnfVfmoduleCvnfcConfigurationCustomization.setVfModuleCustomization(vfModuleCustomization); + vnfVfmoduleCvnfcConfigurationCustomization.setVnfResourceCustomization(vnfResourceCustomization); + + Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizationSet = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); + vnfVfmoduleCvnfcConfigurationCustomizationSet.add(vnfVfmoduleCvnfcConfigurationCustomization); + cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizationSet); + + cvnfcCustomizationRepository.save(cvnfcCustomization); + + List<CvnfcCustomization> cvnfcCustomizationList = cvnfcCustomizationRepository.findByVnfResourceCustomizationAndVfModuleCustomization("cf9f6efc-9f14-11e8-98d0-529269fb1459","cf9f6efc-9f14-11e8-98d0-529269fb1459"); + boolean matchFound = false; + for (CvnfcCustomization foundCvnfcCustomization : cvnfcCustomizationList) { + if (foundCvnfcCustomization.getDescription().equalsIgnoreCase(cvnfcCustomization.getDescription())) { + + assertThat(cvnfcCustomization, sameBeanAs(foundCvnfcCustomization) + .ignoring("id") + .ignoring("created") + .ignoring("vnfVfmoduleCvnfcConfigurationCustomization") + .ignoring("vnfResourceCusteModelCustomizationUUID")); + + matchFound = true; + + Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = foundCvnfcCustomization.getVnfVfmoduleCvnfcConfigurationCustomization(); + for(VnfVfmoduleCvnfcConfigurationCustomization customization : vnfVfmoduleCvnfcConfigurationCustomizations) { + Assert.assertTrue(customization.getConfigurationResource().getToscaNodeType().equalsIgnoreCase("toscaNodeType")); + } + break; + } + } + Assert.assertTrue(matchFound); + + } } |