Add undeploy xApp function
[portal/ric-dashboard.git] / webapp-frontend / src / app / control / control.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { Component, OnInit, ViewEncapsulation } from '@angular/core';
21 import { LocalDataSource } from 'ng2-smart-table';
22 import { ControlService } from '../services/control/control.service';
23 import { Router } from '@angular/router';
24 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service'
25 import { NotificationService } from './../services/ui/notification.service'
26
27
28 @Component({
29   selector: 'app-control',
30   templateUrl: './control.component.html',
31   styleUrls: ['./control.component.css'],
32   encapsulation: ViewEncapsulation.Emulated,
33 })
34 export class ControlComponent {
35
36   settings = {
37     hideSubHeader: true,
38     actions: {
39       columnTitle: 'Actions',
40       add: false,
41       edit: false,
42       delete: false,
43       custom: [
44         { name: 'view', title: '<i class="material-icons">visibility</i>', },
45         { name: 'undeploy', title: '<i class="material-icons red-close">close</i>', },
46       ],
47       position: 'right'
48
49     },
50     columns: {
51       xapp: {
52         title: 'xApp Name',
53         type: 'string',
54       },
55       name: {
56         title: 'Instance Name',
57         type: 'string',
58       },
59       status: {
60         title: 'Status',
61         type: 'string',
62       },
63       ip: {
64         title: 'IP',
65         type: 'string',
66       },
67       port: {
68         title: 'Port',
69         type: 'integer',
70       },
71       txMessages: {
72         title: 'txMessages',
73         type: 'array',
74       },
75       rxMessages: {
76         title: 'rxMessages',
77         type: 'array',
78       },
79     },
80   };
81
82   source: LocalDataSource = new LocalDataSource();
83
84   constructor(
85     private service: ControlService,
86     private router: Router,
87     private confirmDialogService: ConfirmDialogService,
88     private notification: NotificationService) {
89     this.service.getxAppInstances((instances) => { this.source.load(instances); });
90   }
91
92   onxAppControlAction(event) {
93     switch (event.action) {
94       case 'view':
95         this.view(event);
96         break;
97       case 'undeploy':
98         this.undeploy(event);
99         break;
100     }
101   }
102
103   view(event): void {
104     const url = '/xapp';
105     this.router.navigate([url, event]);
106   }
107
108   undeploy(event): void {
109     this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy this xApp ?')
110       .afterClosed().subscribe(res => {
111         if (res) {
112           this.service.undeployxApp(event.data.xapp).subscribe(
113             response => {
114               this.service.getxAppInstances((instances) => { this.source.load(instances); });
115               switch (response.status) {
116                 case 200:
117                   this.notification.success('xApp undeployed successfully!');
118                   break;
119                 default:
120                   this.notification.warn('xApp undeploy failed.');
121               }
122             }
123           );
124         }
125       });
126   }
127
128
129 }