blob: c3533eada25ad243ca179a2956a97731150b07fe [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17*/
18/**
19 * @file NS InstancesAction Component
20 */
21import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core';
22import { Router } from '@angular/router';
23import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24import { TranslateService } from '@ngx-translate/core';
25import { NotifierService } from 'angular-notifier';
26import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
27import { DeleteComponent } from 'DeleteComponent';
28import { environment } from 'environment';
29import { NSDDetails } from 'NSDModel';
30import { NSDInstanceData } from 'NSInstanceModel';
31import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
32import { RestService } from 'RestService';
33import { SharedService } from 'SharedService';
34import { ShowInfoComponent } from 'ShowInfoComponent';
Barath Kumar R1a34b832021-03-05 11:32:19 +053035import { VDU, VNFD } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053036/**
37 * Creating component
38 * @Component takes NSInstancesActionComponent.html as template url
39 */
40@Component({
41 templateUrl: './NSInstancesActionComponent.html',
42 styleUrls: ['./NSInstancesActionComponent.scss'],
43 changeDetection: ChangeDetectionStrategy.OnPush
44})
45/** Exporting a class @exports NSInstancesActionComponent */
46export class NSInstancesActionComponent {
47 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
48 public value: NSDInstanceData;
49
50 /** Invoke service injectors @public */
51 public injector: Injector;
52
53 /** Instance of the modal service @public */
54 public restService: RestService;
55
56 /** Config Status Check @public */
57 public configStatus: string;
58
59 /** Operational Status Check @public */
60 public operationalStatus: string;
61
62 /** Check the loading results for loader status @public */
63 public isLoadingMetricsResult: boolean = false;
64
65 /** Give the message for the loading @public */
66 public message: string = 'PLEASEWAIT';
67
68 /** Instance of the modal service @private */
69 private modalService: NgbModal;
70
71 /** Holds teh instance of AuthService class of type AuthService @private */
72 private router: Router;
73
74 /** Contains instance ID @private */
75 private instanceID: string;
76
77 /** Contains all methods related to shared @private */
78 private sharedService: SharedService;
79
80 /** Notifier service to popup notification @private */
81 private notifierService: NotifierService;
82
83 /** Contains tranlsate instance @private */
84 private translateService: TranslateService;
85
86 /** Detect changes for the User Input */
87 private cd: ChangeDetectorRef;
88
89 /** Set timeout @private */
90 private timeOut: number = 1000;
91
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);
101 }
102
103 /**
104 * Lifecyle Hooks the trigger before component is instantiate
105 */
106 public ngOnInit(): void {
107 this.configStatus = this.value.ConfigStatus;
108 this.operationalStatus = this.value.OperationalStatus;
109 this.instanceID = this.value.identifier;
110 }
111
112 /** Shows information using modalservice @public */
113 public infoNs(): void {
114 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
115 id: this.instanceID,
116 page: 'ns-instance',
117 titleName: 'INSTANCEDETAILS'
118 };
119 }
120
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 };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530125 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530126 if (result) {
127 this.sharedService.callData();
128 }
129 }).catch();
130 }
131
132 /** History of operations for an Instanace @public */
133 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530134 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530135 // Catch Navigation Error
136 });
137 }
138
139 /** NS Topology */
140 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530141 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530142 // Catch Navigation Error
143 });
144 }
145
146 /** Exec NS Primitive @public */
147 public execNSPrimitiveModal(): void {
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530148 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530149 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530150 nsConfig: this.value.nsConfig,
151 name: this.value.NsdName
kumaran.m3b4814a2020-05-01 19:48:54 +0530152 };
153 }
154
155 /** Redirect to Grafana Metrics @public */
156 public metrics(): void {
157 this.isLoadingMetricsResult = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530158 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
159 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530160 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530161 .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);
167 } else {
168 this.isLoadingMetricsResult = false;
169 this.notifierService.notify('error', this.translateService.instant('GRAFANA.METRICSERROR'));
170 }
171 });
172 setTimeout((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530173 this.cd.detectChanges();
174 }, this.timeOut);
Barath Kumar R1a34b832021-03-05 11:32:19 +0530175 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530176 this.restService.handleError(error, 'get');
177 this.isLoadingMetricsResult = false;
178 });
179 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530180 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530181 this.restService.handleError(error, 'get');
182 this.isLoadingMetricsResult = false;
183 });
184 }
185}