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