Search in sources :

Example 1 with Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships 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 Relationships

use of org.onap.aaiclient.client.aai.entities.Relationships 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 Relationships

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

the class AAIQueryTasks method queryNetworkPolicy.

/**
 * BPMN access method to query data for network policies from the AAI result wrapper From the resulting network
 * policy, the network policy fqdn parameter is added to the network bbobject contrail network policy fqdns list
 *
 * @param execution
 */
public void queryNetworkPolicy(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> netPoliciesUriList = networkRelationships.get().getRelatedUris(Types.NETWORK_POLICY);
        if (!netPoliciesUriList.isEmpty()) {
            for (AAIResourceUri netPolicyUri : netPoliciesUriList) {
                Optional<NetworkPolicy> oNetPolicy = aaiNetworkResources.getNetworkPolicy(netPolicyUri);
                if (oNetPolicy.isPresent()) {
                    l3network.getNetworkPolicies().add(modelMapper.map(oNetPolicy.get(), org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy.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) NetworkPolicy(org.onap.aai.domain.yang.NetworkPolicy) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 4 with Relationships

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

the class AppcOrchestratorPreProcessor method getVserversForAppc.

protected void getVserversForAppc(BuildingBlockExecution execution, GenericVnf vnf) throws Exception {
    AAIResultWrapper aaiRW = aaiVnfResources.queryVnfWrapperById(vnf);
    if (aaiRW != null && aaiRW.getRelationships().isPresent()) {
        Relationships relationships = aaiRW.getRelationships().get();
        if (relationships != null) {
            List<AAIResourceUri> vserverUris = relationships.getRelatedUris(Types.VSERVER);
            ArrayList<String> vserverIds = new ArrayList<String>();
            ArrayList<String> vserverSelfLinks = new ArrayList<String>();
            for (AAIResourceUri j : vserverUris) {
                String vserverId = j.getURIKeys().get(AAIFluentTypeBuilder.Types.VSERVER.getUriParams().vserverId);
                vserverIds.add(vserverId);
                Optional<Vserver> oVserver = aaiVnfResources.getVserver(j);
                if (oVserver.isPresent()) {
                    Vserver vserver = oVserver.get();
                    String vserverSelfLink = vserver.getVserverSelflink();
                    vserverSelfLinks.add(vserverSelfLink);
                }
            }
            logger.debug("vmIdsArray is: {}", vserverSelfLinks);
            logger.debug("vserverIdsArray is: {}", vserverIds);
            execution.setVariable("vmIdList", vserverSelfLinks);
            execution.setVariable("vserverIdList", vserverIds);
        }
    }
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Vserver(org.onap.aai.domain.yang.Vserver) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 5 with Relationships

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

the class ActivateVnfOperationalEnvironment method execute.

/**
 * The Point-Of-Entry from APIH with VID request to send activate request
 *
 * @param requestId - String
 * @param request - CloudOrchestrationRequest object
 * @return void - nothing
 */
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    String vnfOperationalEnvironmentId = request.getOperationalEnvironmentId();
    String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
    List<ServiceModelList> serviceModelVersionIdList = request.getRequestDetails().getRequestParameters().getManifest().getServiceModelList();
    String ecompOperationalEnvironmentId = null;
    AAIResultWrapper wrapper = getAAIOperationalEnvironment(vnfOperationalEnvironmentId);
    Optional<Relationships> optRelationships = wrapper.getRelationships();
    if (optRelationships.isPresent()) {
        Relationships relationships = optRelationships.get();
        List<AAIResourceUri> operationalEnvironments = relationships.getRelatedUris(Types.OPERATIONAL_ENVIRONMENT);
        if (!operationalEnvironments.isEmpty()) {
            ecompOperationalEnvironmentId = operationalEnvironments.get(0).getURIKeys().get(AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId);
        }
    }
    logger.debug("  vnfOperationalEnvironmentId   : {}", vnfOperationalEnvironmentId);
    logger.debug("  ecompOperationalEnvironmentId : {}", ecompOperationalEnvironmentId);
    OperationalEnvironment operationalEnv = wrapper.asBean(OperationalEnvironment.class).get();
    String workloadContext = operationalEnv.getWorkloadContext();
    logger.debug("  aai workloadContext: {}", workloadContext);
    if (!vidWorkloadContext.equals(workloadContext)) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
        throw new ValidateException.Builder(" The vid workloadContext did not match from aai record. " + " vid workloadContext:" + vidWorkloadContext + " aai workloadContext:" + workloadContext, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    if (ecompOperationalEnvironmentId == null) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
        throw new ValidateException.Builder(" The ECOMP OE was not in aai record; the value of relationship.relationship-data key: " + AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    processActivateSDCRequest(requestId, ecompOperationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment)

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