summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/main/java/org
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2020-11-03 12:29:22 -0500
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-11-03 13:25:31 -0500
commit6dc5d95ce5fda8a5990f0e150b7b40be98172a08 (patch)
treef0030df74c3158c62e004330a796113623fbc7d9 /adapters/mso-openstack-adapters/src/main/java/org
parent83ff479029986df8326e3119d3ee31f77209c455 (diff)
put back logic to create VNFC edges
put back logic to create VNFC edges Consolidated similiar sim scenrios into 1 and updated robots properties Support macro scerios for vnfc to vfmodule relationship. Issue-ID: SO-3361 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: Idcb9bb179b4dc3c16bc97939c8260462dd27ca4e
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main/java/org')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java4
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java31
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java47
3 files changed, 75 insertions, 7 deletions
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 bafba3e901..1b2fdfedfa 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
@@ -143,8 +143,10 @@ public interface HeatBridgeApi {
* @param genericVnfId AAI generic-vnf-id
* @param vfModuleId AAI vf-module-id
* @param servers Openstack Server list
+ * @throws HeatBridgeException
*/
- void buildAddVserversToAaiAction(String genericVnfId, String vfModuleId, List<Server> servers);
+ void buildAddVserversToAaiAction(String genericVnfId, String vfModuleId, List<Server> servers)
+ throws HeatBridgeException;
/**
* Query and build AAI actions for Openstack Neutron resources associated with a Compute resource to AAI's
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 1264727f35..8ee87b50c3 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
@@ -317,8 +317,8 @@ public class HeatBridgeImpl implements HeatBridgeApi {
@Override
public void buildAddVserversToAaiAction(final String genericVnfId, final String vfModuleId,
- final List<Server> servers) {
- servers.forEach(server -> {
+ final List<Server> servers) throws HeatBridgeException {
+ for (Server server : servers) {
Vserver vserver = aaiHelper.buildVserver(server.getId(), server);
// Build vserver relationships to: image, flavor, pserver, vf-module
@@ -326,11 +326,28 @@ public class HeatBridgeImpl implements HeatBridgeApi {
aaiHelper.getVserverRelationshipList(cloudOwner, cloudRegionId, genericVnfId, vfModuleId, server));
AAIResourceUri vserverUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
.cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.getVserverId()));
+
if (resourcesClient.exists(vserverUri)) {
AAIResultWrapper existingVserver = resourcesClient.get(vserverUri);
+ AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
+ if (!existingVserver.hasRelationshipsTo(Types.VNFC)) {
+ AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
+ if (vfModule.hasRelationshipsTo(Types.VNFC)) {
+ List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
+ Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream().filter(resourceUri -> resourceUri
+ .getURIKeys().get("vnfc-name").startsWith(vserver.getVserverName())).findFirst();
+ if (foundVnfcURI.isEmpty()) {
+ throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
+ }
+ transaction.connect(vserverUri, foundVnfcURI.get());
+ } else {
+ throw new HeatBridgeException(
+ "VF Module contains no relationships to VNFCS, cannot build edge to VServer");
+ }
+ }
+
if (!existingVserver.hasRelationshipsTo(Types.VF_MODULE)) {
- AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(
- AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
transaction.connect(vserverUri, vfModuleUri);
}
if (!existingVserver.hasRelationshipsTo(Types.PSERVER)) {
@@ -341,7 +358,7 @@ public class HeatBridgeImpl implements HeatBridgeApi {
} else {
transaction.create(vserverUri, vserver);
}
- });
+ }
}
@Override
@@ -833,6 +850,10 @@ public class HeatBridgeImpl implements HeatBridgeApi {
}
}
+ protected void setAAIHelper(AaiHelper aaiHelper) {
+ this.aaiHelper = aaiHelper;
+ }
+
protected AAIDSLQueryClient getAAIDSLClient() {
if (aaiDSLClient == null) {
aaiDSLClient = new AAIDSLQueryClient();
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 8e6f8cc69b..32d8f1204c 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
@@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -50,14 +51,20 @@ import org.onap.aai.domain.yang.RelationshipData;
import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.SriovVf;
import org.onap.aai.domain.yang.Vserver;
+import org.onap.aaiclient.client.aai.AAIResourcesClient;
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
+import org.onap.so.heatbridge.HeatBridgeException;
import org.onap.so.heatbridge.constants.HeatBridgeConstants;
import org.openstack4j.model.compute.Server;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
/**
@@ -66,6 +73,14 @@ import com.google.common.base.Preconditions;
*/
public class AaiHelper {
+ private static final Logger logger = LoggerFactory.getLogger(AaiHelper.class);
+
+ private AAIResourcesClient resourcesClient;
+
+ public AaiHelper() {
+ this.resourcesClient = new AAIResourcesClient();
+ }
+
/**
* Build vserver relationship object to entities: pserver, vf-module, image, flavor
*
@@ -74,9 +89,10 @@ public class AaiHelper {
* @param genericVnfId AAI generic-vnf identifier
* @param vfModuleId AAI vf-module identifier
* @param server Openstack Server object
+ * @throws HeatBridgeException
*/
public RelationshipList getVserverRelationshipList(final String cloudOwner, final String cloudRegionId,
- final String genericVnfId, final String vfModuleId, final Server server) {
+ final String genericVnfId, final String vfModuleId, final Server server) throws HeatBridgeException {
RelationshipList relationshipList = new RelationshipList();
List<Relationship> relationships = relationshipList.getRelationship();
@@ -92,6 +108,10 @@ public class AaiHelper {
AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId)));
relationships.add(genericVnfRelationship);
+ // vserver to vnfc relationship
+ if (!StringUtils.isEmpty(server.getName())) {
+ relationships.add(createVnfRelationshiptoVserver(server.getName(), genericVnfId, vfModuleId));
+ }
// vserver to vf-module relationship
Relationship vfModuleRelationship = buildRelationship(AAIUriFactory
.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId)));
@@ -114,6 +134,27 @@ public class AaiHelper {
return relationshipList;
}
+ public Relationship createVnfRelationshiptoVserver(String vserverName, String genericVnfId, String vfModuleId)
+ throws HeatBridgeException {
+ AAIResourceUri vfModuleUri = AAIUriFactory
+ .createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
+ AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
+ if (vfModule.hasRelationshipsTo(Types.VNFC)) {
+ List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
+ Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream()
+ .filter(resourceUri -> resourceUri.getURIKeys().get("vnfc-name").startsWith(vserverName))
+ .findFirst();
+ if (!foundVnfcURI.isPresent()) {
+ throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
+ } else {
+ return buildRelationship(foundVnfcURI.get());
+ }
+ } else {
+ throw new HeatBridgeException("VF Module contains no relationships to VNFCS, cannot build edge to VServer");
+ }
+ }
+
+
public RelationshipList getLInterfaceRelationshipList(final String pserverName, final String pIfName,
final String pfPciId) {
RelationshipList relationshipList = new RelationshipList();
@@ -378,4 +419,8 @@ public class AaiHelper {
relationship.setRelatedLink(relatedLink.build().toString());
return relationship;
}
+
+ public void setAAIResourcesClient(AAIResourcesClient client) {
+ this.resourcesClient = client;
+ }
}