blob: f65712df87698b5874c973353adf0c59845a707b [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.JSb772de02024-12-10 15:21:03 +0530135 this.createdbyosm = data.createdbyosm;
136 this.bootstrap = data.bootstrap;
137 this.key = data.key;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530138 if (!isNullOrUndefined(this.params)) {
139 if (this.params.page === 'instantiateNS') {
140 this.isPage = true;
141 this.title = '';
142 this.createDeleteUrl(data);
143 } else if (this.params.page === 'ns-instance') {
144 this.createDeleteUrl(data);
145 this.isPage = false;
SANDHYA.JS26570112024-07-05 21:35:46 +0530146 } else {
147 this.createTitleandID(data);
148 this.createDeleteUrl(data);
149 this.isPage = false;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530150 }
151 } else {
152 this.createTitleandID(data);
153 this.createDeleteUrl(data);
154 this.isPage = false;
155 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530156 });
157 }
158 /** Generate Title and Id from data @public */
159 public createTitleandID(data: DELETEPARAMS): void {
160 this.title = '';
161 if (data.name !== undefined) {
162 this.title = data.name;
kumaran.m3b4814a2020-05-01 19:48:54 +0530163 } else if (data.projectName !== undefined) {
164 this.title = data.projectName;
165 this.id = this.title;
166 } else if (data.userName !== undefined) {
167 this.title = data.userName;
168 } else if (data.username !== undefined) {
169 this.title = data.username;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530170 } else if (data.productName !== undefined) {
171 this.title = data.productName;
kumaran.m3b4814a2020-05-01 19:48:54 +0530172 }
173 }
174 /** Generate Delete url from data @public */
SANDHYA.JS26570112024-07-05 21:35:46 +0530175 // eslint-disable-next-line complexity
kumaran.m3b4814a2020-05-01 19:48:54 +0530176 public createDeleteUrl(data: DELETEPARAMS): void {
177 this.deleteURL = '';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530178 if (!isNullOrUndefined(this.params)) {
179 if (this.params.page === 'ns-instance') {
180 this.deleteURL = environment.NSINSTANCESCONTENT_URL;
181 this.forceDelete = this.params.forceDeleteType;
182 this.title = this.params.name;
183 this.id = this.params.id;
184 } else if (this.params.page === 'instantiateNS') {
185 this.deleteURL = environment.NSINSTANCESTERMINATE_URL;
186 this.notifyMessage = 'DELETEDSUCCESSFULLY';
187 }
188 }
189 if (data.page === 'ns-package') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530190 this.deleteURL = environment.NSDESCRIPTORSCONTENT_URL;
191 this.notifyMessage = 'DELETEDSUCCESSFULLY';
192 } else if (data.page === 'vnf-package') {
193 this.deleteURL = environment.VNFPACKAGESCONTENT_URL;
194 this.notifyMessage = 'DELETEDSUCCESSFULLY';
195 } else if (data.page === 'vim-account') {
196 this.deleteURL = environment.VIMACCOUNTS_URL;
197 this.notifyMessage = 'DELETEDSUCCESSFULLY';
198 } else if (data.page === 'wim-account') {
199 this.deleteURL = environment.WIMACCOUNTS_URL;
200 this.notifyMessage = 'DELETEDSUCCESSFULLY';
201 } else if (data.page === 'projects') {
202 this.deleteURL = environment.PROJECTS_URL;
203 this.notifyMessage = 'DELETEDSUCCESSFULLY';
204 this.id = data.id;
205 } else if (data.page === 'users') {
206 this.deleteURL = environment.USERS_URL;
207 this.notifyMessage = 'DELETEDSUCCESSFULLY';
208 } else if (data.page === 'network-slice') {
209 this.deleteURL = environment.NETWORKSLICETEMPLATECONTENT_URL;
210 this.notifyMessage = 'DELETEDSUCCESSFULLY';
211 } else if (data.page === 'net-slice-instance') {
212 this.deleteURL = environment.NETWORKSLICEINSTANCESCONTENT_URL;
213 this.forceDelete = this.params.forceDeleteType;
214 } else if (data.page === 'roles') {
215 this.deleteURL = environment.ROLES_URL;
216 this.notifyMessage = 'DELETEDSUCCESSFULLY';
217 } else if (data.page === 'pdu-instances') {
218 this.deleteURL = environment.PDUINSTANCE_URL;
219 } else if (data.page === 'sdn-controller') {
220 this.deleteURL = environment.SDNCONTROLLER_URL;
221 this.notifyMessage = 'DELETEDSUCCESSFULLY';
kumaran.m3b4814a2020-05-01 19:48:54 +0530222 } else if (data.page === 'k8-repo') {
223 this.deleteURL = environment.K8REPOS_URL;
224 this.notifyMessage = 'DELETEDSUCCESSFULLY';
Barath Kumar R403234e2020-07-07 15:48:58 +0530225 } else if (data.page === 'osmrepo') {
226 this.deleteURL = environment.OSMREPOS_URL;
227 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS07decc02024-07-01 21:50:48 +0530228 } else if (data.page === 'ns-config-template') {
229 this.deleteURL = environment.NSCONFIGTEMPLATE_URL;
230 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS26570112024-07-05 21:35:46 +0530231 } else if (data.page === 'k8-infra-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530232 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530233 this.deleteURL = environment.K8SINFRACONFIGPROFILE_URL;
234 } else if (data.page === 'k8-infra-controller') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530235 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530236 this.deleteURL = environment.K8SINFRACONTROLLERPROFILE_URL;
237 } else if (data.page === 'k8-app-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530238 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530239 this.deleteURL = environment.K8SAPPPROFILE_URL;
240 } else if (data.page === 'k8-resource-profile') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530241 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530242 this.deleteURL = environment.K8SRESOURCEPROFILE_URL;
243 } else if (data.page === 'oka-packages') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530244 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530245 this.deleteURL = environment.OKAPACKAGES_URL;
246 } else if (data.page === 'k8-ksu') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530247 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530248 this.deleteURL = environment.KSU_URL;
249 } else if (data.page === 'k8-cluster') {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530250 this.forceDelete = this.params.forceDeleteType;
SANDHYA.JS26570112024-07-05 21:35:46 +0530251 this.page = data.page;
kumaran.m3b4814a2020-05-01 19:48:54 +0530252 }
253 }
254 /** Generate Data function @public */
255 public deleteData(): void {
256 this.isLoadingResults = true;
257 const modalData: MODALCLOSERESPONSEDATA = {
258 message: 'Done'
259 };
260 let deletingURl: string = '';
261 if (this.forceDelete) {
SANDHYA.JS52af4802025-05-22 17:00:15 +0530262 if (this.page === 'k8-cluster') {
263 if (this.createdbyosm === 'true') {
264 this.deleteURL = environment.K8SCREATECLUSTER_URL;
265 }
266 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530267 deletingURl = this.deleteURL + '/' + this.id + '?FORCE=true';
268 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JSb772de02024-12-10 15:21:03 +0530269 } else if (this.page === 'k8-cluster') {
270 if (this.createdbyosm === 'true') {
271 this.deleteURL = environment.K8SCREATECLUSTER_URL;
272 deletingURl = this.deleteURL + '/' + this.id;
273 } else {
274 if (this.bootstrap === false && this.key === true) {
275 this.deleteURL = environment.K8SCLUSTER_URL;
276 deletingURl = this.deleteURL + '/' + this.id;
277 } else if (this.bootstrap === false && this.key === false) {
278 this.deleteURL = environment.K8SCREATECLUSTER_URL;
279 deletingURl = this.deleteURL + '/' + this.id + '/deregister';
280 }
281 else if (this.bootstrap === true) {
282 this.deleteURL = environment.K8SCREATECLUSTER_URL;
283 deletingURl = this.deleteURL + '/' + this.id + '/deregister';
284 }
285 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530286 } else {
287 deletingURl = this.deleteURL + '/' + this.id;
288 }
289 this.restService.deleteResource(deletingURl).subscribe((res: {}) => {
290 this.activeModal.close(modalData);
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530291 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title }));
kumaran.m3b4814a2020-05-01 19:48:54 +0530292 }, (error: ERRORDATA) => {
293 this.isLoadingResults = false;
294 this.restService.handleError(error, 'delete');
295 }, () => {
296 this.isLoadingResults = false;
297 });
298 }
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530299
300 /** terminate multiple ns instances function @public */
301 public terminate(): void {
302 this.isLoadingResults = true;
303 const modalData: MODALCLOSERESPONSEDATA = {
304 message: 'Done'
305 };
306 const idData: string[] = [];
307 this.params.identifierList.forEach((data: DELETEPARAMS) => {
308 idData.push(data.identifier);
309 });
310 if (idData.length > this.noOfInstances) {
311 this.activeModal.close(modalData);
312 this.notifierService.notify('warning', this.translateService.instant('WARNINGMESSAGE'));
313 } else {
314 const postData: {} = {
315 ns_ids: idData
316 };
317 let deletingURl: string = '';
318 deletingURl = this.deleteURL;
319 this.notifyMessage = 'DELETELOADMESSAGE';
320 const apiURLHeader: APIURLHEADER = {
321 url: deletingURl,
322 httpOptions: { headers: this.headers }
323 };
324 this.restService.postResource(apiURLHeader, postData).subscribe(() => {
325 this.activeModal.close(modalData);
326 this.isLoadingResults = false;
327 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage));
328 }, (error: ERRORDATA) => {
329 this.isLoadingResults = false;
330 this.restService.handleError(error, 'post');
331 }, () => {
332 this.isLoadingResults = false;
333 });
334 }
335 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530336}