2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file NS InstancesAction Component
21 import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core';
22 import { Router } from '@angular/router';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { NotifierService } from 'angular-notifier';
26 import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
27 import { DeleteComponent } from 'DeleteComponent';
28 import { environment } from 'environment';
29 import { NSDDetails } from 'NSDModel';
30 import { NSDInstanceData } from 'NSInstanceModel';
31 import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
32 import { NsUpdateComponent } from 'NsUpdateComponent';
33 import { RestService } from 'RestService';
34 import { forkJoin, Observable } from 'rxjs';
35 import { ScalingComponent } from 'ScalingComponent';
36 import { SharedService } from 'SharedService';
37 import { ShowInfoComponent } from 'ShowInfoComponent';
38 import { isNullOrUndefined } from 'util';
39 import { VmMigrationComponent } from 'VmMigrationComponent';
40 import { DF, VDU, VNFD } from 'VNFDModel';
43 * @Component takes NSInstancesActionComponent.html as template url
46 templateUrl: './NSInstancesActionComponent.html',
47 styleUrls: ['./NSInstancesActionComponent.scss'],
48 changeDetection: ChangeDetectionStrategy.OnPush
50 /** Exporting a class @exports NSInstancesActionComponent */
51 export class NSInstancesActionComponent {
52 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
53 public value: NSDInstanceData;
55 /** Invoke service injectors @public */
56 public injector: Injector;
58 /** Instance of the modal service @public */
59 public restService: RestService;
61 /** Config Status Check @public */
62 public configStatus: string;
64 /** Operational Status Check @public */
65 public operationalStatus: string;
67 /** get Admin Details @public */
68 public getAdminDetails: {};
70 /** Scaling is accepted @public */
71 public isScalingPresent: boolean = false;
73 /** Check the loading results for loader status @public */
74 public isLoadingNSInstanceAction: boolean = false;
76 /** Give the message for the loading @public */
77 public message: string = 'PLEASEWAIT';
79 /** Assign the VNF Details @public */
80 public vnfDetails: VNFD[] = [];
82 /** Contains instance ID @public */
83 public instanceID: string;
85 /** Contains operational dashboard view @public */
86 public isShowOperationalDashboard: boolean = false;
88 /** Instance of the modal service @private */
89 private modalService: NgbModal;
91 /** Holds teh instance of AuthService class of type AuthService @private */
92 private router: Router;
94 /** Contains all methods related to shared @private */
95 private sharedService: SharedService;
97 /** Notifier service to popup notification @private */
98 private notifierService: NotifierService;
100 /** Contains tranlsate instance @private */
101 private translateService: TranslateService;
103 /** Detect changes for the User Input */
104 private cd: ChangeDetectorRef;
106 /** Set timeout @private */
107 private timeOut: number = 100;
109 constructor(injector: Injector) {
110 this.injector = injector;
111 this.modalService = this.injector.get(NgbModal);
112 this.restService = this.injector.get(RestService);
113 this.router = this.injector.get(Router);
114 this.sharedService = this.injector.get(SharedService);
115 this.notifierService = this.injector.get(NotifierService);
116 this.translateService = this.injector.get(TranslateService);
117 this.cd = this.injector.get(ChangeDetectorRef);
121 * Lifecyle Hooks the trigger before component is instantiate
123 public ngOnInit(): void {
124 this.configStatus = this.value.ConfigStatus;
125 this.operationalStatus = this.value.OperationalStatus;
126 this.instanceID = this.value.identifier;
127 this.getAdminDetails = this.value.adminDetails;
128 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
129 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
132 /** Shows information using modalservice @public */
133 public infoNs(): void {
134 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
137 titleName: 'INSTANCEDETAILS'
141 /** Delete NS Instanace @public */
142 public deleteNSInstance(forceAction: boolean): void {
143 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
144 modalRef.componentInstance.params = { forceDeleteType: forceAction };
145 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
147 this.sharedService.callData();
152 /** History of operations for an Instanace @public */
153 public historyOfOperations(): void {
154 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
155 // Catch Navigation Error
160 public nsTopology(): void {
161 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
162 // Catch Navigation Error
166 /** Exec NS Primitive @public */
167 public execNSPrimitiveModal(): void {
168 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
169 memberIndex: this.value.memberIndex,
170 nsConfig: this.value.nsConfig,
171 name: this.value.NsdName
175 /** Redirect to Grafana Metrics @public */
176 public metrics(): void {
177 this.isLoadingNSInstanceAction = true;
178 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
179 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
180 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
181 .subscribe((vnfd: VNFD): void => {
182 vnfd.vdu.forEach((vduData: VDU): void => {
183 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
184 this.isLoadingNSInstanceAction = false;
185 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
186 window.open(location);
188 this.isLoadingNSInstanceAction = false;
189 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
193 }, (error: ERRORDATA): void => {
194 this.restService.handleError(error, 'get');
195 this.isLoadingNSInstanceAction = false;
198 }, (error: ERRORDATA): void => {
199 this.restService.handleError(error, 'get');
200 this.isLoadingNSInstanceAction = false;
205 * Do the manual scaling
206 * Here we are going to get a list of VNFD ID used in the instances
207 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
209 public manualScaling(): void {
210 this.isLoadingNSInstanceAction = true;
211 const tempURL: Observable<{}>[] = [];
212 this.value.vnfID.forEach((id: string): void => {
213 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
214 tempURL.push(this.restService.getResource(apiUrl));
216 this.checkScaling(tempURL);
220 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
222 public checkScaling(URLS: Observable<{}>[]): void {
223 forkJoin(URLS).subscribe((data: VNFD[]): void => {
224 this.vnfDetails = data;
225 if (this.vnfDetails.length > 0) {
226 this.vnfDetails.forEach((vnfdData: VNFD): void => {
227 vnfdData.df.forEach((dfData: DF): void => {
228 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
229 this.isScalingPresent = true;
234 this.isLoadingNSInstanceAction = false;
235 if (this.isScalingPresent) {
238 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
244 /** Open the scaling pop-up @public */
245 public openScaling(): void {
246 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
247 modalRef.componentInstance.params = {
249 vnfID: this.value.vnfID,
250 nsID: this.value['nsd-id'],
252 data: this.vnfDetails
254 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
256 this.sharedService.callData();
261 /** To open VM Migration in NS Instances */
262 public openVmMigration(): void {
263 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
264 modalRef.componentInstance.params = {
267 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
269 this.sharedService.callData();
274 /** To open the Ns Update pop-up */
275 public openNsUpdate(): void {
276 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
277 modalRef.componentInstance.params = {
280 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
282 this.sharedService.callData();
288 * Check any changes in the child component @public
290 public doChanges(): void {
291 setTimeout((): void => {
292 this.cd.detectChanges();