From 0b89fc8630cfcab29a5c2736572e9b8b2cd10b62 Mon Sep 17 00:00:00 2001 From: Munir Ahmad Date: Tue, 29 Oct 2019 17:01:21 -0400 Subject: SO and heatbridge integration for delete flow Issue-ID: SO-2272 Signed-off-by: Munir Ahmad Change-Id: Ie1b7ebdd1758478655779d940eabe0836834fcc4 --- .../org/onap/so/adapters/vnf/MsoVnfAdapter.java | 2 + .../onap/so/adapters/vnf/MsoVnfAdapterImpl.java | 11 ++- .../so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java | 4 +- .../so/adapters/vnf/MsoVnfPluginAdapterImpl.java | 4 +- .../org/onap/so/adapters/vnf/VnfAdapterRest.java | 3 +- .../org/onap/so/adapters/vnf/VnfAdapterRestV2.java | 3 +- .../java/org/onap/so/heatbridge/HeatBridgeApi.java | 7 ++ .../org/onap/so/heatbridge/HeatBridgeImpl.java | 80 ++++++++++++++++++++++ .../onap/so/heatbridge/utils/HeatBridgeUtils.java | 16 ++++- .../so/adapters/vnf/MsoVnfAdapterImplTest.java | 3 +- .../vnf/MsoVnfCloudifyAdapterImplTest.java | 6 +- .../vnf/MsoVnfMulticloudAdapterImplTest.java | 3 +- .../adapters/vnf/MsoVnfPluginAdapterImplTest.java | 6 +- 13 files changed, 133 insertions(+), 15 deletions(-) (limited to 'adapters/mso-openstack-adapters/src') diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java index f6ea2261d7..39a380d2cf 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java @@ -121,6 +121,8 @@ public interface MsoVnfAdapter { @WebParam(name = "cloudOwner") @XmlElement(required = false) String cloudOwner, @WebParam(name = "tenantId") @XmlElement(required = true) String tenantId, @WebParam(name = "vfName") @XmlElement(required = true) String vfName, + @WebParam(name = "vnfId") @XmlElement(required = true) String vnfId, + @WebParam(name = "vfModuleId") @XmlElement(required = true) String vfModuleId, @WebParam(name = "request") MsoRequest msoRequest, @WebParam(name = "vfModuleOutputs", mode = Mode.OUT) Holder> vfModuleOutputs) throws VnfException; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index 9d50273b97..77b3ca9f8b 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -63,6 +63,7 @@ import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository; import org.onap.so.db.catalog.data.repository.VnfResourceRepository; import org.onap.so.db.catalog.utils.MavenLikeVersioning; import org.onap.so.entity.MsoRequest; +import org.onap.so.heatbridge.HeatBridgeException; import org.onap.so.heatbridge.HeatBridgeApi; import org.onap.so.heatbridge.HeatBridgeImpl; import org.onap.so.logger.ErrorCode; @@ -1137,8 +1138,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } @Override - public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, - MsoRequest msoRequest, Holder> outputs) throws VnfException { + public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String vnfId, + String vfModuleId, MsoRequest msoRequest, Holder> outputs) throws VnfException { Map stackOutputs; try { stackOutputs = msoHeatUtils.queryStackForOutputs(cloudSiteId, cloudOwner, tenantId, vnfName); @@ -1203,6 +1204,12 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.error("Exception encountered while sending Confirm to Valet ", e); } } + // call heatbridge delete + try { + new HeatBridgeImpl().deleteVfModuleData(vnfId, vfModuleId); + } catch (HeatBridgeException e) { + logger.error("Heatbridge failed to delete AAI data for vf-module: " + vfModuleId, e); + } } @Override diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java index d2d8caa660..d35c34a937 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java @@ -1081,8 +1081,8 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } - public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, - MsoRequest msoRequest, Holder> outputs) throws VnfException { + public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String vnfId, + String vfModuleId, MsoRequest msoRequest, Holder> outputs) throws VnfException { logger.debug("Deleting VF " + vnfName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId); // 1702 capture the output parameters on a delete diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java index ce8e284b1f..561b21250f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java @@ -1072,8 +1072,8 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter { } - public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vfModuleId, - MsoRequest msoRequest, Holder> outputs) throws VnfException { + public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vfModuleId, String vnfId, + String aaiVfModuleId, MsoRequest msoRequest, Holder> outputs) throws VnfException { logger.debug("Deleting VF Module " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java index 3d632ca92f..58899b7f48 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java @@ -179,7 +179,8 @@ public class VnfAdapterRest { Holder> outputs = new Holder<>(); if (cloudsite != null && !cloudsite.equals(TESTING_KEYWORD)) { vnfAdapter.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), - req.getVfModuleStackId(), req.getMsoRequest(), outputs); + req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), req.getMsoRequest(), + outputs); } response = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), outputs.value); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java index 1a9d86752e..0e70c6be53 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java @@ -195,7 +195,8 @@ public class VnfAdapterRestV2 { // Support different Adapter Implementations MsoVnfAdapter adapter = vnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsite); adapter.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), - req.getVfModuleStackId(), req.getMsoRequest(), outputs); + req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), req.getMsoRequest(), + outputs); } response = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), outputs.value); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java index d568bc2807..7eff09b692 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java @@ -150,4 +150,11 @@ public interface HeatBridgeApi { * @throws HeatBridgeException when failing to add openstack resource PoJos to AAI */ void submitToAai() throws HeatBridgeException; + + /** + * Delete heatbridge data for a given vf-module + * + * @throws HeatBridgeException when failing to remove heatbridge data from AAI for a given vf-module + */ + void deleteVfModuleData(String vnfId, String vfModuleId) throws HeatBridgeException; } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index a1b33056da..5e3d36d0d5 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java @@ -58,9 +58,12 @@ import org.onap.aai.domain.yang.SriovVfs; import org.onap.aai.domain.yang.Vlan; import org.onap.aai.domain.yang.Vlans; import org.onap.aai.domain.yang.Vserver; +import org.onap.aai.domain.yang.VfModule; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.AAISingleTransactionClient; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.graphinventory.entities.uri.Depth; @@ -122,6 +125,11 @@ public class HeatBridgeImpl implements HeatBridgeApi { this.transaction = resourcesClient.beginSingleTransaction(); } + public HeatBridgeImpl() { + this.resourcesClient = new AAIResourcesClient(); + this.transaction = resourcesClient.beginSingleTransaction(); + } + @Override public OpenstackClient authenticate() throws HeatBridgeException { this.osClient = new MsoCloudClientFactoryImpl(new OpenstackClientFactoryImpl()).getOpenstackClient( @@ -418,6 +426,78 @@ public class HeatBridgeImpl implements HeatBridgeApi { } } + @Override + public void deleteVfModuleData(@Nonnull final String vnfId, @Nonnull final String vfModuleId) + throws HeatBridgeException { + Objects.requireNonNull(vnfId, "Null vnf-id!"); + Objects.requireNonNull(vfModuleId, "Null vf-module-id!"); + try { + Optional vfModule = resourcesClient.get(VfModule.class, + AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE)); + if (vfModule.isPresent()) { + + AAIResultWrapper resultWrapper = new AAIResultWrapper(vfModule); + Optional relationships = resultWrapper.getRelationships(); + if (relationships.isPresent()) { + List vserverUris = relationships.get().getRelatedUris(AAIObjectType.VSERVER); + createTransactionToDeleteSriovPfFromPserver(vserverUris); + if (!vserverUris.isEmpty()) { + for (AAIResourceUri vserverUri : vserverUris) { + resourcesClient.delete(vserverUri); + } + } + } + } + } catch (Exception e) { + String msg = "Failed to commit delete heatbridge data transaction"; + logger.debug(msg + " with error: " + e); + throw new HeatBridgeException(msg, e); + } + } + + private void createTransactionToDeleteSriovPfFromPserver(List vserverUris) { + Map> pserverToPciIdMap = getPserverToPciIdMap(vserverUris); + for (Map.Entry> entry : pserverToPciIdMap.entrySet()) { + String pserverName = entry.getKey(); + List pciIds = entry.getValue(); + Optional pserver = resourcesClient.get(Pserver.class, + AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, pserverName).depth(Depth.TWO)); + if (pserver.isPresent()) { + // For each pserver/p-interface match sriov-vfs by pic-id and delete them. + pserver.get().getPInterfaces().getPInterface().stream().filter( + pIf -> pIf.getSriovPfs() != null && CollectionUtils.isNotEmpty(pIf.getSriovPfs().getSriovPf())) + .forEach(pIf -> pIf.getSriovPfs().getSriovPf().forEach(sriovPf -> { + if (pciIds.contains(sriovPf.getPfPciId())) { + logger.debug("creating transaction to delete SR-IOV PF: " + pIf.getInterfaceName() + + " from PServer: " + pserverName); + resourcesClient.delete(AAIUriFactory.createResourceUri(AAIObjectType.SRIOV_PF, + pserverName, pIf.getInterfaceName(), sriovPf.getPfPciId())); + } + })); + } + } + } + + private Map> getPserverToPciIdMap(List vserverUris) { + Map> pserverToPciIdMap = new HashMap<>(); + for (AAIResourceUri vserverUri : vserverUris) { + AAIResultWrapper vserverWrapper = resourcesClient.get(vserverUri.depth(Depth.TWO)); + Optional vserverRelationships = vserverWrapper.getRelationships(); + if (vserverRelationships.isPresent() + && CollectionUtils.isNotEmpty(vserverRelationships.get().getRelatedLinks(AAIObjectType.PSERVER))) { + Vserver vserver = vserverWrapper.asBean(Vserver.class).get(); + List pciIds = HeatBridgeUtils.extractPciIdsFromVServer(vserver); + if (CollectionUtils.isNotEmpty(pciIds)) { + List matchingPservers = vserverRelationships.get().getRelatedLinks(AAIObjectType.PSERVER); + if (matchingPservers != null && matchingPservers.size() == 1) { + pserverToPciIdMap.put(matchingPservers.get(0), pciIds); + } + } + } + } + return pserverToPciIdMap; + } + private Predicate distinctByProperty(Function keyExtractor) { Map map = new ConcurrentHashMap<>(); return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java index be086677db..1667f980e1 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java @@ -35,10 +35,15 @@ package org.onap.so.heatbridge.utils; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import javax.annotation.Nonnull; +import org.apache.commons.collections.CollectionUtils; +import org.onap.aai.domain.yang.SriovVf; +import org.onap.aai.domain.yang.Vserver; -public class HeatBridgeUtils { +public final class HeatBridgeUtils { /** * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping @@ -64,4 +69,13 @@ public class HeatBridgeUtils { } return Optional.empty(); } + + public static List extractPciIdsFromVServer(Vserver vserver) { + return vserver.getLInterfaces().getLInterface().stream() + .filter(lInterface -> lInterface.getSriovVfs() != null + && CollectionUtils.isNotEmpty(lInterface.getSriovVfs().getSriovVf())) + .flatMap(lInterface -> lInterface.getSriovVfs().getSriovVf().stream()).map(SriovVf::getPciId) + .collect(Collectors.toList()); + } + } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java index f3cad76c9d..01726acd54 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java @@ -484,7 +484,8 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); MsoRequest msoRequest = getMsoRequest(); try { - instance.deleteVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest, + instance.deleteVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder>()); } catch (Exception e) { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java index 16cc2c34de..e7ef9d9348 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java @@ -101,7 +101,8 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); + instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", "5aae1e49-805c-4f9f-bd78-055bf7451157", + "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); } @Test @@ -124,7 +125,8 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")) .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK))); - instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); + instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", "5aae1e49-805c-4f9f-bd78-055bf7451157", + "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); } @Test diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java index 48ca0fd79c..0ac30cb75c 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java @@ -210,7 +210,8 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils { wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")) .willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT))); - instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>()); + instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", "5aae1e49-805c-4f9f-bd78-055bf7451157", + "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); } @Test diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java index 7ec8e51892..ede25c5dbe 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java @@ -134,7 +134,8 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { expectedException.expect(VnfException.class); MsoRequest msoRequest = getMsoRequest(); msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", - msoRequest, new Holder>()); + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, + new Holder>()); } @Test @@ -151,7 +152,8 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); MsoRequest msoRequest = getMsoRequest(); msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", - msoRequest, new Holder>()); + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, + new Holder>()); } private MsoRequest getMsoRequest() { -- cgit 1.2.3-korg