From dbb9eef1e2aa16c2563a36fd0bacb11741381b96 Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Tue, 16 Jun 2020 08:56:07 +1000
Subject: [PATCH] use a ping url rather than the sshagent to test if a server
 is available

---
 src/app/backend-selection.service.ts     | 2 +-
 src/app/notifications.service.ts         | 4 ++++
 src/app/settings/settings.component.html | 2 +-
 src/app/tes.service.ts                   | 9 ++++++---
 src/assets/config/computesites.json      | 4 ++--
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/app/backend-selection.service.ts b/src/app/backend-selection.service.ts
index 224df91..4a75d8f 100644
--- a/src/app/backend-selection.service.ts
+++ b/src/app/backend-selection.service.ts
@@ -83,7 +83,7 @@ export class BackendSelectionService {
     servers = this.apiservers.value;
     for (let server of servers) {
       combineLatest([of(performance.now()),
-      this.http.get<string>(server.tes+'/sshagent',options).pipe(
+      this.http.get<string>(server.tes+'/ping',options).pipe(
         timeout(timeouts))])
       .subscribe((ok) => {server.ping = (performance.now() - <number>(ok[0]))},
                  (err) => {server.ping = null});
diff --git a/src/app/notifications.service.ts b/src/app/notifications.service.ts
index 58496d7..fe2a805 100644
--- a/src/app/notifications.service.ts
+++ b/src/app/notifications.service.ts
@@ -17,6 +17,10 @@ export class NotificationsService {
   }
 
   notify(msg: any) {
+    if (msg === null || msg === undefined) {
+      this.msg.next("");
+      return
+    }
     if (msg.hasOwnProperty('error')) {
       this.notify(msg.error);
       return;
diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html
index 18a50fa..564fe90 100644
--- a/src/app/settings/settings.component.html
+++ b/src/app/settings/settings.component.html
@@ -28,7 +28,7 @@
         <mat-form-field style="width: 100%">
             <mat-label>API Server</mat-label>
             <mat-select [ngModel]="selectedApiServer" (selectionChange)="backendSelectionService.setApiServer($event.value)">
-                <mat-option *ngFor="let apis of backendSelectionService.apiservers|async" [value]="apis" [disabled] ="apis.ping === undefined">
+                <mat-option *ngFor="let apis of backendSelectionService.apiservers|async" [value]="apis" [disabled] ="apis.ping === undefined || apis.ping === null">
                     {{ apis.name }} <span *ngIf="apis.ping !== undefined">(ping: {{ apis.ping }} ms)</span>
                 </mat-option>
             </mat-select>
diff --git a/src/app/tes.service.ts b/src/app/tes.service.ts
index 5d220e5..e4052fa 100644
--- a/src/app/tes.service.ts
+++ b/src/app/tes.service.ts
@@ -359,10 +359,13 @@ private handleError(error: HttpErrorResponse) {
   if (error.error instanceof ErrorEvent) {
     this.notifications.notify("A networking error occured.")
     return
-  } else {
-    this.notifications.notify("Your login appears to have expired. Please login again");
-    this.authorisationService.updateAgentContents().subscribe((v) => {return});
+  } 
+  if (error.hasOwnProperty("status") && error.status == 500) {
+    this.notifications.notify(error);
+    return
   }
+  this.notifications.notify("Your login appears to have expired. Please login again");
+  this.authorisationService.updateAgentContents().subscribe((v) => {return});
 }
 
 
diff --git a/src/assets/config/computesites.json b/src/assets/config/computesites.json
index 17f7a4f..a2d7b84 100644
--- a/src/assets/config/computesites.json
+++ b/src/assets/config/computesites.json
@@ -1,12 +1,12 @@
 [
   {
-    "url": "https://strudel2-api-dev.cloud.cvl.org.au/m3/",
+    "url": "https://beta-api.cloud.cvl.org.au/m3/",
     "name": "M3",
     "host": "m3-login2.massive.org.au",
     "dtn": "m3-dtn1.massive.org.au",
     "cafingerprint": "RSA SHA256:cmDxHrZQSPlBMUUcI/BWmruXho1XOzfXPDHSqVTwV2I",
     "appCatalog": [],
-    "appCatalogCmd": "cat /usr/local/sv2/dev/apps.json",
+    "appCatalogCmd": "/usr/local/strudel2_cluster/latest/bin/getapps",
     "cancelcmd": "/usr/local/sv2/dev/scripts/bin/s2cancel {jobid}",
     "statcmd": "/usr/local/sv2/dev/scripts/bin/s2stat",
     "userhealth": "/usr/local/userhealth/0.0.2/bin/uijson",
-- 
GitLab