EG version upgrade to 1.3
[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','status','ip','node']
19   appsDataSource = new MatTableDataSource<appsinfo>(APPS_INFO_LIST);
20
21   appsArrayList: appsinfo [];
22
23   pvsColumns: string [] = ['namespace','name','status','volume','storageclass','volumemode']
24   pvsDataSource = new MatTableDataSource<pvpvsinfo>(PVS_INFO_LIST);
25
26   pvsArrayList : pvpvsinfo [];
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       debugger;
76       this.appsDataSource = new MatTableDataSource(this.appsArrayList);
77       this.appsDataSource.paginator = this.paginator;
78
79       this.pvsArrayList = data.pvcData;
80       this.pvsDataSource = new MatTableDataSource(this.pvsArrayList);
81       this.pvsDataSource.paginator = this.paginator;
82      },
83      error => console.log(error)); 
84   }
85
86   getBackupsRestores() {
87     this.roboService.getBackupRestoreInfo()
88       .subscribe(data => {
89       debugger;
90       console.log(data);
91       this.appsinfo = data;
92       this.backupsArrayList = data.backupsData;
93       this.backupsDataSource = new MatTableDataSource(this.backupsArrayList);
94       this.backupsDataSource.paginator = this.paginator;
95
96       this.restoresArrayList = data.restoresData;
97       this.restoresDataSource = new MatTableDataSource(this.restoresArrayList);
98       this.restoresDataSource.paginator = this.paginator;
99      },
100      error => console.log(error));
101   }
102
103   refreshPage() {
104     debugger;
105     this.getBackupsRestores();
106     this.getAppsPvcs();
107   }
108
109   postBackup() {
110     console.log("Inside postBackup.....")
111     this.backupData.backupName = this.selectedBackupName;
112     this.backupData.namespace = this.selectedNamespace;
113     this.showBackupSuccess()
114     this.roboService.postBackup(this.backupData)
115     .subscribe(data => {
116       debugger;
117       if(data.responce == "success"){
118         this.showBackupSuccess();
119       }
120       console.log(data);
121     }
122   ,error => console.log(error)
123   );
124   }
125
126   restore() {
127     console.log("Inside postBackup.....")
128
129     this.restoreData.restoreName = this.selectedRestoreName;
130     this.restoreData.backupName = this.selectedBackupname;
131     this.showRestoreSuccess()
132     this.roboService.postRestore(this.restoreData)
133     .subscribe(data => {
134       debugger;
135       if(data.responce == "success"){
136         this.showRestoreSuccess();
137       }
138       console.log(data);
139     }
140   ,error => console.log(error)
141   );
142   }
143
144   showBackupSuccess() {
145     this.toastService.success('Backup Successful..','Backup Data');
146   }
147
148   showRestoreSuccess() {
149     this.toastService.success('Restore Successful..','Restore Data');
150   }
151
152   simulateDisaster() {
153     console.log("Inside simulateDisaster....")
154     this.roboService.disturbCluster()
155       .subscribe(data => {
156       debugger;
157       console.log(data);
158      },
159      error => console.log(error));
160   }
161
162 }
163
164 const APPS_INFO_LIST: appsinfo[] = [
165   { namespace: '',name: '', status: '', ip: '', node: ''}
166 ];
167
168 const PVS_INFO_LIST: pvpvsinfo[] = [
169   { namespace: '',name: '', status: '', volume: '', storageclass: '', volumemode: '' }
170 ];
171
172 const BACKUPS_INFO_LIST: backupsinfo[] = [
173   { name: '', status: '', errors: '', warnings: '', created: ''}
174 ];
175
176 const RESTORES_INFO_LIST: restoresinfo[] = [
177   { name: '', backup: '', status: ''}
178 ];
179
180
181 // "zone.js": "~0.10.2"