Commit 8decdf39 authored by Chris Hines's avatar Chris Hines
Browse files

ading code to allow custom configs to be loaded

parent 5e6064a2
Pipeline #7117 passed with stages
in 5 minutes and 36 seconds
......@@ -68,6 +68,19 @@ export class AuthorisationService {
this.statusMsg = statusMsg;
}
storeLocalAuthZ(authz: any) {
try {
localStorage.setItem('localauthservers',JSON.stringify(authz));
} catch {
}
this.getSshAuthzServers();
}
removeLocalAuthZ() {
localStorage.removeItem('localauthservers');
console.log('removed local computesites');
this.getSshAuthzServers();
}
getSshAuthzServers() {
let headers = new HttpHeaders();
let options = { headers: headers, withCredentials: false};
......@@ -116,8 +129,19 @@ export class AuthorisationService {
updateSshAuthzServers(resp) {
this.sshAuthzServers.next(<SshAuthzServer[]>resp);
console.log('sshauthzservers set to',this.sshAuthzServers.value);
var auths: SshAuthzServer[];
var localauths: SshAuthzServer[] = [];
var server: SshAuthzServer;
auths = <SshAuthzServer[]>resp;
try {
localauths = JSON.parse(localStorage.getItem('localcomputesites'))
} catch {
localauths = []
}
for (server of localauths) {
auths.push(server);
}
this.sshAuthzServers.next(auths);
}
storeToken(frag: string) {
......
......@@ -44,6 +44,16 @@ export class BackendSelectionService {
this.saveLastApiServer(this.apiserver.value)
}
storeLocalAPIServers(apiservers) {
localStorage.setItem('localAPIServers',JSON.stringify(apiservers));
this.getAPIServers();
}
removeLocalAPIServer() {
localStorage.removeItem('localAPIServers');
this.getAPIServers();
}
getAPIServers() {
let headers = new HttpHeaders();
let options = { headers: headers, withCredentials: false};
......@@ -56,8 +66,15 @@ export class BackendSelectionService {
var list: APIServer[] = []
var current: APIServer;
var found: boolean;
var localServers: APIServer[] = [];
current = this.apiserver.value;
found = false;
try {
localServers = <APIServer[]>JSON.parse(localStorage.getItem('localAPIServers'));
} catch {
localServers = []
}
for (s of <APIServer[]>resp) {
if (s.name == current.name) {
list.push(current);
......@@ -66,6 +83,16 @@ export class BackendSelectionService {
list.push(s);
}
}
if (localServers !== null) {
for (s of localServers) {
if (s.name == current.name) {
list.push(current);
found = true;
} else {
list.push(s);
}
}
}
if (!found) {
list.push(current);
}
......
......@@ -28,8 +28,9 @@ export class ComputesitesService {
this.ftidentities = new BehaviorSubject<Identity[]>([]);
this.computesites.subscribe(computesites => this.getStrudelApps(computesites))
this.getComputeSites();
this.computesites.subscribe((cs) => this.authorisationService.updateAgentContents());
this.authorisationService.agentContents.subscribe(ac => this.updateIdentities(ac));
this.getComputeSites();
}
public setStatusMsg(statusMsg: BehaviorSubject<any>) {
......@@ -44,25 +45,42 @@ export class ComputesitesService {
if (s.appCatalogUri !== null) {
this.http.get<Strudelapp[]>(s.appCatalogUri,options)
.pipe(catchError(this.handleError('getStrudelApps')))
.subscribe(resp => this.updateStrudelApps(s.appCatalog,resp,s.name));
.subscribe(resp => this.updateStrudelApps(s,resp));
}
}
}
storeLocalStrudelApps(name: string, apps: any) {
localStorage.setItem(name+'-apps',JSON.stringify(apps))
}
removeLocalStrudelApps() {
var keys = [];
for (var key in localStorage) {
var idx = key.indexOf('-apps');
if (idx !== -1) {
keys.push(key)
}
}
for (var key in keys) {
localStorage.removeItem(key);
}
}
updateStrudelApps(appCatalog: BehaviorSubject<Strudelapp[]>,apps, sitename) {
updateStrudelApps(site: Computesite, apps) {
var sapps: Strudelapp[];
var localapps: Strudelapp[];
sapps = <Strudelapp[]>apps;
localapps = JSON.parse(localStorage.getItem(sitename+'-apps'))
localapps = JSON.parse(localStorage.getItem(site.name+'-apps'))
if (localapps !== null) {
for (let a of localapps) {
sapps.push(a);
}
}
appCatalog.next(sapps);
site.appCatalog.next(sapps);
}
private handleError<T> (operation = 'operation', result?: T) {
......@@ -81,10 +99,28 @@ export class ComputesitesService {
.subscribe(resp => this.updateComputeSites(resp));
}
storeLocalComputeSites(computesites: any) {
try {
localStorage.setItem('localcomputesites',JSON.stringify(computesites));
} catch {
}
this.getComputeSites();
}
removeLocalComputeSites() {
localStorage.removeItem('localcomputesites');
console.log('removed local computesites');
this.getComputeSites();
}
updateComputeSites(resp) {
var localcomputesites: Computesite[] = [];
var computesites: Computesite[] = []
localcomputesites = JSON.parse(localStorage.getItem('localcomputesites'))
try {
localcomputesites = JSON.parse(localStorage.getItem('localcomputesites'))
} catch {
localcomputesites = []
}
if (localcomputesites !== null ) {
for (let cs of localcomputesites) {
cs.appCatalog = new BehaviorSubject<Strudelapp[]>([]);
......@@ -96,7 +132,6 @@ export class ComputesitesService {
computesite.appCatalog = new BehaviorSubject<Strudelapp[]>([])
computesites.push(computesite);
}
console.log('updating compute sites');
this.computesites.next(computesites);
}
......
......@@ -46,6 +46,9 @@
{{ apis.name }}
</mat-option>
</mat-select>
<button type="button" mat-button (click)="fileInput.click()">Load Config</button>
<input hidden (change)="loadConfig($event)" accept=".json" #fileInput type="file" id="file">
<button mat-button (click)=resetConfig()>Reset Config</button>
</mat-expansion-panel>
</mat-accordion>
</mat-sidenav>
......
......@@ -43,6 +43,8 @@ export class LauncherComponent implements OnInit {
private launchwindow: any;
private launchwindowWatcher: any;
public selectedApiServer: any;
private file: any;
private config: any;
constructor( public dialog: MatDialog,
public tesService: TesService,
......@@ -91,4 +93,35 @@ export class LauncherComponent implements OnInit {
this.tesService.getJobs(id);
}
loadConfig(event) {
const reader = new FileReader();
reader.onload = (e: any) => {
try {
this.config = JSON.parse(e.target.result);
if ('computesites' in this.config) {
this.computeSitesService.storeLocalComputeSites(this.config['computesites'])
}
if ('apps' in this.config) {
this.computeSitesService.storeLocalStrudelApps(this.config['sitename'],this.config['apps']);
}
if ('authz' in this.config) {
this.authService.storeLocalAuthZ(this.config['authz'])
}
} catch {
console.log('local config file is invalid')
}
};
reader.readAsText(event.target.files[0]);
}
resetConfig() {
this.computeSitesService.removeLocalStrudelApps();
this.computeSitesService.removeLocalComputeSites();
this.authService.removeLocalAuthZ()
}
}
......@@ -64,8 +64,6 @@ export class SubmitAppService {
launch() {
let bi = new BatchInterface();
bi.submitcmd = this.submitcmd.value;
console.log('in launch,',bi);
console.log(this.appData.value);
if (this.appData.value != null){
// let appparams = JSON.stringify(this.appData.value);
let appparams = this.appData.value;
......
......@@ -199,10 +199,13 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
submissionError(error: any) {
if (error.status != 0) {
this.statusMsg.next('Job submission failed');
//this.statusMsg.next(error.error.message);
console.error(error.error.message);
if ('error' in error && 'message' in error.error) {
this.statusMsg.next(error.error.message);
} else {
this.statusMsg.next('Job submission failed');
}
this.busy.next(false);
console.log(error);
}
}
......@@ -219,9 +222,7 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
// let body = this.buildBody(app,appparams)
let keys = this.authorisationService.getKeys();
let body = {'app': app, 'appparams': appparams, 'keys': keys}
console.log('tes is submitting the job with body',body);
this.http.post<any>(this.Base+'/submit'+'?'+paramstr, body, options)
.pipe(catchError(this.handleError))
.subscribe(resp => {
this.busy.next(false);
this.statusMsg.next(null)
......@@ -231,7 +232,6 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
submitted(resp: any, identity: Identity ) {
this.busy.next(false);
// this.statusMsg.next(null);
this.getJobs(identity);
}
......@@ -267,7 +267,8 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
job.connectionState = 1;
this.http.get<string>(this.Base+'/appinstance/'+username+'/'+loginhost+'/'+batchhost+'?'+paramstr, options)
// .pipe(catchError(this.handleError))
.subscribe(resp => { job.appinst = resp; this.createTunnel(job) } )
.subscribe(resp => { job.appinst = resp; this.createTunnel(job) },
error => { this.handleAppInstanceError(job,error) })
// let paramstr = this.buildParams(job.app,job.identity,this.batchinterface[job.identity.repr()]);
// let headers = new HttpHeaders();
// let options = { headers: headers, withCredentials: true};
......@@ -316,7 +317,14 @@ public setStatusMsg(statusMsg: BehaviorSubject<any>) {
}
public openAppWindow(url: any) {
let windowloc = url.replace(/\{twsproxy\}/g,this.twsproxy);
//console.log('in openAppWindow',url);
var re = /^https:\/\/([a-z0-9\.-]+)\/?/;
let twshost = this.twsproxy.replace(re,"$1");
//console.log('tws host is',twshost);
//let twshost = this.twsproxy;
let windowloc = url.replace(/\{twsproxy\}/g,this.twsproxy).replace(/twshost/g,twshost);
//let windowloc = url
console.log('window loc is ',windowloc);
// let windowloc = this.router.config
this.appwindow = window.open(windowloc);
......@@ -410,6 +418,17 @@ private httperror(errorstr: string) {
// }
private handleAppInstanceError(job: Job, error: any) {
console.log('in handle appinst error');
job.connectionState=0;
if ('error' in error && 'message' in error['error']) {
this.statusMsg.next(error['error']['message']);
} else {
this.statusMsg.next(error);
}
console.log(error)
}
private handleError(error: HttpErrorResponse) {
console.error('in handleError');
console.error(error);
......
......@@ -22,7 +22,7 @@
"statcmd": "/usr/local/sv2/sv2stat.py"
},
{
"url": "https://vm-118-138-240-255.erc.monash.edu.au/m3siteconfig/",
"url": "https://vm-118-138-240-255.erc.monash.edu.au/cvluwa/",
"name": "CVL@UWA",
"host": "146.118.65.246",
"dtn": "146.118.65.246",
......
[
{ "url": null,
"name": "Desktop",
"startscript": "#!/bin/bash\n/home/chines/sv2/desktop_novnc/desktop.sh\n ",
"paramscmd": "/home/chines/sv2/desktop_novnc/params.py",
"client": {"cmd": null, "redir": "vnc.html?host=vm-118-138-240-255.erc.monash.edu.au&port=443&password={password}" },
"localbind": true,
"applist": null
},
{ "url": null,
"name": "Guacamole Desktop",
"startscript": "#!/bin/bash\n/home/chines/desktop.sh\n ",
"paramscmd": "/home/chines/vdiparam.py",
"client": {"cmd": null, "redir": "guacamole?username={username}&password={password}" },
"startscript": "#!/bin/bash\n/usr/local/sv2/desktop/desktop.slurm\n ",
"paramscmd": "/usr/local/sv2/desktop/params.py",
"client": {"cmd": null, "redir": "vnc.html?password={password}" },
"localbind": true,
"applist": null
},
{
"url": null,
"name": "Jupyter Lab",
"startscript": "#!/bin/bash\n/home/chines/jupyter.slurm\n",
"paramscmd": "/home/chines/jupyter_params.py",
"startscript": "#!/bin/bash\n/usr/local/sv2/jupyter/jupyter.slurm\n",
"paramscmd": "/usr/local/sv2/jupyter/jupyter_params.py",
"client": {"cmd": null, "redir": "?token={token}"},
"localbind": true,
"applist": null
},
{
"url": null,
"name": "LiberTEM",
"startscript": "eval $(cat /home/chines/libertembatch)",
"paramscmd": "/projects/pMOSP/chines/libertem_venv/bin/python /projects/pMOSP/chines/libertem_venv/bin/server_stat.py",
"client": {"cmd": null, "redir": ""},
"localbind": true,
"applist": null
},
{
"url": null,
"name": "CryoSPARC",
"startscript": null,
"paramscmd": "/home/chines/cryosparc_params.py",
"client": {"cmd": null, "redir": ""},
"localbind": true,
"applist": null
},
{
"url": null,
"name": "R Studio Server",
......@@ -54,7 +28,7 @@
{ "url": "transfer",
"name": "Transfer files",
"startscript": "#!/bin/bash\n echo '{appparams}' > ft.json",
"paramscmd": "/home/chines/sv2/desktop_novnc/params.py",
"paramscmd": "/usr/local/sv2/copytool.py",
"client": {"cmd": null, "redir": null },
"localbind": true,
"applist": null
......
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