1 import {Injectable} from '@angular/core';
2 import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
3 import * as _ from 'lodash';
4 import {Observable} from 'rxjs/Observable';
5 import {NgRedux} from "@angular-redux/store";
6 import {AppState} from "../shared/store/reducers";
7 import {AaiService} from "../shared/services/aaiService/aai.service";
8 import {ServiceModel} from "../shared/models/serviceModel";
9 import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
10 import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
11 import {updateDrawingBoardStatus} from "../shared/storeUtil/utils/global/global.actions";
12 import {Router, UrlTree} from "@angular/router";
13 import {of} from "rxjs";
14 import {MsoService} from "../shared/services/msoService/mso.service";
15 import {ServiceAction} from "../shared/models/serviceInstanceActions";
16 import {InstantiationBase} from "../shared/models/InstantiationBase";
18 export let PENDING : string = "pending";
19 export let INPROGRESS : string = "in_progress";
20 export let PAUSE : string = "pause";
21 export let X_O : string = "x-circle-o";
22 export let SUCCESS_CIRCLE : string = "success-circle-o";
23 export let STOPPED : string = "stop";
24 export let COMPLETED_WITH_ERRORS : string = "success_with_warning";
25 export let PAUSE_UPON_COMPLETION : string = "stopped-upon-success";
26 export let FAILED_AND_PAUSED : string = "success_with_warning";
27 export let UNKNOWN : string = "question-mark-circle-o";
31 export class InstantiationStatusComponentService {
32 constructor( private _aaiService: AaiService,
33 private _msoService: MsoService,
34 private _router : Router,
35 private _store: NgRedux<AppState>,
36 private _featureFlagsService:FeatureFlagsService) {
39 generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{
40 let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {};
42 if(_.isNil(serviceInfoData[item.templateId])){
43 serviceInfoData[item.templateId] = [item];
45 serviceInfoData[item.templateId].push(item);
48 return serviceInfoData;
51 convertObjectToArray(arr: ServiceInfoModel[]) : Observable<ServiceInfoUiModel[]>{
52 const obj = this.generateServiceInfoDataMapping(arr);
55 for(let item in obj) {
56 obj[item].map(item => {
57 item['serviceStatus'] = this.getStatus(item.jobStatus);
58 item['serviceIndex'] = index;
61 result = result.concat(obj[item]);
68 isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean {
69 if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI)
70 && serviceModel.vidNotions.viewEditUI !== 'legacy'){
76 open(item: ServiceInfoModel): void {
77 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING)) {
78 this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{
79 const serviceModel = new ServiceModel(result);
81 if (this.isDrawingBoardViewEdit(serviceModel)) {
82 this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT);
86 this.navigateToNewViewOnlyOrOldEditView(item);
91 /*this else is here only to save time in case we don't need to retrieve service model
92 it can be removed once it service model is always needed, and it doesn't save time*/
94 this.navigateToNewViewOnlyOrOldEditView(item);
98 navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) {
99 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT)) {
100 this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW);
103 this.navigateToOldViewEdit(item);
107 navigateToOldViewEdit(item: ServiceInfoModel) {
109 `subscriberId=${item.subscriberId}&` +
110 `subscriberName=${item.subscriberName}&` +
111 `serviceType=${item.serviceType}&` +
112 `serviceInstanceId=${item.serviceInstanceId}`;
114 this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT));
115 window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
118 navigateToNewViewEdit(item: InstantiationBase, mode: DrawingBoardModes): void {
119 console.log("Mode : ", mode);
120 this._store.dispatch(updateDrawingBoardStatus(mode));
121 const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode);
122 this._router.navigateByUrl(viewEditUrlTree);
123 window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree));
126 getNewViewEditUrlTree(item: InstantiationBase, mode: DrawingBoardModes): UrlTree {
127 return this._router.createUrlTree(
128 ['/servicePlanning/' + mode],
131 mode==DrawingBoardModes.RECREATE ?
132 this.getRecreateQueryParams(item) :
133 this.getDefaultViewEditQueryParams(<ServiceInfoModel> item)
137 private getDefaultViewEditQueryParams(item: ServiceInfoModel) {
139 serviceModelId: item.serviceModelId,
140 serviceInstanceId: item.serviceInstanceId,
141 serviceType: item.serviceType,
142 subscriberId: item.subscriberId,
147 private getRecreateQueryParams(item: InstantiationBase) {
149 serviceModelId: item.serviceModelId,
154 getViewEditUrl(viewEditUrlTree:UrlTree): string {
155 return '../../serviceModels.htm#' + viewEditUrlTree.toString();
158 getStatus(status : string) : ServiceStatus {
159 switch(`${status}`.toUpperCase()) {
161 return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.');
163 return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.');
165 return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
167 return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.');
169 return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.');
171 return new ServiceStatus(STOPPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.');
172 case 'COMPLETED_WITH_ERRORS' :
173 return new ServiceStatus(COMPLETED_WITH_ERRORS, 'success', 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.');
174 case 'COMPLETED_AND_PAUSED' :
175 return new ServiceStatus(PAUSE_UPON_COMPLETION, 'default','Pause upon completion. you may resume the instantiation.\n Open the service to check it out.' );
176 case 'FAILED_AND_PAUSED' :
177 return new ServiceStatus(FAILED_AND_PAUSED, 'success','Failed and Paused: you may re-deploy the instantiation.\n Open the service to check it out.' );
179 return new ServiceStatus(UNKNOWN, 'primary', `Unexpected status: "${status}"`);
183 retry(item: ServiceInfoModel): void {
184 this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT);
187 resume(item: ServiceInfoModel): void {
188 this.navigateToNewViewEdit(item, DrawingBoardModes.RESUME);
191 recreate(item: ServiceInfoModel): void {
192 this.navigateToNewViewEdit(item, DrawingBoardModes.RECREATE);
195 isRecreateEnabled(item: ServiceInfoModel): boolean {
196 return item.action === ServiceAction.INSTANTIATE;
199 isRecreateVisible(): boolean {
200 return this._featureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE);
203 isNewViewEditVisible(): boolean {
204 return this._featureFlagsService.getFlagState(Features.FLAG_2006_NEW_VIEW_EDIT_BUTTON_IN_INSTANTIATION_STATUS);
207 forwardToNewViewEdit(item: ServiceInfoModel): void {
208 this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT);
213 export class ServiceStatus {
214 iconClassName : string;
218 constructor(_iconClassName : string, _color : string, _tooltip : string){
219 this.iconClassName = _iconClassName;
221 this.tooltip = _tooltip;