From d98077b7cda0ef1562b81d6433f6d93fc4e722ab Mon Sep 17 00:00:00 2001 From: Munir Ahmad Date: Tue, 29 Oct 2019 09:45:21 -0400 Subject: Create PServer/PInterface Objects in AAI based on openstack's stack resources Issue-ID: SO-2271 Signed-off-by: Munir Ahmad Change-Id: I9ff6a9d820a8f759358cbaa4abf6475c6af4c130 --- .../onap/so/adapters/vnf/MsoVnfAdapterImpl.java | 2 ++ .../java/org/onap/so/heatbridge/HeatBridgeApi.java | 7 ++++ .../org/onap/so/heatbridge/HeatBridgeImpl.java | 41 ++++++++++++++++++++++ .../heatbridge/constants/HeatBridgeConstants.java | 1 + .../org/onap/so/heatbridge/helpers/AaiHelper.java | 34 ++++++++++++++++++ 5 files changed, 85 insertions(+) (limited to 'adapters/mso-openstack-adapters') 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 2769f1c9b8..73eefcf1c9 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 @@ -431,6 +431,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { List osServers = heatBridgeClient.getAllOpenstackServers(stackResources); + heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources); + List osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers); List osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers); 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 aebd04f32c..d568bc2807 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 @@ -137,6 +137,13 @@ public interface HeatBridgeApi { */ void buildAddVserverLInterfacesToAaiAction(List stackResources, List oobMgtNetIds); + /** + * Query and build AAI actions for Openstack Compute resources to AAI's pserver and pinterface objects + * + * @param stackResources Openstack StackResources list + */ + void createPserversAndPinterfacesIfNotPresentInAai(final List stackResources) throws HeatBridgeException; + /** * Execute AAI restful API to update the Openstack resources * 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 ae15b70b00..a1b33056da 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 @@ -32,6 +32,7 @@ */ package org.onap.so.heatbridge; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -49,6 +50,7 @@ import org.onap.aai.domain.yang.Image; import org.onap.aai.domain.yang.L3InterfaceIpv4AddressList; import org.onap.aai.domain.yang.LInterface; import org.onap.aai.domain.yang.PInterface; +import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.SriovPf; import org.onap.aai.domain.yang.SriovPfs; import org.onap.aai.domain.yang.SriovVf; @@ -63,6 +65,7 @@ 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; import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed; +import org.onap.so.client.PreconditionFailedException; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.heatbridge.constants.HeatBridgeConstants; import org.onap.so.heatbridge.factory.MsoCloudClientFactoryImpl; @@ -263,6 +266,44 @@ public class HeatBridgeImpl implements HeatBridgeApi { } } + @Override + public void createPserversAndPinterfacesIfNotPresentInAai(final List stackResources) + throws HeatBridgeException { + Map serverHostnames = getPserverMapping(stackResources); + createPServerIfNotExists(serverHostnames); + List portIds = + extractStackResourceIdsByResourceType(stackResources, HeatBridgeConstants.OS_PORT_RESOURCE_TYPE); + for (String portId : portIds) { + Port port = osClient.getPortById(portId); + if (port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) { + createPServerPInterfaceIfNotExists(serverHostnames.get(port.getHostId()).getHostname(), + aaiHelper.buildPInterface(port)); + } + } + } + + private Map getPserverMapping(final List stackResources) { + List osServers = getAllOpenstackServers(stackResources); + Map pserverMap = new HashMap<>(); + for (Server server : osServers) { + pserverMap.put(server.getHost(), aaiHelper.buildPserver(server)); + } + return pserverMap; + } + + private void createPServerIfNotExists(Map serverHostnames) { + for (Pserver pserver : serverHostnames.values()) { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, pserver.getHostname()); + resourcesClient.createIfNotExists(uri, Optional.of(pserver)); + } + } + + private void createPServerPInterfaceIfNotExists(String pserverHostname, PInterface pInterface) { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.P_INTERFACE, pserverHostname, + pInterface.getInterfaceName()); + resourcesClient.createIfNotExists(uri, Optional.of(pInterface)); + } + private void updateLInterfaceVlan(final Port port, final LInterface lIf) { Vlan vlan = new Vlan(); Network network = osClient.getNetworkById(port.getNetworkId()); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java index f2d61d2587..0e87e1fb31 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java @@ -43,6 +43,7 @@ public class HeatBridgeConstants { public static final String OS_SRIOV_PORT_TYPE = "direct"; public static final String OS_PCI_SLOT_KEY = "pci_slot"; public static final String OS_PHYSICAL_NETWORK_KEY = "physical_network"; + public static final String OS_PHYSICAL_INTERFACE_KEY = "physical-interface"; public static final String OS_VLAN_NETWORK_KEY = "vlan"; public static final String OS_UNKNOWN_KEY = "unknown"; public static final String OS_RESOURCES_SELF_LINK_KEY = "self"; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java index d8a876016f..c578b29664 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java @@ -43,6 +43,8 @@ import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.onap.aai.domain.yang.Flavor; import org.onap.aai.domain.yang.Image; +import org.onap.aai.domain.yang.PInterface; +import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; @@ -50,6 +52,7 @@ import org.onap.aai.domain.yang.SriovVf; import org.onap.aai.domain.yang.Vserver; import org.onap.so.heatbridge.constants.HeatBridgeConstants; import org.openstack4j.model.compute.Server; +import org.openstack4j.model.network.Port; /** * This class provides wrapper methods to manage creation of AAI objects and extracting objects from AAI and @@ -136,6 +139,37 @@ public class AaiHelper { return vserver; } + /** + * Transform Openstack Server object to AAI Pserver object + * + * @param server Openstack server object + * @return AAI Pserver object + */ + public Pserver buildPserver(final Server server) { + Pserver pserver = new Pserver(); + pserver.setInMaint(false); + pserver.setPserverId(server.getId()); + pserver.setHostname(server.getHypervisorHostname()); + pserver.setPserverName2(server.getHost()); + pserver.setProvStatus(server.getStatus().value()); + return pserver; + } + + /** + * Transform Openstack Server object to AAI PInterface object + * + * @param port Openstack port object + * @return AAI PInterface object + */ + public PInterface buildPInterface(Port port) { + Map portProfile = port.getProfile(); + PInterface pInterface = new PInterface(); + pInterface.setInterfaceName(portProfile.get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString()); + pInterface.setInMaint(false); + pInterface.setInterfaceRole(HeatBridgeConstants.OS_PHYSICAL_INTERFACE_KEY); + return pInterface; + } + /** * Transform Openstack Image object to AAI Image object * -- cgit 1.2.3-korg