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 { RestService } from 'RestService';
33 import { SharedService } from 'SharedService';
34 import { ShowInfoComponent } from 'ShowInfoComponent';
35 import { VDU, VNFD } from 'VNFDModel';
38 * @Component takes NSInstancesActionComponent.html as template url
41 templateUrl: './NSInstancesActionComponent.html',
42 styleUrls: ['./NSInstancesActionComponent.scss'],
43 changeDetection: ChangeDetectionStrategy.OnPush
45 /** Exporting a class @exports NSInstancesActionComponent */
46 export class NSInstancesActionComponent {
47 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
48 public value: NSDInstanceData;
50 /** Invoke service injectors @public */
51 public injector: Injector;
53 /** Instance of the modal service @public */
54 public restService: RestService;
56 /** Config Status Check @public */
57 public configStatus: string;
59 /** Operational Status Check @public */
60 public operationalStatus: string;
62 /** Check the loading results for loader status @public */
63 public isLoadingMetricsResult: boolean = false;
65 /** Give the message for the loading @public */
66 public message: string = 'PLEASEWAIT';
68 /** Instance of the modal service @private */
69 private modalService: NgbModal;
71 /** Holds teh instance of AuthService class of type AuthService @private */
72 private router: Router;
74 /** Contains instance ID @private */
75 private instanceID: string;
77 /** Contains all methods related to shared @private */
78 private sharedService: SharedService;
80 /** Notifier service to popup notification @private */
81 private notifierService: NotifierService;
83 /** Contains tranlsate instance @private */
84 private translateService: TranslateService;
86 /** Detect changes for the User Input */
87 private cd: ChangeDetectorRef;
89 /** Set timeout @private */
90 private timeOut: number = 1000;
92 constructor(injector: Injector) {
93 this.injector = injector;
94 this.modalService = this.injector.get(NgbModal);
95 this.restService = this.injector.get(RestService);
96 this.router = this.injector.get(Router);
97 this.sharedService = this.injector.get(SharedService);
98 this.notifierService = this.injector.get(NotifierService);
99 this.translateService = this.injector.get(TranslateService);
100 this.cd = this.injector.get(ChangeDetectorRef);
104 * Lifecyle Hooks the trigger before component is instantiate
106 public ngOnInit(): void {
107 this.configStatus = this.value.ConfigStatus;
108 this.operationalStatus = this.value.OperationalStatus;
109 this.instanceID = this.value.identifier;
112 /** Shows information using modalservice @public */
113 public infoNs(): void {
114 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
117 titleName: 'INSTANCEDETAILS'
121 /** Delete NS Instanace @public */
122 public deleteNSInstance(forceAction: boolean): void {
123 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
124 modalRef.componentInstance.params = { forceDeleteType: forceAction };
125 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
127 this.sharedService.callData();
132 /** History of operations for an Instanace @public */
133 public historyOfOperations(): void {
134 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
135 // Catch Navigation Error
140 public nsTopology(): void {
141 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
142 // Catch Navigation Error
146 /** Exec NS Primitive @public */
147 public execNSPrimitiveModal(): void {
148 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
149 memberIndex: this.value.memberIndex,
150 nsConfig: this.value.nsConfig,
151 name: this.value.NsdName
155 /** Redirect to Grafana Metrics @public */
156 public metrics(): void {
157 this.isLoadingMetricsResult = true;
158 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
159 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
160 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
161 .subscribe((vnfd: VNFD): void => {
162 vnfd.vdu.forEach((vduData: VDU): void => {
163 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
164 this.isLoadingMetricsResult = false;
165 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
166 window.open(location);
168 this.isLoadingMetricsResult = false;
169 this.notifierService.notify('error', this.translateService.instant('GRAFANA.METRICSERROR'));
172 setTimeout((): void => {
173 this.cd.detectChanges();
175 }, (error: ERRORDATA): void => {
176 this.restService.handleError(error, 'get');
177 this.isLoadingMetricsResult = false;
180 }, (error: ERRORDATA): void => {
181 this.restService.handleError(error, 'get');
182 this.isLoadingMetricsResult = false;