From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../AaiServiceInstanceStandardQueryController.java | 173 +++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java (limited to 'vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java new file mode 100644 index 000000000..974ac9883 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java @@ -0,0 +1,173 @@ +package org.onap.vid.controller; + + +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Network; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.ServiceInstance; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Vlan; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Vnf; +import org.onap.vid.aai.util.ServiceInstanceStandardQuery; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.VidNotions; +import org.onap.vid.properties.Features; +import org.onap.vid.services.VidService; +import org.onap.vid.utils.Multival; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.togglz.core.manager.FeatureManager; + +import javax.servlet.http.HttpServletRequest; +import java.util.Collection; +import java.util.Collections; +import java.util.UUID; + +import static java.util.stream.Collectors.toList; + + +@RestController +@RequestMapping(AaiServiceInstanceStandardQueryController.AAI_STANDARD_QUERY) +public class AaiServiceInstanceStandardQueryController extends VidRestrictedBaseController { + + public static final String AAI_STANDARD_QUERY = "aai/standardQuery"; + + private final ServiceInstanceStandardQuery serviceInstanceStandardQuery; + private final FeatureManager featureManager; + private final VidService sdcService; + + @Autowired + public AaiServiceInstanceStandardQueryController(FeatureManager featureManager, ServiceInstanceStandardQuery serviceInstanceStandardQuery, VidService sdcService) { + this.featureManager = featureManager; + this.serviceInstanceStandardQuery = serviceInstanceStandardQuery; + this.sdcService = sdcService; + } + + @RequestMapping(value = "vlansByNetworks", method = RequestMethod.GET) + public VlansByNetworksHierarchy getNetworksToVlansByServiceInstance(HttpServletRequest request, + @RequestParam("sdcModelUuid") UUID sdcModelUuid, + @RequestParam("globalCustomerId") String globalCustomerId, + @RequestParam("serviceType") String serviceType, + @RequestParam("serviceInstanceId") String serviceInstanceId + ) throws AsdcCatalogException { + if (!featureManager.isActive(Features.FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS)) { + return new VlansByNetworksHierarchy(); + } + + if (!isModelOf5g(sdcModelUuid)) { + return new VlansByNetworksHierarchy(); + } + + final ServiceInstance serviceInstance = + serviceInstanceStandardQuery.fetchServiceInstance(globalCustomerId, serviceType, serviceInstanceId); + + Multival>> l3NetworksWithVlansForVnfForService = fetchVnfsForService(serviceInstance); + Multival> l3NetworksWithVlansForService = fetchNetworksForService(serviceInstance); + + // translate to response's format + return new VlansByNetworksHierarchy( + l3NetworksWithVlansForService.getValues().stream().map(this::translateNetworksFormat + ).collect(toList()), + + l3NetworksWithVlansForVnfForService.getValues().stream().map(vnfWithNetworks -> + new VnfVlansByNetworks(vnfWithNetworks.getKey().getVnfId(), + vnfWithNetworks.getValues().stream().map(this::translateNetworksFormat + ).collect(toList()) + ) + ).collect(toList()) + ); + } + + private Multival>> fetchVnfsForService(ServiceInstance serviceInstance) { + final Multival vnfsForService = + serviceInstanceStandardQuery.fetchRelatedVnfs(serviceInstance); + + final Multival> vnfsWithL3NetworksForService = + vnfsForService.mapEachVal(vnf -> serviceInstanceStandardQuery.fetchRelatedL3Networks("vnf", vnf)); + + return vnfsWithL3NetworksForService.mapEachVal(vnfMulti-> + vnfMulti.mapEachVal(serviceInstanceStandardQuery::fetchRelatedVlanTags) + ); + + } + + private Multival> fetchNetworksForService(ServiceInstance serviceInstance) { + final Multival l3NetworksForService = + serviceInstanceStandardQuery.fetchRelatedL3Networks("service", serviceInstance); + + return l3NetworksForService.mapEachVal(serviceInstanceStandardQuery::fetchRelatedVlanTags); + } + + private NetworksToVlans translateNetworksFormat(Multival networkWithVlan) { + return new NetworksToVlans( + networkWithVlan.getKey().getNetworkId(), + networkWithVlan.getKey().getNetworkName(), + networkWithVlan.getKey().getNetworkType(), + networkWithVlan.getKey().getOrchestrationStatus(), + networkWithVlan.getValues().stream().map( + vlan -> new NetworksToVlans.Vlan(vlan.getVlanIdInner()) + ).collect(toList()) + ); + } + + protected boolean isModelOf5g(UUID sdcModelUuid) throws AsdcCatalogException { + final ServiceModel serviceModel = sdcService.getService(sdcModelUuid.toString()); + if (serviceModel == null) { + throw new GenericUncheckedException("Internal error while fetching Service Model: " + sdcModelUuid); + } + VidNotions.ModelCategory serviceModelCategory = serviceModel.getService().getVidNotions().getModelCategory(); + return serviceModelCategory.equals(VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL) || + serviceModelCategory.equals(VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL); + } + + protected static class VlansByNetworksHierarchy { + public final Collection serviceNetworks; + public final Collection vnfNetworks; + + public VlansByNetworksHierarchy() { + this(Collections.emptySet(), Collections.emptySet()); + } + + public VlansByNetworksHierarchy(Collection serviceNetworks, Collection vnfNetworks) { + this.serviceNetworks = serviceNetworks; + this.vnfNetworks = vnfNetworks; + } + } + + protected static class VnfVlansByNetworks { + public final String vnfId; + public final Collection networks; + + public VnfVlansByNetworks(String vnfId, Collection networks) { + this.vnfId = vnfId; + this.networks = networks; + } + } + + protected static class NetworksToVlans { + public final String networkId; + public final String name; + public final String nodeType; + public final String nodeStatus; + public final Collection vlans; + + private NetworksToVlans(String networkId, String name, String nodeType, String nodeStatus, Collection vlans) { + this.networkId = networkId; + this.name = name; + this.nodeType = nodeType; + this.nodeStatus = nodeStatus; + this.vlans = vlans; + } + + private static class Vlan { + public final String vlanIdInner; + + private Vlan(String vlanIdInner) { + this.vlanIdInner = vlanIdInner; + } + } + + } +} -- cgit 1.2.3-korg