Search in sources :

Example 21 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.

the class HeatBridgeImpl method deleteVfModuleData.

@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 {
        AAIResultWrapper vfModule = resourcesClient.get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId)).depth(Depth.ONE), NotFoundException.class);
        Optional<Relationships> relationships = vfModule.getRelationships();
        logger.debug("VfModule contains relationships in AAI: {}", relationships.isPresent());
        if (relationships.isPresent()) {
            deleteL3Networks(relationships.get());
            List<AAIResourceUri> vserverUris = relationships.get().getRelatedUris(Types.VSERVER);
            logger.debug("VServer contains {} relationships in AAI", vserverUris.size());
            createTransactionToDeleteSriovPfFromPserver(vserverUris);
            if (!vserverUris.isEmpty()) {
                for (AAIResourceUri vserverUri : vserverUris) {
                    if (env.getProperty("heatBridgeDryrun", Boolean.class, false)) {
                        logger.debug("Would delete Vserver: {}", vserverUri.build().toString());
                    } else {
                        resourcesClient.deleteIfExists(vserverUri);
                    }
                }
            }
        }
    } catch (NotFoundException e) {
        String msg = "Failed to commit delete heatbridge data transaction";
        logger.debug(msg + " with error: " + e);
        throw new HeatBridgeException(msg, e);
    } catch (Exception e) {
        String msg = "Failed to commit delete heatbridge data transaction";
        logger.debug(msg + " with error: " + e);
        throw new HeatBridgeException(msg, e);
    }
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) NotFoundException(javax.ws.rs.NotFoundException) IPAddressString(inet.ipaddr.IPAddressString) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 22 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.

the class HeatBridgeImpl method buildAddVserversToAaiAction.

@Override
public void buildAddVserversToAaiAction(final String genericVnfId, final String vfModuleId, 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
        vserver.setRelationshipList(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)) {
                transaction.connect(vserverUri, vfModuleUri);
            }
            if (!existingVserver.hasRelationshipsTo(Types.PSERVER)) {
                AAIResourceUri pServerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(server.getHypervisorHostname()));
                transaction.connect(vserverUri, pServerUri);
            }
        } else {
            transaction.create(vserverUri, vserver);
        }
    }
}
Also used : Depth(org.onap.aaiclient.client.graphinventory.entities.uri.Depth) AaiHelper(org.onap.so.heatbridge.helpers.AaiHelper) AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) Node(org.onap.aaiclient.client.graphinventory.entities.Node) Server(org.openstack4j.model.compute.Server) LoggerFactory(org.slf4j.LoggerFactory) HeatBridgeUtils(org.onap.so.heatbridge.utils.HeatBridgeUtils) StringUtils(org.apache.commons.lang3.StringUtils) DSLQueryBuilder(org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder) Map(java.util.Map) Resource(org.openstack4j.model.heat.Resource) AAIDSLQueryClient(org.onap.aaiclient.client.aai.AAIDSLQueryClient) Vlan(org.onap.aai.domain.yang.Vlan) UriBuilder(javax.ws.rs.core.UriBuilder) Pserver(org.onap.aai.domain.yang.Pserver) TypeReference(com.fasterxml.jackson.core.type.TypeReference) L3Network(org.onap.aai.domain.yang.L3Network) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) AAISingleTransactionClient(org.onap.aaiclient.client.aai.AAISingleTransactionClient) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) L3InterfaceIpv4AddressList(org.onap.aai.domain.yang.L3InterfaceIpv4AddressList) Collectors(java.util.stream.Collectors) MsoCloudClientFactoryImpl(org.onap.so.heatbridge.factory.MsoCloudClientFactoryImpl) NotFoundException(javax.ws.rs.NotFoundException) IPAddressString(inet.ipaddr.IPAddressString) Objects(java.util.Objects) NetworkType(org.openstack4j.model.network.NetworkType) VolumeAttachment(org.openstack4j.model.storage.block.VolumeAttachment) List(java.util.List) Environment(org.springframework.core.env.Environment) InetAddressValidator(org.apache.commons.validator.routines.InetAddressValidator) SriovPf(org.onap.aai.domain.yang.SriovPf) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) Flavor(org.onap.aai.domain.yang.Flavor) Results(org.onap.aaiclient.client.aai.entities.Results) Volume(org.onap.aai.domain.yang.Volume) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Image(org.onap.aai.domain.yang.Image) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) Network(org.openstack4j.model.network.Network) Relationship(org.onap.aai.domain.yang.Relationship) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) BulkProcessFailed(org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CollectionUtils(org.apache.commons.collections.CollectionUtils) ServerType(org.onap.so.db.catalog.beans.ServerType) DSLStartNode(org.onap.aaiclient.client.graphinventory.entities.DSLStartNode) OpenstackClientFactoryImpl(org.onap.so.heatbridge.openstack.factory.OpenstackClientFactoryImpl) IP(org.openstack4j.model.network.IP) Start(org.onap.aaiclient.client.graphinventory.entities.Start) HeatBridgeConstants(org.onap.so.heatbridge.constants.HeatBridgeConstants) SpringContextHelper(org.onap.so.spring.SpringContextHelper) LInterface(org.onap.aai.domain.yang.LInterface) Nonnull(javax.annotation.Nonnull) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) org.onap.aaiclient.client.graphinventory.entities.__(org.onap.aaiclient.client.graphinventory.entities.__) Port(org.openstack4j.model.network.Port) Subnets(org.onap.aai.domain.yang.Subnets) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Format(org.onap.aaiclient.client.graphinventory.Format) Logger(org.slf4j.Logger) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Subnet(org.openstack4j.model.network.Subnet) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) TraversalBuilder(org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder) Vserver(org.onap.aai.domain.yang.Vserver) PInterface(org.onap.aai.domain.yang.PInterface) Preconditions(com.google.common.base.Preconditions) SriovVf(org.onap.aai.domain.yang.SriovVf) NodeType(org.onap.so.cloud.resource.beans.NodeType) OpenstackClient(org.onap.so.heatbridge.openstack.api.OpenstackClient) Vserver(org.onap.aai.domain.yang.Vserver) Server(org.openstack4j.model.compute.Server) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 23 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.

the class AAIQueryTasks method querySubnet.

public void querySubnet(BuildingBlockExecution execution) {
    try {
        L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
        AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
        Optional<Relationships> networkRelationships = aaiResultWrapper.getRelationships();
        if (!networkRelationships.isPresent()) {
            throw (new Exception(ERROR_MSG));
        }
        List<AAIResourceUri> subnetsUriList = networkRelationships.get().getRelatedUris(Types.SUBNET);
        if (!subnetsUriList.isEmpty()) {
            for (AAIResourceUri subnetUri : subnetsUriList) {
                Optional<Subnet> oSubnet = aaiNetworkResources.getSubnet(subnetUri);
                if (oSubnet.isPresent()) {
                    l3network.getSubnets().add(modelMapper.map(oSubnet.get(), org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet.class));
                }
            }
        }
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Subnet(org.onap.aai.domain.yang.Subnet) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 24 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.

the class AAIQueryTasks method queryNetworkTableRef.

/**
 * BPMN access method to query data for network table ref from the AAI result wrapper The resulting route table
 * reference is mapped to the corresponding bbobject and added to the network bbobject contrail network route table
 * references list
 *
 * @param execution
 */
public void queryNetworkTableRef(BuildingBlockExecution execution) {
    try {
        L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
        AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
        Optional<Relationships> networkRelationships = aaiResultWrapper.getRelationships();
        if (!networkRelationships.isPresent()) {
            throw (new Exception(ERROR_MSG));
        }
        List<AAIResourceUri> routeTableUriList = networkRelationships.get().getRelatedUris(Types.ROUTE_TABLE_REFERENCE);
        if (!routeTableUriList.isEmpty()) {
            for (AAIResourceUri routeTableUri : routeTableUriList) {
                Optional<RouteTableReference> oRouteTableReference = aaiNetworkResources.getRouteTable(routeTableUri);
                if (oRouteTableReference.isPresent()) {
                    org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference mappedRouteTableReference = modelMapper.map(oRouteTableReference.get(), org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference.class);
                    l3network.getContrailNetworkRouteTableReferences().add(mappedRouteTableReference);
                }
            }
        }
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) RouteTableReference(org.onap.aai.domain.yang.RouteTableReference) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 25 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.

the class AAINetworkResourcesTest method queryNetworkWrapperByIdTest.

@Test
public void queryNetworkWrapperByIdTest() throws Exception {
    final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiQueryAAIResponse-Wrapper.json")));
    AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content);
    L3Network network = new L3Network();
    network.setNetworkId("0384d743-f69b-4cc8-9aa8-c3ae66662c44");
    network.setNetworkName("Dev_Bindings_1802_020118");
    network.setOrchestrationStatus(OrchestrationStatus.CREATED);
    doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class));
    AAIResultWrapper result = aaiNetworkResources.queryNetworkWrapperById(network);
    verify(MOCK_aaiResourcesClient, times(1)).get(isA(AAIResourceUri.class));
    assertEquals(aaiResultWrapper.getJson(), result.getJson());
    assertNotNull(result);
    Optional<Relationships> resultNetworkRelationships = result.getRelationships();
    assertTrue(resultNetworkRelationships.isPresent());
    Optional<org.onap.aai.domain.yang.L3Network> aaiL3Network = result.asBean(org.onap.aai.domain.yang.L3Network.class);
    assertEquals(network.getNetworkId(), aaiL3Network.get().getNetworkId());
    assertEquals(network.getNetworkName(), aaiL3Network.get().getNetworkName());
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Aggregations

Relationships (org.onap.aaiclient.client.aai.entities.Relationships)36 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)27 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)20 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)10 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)6 Configuration (org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration)6 HashMap (java.util.HashMap)4 List (java.util.List)4 VpnBinding (org.onap.aai.domain.yang.VpnBinding)4 IPAddressString (inet.ipaddr.IPAddressString)3 RelationshipList (org.onap.aai.domain.yang.RelationshipList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 NotFoundException (javax.ws.rs.NotFoundException)2