14813: wb2 uses cluster config
authorEric Biagiotti <ebiagiotti@veritasgenetics.com>
Tue, 30 Jul 2019 18:40:42 +0000 (14:40 -0400)
committerEric Biagiotti <ebiagiotti@veritasgenetics.com>
Tue, 30 Jul 2019 18:40:42 +0000 (14:40 -0400)
Also updates auth-action to get remote cluster info from the remotes cluster config, instead of its discovery doc

Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti@veritasgenetics.com>

src/common/config.ts
src/store/auth/auth-action-session.ts
src/store/auth/auth-action.ts

index 71b7774c5fa8d765818b7ce611f6e4bfa1805c11..044d7aa9405ebbd40f13d5bee609c36ccf0b0212 100644 (file)
 
 import Axios from "axios";
 
 
 import Axios from "axios";
 
-export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
+export const WORKBENCH_CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
 
 
-export interface Config {
-    auth: {};
-    basePath: string;
+interface WorkbenchConfig {
+    API_HOST: string;
+    VOCABULARY_URL: string;
+    FILE_VIEWERS_CONFIG_URL: string;
+}
+
+export interface ClusterConfigJSON {
+    ClusterID: string;
+    RemoteClusters:  {
+        [key: string]: {
+            ActivateUsers: boolean
+            Host: string
+            Insecure: boolean
+            Proxy: boolean
+            Scheme: string
+        }
+    };
+    Services: {
+        Controller: {
+            ExternalURL: string
+        }
+        Workbench1: {
+            ExternalURL: string
+        }
+        Workbench2: {
+            ExternalURL: string
+        }
+        Websocket: {
+            ExternalURL: string
+        }
+        WebDAV: {
+            ExternalURL: string
+        }
+    };
+    Workbench: {
+        ArvadosDocsite: string;
+        VocabularyURL: string;
+        FileViewersConfigURL: string;
+    };
+}
+
+export class Config {
     baseUrl: string;
     baseUrl: string;
-    batchPath: string;
-    blobSignatureTtl: number;
-    crunchLimitLogBytesPerJob: number;
-    crunchLogBytesPerEvent: number;
-    crunchLogPartialLineThrottlePeriod: number;
-    crunchLogSecondsBetweenEvents: number;
-    crunchLogThrottleBytes: number;
-    crunchLogThrottleLines: number;
-    crunchLogThrottlePeriod: number;
-    defaultCollectionReplication: number;
-    defaultTrashLifetime: number;
-    description: string;
-    discoveryVersion: string;
-    dockerImageFormats: string[];
-    documentationLink: string;
-    generatedAt: string;
-    gitUrl: string;
-    id: string;
     keepWebServiceUrl: string;
     keepWebServiceUrl: string;
-    kind: string;
-    maxRequestSize: number;
-    name: string;
-    packageVersion: string;
-    parameters: {};
-    protocol: string;
     remoteHosts: {
         [key: string]: string
     };
     remoteHosts: {
         [key: string]: string
     };
-    remoteHostsViaDNS: boolean;
-    resources: {};
-    revision: string;
     rootUrl: string;
     rootUrl: string;
-    schemas: {};
-    servicePath: string;
-    sourceVersion: string;
-    source_version: string;
-    title: string;
     uuidPrefix: string;
     uuidPrefix: string;
-    version: string;
     websocketUrl: string;
     workbenchUrl: string;
     websocketUrl: string;
     workbenchUrl: string;
-    workbench2Url?: string;
+    workbench2Url: string;
     vocabularyUrl: string;
     fileViewersConfigUrl: string;
 }
 
 export const fetchConfig = () => {
     return Axios
     vocabularyUrl: string;
     fileViewersConfigUrl: string;
 }
 
 export const fetchConfig = () => {
     return Axios
-        .get<ConfigJSON>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
+        .get<WorkbenchConfig>(WORKBENCH_CONFIG_URL + "?nocache=" + (new Date()).getTime())
         .then(response => response.data)
         .catch(() => Promise.resolve(getDefaultConfig()))
         .then(response => response.data)
         .catch(() => Promise.resolve(getDefaultConfig()))
-        .then(config => Axios
-            .get<Config>(getDiscoveryURL(config.API_HOST))
-            .then(response => ({
-                // TODO: After tests delete `|| '/vocabulary-example.json'`
-                // TODO: After tests delete `|| '/file-viewers-example.json'`
-                config: {
-                    ...response.data,
-                    vocabularyUrl: config.VOCABULARY_URL || '/vocabulary-example.json',
-                    fileViewersConfigUrl: config.FILE_VIEWERS_CONFIG_URL || '/file-viewers-example.json'
-                },
-                apiHost: config.API_HOST,
-            })));
+        .then(workbenchConfig => Axios
+            .get<ClusterConfigJSON>(getClusterConfigURL(workbenchConfig.API_HOST))
+            .then(response => {
+
+                const config = new Config();
+                const clusterConfigJSON = response.data;
+                const docsite = clusterConfigJSON.Workbench.ArvadosDocsite;
+                const warnDeprecation = (varName: string) => console.warn(
+`A value for ${varName} was found in ${WORKBENCH_CONFIG_URL}. This configuration is deprecated. \
+Please use the centralized configuration instead. See more at ${docsite}admin/config-migration.html`);
 
 
+                // Check if the workbench config has an entry for vocabulary and file viewer URLs
+                // If so, use these values (even if it is an empty string), but print a console warning.
+                // Otherwise, use the cluster config or default values.
+                let fileViewerConfigUrl;
+                if (workbenchConfig.FILE_VIEWERS_CONFIG_URL !== undefined) {
+                    warnDeprecation("FILE_VIEWERS_CONFIG_URL");
+                    fileViewerConfigUrl = workbenchConfig.FILE_VIEWERS_CONFIG_URL;
+                }
+                else {
+                    fileViewerConfigUrl = clusterConfigJSON.Workbench.FileViewersConfigURL || "/file-viewers-example.json";
+                }
+                config.fileViewersConfigUrl = fileViewerConfigUrl;
+
+                let vocabularyUrl;
+                if (workbenchConfig.VOCABULARY_URL !== undefined) {
+                    warnDeprecation("VOCABULARY_URL");
+                    vocabularyUrl = workbenchConfig.VOCABULARY_URL;
+                }
+                else {
+                    vocabularyUrl = clusterConfigJSON.Workbench.VocabularyURL || "/vocabulary-example.json";
+                }
+                config.vocabularyUrl = vocabularyUrl;
+
+                config.rootUrl = clusterConfigJSON.Services.Controller.ExternalURL;
+                config.baseUrl = `${config.rootUrl}/${ARVADOS_API_PATH}`;
+                config.uuidPrefix = clusterConfigJSON.ClusterID;
+                config.websocketUrl = clusterConfigJSON.Services.Websocket.ExternalURL;
+                config.workbench2Url = clusterConfigJSON.Services.Workbench2.ExternalURL;
+                config.workbenchUrl = clusterConfigJSON.Services.Workbench1.ExternalURL;
+                config.keepWebServiceUrl =  clusterConfigJSON.Services.WebDAV.ExternalURL;
+                mapRemoteHosts(clusterConfigJSON, config);
+
+                console.log(config);
+
+                return { config, apiHost: workbenchConfig.API_HOST };
+            })
+        );
+};
+
+// Maps remote cluster hosts and removes the default RemoteCluster entry
+export const mapRemoteHosts = (clusterConfigJSON: ClusterConfigJSON, config: Config) => {
+    config.remoteHosts = {};
+    Object.keys(clusterConfigJSON.RemoteClusters).forEach (k => { config.remoteHosts[k] = clusterConfigJSON.RemoteClusters[k].Host; });
+    delete config.remoteHosts["*"];
 };
 
 export const mockConfig = (config: Partial<Config>): Config => ({
 };
 
 export const mockConfig = (config: Partial<Config>): Config => ({
-    auth: {},
-    basePath: '',
-    baseUrl: '',
-    batchPath: '',
-    blobSignatureTtl: 0,
-    crunchLimitLogBytesPerJob: 0,
-    crunchLogBytesPerEvent: 0,
-    crunchLogPartialLineThrottlePeriod: 0,
-    crunchLogSecondsBetweenEvents: 0,
-    crunchLogThrottleBytes: 0,
-    crunchLogThrottleLines: 0,
-    crunchLogThrottlePeriod: 0,
-    defaultCollectionReplication: 0,
-    defaultTrashLifetime: 0,
-    description: '',
-    discoveryVersion: '',
-    dockerImageFormats: [],
-    documentationLink: '',
-    generatedAt: '',
-    gitUrl: '',
-    id: '',
-    keepWebServiceUrl: '',
-    kind: '',
-    maxRequestSize: 0,
-    name: '',
-    packageVersion: '',
-    parameters: {},
-    protocol: '',
+    baseUrl: "",
+    keepWebServiceUrl: "",
     remoteHosts: {},
     remoteHosts: {},
-    remoteHostsViaDNS: false,
-    resources: {},
-    revision: '',
-    rootUrl: '',
-    schemas: {},
-    servicePath: '',
-    sourceVersion: '',
-    source_version: '',
-    title: '',
-    uuidPrefix: '',
-    version: '',
-    websocketUrl: '',
-    workbenchUrl: '',
-    vocabularyUrl: '',
-    fileViewersConfigUrl: '',
-    ...config
+    rootUrl: "",
+    uuidPrefix: "",
+    websocketUrl: "",
+    workbenchUrl: "",
+    workbench2Url: "",
+    vocabularyUrl: "",
+    fileViewersConfigUrl: ""
 });
 
 });
 
-interface ConfigJSON {
-    API_HOST: string;
-    VOCABULARY_URL: string;
-    FILE_VIEWERS_CONFIG_URL: string;
-}
-
-const getDefaultConfig = (): ConfigJSON => ({
+const getDefaultConfig = (): WorkbenchConfig => ({
     API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
     VOCABULARY_URL: "",
     FILE_VIEWERS_CONFIG_URL: "",
 });
 
     API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
     VOCABULARY_URL: "",
     FILE_VIEWERS_CONFIG_URL: "",
 });
 
-export const DISCOVERY_URL = 'discovery/v1/apis/arvados/v1/rest';
-export const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${DISCOVERY_URL}?nocache=${(new Date()).getTime()}`;
+export const ARVADOS_API_PATH = "arvados/v1";
+export const CLUSTER_CONFIG_URL = "arvados/v1/config";
+export const getClusterConfigURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${CLUSTER_CONFIG_URL}?nocache=${(new Date()).getTime()}`;
\ No newline at end of file
index b889e9cf39d7d301a0c5e8e4b8e70859e7d7c3ff..ca2e23269aff5a82578db3731bfb36d846069848 100644 (file)
@@ -9,7 +9,7 @@ import { ServiceRepository } from "~/services/services";
 import Axios from "axios";
 import { getUserFullname, User } from "~/models/user";
 import { authActions } from "~/store/auth/auth-action";
 import Axios from "axios";
 import { getUserFullname, User } from "~/models/user";
 import { authActions } from "~/store/auth/auth-action";
-import { Config, DISCOVERY_URL } from "~/common/config";
+import { Config, ClusterConfigJSON, CLUSTER_CONFIG_URL, ARVADOS_API_PATH } from "~/common/config";
 import { Session, SessionStatus } from "~/models/session";
 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
 import { AuthService, UserDetailsResponse } from "~/services/auth-service/auth-service";
 import { Session, SessionStatus } from "~/models/session";
 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
 import { AuthService, UserDetailsResponse } from "~/services/auth-service/auth-service";
@@ -24,8 +24,8 @@ const getRemoteHostBaseUrl = async (remoteHost: string): Promise<string | null>
     let baseUrl: string | null = null;
 
     try {
     let baseUrl: string | null = null;
 
     try {
-        const resp = await Axios.get<Config>(`${origin}/${DISCOVERY_URL}`);
-        baseUrl = resp.data.baseUrl;
+        const resp = await Axios.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_URL}`);
+        baseUrl = `${resp.data.Services.Controller.ExternalURL}/${ARVADOS_API_PATH}`;
     } catch (err) {
         try {
             const resp = await Axios.get<any>(`${origin}/status.json`);
     } catch (err) {
         try {
             const resp = await Axios.get<any>(`${origin}/status.json`);
index 1d1ad18cbd8c985218fc7aa433b04056d76d031d..6356eaa8bdc9e5b8771feacb7ea2c26241842002 100644 (file)
@@ -10,7 +10,7 @@ import { ServiceRepository } from "~/services/services";
 import { SshKeyResource } from '~/models/ssh-key';
 import { User, UserResource } from "~/models/user";
 import { Session } from "~/models/session";
 import { SshKeyResource } from '~/models/ssh-key';
 import { User, UserResource } from "~/models/user";
 import { Session } from "~/models/session";
-import { getDiscoveryURL, Config } from '~/common/config';
+import { getClusterConfigURL, Config, ClusterConfigJSON, mapRemoteHosts } from '~/common/config';
 import { initSessions } from "~/store/auth/auth-action-session";
 import { cancelLinking } from '~/store/link-account-panel/link-account-panel-actions';
 import { matchTokenRoute, matchFedTokenRoute } from '~/routes/routes';
 import { initSessions } from "~/store/auth/auth-action-session";
 import { cancelLinking } from '~/store/link-account-panel/link-account-panel-actions';
 import { matchTokenRoute, matchFedTokenRoute } from '~/routes/routes';
@@ -88,8 +88,13 @@ const init = (config: Config) => (dispatch: Dispatch, getState: () => RootState,
         });
     }
     Object.keys(config.remoteHosts).map((k) => {
         });
     }
     Object.keys(config.remoteHosts).map((k) => {
-        Axios.get<Config>(getDiscoveryURL(config.remoteHosts[k]))
-            .then(response => dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config: response.data })));
+        Axios.get<ClusterConfigJSON>(getClusterConfigURL(config.remoteHosts[k]))
+            .then(response => {
+                const remoteConfig = new Config();
+                remoteConfig.workbench2Url = response.data.Services.Workbench2.ExternalURL;
+                mapRemoteHosts(response.data, remoteConfig);
+                dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config: remoteConfig}));
+            });
     });
 };
 
     });
 };