Search in sources :

Example 1 with VpnBinding

use of org.onap.aai.domain.yang.VpnBinding in project so by onap.

the class AAIQueryTasks method queryNetworkVpnBinding.

/**
 * BPMN access method to query data for VPN bindings from the AAI result wrapper. The resulting VPN bindings are
 * mapped to the corresponding bbobject and placed in the customer bbobject
 *
 * @param execution
 */
public void queryNetworkVpnBinding(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> netBindingsUriList = networkRelationships.get().getRelatedUris(Types.VPN_BINDING);
        List<org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding> mappedVpnBindings = new ArrayList<>();
        if (netBindingsUriList != null && !netBindingsUriList.isEmpty()) {
            for (AAIResourceUri netBindingUri : netBindingsUriList) {
                Optional<VpnBinding> oVpnBinding = aaiNetworkResources.getVpnBinding(netBindingUri);
                if (oVpnBinding.isPresent()) {
                    org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding mappedVpnBinding = modelMapper.map(oVpnBinding.get(), org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding.class);
                    if (oVpnBinding.get().getRouteTargets() != null) {
                        mappedVpnBinding.getRouteTargets().addAll(mapRouteTargets(oVpnBinding.get().getRouteTargets().getRouteTarget()));
                        mappedVpnBindings.add(mappedVpnBinding);
                    }
                }
            }
        }
        execution.getGeneralBuildingBlock().getCustomer().getVpnBindings().addAll(mappedVpnBindings);
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) VpnBinding(org.onap.aai.domain.yang.VpnBinding) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 2 with VpnBinding

use of org.onap.aai.domain.yang.VpnBinding in project so by onap.

the class AAIQueryTasks method getNetworkVpnBinding.

/**
 * BPMN access method to extract VPN Binding data from AAI result and populate proper fields into
 * CreateNetworkRequest
 */
public void getNetworkVpnBinding(BuildingBlockExecution execution) {
    try {
        L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
        AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
        CreateNetworkRequest createNetworkRequest = execution.getVariable("createNetworkRequest");
        Optional<Relationships> networkRelationships = aaiResultWrapper.getRelationships();
        if (!networkRelationships.isPresent()) {
            throw (new Exception(ERROR_MSG));
        }
        List<AAIResourceUri> netBindingsUriList = networkRelationships.get().getRelatedUris(Types.VPN_BINDING);
        List<org.onap.so.openstack.beans.RouteTarget> routeTargets = new ArrayList<>();
        for (AAIResourceUri netBindingUri : netBindingsUriList) {
            logger.info("Get Route Targests");
            Optional<VpnBinding> oVpnBinding = aaiNetworkResources.getVpnBinding(netBindingUri);
            if (oVpnBinding.isPresent()) {
                VpnBinding vpnBinding = oVpnBinding.get();
                RouteTargets rts = vpnBinding.getRouteTargets();
                if (rts != null) {
                    List<org.onap.aai.domain.yang.RouteTarget> rtList = rts.getRouteTarget();
                    if (!rtList.isEmpty()) {
                        PropertyMap<org.onap.aai.domain.yang.RouteTarget, org.onap.so.openstack.beans.RouteTarget> personMap = new PropertyMap<org.onap.aai.domain.yang.RouteTarget, org.onap.so.openstack.beans.RouteTarget>() {

                            @Override
                            protected void configure() {
                                map().setRouteTarget(source.getGlobalRouteTarget());
                                map(source.getRouteTargetRole(), destination.getRouteTargetRole());
                            }
                        };
                        modelMapper.addMappings(personMap);
                        for (org.onap.aai.domain.yang.RouteTarget rt : rtList) {
                            org.onap.so.openstack.beans.RouteTarget openstackRtBean = modelMapper.map(rt, org.onap.so.openstack.beans.RouteTarget.class);
                            routeTargets.add(openstackRtBean);
                        }
                    }
                }
            }
        }
        // store route targets data in execution - to be used as part of
        // Network adapter input
        createNetworkRequest.getContrailNetwork().setRouteTargets(routeTargets);
        execution.setVariable("createNetworkRequest", createNetworkRequest);
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) ArrayList(java.util.ArrayList) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) RouteTargets(org.onap.aai.domain.yang.RouteTargets) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) VpnBinding(org.onap.aai.domain.yang.VpnBinding) PropertyMap(org.modelmapper.PropertyMap)

Example 3 with VpnBinding

use of org.onap.aai.domain.yang.VpnBinding in project so by onap.

the class WorkflowActionExtractResourcesAAI method extractRelationshipsVpnBinding.

public Optional<VpnBinding> extractRelationshipsVpnBinding(Relationships relationships) {
    List<AAIResourceUri> configurations = relationships.getRelatedUris(Types.VPN_BINDING);
    for (AAIResourceUri vpnBindingUri : configurations) {
        AAIResultWrapper vpnBindingWrapper = bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUri);
        Optional<VpnBinding> vpnBinding = vpnBindingWrapper.asBean(VpnBinding.class);
        if (vpnBinding.isPresent()) {
            return vpnBinding;
        }
    }
    return Optional.empty();
}
Also used : VpnBinding(org.onap.aai.domain.yang.VpnBinding) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 4 with VpnBinding

use of org.onap.aai.domain.yang.VpnBinding in project so by onap.

the class BBInputSetupUtilsTest method getAICVpnBindingFromNetwork_noVpnBindingTest.

@Test
public void getAICVpnBindingFromNetwork_noVpnBindingTest() throws IOException {
    L3Network l3Network = mapper.readValue(new File(RESOURCE_PATH + "aaiL3NetworkInputWithSubnets.json"), L3Network.class);
    Optional<VpnBinding> actual = bbInputSetupUtils.getAICVpnBindingFromNetwork(l3Network);
    assertEquals(Optional.empty(), actual);
}
Also used : L3Network(org.onap.aai.domain.yang.L3Network) VpnBinding(org.onap.aai.domain.yang.VpnBinding) File(java.io.File) Test(org.junit.Test)

Example 5 with VpnBinding

use of org.onap.aai.domain.yang.VpnBinding in project so by onap.

the class AAINetworkResourcesTest method getVpnBindingTest.

@Test
public void getVpnBindingTest() throws Exception {
    final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiVpnBinding.json")));
    AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content);
    Optional<VpnBinding> oVpnBinding = Optional.empty();
    AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vpnBinding("ModelInvariantUUID"));
    doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class));
    oVpnBinding = aaiNetworkResources.getVpnBinding(aaiUri);
    verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class));
    if (oVpnBinding.isPresent()) {
        VpnBinding vpnBinding = oVpnBinding.get();
        assertThat(aaiResultWrapper.asBean(VpnBinding.class).get(), sameBeanAs(vpnBinding));
    }
}
Also used : VpnBinding(org.onap.aai.domain.yang.VpnBinding) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Aggregations

VpnBinding (org.onap.aai.domain.yang.VpnBinding)9 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)7 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)7 Test (org.junit.Test)6 Relationships (org.onap.aaiclient.client.aai.entities.Relationships)5 ArrayList (java.util.ArrayList)4 File (java.io.File)2 L3Network (org.onap.aai.domain.yang.L3Network)2 RouteTargets (org.onap.aai.domain.yang.RouteTargets)2 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)2 PropertyMap (org.modelmapper.PropertyMap)1 RouteTarget (org.onap.aai.domain.yang.RouteTarget)1 CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)1 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)1