blob: adb7017be3ffd84feba55d7407f1b7db135c0823 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {NgRedux} from "@angular-redux/store";
2import {HttpClient} from '@angular/common/http';
3import {Injectable} from '@angular/core';
4import * as _ from 'lodash';
5import 'rxjs/add/operator/catch';
6import 'rxjs/add/operator/do';
Eylon Malin5438f8b2019-09-26 10:04:17 +03007import {Observable, of} from "rxjs";
Ittay Stern6f900cc2018-08-29 17:01:32 +03008
9import {AicZone} from "../../models/aicZone";
10import {CategoryParams} from "../../models/categoryParams";
11import {LcpRegion} from "../../models/lcpRegion";
12import {LcpRegionsAndTenants} from "../../models/lcpRegionsAndTenants";
13import {OwningEntity} from "../../models/owningEntity";
14import {ProductFamily} from "../../models/productFamily";
15import {Project} from "../../models/project";
16import {SelectOption} from '../../models/selectOption';
17import {ServiceType} from "../../models/serviceType";
18import {Subscriber} from "../../models/subscriber";
19import {Tenant} from "../../models/tenant";
20import {Constants} from '../../utils/constants';
21import {AppState} from "../../store/reducers";
22import {GetAicZonesResponse} from "./responseInterfaces/getAicZonesResponseInterface";
23import {GetCategoryParamsResponseInterface} from "./responseInterfaces/getCategoryParamsResponseInterface";
24import {GetServicesResponseInterface} from "./responseInterfaces/getServicesResponseInterface";
25import {GetSubDetailsResponse} from "./responseInterfaces/getSubDetailsResponseInterface";
26import {GetSubscribersResponse} from "./responseInterfaces/getSubscribersResponseInterface";
27import {Root} from "./model/crawledAaiService";
28import {VnfInstance} from "../../models/vnfInstance";
29import {VfModuleInstance} from "../../models/vfModuleInstance";
30import {ServiceInstance} from "../../models/serviceInstance";
31import {VfModuleMap} from "../../models/vfModulesMap";
Ittay Sterne2a7abb2020-02-18 16:58:16 +020032import {
33 updateAicZones,
34 updateCategoryParameters,
35 updateLcpRegionsAndTenants,
36 updateServiceTypes,
37 updateSubscribers,
38 updateUserId
39} from "../../storeUtil/utils/general/general.actions";
Eylon Malin5438f8b2019-09-26 10:04:17 +030040import {createServiceInstance, updateModel,} from "../../storeUtil/utils/service/service.actions";
Ittay Stern6f900cc2018-08-29 17:01:32 +030041import {FeatureFlagsService, Features} from "../featureFlag/feature-flags.service";
42import {VnfMember} from "../../models/VnfMember";
43import {setOptionalMembersVnfGroupInstance} from "../../storeUtil/utils/vnfGroup/vnfGroup.actions";
Eylon Malin5438f8b2019-09-26 10:04:17 +030044import {NetworkModalRow} from "../../../drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/networkStep/network.step.model";
Ittay Sternf7926712019-07-07 19:23:03 +030045import {VPNModalRow} from "../../../drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.model";
Einat Vinouzee1f79742019-08-27 16:01:01 +030046import {ModelInfo} from "../../models/modelInfo";
Ittay Stern6f900cc2018-08-29 17:01:32 +030047
48@Injectable()
49export class AaiService {
50 constructor(private http: HttpClient, private store: NgRedux<AppState>, private featureFlagsService:FeatureFlagsService) {
51
52 }
53
Yoav Schneiderman3f216a52020-01-22 11:07:00 +020054 sdncPreload(): Observable<boolean> {
55 let pathQuery: string = Constants.Path.PRE_LOAD;
56 return this.http.post<boolean>(pathQuery, {})
57 }
58
Ittay Stern6f900cc2018-08-29 17:01:32 +030059 getServiceModelById = (serviceModelId: string): Observable<any> => {
60 if (_.has(this.store.getState().service.serviceHierarchy, serviceModelId)) {
61 return of(<any> JSON.parse(JSON.stringify(this.store.getState().service.serviceHierarchy[serviceModelId])));
62 }
63 let pathQuery: string = Constants.Path.SERVICES_PATH + serviceModelId;
64 return this.http.get(pathQuery).map(res => res)
65 .do((res) => {
66 this.store.dispatch(updateModel(res));
67 });
68 };
69
Einat Vinouzee1f79742019-08-27 16:01:01 +030070 retrieveServiceLatestUpdateableVersion = (modelInvariantId: string): Observable<ModelInfo> => {
Eylon Malin5438f8b2019-09-26 10:04:17 +030071 let pathQuery: string = Constants.Path.SERVICE_LATEST_VERSION + modelInvariantId;
72 return this.http.get<ModelInfo>(pathQuery)
Einat Vinouzee1f79742019-08-27 16:01:01 +030073 };
74
Ittay Stern6f900cc2018-08-29 17:01:32 +030075 getUserId = (): Observable<any> => {
76 return this.http.get("../../getuserID", {responseType: 'text'}).do((res) => this.store.dispatch(updateUserId(res)));
77 };
78
79
80 resolve = (root: Root, serviceInstance: ServiceInstance) => {
81 if (root.type === 'service-instance') {
82 serviceInstance.instanceName = root.name;
83 serviceInstance.orchStatus = root.orchestrationStatus;
84 serviceInstance.modelInavariantId = root.modelInvariantId;
85 for (let i = 0; i < root.children.length; i++) {
86 let child = root.children[i];
87 if (child.type === 'generic-vnf') {
88 let vnf = new VnfInstance();
89 vnf.originalName = child.name;
90 vnf.orchStatus = child.orchestrationStatus
91 if (child.children.length > 0) {
92 let vfModuleMap = new VfModuleMap();
93 for (let j = 0; j < child.children.length; j++) {
94 let child = root.children[i];
95 if (child.type === 'vf-module') {
96 let vfModule = new VfModuleInstance();
97 vfModule.instanceName = child.name;
98 vfModule.orchStatus = child.orchestrationStatus;
99 vfModuleMap.vfModules[child.name] = vfModule;
100 }
101 }
102 vnf.vfModules = {"a": vfModuleMap};
103 }
104 serviceInstance.vnfs[child.name] = vnf;
105
106 }
107 }
108
109 }
110 };
111
112
113 getCRAccordingToNetworkFunctionId = (networkCollectionFunction, cloudOwner, cloudRegionId) => {
114 return this.http.get('../../aai_get_instance_groups_by_cloudregion/' + cloudOwner + '/' + cloudRegionId + '/' + networkCollectionFunction)
115 .map(res => res).do((res) => console.log(res));
116 };
117
118 getCategoryParameters = (familyName): Observable<CategoryParams> => {
119 familyName = familyName || Constants.Path.PARAMETER_STANDARDIZATION_FAMILY;
120 let pathQuery: string = Constants.Path.GET_CATEGORY_PARAMETERS + "?familyName=" + familyName + "&r=" + Math.random();
121
122 return this.http.get<GetCategoryParamsResponseInterface>(pathQuery)
123 .map(this.categoryParametersResponseToProductAndOwningEntity)
124 .do(res => {
125 this.store.dispatch(updateCategoryParameters(res))
126 });
127 };
128
129
130 categoryParametersResponseToProductAndOwningEntity = (res: GetCategoryParamsResponseInterface): CategoryParams => {
131 if (res && res.categoryParameters) {
132 const owningEntityList = res.categoryParameters.owningEntity.map(owningEntity => new OwningEntity(owningEntity));
133 const projectList = res.categoryParameters.project.map(project => new Project(project));
134 const lineOfBusinessList = res.categoryParameters.lineOfBusiness.map(owningEntity => new SelectOption(owningEntity));
135 const platformList = res.categoryParameters.platform.map(platform => new SelectOption(platform));
136
137 return new CategoryParams(owningEntityList, projectList, lineOfBusinessList, platformList);
138 } else {
139 return new CategoryParams();
140 }
141 };
142
143 getProductFamilies = (): Observable<ProductFamily[]> => {
144
145 let pathQuery: string = Constants.Path.AAI_GET_SERVICES + Constants.Path.ASSIGN + Math.random();
146
147 return this.http.get<GetServicesResponseInterface>(pathQuery).map(res => res.service.map(service => new ProductFamily(service)));
148 };
149
150 getServices = (): Observable<GetServicesResponseInterface> => {
151 let pathQuery: string = Constants.Path.AAI_GET_SERVICES + Constants.Path.ASSIGN + Math.random();
152
153 return this.http.get<GetServicesResponseInterface>(pathQuery);
154 };
155
156 getSubscribers = (): Observable<Subscriber[]> => {
157
158 if (this.store.getState().service.subscribers) {
159 return of(<any> JSON.parse(JSON.stringify(this.store.getState().service.subscribers)));
160 }
161
162 let pathQuery: string = Constants.Path.AAI_GET_SUBSCRIBERS + Constants.Path.ASSIGN + Math.random();
163
164 return this.http.get<GetSubscribersResponse>(pathQuery).map(res =>
165 res.customer.map(subscriber => new Subscriber(subscriber))).do((res) => {
166 this.store.dispatch(updateSubscribers(res));
167 });
168 };
169
170 getAicZones = (): Observable<AicZone[]> => {
171 if (this.store.getState().service.aicZones) {
172 return of(<any> JSON.parse(JSON.stringify(this.store.getState().service.aicZones)));
173 }
174
175 let pathQuery: string = Constants.Path.AAI_GET_AIC_ZONES + Constants.Path.ASSIGN + Math.random();
176
177 return this.http.get<GetAicZonesResponse>(pathQuery).map(res =>
178 res.zone.map(aicZone => new AicZone(aicZone))).do((res) => {
179 this.store.dispatch(updateAicZones(res));
180 });
181 };
182
183 getLcpRegionsAndTenants = (globalCustomerId, serviceType): Observable<LcpRegionsAndTenants> => {
184
185 let pathQuery: string = Constants.Path.AAI_GET_TENANTS
186 + globalCustomerId + Constants.Path.FORWARD_SLASH + serviceType + Constants.Path.ASSIGN + Math.random();
187
188 console.log("AaiService:getSubscriptionServiceTypeList: globalCustomerId: "
189 + globalCustomerId);
190 if (globalCustomerId != null) {
191 return this.http.get(pathQuery)
192 .map(this.tenantResponseToLcpRegionsAndTenants).do((res) => {
193 this.store.dispatch(updateLcpRegionsAndTenants(res));
194 });
195 }
196 };
197
198 tenantResponseToLcpRegionsAndTenants = (cloudRegionTenantList): LcpRegionsAndTenants => {
199
200 const lcpRegionsTenantsMap = {};
201
202 const lcpRegionList = _.uniqBy(cloudRegionTenantList, 'cloudRegionID').map((cloudRegionTenant) => {
203 const cloudOwner:string = cloudRegionTenant["cloudOwner"];
204 const cloudRegionId:string = cloudRegionTenant["cloudRegionID"];
205 const name:string = this.extractLcpRegionName(cloudRegionId, cloudOwner);
206 const isPermitted:boolean = cloudRegionTenant["is-permitted"];
207 return new LcpRegion(cloudRegionId, name, isPermitted, cloudOwner);
208 });
209
210 lcpRegionList.forEach(region => {
211 lcpRegionsTenantsMap[region.id] = _.filter(cloudRegionTenantList, {'cloudRegionID': region.id})
212 .map((cloudRegionTenant) => {
213 return new Tenant(cloudRegionTenant)
214 });
215 const reducer = (accumulator, currentValue) => {
216 accumulator.isPermitted = accumulator.isPermitted || currentValue.isPermitted;
217
218 return accumulator;
219 };
220 region.isPermitted = lcpRegionsTenantsMap[region.id].reduce(reducer).isPermitted;
221 });
222
223 return new LcpRegionsAndTenants(lcpRegionList, lcpRegionsTenantsMap);
224 };
225
226 public extractLcpRegionName(cloudRegionId: string, cloudOwner: string):string {
Einat Vinouzee1f79742019-08-27 16:01:01 +0300227 return this.featureFlagsService.getFlagState(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST) ?
Ittay Stern6f900cc2018-08-29 17:01:32 +0300228 cloudRegionId+AaiService.formatCloudOwnerTrailer(cloudOwner) : cloudRegionId;
229 };
230
231 public static formatCloudOwnerTrailer(cloudOwner: string):string {
Ittay Sternf7926712019-07-07 19:23:03 +0300232 return " ("+ cloudOwner.trim().toLowerCase().replace(/^[^-]*-/, "").toUpperCase() + ")";
Ittay Stern6f900cc2018-08-29 17:01:32 +0300233 }
234
235 getServiceTypes = (subscriberId): Observable<ServiceType[]> => {
236
237 console.log("AaiService:getSubscriptionServiceTypeList: globalCustomerId: " + subscriberId);
238 if (_.has(this.store.getState().service.serviceTypes, subscriberId)) {
239 return of(<ServiceType[]> JSON.parse(JSON.stringify(this.store.getState().service.serviceTypes[subscriberId])));
240 }
241
242 return this.getSubscriberDetails(subscriberId)
243 .map(this.subDetailsResponseToServiceTypes)
244 .do((res) => {
245 this.store.dispatch(updateServiceTypes(res, subscriberId));
246 });
247 };
248
249 getSubscriberDetails = (subscriberId): Observable<GetSubDetailsResponse> => {
Ittay Sternf7926712019-07-07 19:23:03 +0300250 let pathQuery: string = Constants.Path.AAI_SUB_DETAILS_PATH + subscriberId + Constants.Path.ASSIGN + Math.random() + Constants.Path.AAI_OMIT_SERVICE_INSTANCES + true;
Ittay Stern6f900cc2018-08-29 17:01:32 +0300251
252 if (subscriberId != null) {
253 return this.http.get<GetSubDetailsResponse>(pathQuery);
254 }
255 };
256
257 subDetailsResponseToServiceTypes = (res: GetSubDetailsResponse): ServiceType[] => {
258 if (res && res['service-subscriptions']) {
259 const serviceSubscriptions = res['service-subscriptions']['service-subscription'];
260 return serviceSubscriptions.map((subscription, index) => new ServiceType(String(index), subscription))
261 } else {
262 return [];
263 }
264 };
265
266
267 public retrieveServiceInstanceTopology(serviceInstanceId : string, subscriberId: string, serviceType: string):Observable<ServiceInstance> {
268 let pathQuery: string = `${Constants.Path.AAI_GET_SERVICE_INSTANCE_TOPOLOGY_PATH}${subscriberId}/${serviceType}/${serviceInstanceId}`;
269 return this.http.get<ServiceInstance>(pathQuery);
270 }
271
Ittay Sternf7926712019-07-07 19:23:03 +0300272 public retrieveActiveNetwork(cloudRegion : string, tenantId: string) : Observable<NetworkModalRow[]>{
273 let pathQuery: string = `${Constants.Path.AAI_GET_ACTIVE_NETWORKS_PATH}?cloudRegion=${cloudRegion}&tenantId=${tenantId}`;
274 return this.http.get<NetworkModalRow[]>(pathQuery);
275 }
276
277 public retrieveActiveVPNs() : Observable<VPNModalRow[]>{
278 let pathQuery: string = `${Constants.Path.AAI_GET_VPNS_PATH}`;
279 return this.http.get<VPNModalRow[]>(pathQuery);
280 }
281
Ittay Stern6f900cc2018-08-29 17:01:32 +0300282 public retrieveAndStoreServiceInstanceTopology(serviceInstanceId: string, subscriberId: string, serviceType: string, serviceModeId: string):Observable<ServiceInstance> {
283 return this.retrieveServiceInstanceTopology(serviceInstanceId, subscriberId, serviceType).do((service:ServiceInstance) => {
284 this.store.dispatch(createServiceInstance(service, serviceModeId));
Einat Vinouzee1f79742019-08-27 16:01:01 +0300285 });
Ittay Stern6f900cc2018-08-29 17:01:32 +0300286 };
287
288
289 public retrieveServiceInstanceRetryTopology(jobId : string) :Observable<ServiceInstance> {
290 let pathQuery: string = `${Constants.Path.SERVICES_RETRY_TOPOLOGY}/${jobId}`;
291 return this.http.get<ServiceInstance>(pathQuery);
292
Ittay Stern6f900cc2018-08-29 17:01:32 +0300293 }
294
295 public retrieveAndStoreServiceInstanceRetryTopology(jobId: string, serviceModeId : string):Observable<ServiceInstance> {
296 return this.retrieveServiceInstanceRetryTopology(jobId).do((service:ServiceInstance) => {
297 this.store.dispatch(createServiceInstance(service, serviceModeId));
298 });
299 };
300
301 public getOptionalGroupMembers(serviceModelId: string, subscriberId: string, serviceType: string, serviceInvariantId: string, groupType: string, groupRole: string): Observable<VnfMember[]> {
302 let pathQuery: string = `${Constants.Path.AAI_GET_SERVICE_GROUP_MEMBERS_PATH}${subscriberId}/${serviceType}/${serviceInvariantId}/${groupType}/${groupRole}`;
303 if(_.has(this.store.getState().service.serviceInstance[serviceModelId].optionalGroupMembersMap,pathQuery)){
304 return of(<VnfMember[]> JSON.parse(JSON.stringify(this.store.getState().service.serviceInstance[serviceModelId].optionalGroupMembersMap[pathQuery])));
305 }
306 return this.http.get<VnfMember[]>(pathQuery)
307 .do((res) => {
308 this.store.dispatch(setOptionalMembersVnfGroupInstance(serviceModelId, pathQuery, res))
309 });
Ittay Stern6f900cc2018-08-29 17:01:32 +0300310 }
311
312 //TODO: make other places use this function
313 extractSubscriberNameBySubscriberId(subscriberId: string) {
314 let result: string = null;
315 let filteredArray: any = _.filter(this.store.getState().service.subscribers, function (o: Subscriber) {
316 return o.id === subscriberId
317 });
318 if (filteredArray.length > 0) {
319 result = filteredArray[0].name;
320 }
321 return result;
322 }
323
324 loadMockMembers(): any {
325 return [
326 {
327 "action":"None",
328 "instanceName":"VNF1_INSTANCE_NAME",
329 "instanceId":"VNF1_INSTANCE_ID",
330 "orchStatus":null,
331 "productFamilyId":null,
Ittay Sternf7926712019-07-07 19:23:03 +0300332 "lcpCloudRegionId":"hvf23b",
Ittay Stern6f900cc2018-08-29 17:01:32 +0300333 "tenantId":"3e9a20a3e89e45f884e09df0cc2d2d2a",
334 "tenantName":"APPC-24595-T-IST-02C",
335 "modelInfo":{
336 "modelInvariantId":"vnf-instance-model-invariant-id",
337 "modelVersionId":"7a6ee536-f052-46fa-aa7e-2fca9d674c44",
338 "modelVersion":"2.0",
339 "modelName":"vf_vEPDG",
340 "modelType":"vnf"
341 },
342 "instanceType":"VNF1_INSTANCE_TYPE",
343 "provStatus":null,
344 "inMaint":false,
345 "uuid":"7a6ee536-f052-46fa-aa7e-2fca9d674c44",
346 "originalName":null,
347 "legacyRegion":null,
348 "lineOfBusiness":null,
349 "platformName":null,
350 "trackById":"7a6ee536-f052-46fa-aa7e-2fca9d674c44:002",
351 "serviceInstanceId":"service-instance-id1",
352 "serviceInstanceName":"service-instance-name"
353 },
354 {
355 "action":"None",
356 "instanceName":"VNF2_INSTANCE_NAME",
357 "instanceId":"VNF2_INSTANCE_ID",
358 "orchStatus":null,
359 "productFamilyId":null,
Ittay Sternf7926712019-07-07 19:23:03 +0300360 "lcpCloudRegionId":"hvf23b",
Ittay Stern6f900cc2018-08-29 17:01:32 +0300361 "tenantId":"3e9a20a3e89e45f884e09df0cc2d2d2a",
362 "tenantName":"APPC-24595-T-IST-02C",
363 "modelInfo":{
364 "modelInvariantId":"vnf-instance-model-invariant-id",
365 "modelVersionId":"eb5f56bf-5855-4e61-bd00-3e19a953bf02",
366 "modelVersion":"1.0",
367 "modelName":"vf_vEPDG",
368 "modelType":"vnf"
369 },
370 "instanceType":"VNF2_INSTANCE_TYPE",
371 "provStatus":null,
372 "inMaint":true,
373 "uuid":"eb5f56bf-5855-4e61-bd00-3e19a953bf02",
374 "originalName":null,
375 "legacyRegion":null,
376 "lineOfBusiness":null,
377 "platformName":null,
378 "trackById":"eb5f56bf-5855-4e61-bd00-3e19a953bf02:003",
379 "serviceInstanceId":"service-instance-id2",
380 "serviceInstanceName":"service-instance-name"
381 }
382 ]
383
384 }
385
386
387}