blob: a54b67e91e9e6afe4a556f2dac12e07bc2548c9b [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 Delete Model
20 */
21import { HttpHeaders } from '@angular/common/http';
22import { Component, Injector, Input } from '@angular/core';
23import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24import { TranslateService } from '@ngx-translate/core';
25import { NotifierService } from 'angular-notifier';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053026import { APIURLHEADER, DELETEPARAMS, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { DataService } from 'DataService';
28import { environment } from 'environment';
29import { RestService } from 'RestService';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053030import { isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053031
32/**
33 * Creating component
34 * @Component takes DeleteComponent.html as template url
35 */
36@Component({
37 selector: 'app-delete',
38 templateUrl: './DeleteComponent.html',
39 styleUrls: ['./DeleteComponent.scss']
40})
41/** Exporting a class @exports DeleteComponent */
42export class DeleteComponent {
43 /** To inject services @public */
44 public injector: Injector;
45
46 /** Instance for active modal service @public */
47 public activeModal: NgbActiveModal;
48
49 /** Instance of the modal service @public */
50 public title: string;
51
52 /** Show the Delete Ok button to trigger the terminate and delete */
53 public forceDelete: boolean = false;
54
55 /** Check the loading results @public */
56 public isLoadingResults: Boolean = false;
57
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053058 /** Check the page @public */
SANDHYA.JS26570112024-07-05 21:35:46 +053059 public isPage = false;
60
61 /** Check the register page @public */
62 public isRegisterPage = false;
63
64 /** contain page @public */
65 public page: string;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053066
67 /** Number of instances @public */
68 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
SANDHYA.JSb772de02024-12-10 15:21:03 +053069 public noOfInstances: number = 10;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053070
kumaran.m3b4814a2020-05-01 19:48:54 +053071 /** Give the message for the loading @public */
72 public notifyMessage: string = 'DELETELOADERMESSAGE';
73
74 /** Give the message for the loading @public */
75 public message: string = 'PLEASEWAIT';
76
SANDHYA.JSb772de02024-12-10 15:21:03 +053077 /** Check whether cluster is credated or registered @public */
78 public createdbyosm: string;
79
kumaran.m3b4814a2020-05-01 19:48:54 +053080 /** DataService to pass the data from one component to another @private */
81 private dataService: DataService;
82
83 /** Instance of the rest service @private */
84 private restService: RestService;
85
86 /** Instance of the modal service @private */
87 private id: string;
88
SANDHYA.JSb772de02024-12-10 15:21:03 +053089 /** contsians bootstrap value @private */
90 private bootstrap: boolean;
91
92 /** Check whether cluster is registered or not @private */
93 private key: boolean;
94
kumaran.m3b4814a2020-05-01 19:48:54 +053095 /** Variables holds url to be delete @private */
96 private deleteURL: string;
97
98 /** Controls the header form @private */
99 private headers: HttpHeaders;
100
101 /** Input contains component objects @private */
102 @Input() private params: URLPARAMS;
103
104 /** Notifier service to popup notification @private */
105 private notifierService: NotifierService;
106
107 /** Contains tranlsate instance @private */
108 private translateService: TranslateService;
109
110 constructor(injector: Injector) {
111 this.injector = injector;
112 this.restService = this.injector.get(RestService);
113 this.dataService = this.injector.get(DataService);
114 this.activeModal = this.injector.get(NgbActiveModal);
115 this.notifierService = this.injector.get(NotifierService);
116 this.translateService = this.injector.get(TranslateService);
117 }
118
119 /**
120 * Lifecyle Hooks the trigger before component is instantiate
121 */
122 public ngOnInit(): void {
123 this.headers = new HttpHeaders({
124 'Content-Type': 'application/json',
125 Accept: 'application/json',
126 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
127 });
128 this.dataService.currentMessage.subscribe((data: DELETEPARAMS) => {
129 if (data.identifier !== undefined || data.identifier !== '' || data.identifier !== null) {
130 this.id = data.identifier;
131 }
SANDHYA.JS26570112024-07-05 21:35:46 +0530132 if (sessionStorage.getItem('clusterType') === 'Registered') {
133 this.isRegisterPage = true;
134 }
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530135 if (data.createdbyosm === 'NO' || data.createdbyosm === 'false') {
136 this.createdbyosm = 'false';
137 } else {
138 this.createdbyosm = 'true';
139 }
SANDHYA.JSb772de02024-12-10 15:21:03 +0530140 this.bootstrap = data.bootstrap;
141 this.key = data.key;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530142 if (!isNullOrUndefined(this.params)) {
143 if (this.params.page === 'instantiateNS') {
144 this.isPage = true;
145 this.title = '';
146 this.createDeleteUrl(data);
147 } else if (this.params.page === 'ns-instance') {
148 this.createDeleteUrl(data);
149 this.isPage = false;
SANDHYA.JS26570112024-07-05 21:35:46 +0530150 } else {
151 this.createTitleandID(data);
152 this.createDeleteUrl(data);
153 this.isPage = false;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530154 }
155 } else {
156 this.createTitleandID(data);
157 this.createDeleteUrl(data);
158 this.isPage = false;
159 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530160 });
161 }
162 /** Generate Title and Id from data @public */
163 public createTitleandID(data: DELETEPARAMS): void {
164 this.title = '';
165 if (data.name !== undefined) {
166 this.title = data.name;
kumaran.m3b4814a2020-05-01 19:48:54 +0530167 } else if (data.projectName !== undefined) {
168 this.title = data.projectName;
169 this.id = this.title;
170 } else if (data.userName !== undefined) {
171 this.title = data.userName;
172 } else if (data.username !== undefined) {
173 this.title = data.username;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530174 } else if (data.productName !== undefined) {
175 this.title = data.productName;
kumaran.m3b4814a2020-05-01 19:48:54 +0530176 }
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530177 if (data.createdbyosm === 'NO' || data.createdbyosm === 'false') {
178 this.createdbyosm = 'false';
179 } else {
180 this.createdbyosm = 'true';
181 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530182 }
183 /** Generate Delete url from data @public */
SANDHYA.JS26570112024-07-05 21:35:46 +0530184 // eslint-disable-next-line complexity
kumaran.m3b4814a2020-05-01 19:48:54 +0530185 public createDeleteUrl(data: DELETEPARAMS): void {
186 this.deleteURL = '';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530187 if (!isNullOrUndefined(this.params)) {
188 if (this.params.page === 'ns-instance') {
189 this.deleteURL = environment.NSINSTANCESCONTENT_URL;
190 this.forceDelete = this.params.forceDeleteType;
191 this.title = this.params.name;
192 this.id = this.params.id;
193 } else if (this.params.page === 'instantiateNS') {
194 this.deleteURL = environment.NSINSTANCESTERMINATE_URL;
195 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530196 } else if (this.params.page === 'card-node') {
197 this.title = this.params.name;
198 } else if (this.params.page === 'card-ksu') {
199 this.title = this.params.name;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530200 }
201 }
202 if (data.page === 'ns-package') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530203 this.deleteURL = environment.NSDESCRIPTORSCONTENT_URL;
204 this.notifyMessage = 'DELETEDSUCCESSFULLY';
205 } else if (data.page === 'vnf-package') {
206 this.deleteURL = environment.VNFPACKAGESCONTENT_URL;
207 this.notifyMessage = 'DELETEDSUCCESSFULLY';
208 } else if (data.page === 'vim-account') {
209 this.deleteURL = environment.VIMACCOUNTS_URL;
210 this.notifyMessage = 'DELETEDSUCCESSFULLY';
211 } else if (data.page === 'wim-account') {
212 this.deleteURL = environment.WIMACCOUNTS_URL;
213 this.notifyMessage = 'DELETEDSUCCESSFULLY';
214 } else if (data.page === 'projects') {
215 this.deleteURL = environment.PROJECTS_URL;
216 this.notifyMessage = 'DELETEDSUCCESSFULLY';
217 this.id = data.id;
218 } else if (data.page === 'users') {
219 this.deleteURL = environment.USERS_URL;
220 this.notifyMessage = 'DELETEDSUCCESSFULLY';
221 } else if (data.page === 'network-slice') {
222 this.deleteURL = environment.NETWORKSLICETEMPLATECONTENT_URL;
223 this.notifyMessage = 'DELETEDSUCCESSFULLY';
224 } else if (data.page === 'net-slice-instance') {
225 this.deleteURL = environment.NETWORKSLICEINSTANCESCONTENT_URL;
226 this.forceDelete = this.params.forceDeleteType;
227 } else if (data.page === 'roles') {
228 this.deleteURL = environment.ROLES_URL;
229 this.notifyMessage = 'DELETEDSUCCESSFULLY';
230 } else if (data.page === 'pdu-instances') {
231 this.deleteURL = environment.PDUINSTANCE_URL;
232 } else if (data.page === 'sdn-controller') {
233 this.deleteURL = environment.SDNCONTROLLER_URL;
234 this.notifyMessage = 'DELETEDSUCCESSFULLY';
kumaran.m3b4814a2020-05-01 19:48:54 +0530235 } else if (data.page === 'k8-repo') {
236 this.deleteURL = environment.K8REPOS_URL;
237 this.notifyMessage = 'DELETEDSUCCESSFULLY';
Barath Kumar R403234e2020-07-07 15:48:58 +0530238 } else if (data.page === 'osmrepo') {
239 this.deleteURL = environment.OSMREPOS_URL;
240 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS07decc02024-07-01 21:50:48 +0530241 } else if (data.page === 'ns-config-template') {
242 this.deleteURL = environment.NSCONFIGTEMPLATE_URL;
243 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS26570112024-07-05 21:35:46 +0530244 } else if (data.page === 'k8-infra-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530245 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530246 this.deleteURL = environment.K8SINFRACONFIGPROFILE_URL;
247 } else if (data.page === 'k8-infra-controller') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530248 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530249 this.deleteURL = environment.K8SINFRACONTROLLERPROFILE_URL;
250 } else if (data.page === 'k8-app-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530251 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530252 this.deleteURL = environment.K8SAPPPROFILE_URL;
253 } else if (data.page === 'k8-resource-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530254 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530255 this.deleteURL = environment.K8SRESOURCEPROFILE_URL;
256 } else if (data.page === 'oka-packages') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530257 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530258 this.deleteURL = environment.OKAPACKAGES_URL;
259 } else if (data.page === 'k8-ksu') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530260 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530261 this.deleteURL = environment.KSU_URL;
262 } else if (data.page === 'k8-cluster') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530263 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530264 this.page = data.page;
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530265 } else if (data.page === 'k8s-node') {
266 this.deleteURL = environment.K8SCREATECLUSTER_URL + '/' + data.cluster_id + '/node';
kumaran.m3b4814a2020-05-01 19:48:54 +0530267 }
268 }
269 /** Generate Data function @public */
270 public deleteData(): void {
271 this.isLoadingResults = true;
272 const modalData: MODALCLOSERESPONSEDATA = {
273 message: 'Done'
274 };
275 let deletingURl: string = '';
276 if (this.forceDelete) {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530277 if (this.page === 'k8-cluster') {
278 if (this.createdbyosm === 'true') {
279 this.deleteURL = environment.K8SCREATECLUSTER_URL;
280 }
281 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530282 deletingURl = this.deleteURL + '/' + this.id + '?FORCE=true';
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530283 this.notifyMessage = 'DELETELOADMESSAGE';
SANDHYA.JSb772de02024-12-10 15:21:03 +0530284 } else if (this.page === 'k8-cluster') {
285 if (this.createdbyosm === 'true') {
286 this.deleteURL = environment.K8SCREATECLUSTER_URL;
287 deletingURl = this.deleteURL + '/' + this.id;
288 } else {
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530289 if (this.key === false) {
290 this.deleteURL = environment.K8SCREATECLUSTER_URL;
291 deletingURl = this.deleteURL + '/' + this.id + '/deregister';
292 } else if (this.key === true) {
SANDHYA.JSb772de02024-12-10 15:21:03 +0530293 this.deleteURL = environment.K8SCLUSTER_URL;
294 deletingURl = this.deleteURL + '/' + this.id;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530295 }
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530296 }
297 } else if (!isNullOrUndefined(this.params)) {
298 if (this.params.page === 'card-node') {
299 this.createdbyosm = 'true';
300 deletingURl = environment.K8SCREATECLUSTER_URL + '/' + this.params.cluster_id + '/nodegroup' + '/' + this.params.id;
301 } else if (this.params.page === 'card-ksu') {
302 deletingURl = environment.KSU_URL + '/' + this.params.id;
SANDHYA.JSb772de02024-12-10 15:21:03 +0530303 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530304 } else {
305 deletingURl = this.deleteURL + '/' + this.id;
306 }
307 this.restService.deleteResource(deletingURl).subscribe((res: {}) => {
308 this.activeModal.close(modalData);
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530309 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title }));
kumaran.m3b4814a2020-05-01 19:48:54 +0530310 }, (error: ERRORDATA) => {
311 this.isLoadingResults = false;
312 this.restService.handleError(error, 'delete');
313 }, () => {
314 this.isLoadingResults = false;
315 });
316 }
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530317
318 /** terminate multiple ns instances function @public */
319 public terminate(): void {
320 this.isLoadingResults = true;
321 const modalData: MODALCLOSERESPONSEDATA = {
322 message: 'Done'
323 };
324 const idData: string[] = [];
325 this.params.identifierList.forEach((data: DELETEPARAMS) => {
326 idData.push(data.identifier);
327 });
328 if (idData.length > this.noOfInstances) {
329 this.activeModal.close(modalData);
330 this.notifierService.notify('warning', this.translateService.instant('WARNINGMESSAGE'));
331 } else {
332 const postData: {} = {
333 ns_ids: idData
334 };
335 let deletingURl: string = '';
336 deletingURl = this.deleteURL;
337 this.notifyMessage = 'DELETELOADMESSAGE';
338 const apiURLHeader: APIURLHEADER = {
339 url: deletingURl,
340 httpOptions: { headers: this.headers }
341 };
342 this.restService.postResource(apiURLHeader, postData).subscribe(() => {
343 this.activeModal.close(modalData);
344 this.isLoadingResults = false;
345 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage));
346 }, (error: ERRORDATA) => {
347 this.isLoadingResults = false;
348 this.restService.handleError(error, 'post');
349 }, () => {
350 this.isLoadingResults = false;
351 });
352 }
353 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530354}