-
Notifications
You must be signed in to change notification settings - Fork 443
/
experiment-details.component.ts
259 lines (220 loc) · 7.32 KB
/
experiment-details.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatTabChangeEvent } from '@angular/material/tabs';
import {
ConfirmDialogService,
DIALOG_RESP,
ExponentialBackoff,
getCondition,
NamespaceService,
ToolbarButton,
} from 'kubeflow';
import { KWABackendService } from '../../services/backend.service';
import { StatusEnum } from '../../enumerations/status.enum';
import { Subscription } from 'rxjs';
import {
numberToExponential,
transformStringResponses,
} from '../../shared/utils';
import { getDeleteDialogConfig } from '../experiments/delete-modal-config';
import { ExperimentK8s } from '../../models/experiment.k8s.model';
@Component({
selector: 'app-experiment-details',
templateUrl: './experiment-details.component.html',
styleUrls: ['./experiment-details.component.scss'],
})
export class ExperimentDetailsComponent implements OnInit, OnDestroy {
name: string;
namespace: string;
columns: string[] = [];
details: string[][] = [];
experimentTrialsCsv: string;
hoveredTrial: number;
experimentDetails: ExperimentK8s;
showGraph: boolean;
bestTrialName: string;
pageLoading = true;
selectedTab = 0;
tabs = new Map<string, number>([
['overview', 0],
['trials', 1],
['details', 2],
['yaml', 3],
]);
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private backendService: KWABackendService,
private confirmDialog: ConfirmDialogService,
private namespaceService: NamespaceService,
) {}
buttonsConfig: ToolbarButton[] = [
new ToolbarButton({
text: 'DELETE',
icon: 'delete',
fn: () => {
this.deleteExperiment(this.name, this.namespace);
},
}),
];
private poller: ExponentialBackoff;
private subs = new Subscription();
ngOnInit() {
this.activatedRoute.params.subscribe(params => {
this.namespaceService.updateSelectedNamespace(params.namespace);
this.name = params.experimentName;
this.namespace = params.namespace;
this.updateExperimentInfo();
});
this.activatedRoute.queryParams.subscribe(queryParams => {
this.selectedTab = this.tabs.get(queryParams.tab);
});
}
tabChanged(event: MatTabChangeEvent) {
this.selectedTab = event.index;
}
ngOnDestroy(): void {
this.subs.unsubscribe();
}
returnToExperiments() {
this.router.navigate(['']);
}
mouseLeftTrial() {
this.hoveredTrial = null;
}
mouseOverTrial = (index: number) => (this.hoveredTrial = index);
private updateExperimentInfo() {
this.backendService
.getExperimentTrialsInfo(this.name, this.namespace)
.subscribe(response => {
this.experimentTrialsCsv = response;
const data = transformStringResponses(response);
this.columns = data.types;
this.details = this.parseTrialsDetails(data.details);
this.showGraph = this.showGraphFn(response);
});
this.backendService
.getExperiment(this.name, this.namespace)
.subscribe((response: ExperimentK8s) => {
this.experimentDetails = response;
this.bestTrialName = response.status.currentOptimalTrial
? response.status.currentOptimalTrial.bestTrialName
: '';
const status = this.experimentStatus(response);
if (
status &&
!(status === StatusEnum.FAILED || status === StatusEnum.SUCCEEDED)
) {
// if the status of the experiment is not succeeded either failed
// then start polling the trials
this.startTrialsPolling();
this.startExperimentsPolling();
}
this.pageLoading = false;
});
}
private deleteExperiment(name: string, namespace: string) {
const deleteDialogConfig = getDeleteDialogConfig(name, namespace);
const ref = this.confirmDialog.open(name, deleteDialogConfig);
const delSub = ref.componentInstance.applying$.subscribe(applying => {
if (!applying) {
return;
}
// Close the open dialog only if the DELETE request succeeded
this.backendService.deleteExperiment(name, namespace).subscribe({
next: _ => {
ref.close(DIALOG_RESP.ACCEPT);
},
error: err => {
deleteDialogConfig.error = err;
ref.componentInstance.applying$.next(false);
},
});
// DELETE request has succeeded
ref.afterClosed().subscribe(res => {
delSub.unsubscribe();
if (res !== DIALOG_RESP.ACCEPT) {
return;
}
this.returnToExperiments();
});
});
}
private startTrialsPolling() {
this.poller = new ExponentialBackoff({
interval: 5000,
retries: 1,
maxInterval: 5001,
});
// Poll for new data and reset the poller if different data is found
this.subs.add(
this.poller.start().subscribe(() => {
this.backendService
.getExperimentTrialsInfo(this.name, this.namespace)
.subscribe(trials => {
this.experimentTrialsCsv = trials;
const data = transformStringResponses(trials);
this.columns = data.types;
this.details = this.parseTrialsDetails(data.details);
this.showGraph = this.showGraphFn(trials);
});
}),
);
}
private startExperimentsPolling() {
this.poller = new ExponentialBackoff({
interval: 5000,
retries: 1,
maxInterval: 5001,
});
// Poll for new data and reset the poller if different data is found
this.subs.add(
this.poller.start().subscribe(() => {
this.backendService
.getExperiment(this.name, this.namespace)
.subscribe(response => {
this.experimentDetails = response;
this.bestTrialName = response.status.currentOptimalTrial
? response.status.currentOptimalTrial.bestTrialName
: '';
});
}),
);
}
private parseTrialsDetails(details: string[][]): string[][] {
return details.map((detail, index) => {
const updatedDetail = detail.map(value =>
isNaN(+value) || value === '' ? value : numberToExponential(+value, 6),
);
updatedDetail.push(index.toString());
return updatedDetail;
});
}
private experimentStatus(experiment: ExperimentK8s): StatusEnum {
const succeededCondition = getCondition(experiment, StatusEnum.SUCCEEDED);
if (succeededCondition && succeededCondition.status === 'True') {
return StatusEnum.SUCCEEDED;
}
const failedCondition = getCondition(experiment, StatusEnum.FAILED);
if (failedCondition && failedCondition.status === 'True') {
return StatusEnum.FAILED;
}
const runningCondition = getCondition(experiment, StatusEnum.RUNNING);
if (runningCondition && runningCondition.status === 'True') {
return StatusEnum.RUNNING;
}
const restartingCondition = getCondition(experiment, StatusEnum.RESTARTING);
if (restartingCondition && restartingCondition.status === 'True') {
return StatusEnum.RESTARTING;
}
const createdCondition = getCondition(experiment, StatusEnum.CREATED);
if (createdCondition && createdCondition.status === 'True') {
return StatusEnum.CREATED;
}
}
private showGraphFn(response: string): boolean {
if (!response.includes(',,') && response.includes('\n')) {
return true;
}
}
}