2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.controller;
23 import java.util.List;
24 import java.util.stream.Collectors;
25 import javax.servlet.http.HttpServletRequest;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.vid.aai.AaiClientInterface;
28 import org.onap.vid.aai.AaiGetVnfResponse;
29 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
30 import org.onap.vid.aai.model.ModelVer;
31 import org.onap.vid.aai.model.Permissions;
32 import org.onap.vid.model.aaiTree.Network;
33 import org.onap.vid.model.aaiTree.RelatedVnf;
34 import org.onap.vid.model.aaiTree.VpnBinding;
35 import org.onap.vid.properties.Features;
36 import org.onap.vid.roles.RoleProvider;
37 import org.onap.vid.services.AaiService;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.MediaType;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.PathVariable;
43 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestMethod;
45 import org.springframework.web.bind.annotation.RequestParam;
46 import org.springframework.web.bind.annotation.ResponseStatus;
47 import org.springframework.web.bind.annotation.RestController;
48 import org.togglz.core.manager.FeatureManager;
51 * Controller to handle a&ai new requests.
55 public class AaiController2 extends VidRestrictedBaseController {
57 private final AaiService aaiService;
58 private final RoleProvider roleProvider;
59 private final AaiClientInterface aaiClient;
60 private final FeatureManager featureManager;
63 public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient, FeatureManager featureManager) {
64 this.aaiService = aaiService;
65 this.roleProvider = roleProvider;
66 this.aaiClient = aaiClient;
67 this.featureManager = featureManager;
70 @RequestMapping(value = "/aai_get_homing_by_vfmodule/{vnfInstanceId}/{vfModuleId}", method = RequestMethod.GET)
71 public GetTenantsResponse getHomingDataByVfModule(@PathVariable("vnfInstanceId") String vnfInstanceId,
72 @PathVariable("vfModuleId") String vfModuleId){
73 return aaiService.getHomingDataByVfModule(vnfInstanceId, vfModuleId);
76 @RequestMapping(value = "/aai_get_service_instance_topology/{subscriberId}/{serviceType}/{serviceInstanceId}",
77 method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
78 public String getServiceInstanceTree(@PathVariable("subscriberId") String globalCustomerId,
79 @PathVariable("serviceType") String serviceInstanceType,
80 @PathVariable("serviceInstanceId") String serviceInstanceId) {
81 return aaiService.getAAIServiceTree(globalCustomerId, serviceInstanceType, serviceInstanceId);
84 @RequestMapping(value = "/aai_reset_cache/{cacheName}", method = RequestMethod.DELETE)
85 @ResponseStatus(HttpStatus.ACCEPTED)
86 public void resetCache(@PathVariable("cacheName") String cacheName) {
87 aaiClient.resetCache(cacheName);
90 @RequestMapping(value = "/roles/service_permissions", method = RequestMethod.GET)
91 public Permissions servicePermissions(HttpServletRequest request,
92 @RequestParam(value = "subscriberId") String subscriberId,
93 @RequestParam(value = "serviceType") String serviceType) {
95 final boolean isEditPermitted = roleProvider
96 .getUserRolesValidator(request)
97 .isServicePermitted(subscriberId, serviceType);
99 return new Permissions(isEditPermitted);
102 @RequestMapping(value = "/aai_search_group_members",
103 method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
104 public List<RelatedVnf> searchGroupMembers(@RequestParam("subscriberId") String globalCustomerId,
105 @RequestParam("serviceType") String serviceType,
106 @RequestParam("serviceInvariantId") String invariantId,
107 @RequestParam("groupType") String groupType,
108 @RequestParam("groupRole") String groupRole) {
109 return aaiService.searchGroupMembers(globalCustomerId, serviceType, invariantId, groupType, groupRole);
112 @RequestMapping(value = "/aai_get_vpn_list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
113 public List<VpnBinding> getVpnList() {
114 return aaiService.getVpnListByVpnType("SERVICE-INFRASTRUCTURE");
117 @RequestMapping(value = "/aai_get_active_networks",
118 method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
119 public List<Network> getActiveNetworkList(
120 @RequestParam("cloudRegion") String cloudRegion,
121 @RequestParam("tenantId") String tenantId,
122 @RequestParam(value = "networkRole", required = false) String networkRole) {
123 return aaiService.getL3NetworksByCloudRegion(cloudRegion, tenantId, networkRole)
125 .filter(Network::isBoundToVpn)
126 .filter(network -> StringUtils.isNotEmpty(network.getInstanceName()))
127 .filter(network -> StringUtils.equalsIgnoreCase(network.getOrchStatus(), "active"))
128 .collect(Collectors.toList());
131 @RequestMapping(value = "/aai_get_newest_model_version_by_invariant/{invariantId}",
132 method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
133 public ModelVer getNewestModelVersionByInvariant(@PathVariable("invariantId") String invariantId) {
134 return aaiService.getNewestModelVersionByInvariantId(invariantId);
137 @GetMapping(value = "/get_vnf_data_by_globalid_and_service_type/{globalCustomerId}/{serviceType}")
138 public AaiGetVnfResponse getVnfDataByGlobalIdAndServiceType(
139 @PathVariable("globalCustomerId") String globalCustomerId,
140 @PathVariable("serviceType") String serviceType,
141 @RequestParam(name="nfRole", required = false) String nfRole,
142 @RequestParam(name="cloudRegion", required = false) String cloudRegion) {
143 if (featureManager.isActive(Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG)){
144 return aaiClient.getVnfsByParamsForChangeManagement(globalCustomerId, serviceType, nfRole, cloudRegion).getT();
146 return aaiService.getVNFData(globalCustomerId, serviceType).getT();