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