Skip to content

Commit

Permalink
[YUNIKORN-357] Show REST API availability (apache#46)
Browse files Browse the repository at this point in the history
If the scheduler core is not up or the port of the REST API is not
reachable an empty page was shown. Now we show an error message with the
reason that there is no data to show.

Fixes: apache#46
  • Loading branch information
akhilpb001 authored and wilfred-s committed Sep 1, 2020
1 parent fcf9729 commit 6468c6e
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 135 deletions.
6 changes: 6 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DashboardComponent } from './components/dashboard/dashboard.component';
import { QueuesViewComponent } from './components/queues-view/queues-view.component';
import { AppsViewComponent } from './components/apps-view/apps-view.component';
import { NodesViewComponent } from './components/nodes-view/nodes-view.component';
import { ErrorViewComponent } from './components/error-view/error-view.component';

const appRoutes: Routes = [
{
Expand All @@ -45,6 +46,11 @@ const appRoutes: Routes = [
component: NodesViewComponent,
data: { breadcrumb: 'Nodes' }
},
{
path: 'error',
component: ErrorViewComponent,
data: { breadcrumb: 'Error' }
},
{
path: '',
pathMatch: 'full',
Expand Down
12 changes: 10 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgxSpinnerModule } from 'ngx-spinner';
import { FormsModule } from '@angular/forms';
import {
Expand All @@ -40,6 +40,7 @@ import {

import { AppRoutingModule } from './app-routing.module';
import { envConfigFactory, EnvconfigService } from './services/envconfig/envconfig.service';
import { ApiErrorInterceptor } from './interceptors/api-error/api-error.interceptor';
import { AppComponent } from './app.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { QueuesViewComponent } from './components/queues-view/queues-view.component';
Expand All @@ -52,6 +53,7 @@ import { ContainerHistoryComponent } from './components/container-history/contai
import { QueueRackComponent } from './components/queue-rack/queue-rack.component';
import { AppsViewComponent } from './components/apps-view/apps-view.component';
import { NodesViewComponent } from './components/nodes-view/nodes-view.component';
import { ErrorViewComponent } from './components/error-view/error-view.component';

@NgModule({
declarations: [
Expand All @@ -66,7 +68,8 @@ import { NodesViewComponent } from './components/nodes-view/nodes-view.component
ContainerHistoryComponent,
QueueRackComponent,
AppsViewComponent,
NodesViewComponent
NodesViewComponent,
ErrorViewComponent
],
imports: [
BrowserModule,
Expand Down Expand Up @@ -95,6 +98,11 @@ import { NodesViewComponent } from './components/nodes-view/nodes-view.component
useFactory: envConfigFactory,
deps: [EnvconfigService],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ApiErrorInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
Expand Down
20 changes: 10 additions & 10 deletions src/app/components/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
<mat-card *ngIf="clusterInfo">
<div class="flex-grid">
<div class="flex-primary">
<div class="text-uppercase hwx-light">Name</div>
<div class="info-value hwx-strong">{{ clusterInfo.clusterName }}</div>
<div class="text-uppercase light-text">Name</div>
<div class="info-value strong-text">{{ clusterInfo.clusterName }}</div>
</div>
<div class="flex-primary">
<div class="text-uppercase hwx-light">Status</div>
<div class="info-value hwx-strong">{{ clusterInfo.clusterStatus }}</div>
<div class="text-uppercase light-text">Status</div>
<div class="info-value strong-text">{{ clusterInfo.clusterStatus }}</div>
</div>
<div class="flex-primary">
<div class="text-uppercase hwx-light">Nodes</div>
<div class="info-value hwx-strong">{{ clusterInfo.activeNodes }}</div>
<div class="text-uppercase light-text">Nodes</div>
<div class="info-value strong-text">{{ clusterInfo.activeNodes }}</div>
</div>
<div class="flex-primary">
<div class="text-uppercase hwx-light">Applications</div>
<div class="info-value hwx-strong">{{ clusterInfo.runningApplications }}</div>
<div class="text-uppercase light-text">Applications</div>
<div class="info-value strong-text">{{ clusterInfo.runningApplications }}</div>
</div>
<div class="flex-primary">
<div class="text-uppercase hwx-light">Containers</div>
<div class="info-value hwx-strong">{{ clusterInfo.runningContainers }}</div>
<div class="text-uppercase light-text">Containers</div>
<div class="info-value strong-text">{{ clusterInfo.runningContainers }}</div>
</div>
</div>
</mat-card>
Expand Down
21 changes: 21 additions & 0 deletions src/app/components/error-view/error-view.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->

<mat-card class="error-view">
Oops, Something went wrong. YuniKorn scheduler is not accessible.
</mat-card>
22 changes: 22 additions & 0 deletions src/app/components/error-view/error-view.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.error-view {
color: #cb0100;
text-align: center;
}
45 changes: 45 additions & 0 deletions src/app/components/error-view/error-view.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { configureTestSuite } from 'ng-bullet';
import { MatCardModule } from '@angular/material';

import { ErrorViewComponent } from './error-view.component';

describe('ErrorViewComponent', () => {
let component: ErrorViewComponent;
let fixture: ComponentFixture<ErrorViewComponent>;

configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [MatCardModule],
declarations: [ErrorViewComponent]
});
});

beforeEach(() => {
fixture = TestBed.createComponent(ErrorViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create the component', () => {
expect(component).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions src/app/components/error-view/error-view.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-error-view',
templateUrl: './error-view.component.html',
styleUrls: ['./error-view.component.scss']
})
export class ErrorViewComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
42 changes: 42 additions & 0 deletions src/app/interceptors/api-error/api-error.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { TestBed } from '@angular/core/testing';
import { configureTestSuite } from 'ng-bullet';
import { RouterTestingModule } from '@angular/router/testing';

import { ApiErrorInterceptor } from './api-error.interceptor';

describe('ApiErrorInterceptor', () => {
let interceptor: ApiErrorInterceptor;

configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
providers: [ApiErrorInterceptor]
});
});

beforeEach(() => {
interceptor = TestBed.get(ApiErrorInterceptor);
});

it('should create the interceptor', () => {
expect(interceptor).toBeTruthy();
});
});
43 changes: 43 additions & 0 deletions src/app/interceptors/api-error/api-error.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
HttpErrorResponse
} from '@angular/common/http';

@Injectable()
export class ApiErrorInterceptor implements HttpInterceptor {
constructor(private router: Router) {}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(this.handleApiError.bind(this)));
}

handleApiError(error: HttpErrorResponse) {
this.router.navigate(['/error']);
return throwError(error);
}
}
Loading

0 comments on commit 6468c6e

Please sign in to comment.