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';
37 * @Component takes NSInstancesActionComponent.html as template url
40 templateUrl: './NSInstancesActionComponent.html',
41 styleUrls: ['./NSInstancesActionComponent.scss'],
42 changeDetection: ChangeDetectionStrategy.OnPush
44 /** Exporting a class @exports NSInstancesActionComponent */
45 export class NSInstancesActionComponent {
46 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
47 public value: NSDInstanceData;
49 /** Invoke service injectors @public */
50 public injector: Injector;
52 /** Instance of the modal service @public */
53 public restService: RestService;
55 /** Config Status Check @public */
56 public configStatus: string;
58 /** Operational Status Check @public */
59 public operationalStatus: string;
61 /** Check the loading results for loader status @public */
62 public isLoadingMetricsResult: boolean = false;
64 /** Give the message for the loading @public */
65 public message: string = 'PLEASEWAIT';
67 /** Instance of the modal service @private */
68 private modalService: NgbModal;
70 /** Holds teh instance of AuthService class of type AuthService @private */
71 private router: Router;
73 /** Contains instance ID @private */
74 private instanceID: string;
76 /** Contains all methods related to shared @private */
77 private sharedService: SharedService;
79 /** Notifier service to popup notification @private */
80 private notifierService: NotifierService;
82 /** Contains tranlsate instance @private */
83 private translateService: TranslateService;
85 /** Detect changes for the User Input */
86 private cd: ChangeDetectorRef;
88 /** Set timeout @private */
89 private timeOut: number = 1000;
91 constructor(injector: Injector) {
92 this.injector = injector;
93 this.modalService = this.injector.get(NgbModal);
94 this.restService = this.injector.get(RestService);
95 this.router = this.injector.get(Router);
96 this.sharedService = this.injector.get(SharedService);
97 this.notifierService = this.injector.get(NotifierService);
98 this.translateService = this.injector.get(TranslateService);
99 this.cd = this.injector.get(ChangeDetectorRef);
103 * Lifecyle Hooks the trigger before component is instantiate
105 public ngOnInit(): void {
106 this.configStatus = this.value.ConfigStatus;
107 this.operationalStatus = this.value.OperationalStatus;
108 this.instanceID = this.value.identifier;
111 /** Shows information using modalservice @public */
112 public infoNs(): void {
113 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
116 titleName: 'INSTANCEDETAILS'
120 /** Delete NS Instanace @public */
121 public deleteNSInstance(forceAction: boolean): void {
122 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
123 modalRef.componentInstance.params = { forceDeleteType: forceAction };
124 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
126 this.sharedService.callData();
131 /** History of operations for an Instanace @public */
132 public historyOfOperations(): void {
133 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch(() => {
134 // Catch Navigation Error
139 public nsTopology(): void {
140 this.router.navigate(['/instances/ns/', this.instanceID]).catch(() => {
141 // Catch Navigation Error
145 /** Exec NS Primitive @public */
146 public execNSPrimitiveModal(): void {
147 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
148 memberIndex: this.value.memberIndex,
149 nsConfig: this.value.nsConfig,
150 name: this.value.NsdName
154 /** Redirect to Grafana Metrics @public */
155 public metrics(): void {
156 this.isLoadingMetricsResult = true;
157 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]) => {
158 nsData['vnfd-id'].forEach((vnfdID: string[]) => {
159 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
160 .subscribe((vnfd: {}[]) => {
161 if (vnfd['monitoring-param'] !== undefined && vnfd['monitoring-param'].length > 0) {
162 this.isLoadingMetricsResult = false;
163 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
164 window.open(location);
166 this.isLoadingMetricsResult = false;
167 this.notifierService.notify('error', this.translateService.instant('GRAFANA.METRICSERROR'));
170 this.cd.detectChanges();
172 }, (error: ERRORDATA) => {
173 this.restService.handleError(error, 'get');
174 this.isLoadingMetricsResult = false;
177 }, (error: ERRORDATA) => {
178 this.restService.handleError(error, 'get');
179 this.isLoadingMetricsResult = false;