| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 21 | import { HttpHeaders } from '@angular/common/http'; |
| 22 | import { Component, Injector, Input } from '@angular/core'; |
| 23 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
| 24 | import { TranslateService } from '@ngx-translate/core'; |
| 25 | import { NotifierService } from 'angular-notifier'; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 26 | import { APIURLHEADER, DELETEPARAMS, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 27 | import { DataService } from 'DataService'; |
| 28 | import { environment } from 'environment'; |
| 29 | import { RestService } from 'RestService'; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 30 | import { isNullOrUndefined } from 'SharedService'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 31 | |
| 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 */ |
| 42 | export 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.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 58 | /** Check the page @public */ |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame] | 59 | public isPage = false; |
| 60 | |
| 61 | /** Check the register page @public */ |
| 62 | public isRegisterPage = false; |
| 63 | |
| 64 | /** contain page @public */ |
| 65 | public page: string; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 66 | |
| 67 | /** Number of instances @public */ |
| 68 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| SANDHYA.JS | b772de0 | 2024-12-10 15:21:03 +0530 | [diff] [blame^] | 69 | public noOfInstances: number = 10; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 70 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 71 | /** 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.JS | b772de0 | 2024-12-10 15:21:03 +0530 | [diff] [blame^] | 77 | /** Check whether cluster is credated or registered @public */ |
| 78 | public createdbyosm: string; |
| 79 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 80 | /** 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.JS | b772de0 | 2024-12-10 15:21:03 +0530 | [diff] [blame^] | 89 | /** contsians bootstrap value @private */ |
| 90 | private bootstrap: boolean; |
| 91 | |
| 92 | /** Check whether cluster is registered or not @private */ |
| 93 | private key: boolean; |
| 94 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 95 | /** 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.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame] | 132 | if (sessionStorage.getItem('clusterType') === 'Registered') { |
| 133 | this.isRegisterPage = true; |
| 134 | } |
| SANDHYA.JS | b772de0 | 2024-12-10 15:21:03 +0530 | [diff] [blame^] | 135 | this.createdbyosm = data.createdbyosm; |
| 136 | this.bootstrap = data.bootstrap; |
| 137 | this.key = data.key; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 138 | 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.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame] | 146 | } else { |
| 147 | this.createTitleandID(data); |
| 148 | this.createDeleteUrl(data); |
| 149 | this.isPage = false; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 150 | } |
| 151 | } else { |
| 152 | this.createTitleandID(data); |
| 153 | this.createDeleteUrl(data); |
| 154 | this.isPage = false; |
| 155 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 156 | }); |
| 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.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 163 | } 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 R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 170 | } else if (data.productName !== undefined) { |
| 171 | this.title = data.productName; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | /** Generate Delete url from data @public */ |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame] | 175 | // eslint-disable-next-line complexity |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 176 | public createDeleteUrl(data: DELETEPARAMS): void { |
| 177 | this.deleteURL = ''; |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 178 | 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.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 190 | 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.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 222 | } else if (data.page === 'k8-repo') { |
| 223 | this.deleteURL = environment.K8REPOS_URL; |
| 224 | this.notifyMessage = 'DELETEDSUCCESSFULLY'; |
| Barath Kumar R | 403234e | 2020-07-07 15:48:58 +0530 | [diff] [blame] | 225 | } else if (data.page === 'osmrepo') { |
| 226 | this.deleteURL = environment.OSMREPOS_URL; |
| 227 | this.notifyMessage = 'DELETEDSUCCESSFULLY'; |
| SANDHYA.JS | 07decc0 | 2024-07-01 21:50:48 +0530 | [diff] [blame] | 228 | } else if (data.page === 'ns-config-template') { |
| 229 | this.deleteURL = environment.NSCONFIGTEMPLATE_URL; |
| 230 | this.notifyMessage = 'DELETEDSUCCESSFULLY'; |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame] | 231 | } else if (data.page === 'k8-infra-profile') { |
| 232 | this.deleteURL = environment.K8SINFRACONFIGPROFILE_URL; |
| 233 | } else if (data.page === 'k8-infra-controller') { |
| 234 | this.deleteURL = environment.K8SINFRACONTROLLERPROFILE_URL; |
| 235 | } else if (data.page === 'k8-app-profile') { |
| 236 | this.deleteURL = environment.K8SAPPPROFILE_URL; |
| 237 | } else if (data.page === 'k8-resource-profile') { |
| 238 | this.deleteURL = environment.K8SRESOURCEPROFILE_URL; |
| 239 | } else if (data.page === 'oka-packages') { |
| 240 | this.deleteURL = environment.OKAPACKAGES_URL; |
| 241 | } else if (data.page === 'k8-ksu') { |
| 242 | this.deleteURL = environment.KSU_URL; |
| 243 | } else if (data.page === 'k8-cluster') { |
| 244 | this.page = data.page; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | /** Generate Data function @public */ |
| 248 | public deleteData(): void { |
| 249 | this.isLoadingResults = true; |
| 250 | const modalData: MODALCLOSERESPONSEDATA = { |
| 251 | message: 'Done' |
| 252 | }; |
| 253 | let deletingURl: string = ''; |
| 254 | if (this.forceDelete) { |
| 255 | deletingURl = this.deleteURL + '/' + this.id + '?FORCE=true'; |
| 256 | this.notifyMessage = 'DELETEDSUCCESSFULLY'; |
| SANDHYA.JS | b772de0 | 2024-12-10 15:21:03 +0530 | [diff] [blame^] | 257 | } else if (this.page === 'k8-cluster') { |
| 258 | if (this.createdbyosm === 'true') { |
| 259 | this.deleteURL = environment.K8SCREATECLUSTER_URL; |
| 260 | deletingURl = this.deleteURL + '/' + this.id; |
| 261 | } else { |
| 262 | if (this.bootstrap === false && this.key === true) { |
| 263 | this.deleteURL = environment.K8SCLUSTER_URL; |
| 264 | deletingURl = this.deleteURL + '/' + this.id; |
| 265 | } else if (this.bootstrap === false && this.key === false) { |
| 266 | this.deleteURL = environment.K8SCREATECLUSTER_URL; |
| 267 | deletingURl = this.deleteURL + '/' + this.id + '/deregister'; |
| 268 | } |
| 269 | else if (this.bootstrap === true) { |
| 270 | this.deleteURL = environment.K8SCREATECLUSTER_URL; |
| 271 | deletingURl = this.deleteURL + '/' + this.id + '/deregister'; |
| 272 | } |
| 273 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 274 | } else { |
| 275 | deletingURl = this.deleteURL + '/' + this.id; |
| 276 | } |
| 277 | this.restService.deleteResource(deletingURl).subscribe((res: {}) => { |
| 278 | this.activeModal.close(modalData); |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 279 | this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title })); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 280 | }, (error: ERRORDATA) => { |
| 281 | this.isLoadingResults = false; |
| 282 | this.restService.handleError(error, 'delete'); |
| 283 | }, () => { |
| 284 | this.isLoadingResults = false; |
| 285 | }); |
| 286 | } |
| SANDHYA.JS | 8ead52b | 2024-06-10 18:23:41 +0530 | [diff] [blame] | 287 | |
| 288 | /** terminate multiple ns instances function @public */ |
| 289 | public terminate(): void { |
| 290 | this.isLoadingResults = true; |
| 291 | const modalData: MODALCLOSERESPONSEDATA = { |
| 292 | message: 'Done' |
| 293 | }; |
| 294 | const idData: string[] = []; |
| 295 | this.params.identifierList.forEach((data: DELETEPARAMS) => { |
| 296 | idData.push(data.identifier); |
| 297 | }); |
| 298 | if (idData.length > this.noOfInstances) { |
| 299 | this.activeModal.close(modalData); |
| 300 | this.notifierService.notify('warning', this.translateService.instant('WARNINGMESSAGE')); |
| 301 | } else { |
| 302 | const postData: {} = { |
| 303 | ns_ids: idData |
| 304 | }; |
| 305 | let deletingURl: string = ''; |
| 306 | deletingURl = this.deleteURL; |
| 307 | this.notifyMessage = 'DELETELOADMESSAGE'; |
| 308 | const apiURLHeader: APIURLHEADER = { |
| 309 | url: deletingURl, |
| 310 | httpOptions: { headers: this.headers } |
| 311 | }; |
| 312 | this.restService.postResource(apiURLHeader, postData).subscribe(() => { |
| 313 | this.activeModal.close(modalData); |
| 314 | this.isLoadingResults = false; |
| 315 | this.notifierService.notify('success', this.translateService.instant(this.notifyMessage)); |
| 316 | }, (error: ERRORDATA) => { |
| 317 | this.isLoadingResults = false; |
| 318 | this.restService.handleError(error, 'post'); |
| 319 | }, () => { |
| 320 | this.isLoadingResults = false; |
| 321 | }); |
| 322 | } |
| 323 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 324 | } |