Commit ab80a972 authored by Chris Hines's avatar Chris Hines
Browse files

fix up backend selection

parent d90906a7
Pipeline #6945 passed with stages
in 5 minutes and 16 seconds
......@@ -27,6 +27,7 @@ import { FileExplorerModule } from './file-explorer/file-explorer.module';
import { TesService} from './tes.service';
import { BackendSelectionService} from './backend-selection.service';
import { SubmitAppService } from './submit-app.service';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
......@@ -97,7 +98,7 @@ import { ModaldialogComponent } from './modaldialog/modaldialog.component'
],
entryComponents: [ LogoutdialogComponent, LaunchDialogComponent, ModaldialogComponent],
providers: [ StrudelappsService, ComputesitesService, TesService, SubmitAppService, MatDialog, AuthorisationService],
providers: [ StrudelappsService, ComputesitesService, TesService, SubmitAppService, MatDialog, AuthorisationService,BackendSelectionService],
bootstrap: [AppComponent]
})
export class AppModule { }
......@@ -11,7 +11,7 @@ import * as forge from "node-forge";
import { Identity, AuthToken, KeyCert, SshAuthzServer } from './identity';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Subject} from 'rxjs/Subject';
import {TesService} from './tes.service';
import {BackendSelectionService} from './backend-selection.service';
import { throwError } from 'rxjs';
import { environment } from '../environments/environment';
......@@ -41,6 +41,7 @@ export class AuthorisationService {
private locationStrategy: LocationStrategy,
private route: ActivatedRoute,
private router: Router,
private backendSelectionService: BackendSelectionService,
private location: Location) {
console.log('created AuthorisationService');
// this.token = new BehaviorSubject<AuthToken>(new AuthToken('',''));
......@@ -58,6 +59,7 @@ export class AuthorisationService {
this.keys = [];
this.getSshAuthzServers();
this.keys = [];
this.backendSelectionService.apiserver.subscribe((value) => { this.backendURI = value.tes ; this.updateAgentContents() })
this.agentContents.subscribe((value) => this.updateLoggedAuthZ());
this.sshAuthzServers.subscribe((value) => this.updateLoggedAuthZ());
}
......@@ -224,7 +226,10 @@ public getKeys(id?: Identity) {
}
public updateAgentContents() {
this.statusMsg.next("Updating the list of available accounts");
if (this.statusMsg !== undefined) {
this.statusMsg.next("Updating the list of available accounts");
};
console.log('querying ',this.backendURI+'/sshagent');
let headers = new HttpHeaders();
let options = { headers: headers, withCredentials: true};
var anyvar: any;
......
import { TestBed } from '@angular/core/testing';
import { BackendSelectionService } from './backend-selection.service';
describe('BackendSelectionService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: BackendSelectionService = TestBed.get(BackendSelectionService);
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { APIServer } from './apiserver';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import { HttpClientModule, HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class BackendSelectionService {
public apiservers: BehaviorSubject<APIServer[]>;
public apiserver: BehaviorSubject<APIServer>;
constructor(private http: HttpClient) {
this.apiservers = new BehaviorSubject([]);
this.apiserver = new BehaviorSubject(undefined);
this.initApiServer();
this.getAPIServers();
}
private initApiServer() {
try {
this.apiserver.next(<APIServer>JSON.parse(localStorage.getItem('apiserver')));
} catch {
this.apiserver.next(<APIServer>environment.apiserver);
}
}
private saveLastApiServer(s: APIServer) {
console.log('saving api server value to local storage')
localStorage.setItem('apiserver', JSON.stringify(s));
}
setApiServer(server: APIServer) {
console.log('calling setAPIServer');
this.apiserver.next(server);
console.log(this.apiserver);
this.saveLastApiServer(this.apiserver.value)
}
getAPIServers() {
let headers = new HttpHeaders();
let options = { headers: headers, withCredentials: false};
this.http.get<APIServer[]>('./assets/config/apiservers.json',options)
.subscribe(resp => this.updateAPIServers(resp));
}
private updateAPIServers(resp) {
var s: APIServer;
var list: APIServer[] = []
var current: APIServer;
var found: boolean;
current = this.apiserver.value;
found = false;
for (s of <APIServer[]>resp) {
if (s.name == current.name) {
list.push(current);
found = true;
} else {
list.push(s);
}
}
if (!found) {
list.push(current);
}
this.apiservers.next(list);
}
}
......@@ -17,7 +17,7 @@
Cancel
</button>
</div>
<div fxFlex *ngIf="available">
<div fxFlex *ngIf="jobdata.state == 'RUNNING'">
<button mat-button (click)="onConnect()" [disabled]="busy">
Connect
</button>
......
import { Component, OnInit } from '@angular/core';
import { AuthorisationService } from '../authorisation.service';
import {TesService} from '../tes.service';
import { Router, NavigationStart } from '@angular/router';
import { timer } from 'rxjs/observable/timer';
......@@ -13,7 +14,8 @@ import { timer } from 'rxjs/observable/timer';
})
export class KeygenComponent implements OnInit {
constructor(private router: Router, private authService: AuthorisationService) { }
constructor(private router: Router, private tesService: TesService, private authService: AuthorisationService) { }
//constructor(private router: Router, private authService: AuthorisationService) { }
ngOnInit() {
// The sequence is tricky here:
......
......@@ -41,17 +41,11 @@
Advanced Options
</mat-expansion-panel-header>
Select an API server
<!--(selectionChange)="tesService.setApiServer($event.value)" [compareWith]="tesService.compareServers"-->
<mat-select [ngModel]="selectedApiServer" (selectionChange)="tesService.setApiServer($event.value)">
<mat-option *ngFor="let apis of tesService.apiservers|async" [value]="apis">
<mat-select [ngModel]="selectedApiServer" (selectionChange)="backendSelectionService.setApiServer($event.value)">
<mat-option *ngFor="let apis of backendSelectionService.apiservers|async" [value]="apis">
{{ apis.name }}
</mat-option>
</mat-select>
<!--<mat-select [ngModel]="tesService.apiserver | async" (ngModelChange)="tesService.setApiServer($event)">
<mat-option *ngFor="let apis of tesService.apiservers|async" [value]="apis">
{{ apis.name }}
</mat-option>
</mat-select>-->
</mat-expansion-panel>
</mat-accordion>
</mat-sidenav>
......
......@@ -10,6 +10,7 @@ import { repeat } from 'rxjs/operators';
import {Strudelapp} from '../strudelapp';
import { StrudelappsService } from '../strudelapps.service';
import { TesService } from '../tes.service';
import {BackendSelectionService } from '../backend-selection.service';
import { AuthorisationService } from '../authorisation.service';
import { Identity } from '../identity';
import { Computesite } from '../computesite';
......@@ -45,17 +46,18 @@ export class LauncherComponent implements OnInit {
constructor( public dialog: MatDialog,
public tesService: TesService,
public backendSelectionService: BackendSelectionService,
public authService: AuthorisationService,
public computeSitesService: ComputesitesService,
) {
this.authService.sshAuthzServers.subscribe(o => {this.sshauthzservers = o});
this.identitySubject = new BehaviorSubject(undefined);
this.tesService.apiserver.subscribe((s) => this.selectedApiServer = s);
this.backendSelectionService.apiserver.subscribe((s) => this.selectedApiServer = s);
}
ngOnInit() {
this.strudelapps = [];
setTimeout( () => this.authService.updateAgentContents() )
// setTimeout( () => this.authService.updateAgentContents() )
}
......
......@@ -22,6 +22,7 @@ import { ModaldialogComponent } from './modaldialog/modaldialog.component';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material';
import { AuthorisationService } from './authorisation.service';
import { environment } from '../environments/environment';
import { BackendSelectionService } from './backend-selection.service';
/** The TES service contains ways to start Tunnels, and Execute programs
Its also responsible for querying a compute site for running jobs */
......@@ -55,17 +56,18 @@ public apiservers: BehaviorSubject<APIServer[]>;
private computesitesService: ComputesitesService,
private authorisationService: AuthorisationService,
private strudelappsService: StrudelappsService,
private backendSelectionService: BackendSelectionService,
private location: Location ) {
this.busy = new BehaviorSubject<boolean>(false);
// this.joblist = new BehaviorSubject<{[id: string]: Job[]}>({});
this.joblist = new BehaviorSubject<Job[]>([]);
this.apiserver = new BehaviorSubject<APIServer>(null);
this.apiserver = new BehaviorSubject<APIServer>(null);
this.apiservers = new BehaviorSubject<APIServer[]>([]);
this.timerSubscription = null;
this.appwindowWatcher = null;
this.getAPIServers();
this.backendSelectionService.apiserver.subscribe( (value) => { this.twsproxy = value.tws ; this.Base = value.tes });
// this.batchinterface = {};
// this.computesitesService.identities.subscribe(identities => this.startPolling(identities));
}
......@@ -74,71 +76,6 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
this.statusMsg = statusMsg;
}
public compareServer(a: APIServer, b: APIServer) {
if (a.name == b.name) {
return true;
}
return false;
}
private loadLastApiServer() {
var lastserver: APIServer;
try {
console.log('loading api server from local storage');
lastserver = JSON.parse(localStorage.getItem('apiserver'));
} catch {
lastserver = undefined;
}
// If we got a value for the last server used, we need to search the list of available servers for a match
if (lastserver != undefined) {
for (let s of this.apiservers.value) {
if (lastserver.name == s.name) {
this.apiserver.next(s);
}
}
}
// If we didn't get a match, we'll just pick the first available server
if (this.apiserver.value == null) {
if (this.apiservers.value.length > 0) {
this.apiserver.next(this.apiservers.value[0]);
} else {
// If there are NO available backed servers ... well we shouldn't get here.
// In the future if we start detecting backends as down for maintainnce it might happen
this.statusMsg.next("There was an error selecting a backend API server. Please try reloading");
return;
}
}
this.Base = this.apiserver.value.tes;
this.twsproxy = this.apiserver.value.tws;
this.authorisationService.backendURI = this.Base;
console.log('load succeeded');
}
private saveLastApiServer(s: APIServer) {
console.log('saving api server value to local storage')
localStorage.setItem('apiserver', JSON.stringify(s));
}
setApiServer(server: APIServer) {
console.log('calling setAPIServer');
this.apiserver.next(server);
console.log(this.apiserver);
this.Base = this.apiserver.value.tes;
this.twsproxy = this.apiserver.value.tws;
this.saveLastApiServer(this.apiserver.value)
}
getAPIServers() {
let headers = new HttpHeaders();
let options = { headers: headers, withCredentials: false};
this.http.get<SshAuthzServer[]>('./assets/config/apiservers.json',options)
.subscribe(resp => this.updateAPIServers(resp));
}
private updateAPIServers(resp) {
this.apiservers.next(<APIServer[]>resp);
this.loadLastApiServer();
}
private buildParams(app: Strudelapp, identity: Identity, batchinterface: BatchInterface, appinst?: any): string {
let params = new URLSearchParams();
......
export const environment = {
production: true,
tesurl: "https://strudel2-test.cloud.cvl.org.au/tes",
twsurl: "https://strudel2-test.cloud.cvl.org.au"
apiserver: {
tes: "https://strudel2-test.cloud.cvl.org.au/tes",
tws: "https://strudel2-test.cloud.cvl.org.au",
name: "Test"
}
};
......@@ -5,6 +5,9 @@
export const environment = {
production: false,
tesurl: "https://strudel2-test.cloud.cvl.org.au/tes",
twsurl: "https://strudel2-test.cloud.cvl.org.au"
apiserver: {
tes: "https://strudel2-test.cloud.cvl.org.au/tes",
tws: "https://strudel2-test.cloud.cvl.org.au",
name: "Test"
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment