Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixing #127

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions src/app/pages/tests/tests.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class TestsComponent implements OnInit {
yamlContent!: string;
yamlFiles: string[] = [];
isLoading = false;
fileName2!: string;
fileName!: string;
response!: any;
tpa!: string;
Expand Down Expand Up @@ -138,7 +139,7 @@ export class TestsComponent implements OnInit {
}
}
if (conditions.expectedValue !== undefined) {
if (value === conditions.expectedValue) {
if (Number(value) === Number(conditions.expectedValue)) {
this.testStatuses.push({ text: `Test successfully completed.\nCondition: expectedValue=${conditions.expectedValue}\nResult: ${key}=${value}`, success: true });
} else {
this.testStatuses.push({ text: `Test failed.\nCondition: expectedValue=${conditions.expectedValue}\nResult: ${key}=${value}`, success: false });
Expand Down Expand Up @@ -177,7 +178,8 @@ export class TestsComponent implements OnInit {
// Leer el contenido del archivo
const tpa = step.with['tpa'];
const metric = step.with['metric'];
return this.loadData(tpa, metric).toPromise().then((data) => {
const time = step.with['actualTime'] === 'true';
return this.loadData(tpa, metric, time).toPromise().then((data) => {
// Imprimir los datos devueltos por loadData
console.log(data);

Expand All @@ -193,8 +195,9 @@ export class TestsComponent implements OnInit {
'bluejay/compute/metric': (step: { with: { [x: string]: string; }; }) => {
// Leer el contenido del archivo
const metric = step.with['metric'];
const time = step.with['actualTime'] === 'true';
return new Promise<void>((resolve, reject) => {
this.loadIndividualData(metric).subscribe(
this.loadIndividualData(metric, time).subscribe(
() => {
// Ejecutar postComputation
this.postContent().subscribe(response => {
Expand All @@ -211,12 +214,14 @@ export class TestsComponent implements OnInit {
},
//DEPRECADO
'bluejay/checkContain': (step: { with: { [x: string]: string; }; }) => {
console.warn("Deprecation Warning: 'bluejay/checkContain' has been deprecated. Please use 'TEST' method with 'bluejay/check' instead.");
const key = step.with['key'];
const minExpectedValue = Number(step.with['minExpectedValue']);
this.isLoading = true;
return new Promise<void>((resolve, reject) => {
setTimeout(() => {
this.http.get<any>(`http://localhost:6012/glassmatrix/api/v1/getData/${key}`, {}).subscribe((data: any) => {
this.testStatuses.push({ text: `Deprecation Warning: 'bluejay/checkContain' has been deprecated. Please use 'TEST' method with 'bluejay/check' instead.`, success: false });
if (data && data[0] && data[0][key]) {
const value = data[0][key];
if (value >= minExpectedValue) {
Expand Down Expand Up @@ -363,27 +368,34 @@ export class TestsComponent implements OnInit {
}, 5000);
}
}
private loadData(tpa: string, metric: string): Observable<any> {
private loadData(tpa: string, metric: string, time: boolean): Observable<any> {
this.tpa = tpa;
this.fileName = metric;
return this.glassmatrixService.loadFileContent(tpa, this.fileName).pipe(
this.fileName2 = metric;
return this.glassmatrixService.loadFileContent(tpa, this.fileName2).pipe(
tap(data => {
this.data = JSON.stringify(data, null, 2);
const parsedData = JSON.parse(this.data);
const now = new Date();
const startOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours());
const endOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1, -1);

this.window.from = startOfHour.toISOString();
this.window.initial = startOfHour.toISOString();
this.window.end = endOfHour.toISOString();
if (parsedData && parsedData.metric) {
if (parsedData.metric.scope) {
this.scope.project = parsedData.metric.scope.project || '';
this.scope.class = parsedData.metric.scope.class || '';
this.scope.member = parsedData.metric.scope.member || '';
}
if(parsedData.metric.window) {
if(time){
const now = new Date();
const startOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours());
const endOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1, -1);

this.window.from = startOfHour.toISOString();
this.window.initial = startOfHour.toISOString();
this.window.end = endOfHour.toISOString();
}else{
this.window.from = parsedData.metric.window.from || '';
this.window.initial = parsedData.metric.window.initial || '';
this.window.end = parsedData.metric.window.end || '';
}
this.window.type = parsedData.metric.window.type || '';
this.window.period = parsedData.metric.window.period || '';
this.window.timeZone = parsedData.metric.window.timeZone || '';
Expand All @@ -394,22 +406,15 @@ export class TestsComponent implements OnInit {
})
);
}
private loadIndividualData(metric: string): Observable<any> {
this.fileName = metric;
return this.filesService.getSavedMetric(this.fileName).pipe(
private loadIndividualData(metric: string, time: boolean): Observable<any> {
this.fileName2 = metric;
return this.filesService.getSavedMetric(this.fileName2).pipe(
tap(data => {
this.data = JSON.stringify(data, null, 2);

const parsedData = JSON.parse(this.data);
/* Esta zona actualiza la fecha del tpa a la actual */
const now = new Date();
const startOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours());
let endOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1);
endOfHour.setSeconds(endOfHour.getSeconds() - 1);

this.window.from = startOfHour.toISOString();
this.window.initial = startOfHour.toISOString();
this.window.end = endOfHour.toISOString();
/**/
if (parsedData && parsedData.metric) {
if (parsedData.metric.scope) {
Expand All @@ -418,6 +423,20 @@ export class TestsComponent implements OnInit {
this.scope.member = parsedData.metric.scope.member || '';
}
if(parsedData.metric.window) {
if(time){
const now = new Date();
const startOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours()+2);
let endOfHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 3);
endOfHour.setSeconds(endOfHour.getSeconds() - 1);

this.window.from = startOfHour.toISOString();
this.window.initial = startOfHour.toISOString();
this.window.end = endOfHour.toISOString();
}else{
this.window.from = parsedData.metric.window.from;
this.window.initial = parsedData.metric.window.initial;
this.window.end = parsedData.metric.window.end;
}
this.window.type = parsedData.metric.window.type || '';
this.window.period = parsedData.metric.window.period || '';
this.window.timeZone = parsedData.metric.window.timeZone || '';
Expand Down
29 changes: 29 additions & 0 deletions src/app/pages/tests/yaml-edit/yaml-edit.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ body {
border: 2px solid #007BFF;
margin: 20px 40px 20px auto;
}
.loading-overlay {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(128, 128, 128, 0.5);
z-index: 9999;
}
.alert {
position: relative;
padding: 20px;
}
.loader {
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
.btn.btn-outline-primary{
margin-bottom: 20px;
}
Expand Down Expand Up @@ -75,3 +100,7 @@ button.update-button {
cursor: pointer;
padding: 0 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
4 changes: 4 additions & 0 deletions src/app/pages/tests/yaml-edit/yaml-edit.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<div class="loading-overlay" *ngIf="isLoading">
<div class="loader"></div>
<p class="loading-text">{{ 'METRICS_TESTER.COLLECTING_RESOURCES' | translate }}</p>
</div>
<body>
<div class="row justify-content-end">
<button class="common-button btn-right2" id="volver" (click)="goBack()">{{ 'COMMON.BACK' | translate }}
Expand Down
Loading