blob: 072838150aaa3b43b921bce33f9033df9eacbb1f [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
SANDHYA.JS26570112024-07-05 21:35:46 +053010 Unless required by applicable law or agreed to in writing, software
kumaran.m3b4814a2020-05-01 19:48:54 +053011 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 K8 Action Component
20 */
SANDHYA.JSb5347152024-10-15 11:41:45 +053021import { HttpHeaders } from '@angular/common/http';
22import { ChangeDetectorRef, Component, Injector } from '@angular/core';
SANDHYA.JS92379ec2025-06-13 17:29:35 +053023import { Router } from '@angular/router';
kumaran.m3b4814a2020-05-01 19:48:54 +053024import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
25import { TranslateService } from '@ngx-translate/core';
SANDHYA.JSb5347152024-10-15 11:41:45 +053026import { NotifierService } from 'angular-notifier';
27import { ERRORDATA, GETAPIURLHEADER, MODALCLOSERESPONSEDATA } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053028import { DeleteComponent } from 'DeleteComponent';
SANDHYA.JSb5347152024-10-15 11:41:45 +053029import { environment } from 'environment';
SANDHYA.JS26570112024-07-05 21:35:46 +053030import { K8sAddClusterComponent } from 'K8sAddClusterComponent';
31import { K8sAttachProfileComponent } from 'K8sAttachProfileComponent';
32import { K8sInfraConfigAddComponent } from 'K8sInfraConfigAddComponent';
33import { INFRACONFIGPAYLOAD, K8SCLUSTERDATADISPLAY, K8SPayload, K8SREPODATADISPLAY } from 'K8sModel';
34import { KSUAddComponent } from 'KSUAddComponent';
SANDHYA.JS92379ec2025-06-13 17:29:35 +053035import { NodeAddComponent } from 'NodeAddComponent';
SANDHYA.JSb5347152024-10-15 11:41:45 +053036import { RestService } from 'RestService';
37import { isNullOrUndefined, SharedService } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053038import { ShowInfoComponent } from 'ShowInfoComponent';
39/**
40 * Creating component
41 * @Component takes K8sActionComponent.html as template url
42 */
43@Component({
44 selector: 'app-k8s-action',
45 templateUrl: './K8sActionComponent.html',
46 styleUrls: ['./K8sActionComponent.scss']
47})
48/** Exporting a class @exports K8sActionComponent */
SANDHYA.JS26570112024-07-05 21:35:46 +053049export class K8sActionComponent {
kumaran.m3b4814a2020-05-01 19:48:54 +053050 /** To inject services @public */
51 public injector: Injector;
52
53 /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */
SANDHYA.JS26570112024-07-05 21:35:46 +053054 public value: K8SCLUSTERDATADISPLAY | K8SREPODATADISPLAY | INFRACONFIGPAYLOAD;
kumaran.m3b4814a2020-05-01 19:48:54 +053055
56 /** handle translate @public */
57 public translateService: TranslateService;
58
SANDHYA.JS26570112024-07-05 21:35:46 +053059 /** Contains K8s Type @public */
kumaran.m3b4814a2020-05-01 19:48:54 +053060 public getK8sType: string;
61
SANDHYA.JS26570112024-07-05 21:35:46 +053062 /** Check register page @public */
63 public checkRegister = false;
64
65 /** Contains state @public */
66 public state: string;
67
68 /** Check profile or not @public */
69 public isProfile = false;
70
71 /** Check ksu or not @public */
72 public isKSU = false;
73
74 /** Check cluster or not @public */
75 public isCluster = false;
76
SANDHYA.JS92379ec2025-06-13 17:29:35 +053077 /** Check node group or not @public */
78 public isNode = false;
79
SANDHYA.JSb5347152024-10-15 11:41:45 +053080 /** Check the loading results for loader status @public */
81 public isLoadingDownloadResult: boolean = false;
82
kumaran.m3b4814a2020-05-01 19:48:54 +053083 /** Instance of the modal service @private */
84 private modalService: NgbModal;
85
86 /** Contains all methods related to shared @private */
87 private sharedService: SharedService;
88
89 /** Contains instance ID @private */
SANDHYA.JS92379ec2025-06-13 17:29:35 +053090 private k8sID: string;
91
92 /** Contains instance name @private */
93 private k8sName: string;
kumaran.m3b4814a2020-05-01 19:48:54 +053094
SANDHYA.JSb5347152024-10-15 11:41:45 +053095 /** Utilizes rest service for any CRUD operations @private */
96 private restService: RestService;
97
98 /** Notifier service to popup notification @private */
99 private notifierService: NotifierService;
100
101 /** Detect changes for the User Input */
102 private cd: ChangeDetectorRef;
103
104 /** Set timeout @private */
105 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
106 private timeOut: number = 1000;
107
108 /** Controls the header form @private */
109 private headers: HttpHeaders;
110
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530111 /** Holds teh instance of AuthService class of type AuthService @private */
112 private router: Router;
113
kumaran.m3b4814a2020-05-01 19:48:54 +0530114 constructor(injector: Injector) {
115 this.injector = injector;
116 this.modalService = this.injector.get(NgbModal);
SANDHYA.JSb5347152024-10-15 11:41:45 +0530117 this.notifierService = this.injector.get(NotifierService);
kumaran.m3b4814a2020-05-01 19:48:54 +0530118 this.sharedService = this.injector.get(SharedService);
119 this.translateService = this.injector.get(TranslateService);
SANDHYA.JSb5347152024-10-15 11:41:45 +0530120 this.restService = this.injector.get(RestService);
121 this.cd = this.injector.get(ChangeDetectorRef);
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530122 this.router = this.injector.get(Router);
kumaran.m3b4814a2020-05-01 19:48:54 +0530123 }
124
125 /**
126 * Lifecyle Hooks the trigger before component is instantiate
127 */
128 public ngOnInit(): void {
SANDHYA.JSb5347152024-10-15 11:41:45 +0530129 this.headers = new HttpHeaders({
130 Accept: 'application/zip, application/json',
131 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
132 });
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530133 this.k8sID = this.value.identifier;
134 this.k8sName = this.value.name;
kumaran.m3b4814a2020-05-01 19:48:54 +0530135 this.getK8sType = this.value.pageType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530136 this.state = this.value.state;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530137 if ((this.value.createdbyosm) === 'true') {
SANDHYA.JS26570112024-07-05 21:35:46 +0530138 this.isCluster = true;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530139 } else if ((this.value.createdbyosm) === 'false') {
140 this.isCluster = false;
SANDHYA.JS26570112024-07-05 21:35:46 +0530141 }
142 if (this.getK8sType === 'k8-ksu') {
143 this.isKSU = true;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530144 } else {
145 this.isKSU = false;
146 }
147
148 if (this.getK8sType === 'infra-config' || this.getK8sType === 'infra-controller' || this.getK8sType === 'app-profile' || this.getK8sType === 'resource-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530149 this.isProfile = true;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530150 } else {
SANDHYA.JS26570112024-07-05 21:35:46 +0530151 this.isProfile = false;
152 }
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530153
154 if (this.value.pageType === 'node') {
155 this.isNode = true;
156 } else {
157 this.isNode = false;
158 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530159 }
160
161 /** Delete User Account @public */
SANDHYA.JS52af4802025-05-22 17:00:15 +0530162 public deleteK8s(forceAction: boolean): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530163 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530164 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
SANDHYA.JS52af4802025-05-22 17:00:15 +0530165 modalRef.componentInstance.params = {
166 forceDeleteType: forceAction
167 };
kumaran.m3b4814a2020-05-01 19:48:54 +0530168 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
169 if (result) {
170 this.sharedService.callData();
171 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530172 }).catch((): void => {
173 // Catch Navigation Error
SANDHYA.JS26570112024-07-05 21:35:46 +0530174 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530175 }
176
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530177 /** Details page @public */
178 public nodeK8s(): void {
179 this.router.navigate(['/k8s/details/' + this.k8sID]).catch((): void => {
180 // Catch Navigation Error
181 });
182 }
183
kumaran.m3b4814a2020-05-01 19:48:54 +0530184 /** Shows information using modalservice @public */
185 public infoK8s(pageType: string): void {
186 let pageName: string = '';
187 let title: string = '';
188 if (pageType === 'repo') {
189 pageName = 'k8s-repo';
190 title = 'PAGE.K8S.K8SREPODETAILS';
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530191 } else if (pageType === 'node') {
192 pageName = 'k8s-node';
193 title = 'Node Details';
194 } else if (pageType === 'k8-ksu') {
195 pageName = 'k8s-ksu';
196 title = 'KSU Details';
kumaran.m3b4814a2020-05-01 19:48:54 +0530197 } else {
198 pageName = 'k8s-cluster';
199 title = 'PAGE.K8S.K8SCLUSTERDETAILS';
200 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530201 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530202 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530203 id: this.k8sID,
kumaran.m3b4814a2020-05-01 19:48:54 +0530204 page: pageName,
SANDHYA.JSb772de02024-12-10 15:21:03 +0530205 titleName: title,
206 createdbyosm: this.value.createdbyosm,
207 bootstrap: this.value.bootstrap,
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530208 key: this.value.key,
209 cluster_mode: this.value.cluster_mode,
210 cluster_id: this.value.cluster_id
kumaran.m3b4814a2020-05-01 19:48:54 +0530211 };
212 }
SANDHYA.JS26570112024-07-05 21:35:46 +0530213 /** Edit profile @public */
214 public editProfile(editType: string): void {
215 // eslint-disable-next-line security/detect-non-literal-fs-filename
216 const modalRef: NgbModalRef = this.modalService.open(K8sInfraConfigAddComponent, { backdrop: 'static' });
217 modalRef.componentInstance.profileID = this.value.identifier;
218 modalRef.componentInstance.profileType = editType;
219 modalRef.componentInstance.profileName = this.value.name;
220 modalRef.componentInstance.profileDescription = this.value.description;
221 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
222 if (result) {
223 this.sharedService.callData();
224 }
225 }).catch((): void => {
226 // Catch Navigation Error
227 });
228 }
229
230 /** Edit cluster @public */
231 public editCluster(editType: string): void {
232 // eslint-disable-next-line security/detect-non-literal-fs-filename
233 const modalRef: NgbModalRef = this.modalService.open(K8sAddClusterComponent, { backdrop: 'static' });
234 modalRef.componentInstance.profileID = this.value.identifier;
235 modalRef.componentInstance.profileType = editType;
236 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
237 if (result) {
238 this.sharedService.callData();
239 }
240 }).catch((): void => {
241 // Catch Navigation Error
242 });
243 }
244
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530245 /** Handle Scaling @public */
246 public scaling(editType: string): void {
247 // eslint-disable-next-line security/detect-non-literal-fs-filename
248 const modalRef: NgbModalRef = this.modalService.open(NodeAddComponent, { backdrop: 'static' });
249 modalRef.componentInstance.profileID = this.value.identifier;
250 modalRef.componentInstance.clusterId = this.value.cluster_id;
251 modalRef.componentInstance.profileType = editType;
252 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
253 if (result) {
254 this.sharedService.callData();
255 }
256 }).catch((): void => {
257 // Catch Navigation Error
258 });
259 }
260
SANDHYA.JS26570112024-07-05 21:35:46 +0530261
262 /** Edit profile under cluster @public */
263 public editClusterProfile(editType: string): void {
264 // eslint-disable-next-line security/detect-non-literal-fs-filename
265 const modalRef: NgbModalRef = this.modalService.open(K8sAttachProfileComponent, { backdrop: 'static' });
266 modalRef.componentInstance.profileID = this.value.identifier;
267 modalRef.componentInstance.profileType = editType;
268 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
269 if (result) {
270 this.sharedService.callData();
271 }
272 }).catch((): void => {
273 // Catch Navigation Error
274 });
275 }
276
277 /** Move KSU @public */
278 public moveKsu(): void {
279 // eslint-disable-next-line security/detect-non-literal-fs-filename
280 const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' });
281 modalRef.componentInstance.profileID = this.value.identifier;
282 modalRef.componentInstance.profileType = 'move';
283 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
284 if (result) {
285 this.sharedService.callData();
286 }
287 }).catch((): void => {
288 // Catch Navigation Error
289 });
290 }
291
292 /** Edit KSU @public */
293 public editKsu(): void {
294 // eslint-disable-next-line security/detect-non-literal-fs-filename
295 const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' });
296 modalRef.componentInstance.profileID = this.value.identifier;
297 modalRef.componentInstance.profileType = 'edit';
298 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
299 if (result) {
300 this.sharedService.callData();
301 }
302 }).catch((): void => {
303 // Catch Navigation Error
304 });
305 }
306
SANDHYA.JSb5347152024-10-15 11:41:45 +0530307 /** Download credentials @public */
308 public getCredentials(): void {
309 this.isLoadingDownloadResult = true;
310 const httpOptions: GETAPIURLHEADER = {
311 headers: this.headers,
312 responseType: 'blob'
313 };
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530314 this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.k8sID + '/get_creds')
SANDHYA.JSb5347152024-10-15 11:41:45 +0530315 .subscribe((res: { op_id: string }) => {
316 if (!isNullOrUndefined(res.op_id)) {
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530317 this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.k8sID + '/get_creds_file' + '/' + res.op_id, httpOptions)
SANDHYA.JSb5347152024-10-15 11:41:45 +0530318 .subscribe((response: Blob) => {
319 this.isLoadingDownloadResult = true;
320 if (!isNullOrUndefined(response)) {
321 this.isLoadingDownloadResult = false;
322 const binaryData: Blob[] = [];
323 binaryData.push(response);
324 this.sharedService.downloadFiles(this.value.name, binaryData, response.type);
325 this.isLoadingDownloadResult = false;
326 this.changeDetactionforDownload();
327 }
328 }, (error: ERRORDATA) => {
329 this.isLoadingDownloadResult = false;
330 this.notifierService.notify('error', this.translateService.instant('ERROR'));
331 this.changeDetactionforDownload();
332 if (typeof error.error === 'object') {
333 error.error.text().then((data: string): void => {
334 error.error = JSON.parse(data);
335 this.restService.handleError(error, 'getBlob');
336 });
337 }
338 });
339 }
340 }, (error: ERRORDATA) => {
341 this.isLoadingDownloadResult = false;
342 this.restService.handleError(error, 'get');
343 });
344 }
345
SANDHYA.JS26570112024-07-05 21:35:46 +0530346 /** Clone KSU @public */
347 public cloneKsu(): void {
348 // eslint-disable-next-line security/detect-non-literal-fs-filename
349 const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' });
350 modalRef.componentInstance.profileID = this.value.identifier;
351 modalRef.componentInstance.profileType = 'clone';
352 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
353 if (result) {
354 this.sharedService.callData();
355 }
356 }).catch((): void => {
357 // Catch Navigation Error
358 });
359 }
SANDHYA.JSb5347152024-10-15 11:41:45 +0530360
361 /** Change the detaction @public */
362 public changeDetactionforDownload(): void {
363 setTimeout(() => {
364 this.cd.detectChanges();
365 }, this.timeOut);
366 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530367}