From 1483343c48d2de5e7a6efcc6da0d7d58bcbc1562 Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Fri, 14 Feb 2020 19:35:10 +1100
Subject: [PATCH] refactor the connect method for opening a window to make it
 clearer

---
 src/app/authorisation.service.ts     | 21 +++++++++++++++++----
 src/app/joblist/joblist.component.ts |  8 +++++++-
 src/assets/config/m3apps.dev.json    |  4 ++++
 src/assets/config/m3apps.test.json   |  3 +++
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/app/authorisation.service.ts b/src/app/authorisation.service.ts
index 0eccf69..e52c59f 100644
--- a/src/app/authorisation.service.ts
+++ b/src/app/authorisation.service.ts
@@ -20,11 +20,12 @@ export class SshauthzServer {}
 })
 export class AuthorisationService {
   // public token: BehaviorSubject<AuthToken>;
-  public token: BehaviorSubject<AuthToken>;
   public readonly sshAuthzServers: BehaviorSubject<SshAuthzServer[]>;
   public readonly agentContents: BehaviorSubject<any>;
   public loggedInAuthZ: BehaviorSubject<SshAuthzServer[]>;
   public loggedOutAuthZ: BehaviorSubject<SshAuthzServer[]>;
+  public loggedInAuthZ$: Observable<SshAuthzServer[]>;
+  public loggedOutAuthZ$: Observable<SshAuthzServer[]>;
   //public progress: Subject<string>;
   // private keyCert: Subject<KeyCert>;
   public backendURI: string;
@@ -36,7 +37,6 @@ export class AuthorisationService {
               private backendSelectionService: BackendSelectionService,
               private location: Location, 
               private notifications: NotificationsService) {
-                this.token = new BehaviorSubject<AuthToken>(null);
                 this.sshAuthzServers = new BehaviorSubject<SshAuthzServer[]>([]);
                 this.loggedInAuthZ = new BehaviorSubject<SshAuthzServer[]>(null);
                 this.loggedOutAuthZ = new BehaviorSubject<SshAuthzServer[]>([]);
@@ -54,15 +54,27 @@ export class AuthorisationService {
     // Once we have backend server, check what our ssh agent has in it
     this.backendSelectionService.apiserver.pipe(
       filter((v) => v !== null && v !== undefined),
-      switchMap((v) => this.updateAgentContents(v.tes))
-    ).subscribe((_) => { return });  // An empty subscription is necessary for the observables to fire
+      switchMap((v) => this.updateAgentContents(v.tes)),
+      tap((v) => console.log(v))
+    ).subscribe((_) => { return }, (err) => console.error(err));  // An empty subscription is necessary for the observables to fire
 
 
     /* Once we have a value for agent Conents, and a list of servers, we can figure out which ones we hav elogged into and which ones we haven't */
+    /*
     combineLatest([this.agentContents.pipe(filter((v) => v !== null && v !== undefined)),this.sshAuthzServers.pipe(filter((v) => v !== null && v !== undefined))]).pipe(
       map(([agentContents,authzServers]) => { return this.updateLoggedAuthZ(agentContents,authzServers)}),
       catchError((e) => { console.error('errort getting values for logged in and out',e); throwError(e) ; return of([]) }),
     ).subscribe(([loggedin,loggedout]) => { this.loggedInAuthZ.next(loggedin); this.loggedOutAuthZ.next(loggedout); console.log('updated subjects'); })
+     */
+
+    var authZ$: Observable<any>;
+    authZ$ = combineLatest([this.agentContents.pipe(filter((v) => v !== null && v !== undefined)),this.sshAuthzServers.pipe(filter((v) => v !== null && v !== undefined))]).pipe(
+      map(([agentContents,authzServers]) => { return this.updateLoggedAuthZ(agentContents,authzServers)}),
+      catchError((e) => { console.error('errort getting values for logged in and out',e); return throwError(e) })
+    );
+    authZ$.subscribe(([loggedin,loggedout]) => { this.loggedInAuthZ.next(loggedin); this.loggedOutAuthZ.next(loggedout); console.log('updated subjects'); })
+    this.loggedInAuthZ$ = authZ$[0];
+    this.loggedOutAuthZ$ = authZ$[1];
  }
 
 
@@ -200,6 +212,7 @@ public getKeys(id?: Identity) {
    let agentpipe$ = agentquery$.pipe(
      catchError((e) => { this.querySshAgentError(e); return of([])}),
      tap((resp) => this.agentContents.next(resp)),
+     tap((resp) => console.log('update agent contents with',resp)),
      tap((v) => console.log('agentContents.next called')),
      tap((_) => this.notifications.notify(""))
    )
diff --git a/src/app/joblist/joblist.component.ts b/src/app/joblist/joblist.component.ts
index a6bc502..92d3ff9 100644
--- a/src/app/joblist/joblist.component.ts
+++ b/src/app/joblist/joblist.component.ts
@@ -10,6 +10,7 @@ import { Strudelapp } from '../strudelapp';
 import { TesService } from '../tes.service';
 import { Job } from '../job';
 import { Identity } from '../identity';
+import { AuthorisationService } from '../authorisation.service';
 
 
 
@@ -26,7 +27,7 @@ export class JoblistComponent implements OnInit {
   public joblist: Job[];
 
 
-  constructor(private tes: TesService ) {
+  constructor(private tes: TesService, private authService: AuthorisationService ) {
   }
 
   public ngOnInit(): void {
@@ -45,6 +46,11 @@ export class JoblistComponent implements OnInit {
   }
 
  getJobsError(error,identitiy) {
+   // if an error occurs, pause polling, update the list of sites, and attempt to resume polling
+   // if the current site is no longer logged in, nagivate away
+   this.sub.unsubscribe()
+   this.authService.updateAgentContents().subscribe((v) =>
+     {this.sub = timer(5000).pipe(repeat()).subscribe( () => this.getJobs() )});
    console.log('getjobs error',error);
  }
  updateJoblist(jobquery: Job[], identity: Identity) {
diff --git a/src/assets/config/m3apps.dev.json b/src/assets/config/m3apps.dev.json
index fcc304c..f922fcd 100644
--- a/src/assets/config/m3apps.dev.json
+++ b/src/assets/config/m3apps.dev.json
@@ -58,6 +58,7 @@
            "name": "Remove log",
            "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
            "client": null,
+            "notunnel": true,
            "states": ["Finished"]
        }
    ],
@@ -91,6 +92,7 @@
            "name": "Remove log",
            "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
            "client": null,
+            "notunnel": true,
            "states": ["Finished"]
        }
 
@@ -168,6 +170,7 @@
            "name": "Remove log",
            "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
            "client": null,
+            "notunnel": true,
            "states": ["Finished"]
        }
     ],
@@ -209,6 +212,7 @@
             "name": "Remove log",
             "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
             "client": null,
+            "notunnel": true,
             "states": ["Finished"]
         }
     ],
diff --git a/src/assets/config/m3apps.test.json b/src/assets/config/m3apps.test.json
index d502670..1a86a9a 100644
--- a/src/assets/config/m3apps.test.json
+++ b/src/assets/config/m3apps.test.json
@@ -27,6 +27,7 @@
             "name": "Remove log",
             "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
             "client": null,
+            "notunnel": true,
             "states": ["Finished"]
         }
 
@@ -62,6 +63,7 @@
            "name": "Remove log",
            "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
            "client": null,
+            "notunnel": true,
            "states": ["Finished"]
        }
 
@@ -96,6 +98,7 @@
            "name": "Remove log",
            "paramscmd": "/usr/local/sv2/dev/rmlog.py {jobid}",
            "client": null,
+            "notunnel": true,
            "states": ["Finished"]
        }
 
-- 
GitLab