b5631f329197572a95684dc6ee9693c18c6a465f
[ealt-edge.git] / example-apps / ROBO / RoboUI / src / app / backuprestore / backuprestore.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core';
2
3 import {MatTableDataSource} from '@angular/material/table';
4 import { MatPaginator } from '@angular/material/paginator';
5 import { RoboService } from './../../app/robo.service';
6
7 import { appsinfo,pvpvsinfo,backupsinfo,restoresinfo,backupData,restoreData } from './../../app/datainterface'
8
9 import { ToastrService } from 'ngx-toastr';
10
11 @Component({
12   selector: 'app-backuprestore',
13   templateUrl: './backuprestore.component.html',
14   styleUrls: ['./backuprestore.component.scss']
15 })
16 export class BackuprestoreComponent implements OnInit {
17
18   appsColumns: string [] = ['namespace','name','ready','status','restarts','age','ip','node','nominatednode','readinessgates']
19   appsDataSource = new MatTableDataSource<appsinfo>(APPS_INFO_LIST);
20
21   appsArrayList = [];
22
23   pvsColumns: string [] = ['namespace','name','status','volume','capacity','accessmodes','storageclass','age','volumemode']
24   pvsDataSource = new MatTableDataSource<pvpvsinfo>(PVS_INFO_LIST);
25
26   pvsArrayList = [];
27
28   backupsColumns: string [] = ['name','status','errors','warnings','created']
29   backupsDataSource = new MatTableDataSource<backupsinfo>(BACKUPS_INFO_LIST);
30
31   backupsArrayList = [];
32
33   restoresColumns: string [] = ['name','backup','status']
34   restoresDataSource = new MatTableDataSource<restoresinfo>(RESTORES_INFO_LIST);
35
36   restoresArrayList = [];
37
38   selectedNamespace : string
39   selectedBackupName : string
40
41   selectedRestoreName: string
42   selectedBackupname : string
43
44   appsinfo = {}
45
46   backupData = {} as backupData
47
48   restoreData = {} as restoreData
49
50   @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
51
52   constructor(
53     private roboService: RoboService,
54     private toastService: ToastrService
55     ) {}
56
57   ngOnInit(): void {
58     this.selectedBackupName = "backup01"
59     this.selectedRestoreName = "restore01"
60     this.selectedNamespace = "default"
61     this.selectedBackupname = "backup01"
62
63     this.getAppsPvcs();
64
65     this.getBackupsRestores();
66   }
67
68   getAppsPvcs() {
69     this.roboService.getAppsPvcsInfo()
70       .subscribe(data => {
71       debugger;
72       console.log(data);
73       this.appsinfo = data;
74       this.appsArrayList = data.appsData;
75       this.appsDataSource = new MatTableDataSource(this.appsArrayList);
76       this.appsDataSource.paginator = this.paginator;
77
78       this.pvsArrayList = data.pvcData;
79       this.pvsDataSource = new MatTableDataSource(this.pvsArrayList);
80       this.pvsDataSource.paginator = this.paginator;
81      },
82      error => console.log(error)); 
83   }
84
85   getBackupsRestores() {
86     this.roboService.getBackupRestoreInfo()
87       .subscribe(data => {
88       debugger;
89       console.log(data);
90       this.appsinfo = data;
91       this.backupsArrayList = data.backupsData;
92       this.backupsDataSource = new MatTableDataSource(this.backupsArrayList);
93       this.backupsDataSource.paginator = this.paginator;
94
95       this.restoresArrayList = data.restoresData;
96       this.restoresDataSource = new MatTableDataSource(this.restoresArrayList);
97       this.restoresDataSource.paginator = this.paginator;
98      },
99      error => console.log(error));
100   }
101
102   refreshPage() {
103     debugger;
104     this.getBackupsRestores();
105     this.getAppsPvcs();
106   }
107
108   postBackup() {
109     console.log("Inside postBackup.....")
110     this.backupData.backupName = this.selectedBackupName;
111     this.backupData.namespace = this.selectedNamespace;
112     this.showBackupSuccess()
113     this.roboService.postBackup(this.backupData)
114     .subscribe(data => {
115       debugger;
116       if(data.responce == "success"){
117         this.showBackupSuccess();
118       }
119       console.log(data);
120     }
121   ,error => console.log(error)
122   );
123   }
124
125   restore() {
126     console.log("Inside postBackup.....")
127
128     this.restoreData.restoreName = this.selectedRestoreName;
129     this.restoreData.backupName = this.selectedBackupname;
130     this.showRestoreSuccess()
131     this.roboService.postRestore(this.restoreData)
132     .subscribe(data => {
133       debugger;
134       if(data.responce == "success"){
135         this.showRestoreSuccess();
136       }
137       console.log(data);
138     }
139   ,error => console.log(error)
140   );
141   }
142
143   showBackupSuccess() {
144     this.toastService.success('Backup Successful..','Backup Data');
145   }
146
147   showRestoreSuccess() {
148     this.toastService.success('Restore Successful..','Restore Data');
149   }
150
151   simulateDisaster() {
152     console.log("Inside simulateDisaster....")
153     this.roboService.disturbCluster()
154       .subscribe(data => {
155       debugger;
156       console.log(data);
157      },
158      error => console.log(error));
159   }
160
161 }
162
163 const APPS_INFO_LIST: appsinfo[] = [
164   { namespace: '',name: '', ready: '', status: '', restarts: '', age: '', ip: '', node: '', nominatednode: '', readinessgates: '' }
165 ];
166
167 const PVS_INFO_LIST: pvpvsinfo[] = [
168   { namespace: '',name: '', status: '', volume: '', capacity: '', accessmodes: '', storageclass: '', age: '', volumemode: '' }
169 ];
170
171 const BACKUPS_INFO_LIST: backupsinfo[] = [
172   { name: '', status: '', errors: '', warnings: '', created: ''}
173 ];
174
175 const RESTORES_INFO_LIST: restoresinfo[] = [
176   { name: '', backup: '', status: ''}
177 ];
178
179
180 // "zone.js": "~0.10.2"