diff options
author | MichaelMorris <michael.morris@est.tech> | 2019-09-19 10:21:21 +0100 |
---|---|---|
committer | MichaelMorris <michael.morris@est.tech> | 2019-09-19 10:24:01 +0100 |
commit | 5c869b76bc052104f6720a304344e9c0a4494f1d (patch) | |
tree | 15b5280dffd2b1618ab183ffc176b49bb9a5c01f /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src | |
parent | a1f8a0c1ce64e90653397c5ce8d4949fe0244d07 (diff) |
VNFM adapter relationship handling improvements
Change-Id: I8fd7af559448b9cdd6fab4bedd8ec001f196a200
Issue-ID: SO-2352
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src')
7 files changed, 82 insertions, 122 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java index 110bbabdb2..fc9efef947 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java @@ -31,14 +31,10 @@ import org.onap.aai.domain.yang.EsrVnfmList; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.Vserver; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs; import org.onap.so.adapters.vnfmadapter.rest.exceptions.TenantNotFoundException; import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; -import org.onap.so.client.aai.AAIObjectType; -import org.onap.so.client.aai.AAIVersion; -import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.vnfmadapter.v1.model.Tenant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,38 +57,6 @@ public class AaiHelper { } /** - * Add a relationship to the given generic VNF to the given VNFM. - * - * @param vnf the generic VNF - * @param vnfmId the ID of the VNFM - */ - public void addRelationshipFromGenericVnfToVnfm(final GenericVnf vnf, final String vnfmId) { - if (vnf.getRelationshipList() == null) { - vnf.setRelationshipList(new RelationshipList()); - } - final RelationshipList vnfmRelationshiplist = vnf.getRelationshipList(); - vnfmRelationshiplist.getRelationship().add(createRelationshipToVnfm(vnfmId)); - - } - - private Relationship createRelationshipToVnfm(final String vnfmId) { - final Relationship relationship = new Relationship(); - relationship.setRelatedTo("esr-vnfm"); - relationship.setRelationshipLabel("tosca.relationships.DependsOn"); - relationship.setRelatedLink("/aai/" + AAIVersion.LATEST - + AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).build().toString()); - relationship.getRelationshipData().add(createRelationshipData("esr-vnfm.vnfm-id", vnfmId)); - return relationship; - } - - private RelationshipData createRelationshipData(final String key, final String value) { - final RelationshipData data = new RelationshipData(); - data.setRelationshipKey(key); - data.setRelationshipValue(value); - return data; - } - - /** * Get the VNFM assigned for use for the given generic VNF. * * @param vnf the generic VNF @@ -242,30 +206,6 @@ public class AaiHelper { return vserver; } - /** - * Add a relationship to the given vserver to the given VNF. - * - * @param vnf the vserver - * @param vnfmId the ID of the VNF - */ - public void addRelationshipFromVserverVnfToGenericVnf(final Vserver vserver, final String vnfId) { - if (vserver.getRelationshipList() == null) { - vserver.setRelationshipList(new RelationshipList()); - } - final RelationshipList vserverRelationshiplist = vserver.getRelationshipList(); - vserverRelationshiplist.getRelationship().add(createRelationshipToGenericVnf(vnfId)); - } - - private Relationship createRelationshipToGenericVnf(final String vnfId) { - final Relationship relationship = new Relationship(); - relationship.setRelatedTo("generic-vnf"); - relationship.setRelationshipLabel("tosca.relationships.HostedOn"); - relationship.setRelatedLink("/aai/" + AAIVersion.LATEST - + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).build().toString()); - relationship.getRelationshipData().add(createRelationshipData("generic-vnf.vnf-id", vnfId)); - return relationship; - } - public void setOamIpAddressSource(final String vnfId, final OamIpAddressSource oamIpAddressSource) { mapOfVnfIdToOamIpAddressHolder.put(vnfId, oamIpAddressSource); } @@ -274,32 +214,4 @@ public class AaiHelper { return mapOfVnfIdToOamIpAddressHolder.get(vnfId); } - /** - * Add a relationship to the given tenant to the given VNF. - * - * @param vnf the generic vnf - * @param tenant the Tenant - */ - - public void addRelationshipFromGenericVnfToTenant(final GenericVnf vnf, final Tenant tenant) { - if (vnf.getRelationshipList() == null) { - vnf.setRelationshipList(new RelationshipList()); - } - final RelationshipList vnfmRelationshiplist = vnf.getRelationshipList(); - vnfmRelationshiplist.getRelationship().add(createRelationshipToTenant(tenant)); - } - - private Relationship createRelationshipToTenant(final Tenant tenant) { - final Relationship relationship = new Relationship(); - relationship.setRelatedTo("tenant"); - relationship.setRelatedLink("/aai/" + AAIVersion.LATEST + AAIUriFactory.createResourceUri(AAIObjectType.TENANT, - tenant.getCloudOwner(), tenant.getRegionName(), tenant.getTenantId()).build().toString()); - relationship.getRelationshipData() - .add(createRelationshipData("cloud-region.cloud-owner", tenant.getCloudOwner())); - relationship.getRelationshipData() - .add(createRelationshipData("cloud-region.cloud-region-id", tenant.getRegionName())); - relationship.getRelationshipData().add(createRelationshipData("tenant.tenant-id", tenant.getTenantId())); - return relationship; - } - } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java index 7021c02511..d19190d88e 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java @@ -72,12 +72,22 @@ public interface AaiServiceProvider { EsrVnfm invokeGetVnfm(final String vnfmId); /** - * Invoke a PUT request for a generic vnf. + * Invoke a PATCH request for a generic vnf. * * @param vnf the generic vnf * @return */ - void invokePutGenericVnf(GenericVnf vnf); + void invokePatchGenericVnf(GenericVnf vnf); + + /** + * Invoke a PUT request for a relationship from a generic vnf to a VNFM. + * + * @param vnf the generic vnf + * @param vnfmId the ID of the VNFM + * @return + */ + void invokePutGenericVnfToVnfmRelationship(GenericVnf vnf, final String vnfmId); + /** * Invoke a PUT request for a vserver. @@ -92,6 +102,19 @@ public interface AaiServiceProvider { final Vserver vserver); /** + * Invoke a PUT request for a relationship from a vserver to a generic vnf. + * + * @param cloudOwner the cloud owner + * @param cloudRegion the cloud region the vserver is deployed on + * @param tenantId the ID of the tenant the vserver is deployed on + * @param vserver the vserver + * @param vnfId the ID of the generic vnf + * @return + */ + void invokePutVserverToVnfRelationship(final String cloudOwner, final String cloudRegion, final String tenantId, + final Vserver vserver, final String vnfId); + + /** * Invoke a DELETE request for a vserver. * * @param cloudOwner the cloud owner diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java index 019a08af78..6dc6020834 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java @@ -98,12 +98,18 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { } @Override - public void invokePutGenericVnf(final GenericVnf vnf) { + public void invokePatchGenericVnf(final GenericVnf vnf) { aaiClientProvider.getAaiClient() .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()), vnf); } @Override + public void invokePutGenericVnfToVnfmRelationship(final GenericVnf vnf, final String vnfmId) { + aaiClientProvider.getAaiClient().connect(AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId), + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId())); + } + + @Override public void invokePutVserver(final String cloudOwner, final String cloudRegion, final String tenant, final Vserver vserver) { aaiClientProvider.getAaiClient().create(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, @@ -111,6 +117,16 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { } @Override + public void invokePutVserverToVnfRelationship(final String cloudOwner, final String cloudRegion, + final String tenant, final Vserver vserver, final String vnfId) { + aaiClientProvider.getAaiClient() + .connect( + AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenant, + vserver.getVserverId()), + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + } + + @Override public void invokeDeleteVserver(final String cloudOwner, final String cloudRegion, final String tenant, final String vserverId) { aaiClientProvider.getAaiClient().delete( diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java index 0aad91e5be..461c15a512 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java @@ -81,21 +81,25 @@ public class LifecycleManager { * @return the response to the request */ public CreateVnfResponse createVnf(final String vnfIdInAai, final CreateVnfRequest request) { - final GenericVnf genericVnf = getGenericVnfFromAai(vnfIdInAai); + GenericVnf genericVnf = getGenericVnfFromAai(vnfIdInAai); EsrVnfm vnfm = aaiHelper.getAssignedVnfm(genericVnf); checkIfVnfAlreadyExistsInVnfm(vnfm, genericVnf); if (vnfm == null) { vnfm = aaiHelper.selectVnfm(genericVnf); - aaiHelper.addRelationshipFromGenericVnfToVnfm(genericVnf, vnfm.getVnfmId()); + aaiServiceProvider.invokePutGenericVnfToVnfmRelationship(genericVnf, vnfm.getVnfmId()); } - aaiHelper.addRelationshipFromGenericVnfToTenant(genericVnf, request.getTenant()); final InlineResponse201 vnfmResponse = sendCreateRequestToVnfm(request, genericVnf, vnfIdInAai, vnfm); logger.info("Create response: {}", vnfmResponse); genericVnf.setSelflink(getSelfLink(vnfmResponse, vnfm)); - aaiServiceProvider.invokePutGenericVnf(genericVnf); + + GenericVnf genericVnfPatch = new GenericVnf(); + genericVnfPatch.setVnfId(genericVnf.getVnfId()); + genericVnfPatch.setSelflink(genericVnf.getSelflink()); + aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); + final String vnfIdInVnfm = vnfmResponse.getId(); final OamIpAddressSource oamIpAddressSource = extractOamIpAddressSource(request); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java index eb912c8775..7a6bbfe0d9 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java @@ -97,10 +97,12 @@ public class NotificationHandler implements Runnable { private void handleVnfInstantiateCompleted() { final GenericVnf genericVnf = aaiServiceProvider .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); - setOamIpAddress(genericVnf, vnfInstance); - genericVnf.setOrchestrationStatus("Created"); - aaiServiceProvider.invokePutGenericVnf(genericVnf); + final GenericVnf genericVnfPatch = new GenericVnf(); + genericVnfPatch.setVnfId(genericVnf.getVnfId()); + setOamIpAddress(genericVnfPatch, vnfInstance); + genericVnfPatch.setOrchestrationStatus("Created"); + aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); addVservers(vnfLcmOperationOccurrenceNotification, genericVnf.getVnfId(), vnfInstance.getVimConnectionInfo()); @@ -162,9 +164,12 @@ public class NotificationHandler implements Runnable { jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId(), deleteSuccessful); jobManager.vnfDeleted(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId()); - genericVnf.setOrchestrationStatus("Assigned"); - genericVnf.setSelflink(""); - aaiServiceProvider.invokePutGenericVnf(genericVnf); + + final GenericVnf genericVnfPatch = new GenericVnf(); + genericVnfPatch.setVnfId(genericVnf.getVnfId()); + genericVnfPatch.setOrchestrationStatus("Assigned"); + genericVnfPatch.setSelflink(""); + aaiServiceProvider.invokePatchGenericVnf(genericVnfPatch); } } @@ -180,10 +185,11 @@ public class NotificationHandler implements Runnable { getVimConnectionInfo(vimConnectionIdToVimConnectionInfo, vnfc); if (ChangeTypeEnum.ADDED.equals(vnfc.getChangeType())) { final Vserver vserver = aaiHelper.createVserver(vnfc); - aaiHelper.addRelationshipFromVserverVnfToGenericVnf(vserver, vnfId); - aaiServiceProvider.invokePutVserver(getCloudOwner(vimConnectionInfo), getCloudRegion(vimConnectionInfo), getTenant(vimConnectionInfo), vserver); + + aaiServiceProvider.invokePutVserverToVnfRelationship(getCloudOwner(vimConnectionInfo), + getCloudRegion(vimConnectionInfo), getTenant(vimConnectionInfo), vserver, vnfId); } } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java index 89a2c102f4..f83e9c94d2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java @@ -212,12 +212,16 @@ public class Sol003LcnControllerTest { final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0); assertEquals("myVnfc1", vserver.getVserverId()); - final Relationship relationship = vserver.getRelationshipList().getRelationship().get(0); - assertEquals("generic-vnf", relationship.getRelatedTo()); - assertEquals("tosca.relationships.HostedOn", relationship.getRelationshipLabel()); - assertEquals("/aai/v15/network/generic-vnfs/generic-vnf/myTestVnfId", relationship.getRelatedLink()); - assertEquals("generic-vnf.vnf-id", relationship.getRelationshipData().get(0).getRelationshipKey()); - assertEquals("myTestVnfId", relationship.getRelationshipData().get(0).getRelationshipValue()); + + final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class); + final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class); + verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture()); + assertEquals( + "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/" + + TENANT_ID + "/vservers/vserver/myVnfc1", + uriArgument1Connect.getAllValues().get(0).build().toString()); + assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", + uriArgument2Connect.getAllValues().get(0).build().toString()); } @Test diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java index fe55907420..297f74433e 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; @@ -175,20 +176,14 @@ public class VnfmAdapterControllerTest { assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString()); assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId()); - assertEquals(2, genericVnfArgument.getValue().getRelationshipList().getRelationship().size()); - final Relationship vnfmRelationship = - genericVnfArgument.getValue().getRelationshipList().getRelationship().get(0); - assertEquals("esr-vnfm", vnfmRelationship.getRelatedTo()); - assertEquals("tosca.relationships.DependsOn", vnfmRelationship.getRelationshipLabel()); - assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", vnfmRelationship.getRelatedLink()); - - final Relationship tenantRelationship = - genericVnfArgument.getValue().getRelationshipList().getRelationship().get(1); - assertEquals("tenant", tenantRelationship.getRelatedTo()); - assertEquals( - "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/myTestCloudOwner/myTestRegion/tenants/tenant/myTestTenantId", - tenantRelationship.getRelatedLink()); + final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class); + final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class); + verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture()); + assertEquals("/external-system/esr-vnfm-list/esr-vnfm/vnfm2", + uriArgument1Connect.getAllValues().get(0).build().toString()); + assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", + uriArgument2Connect.getAllValues().get(0).build().toString()); // check the job status |