diff --git a/app/config/services.js b/app/config/services.js index ad16f7e88..5a6388e2c 100644 --- a/app/config/services.js +++ b/app/config/services.js @@ -18,17 +18,17 @@ const services = { bookkeeping: { url: { rct: 'http://rct-bookkeeping.cern.ch:4000/api/runs', - ali: ResProvider.endpointFor('BK_RUNS'), + ali: ResProvider.getServiceEndpoint('BK_RUNS'), }, }, monalisa: { url: { - dataPassesRaw: ResProvider.endpointFor('ML_DP_RAW'), - dataPassesDetailed: ResProvider.endpointFor('ML_DP_DET'), + dataPassesRaw: ResProvider.getServiceEndpoint('ML_DP_RAW'), + dataPassesDetailed: ResProvider.getServiceEndpoint('ML_DP_DET'), - mcRaw: ResProvider.endpointFor('ML_MC_RAW'), - mcDetailed: ResProvider.endpointFor('ML_MC_DET'), - mcDetTag: ResProvider.endpointFor('ML_MC_TAG'), + mcRaw: ResProvider.getServiceEndpoint('ML_MC_RAW'), + mcDetailed: ResProvider.getServiceEndpoint('ML_MC_DET'), + mcDetTag: ResProvider.getServiceEndpoint('ML_MC_TAG'), }, }, }; diff --git a/app/lib/ResProvider.js b/app/lib/ResProvider.js index 740f3ffed..fd3da1c2f 100644 --- a/app/lib/ResProvider.js +++ b/app/lib/ResProvider.js @@ -225,13 +225,30 @@ class ResProvider { varsDef[`RCT_EP_${serviceAbbr}_PORT`] = 'port'; varsDef[`RCT_EP_${serviceAbbr}_PATH`] = 'path'; const p = ResProvider.viaEnvVars(varsDef, null, 'warn'); - const { host } = p; + let { host } = p; let { path } = p; // eslint-disable-next-line prefer-destructuring let prot = p['prot']; - prot = prot ? prot : 'https'; + prot = prot ? prot.trim().replace('://', '') : 'https'; // eslint-disable-next-line prefer-destructuring let port = p['port']; + const hs = host.split(':'); + if (hs.length === 2) { + // eslint-disable-next-line prefer-destructuring + port = hs[1]; + // eslint-disable-next-line prefer-destructuring + host = hs[0]; + } else if (hs.length != 1) { + const mess = `incorrect format of hostname: ${host}`; + logger.error(mess); + throw mess; + } + + if (port && isNaN(port)) { + const mess = `incorrect port <${port}> for hostname: ${host}`; + logger.error(mess); + throw mess; + } port = port ? `:${port}` : ''; path = path ? path.trim().replace(/^\/*/, '') : ''; return `${prot}://${host}${port}/${path}`; diff --git a/docker/dev.env b/docker/dev.env index 11825d9d2..eebcac68e 100644 --- a/docker/dev.env +++ b/docker/dev.env @@ -25,43 +25,36 @@ CERN_SOCKS=${CERN_SOCKS:-true} ### endpoints _DEF_BK_HOST=ali-bookkeeping.cern.ch _DEF_ML_HOST=alimonitor.cern.ch -_DEF_PORT=443 _DEF_ML_PROT=https ### bkp RCT_EP_BK_RUNS_PROT=https RCT_EP_BK_RUNS_HOST=${RCT_EP_BK_RUNS_HOST:-$_DEF_BK_HOST} -RCT_EP_BK_RUNS_PORT=${RCT_EP_BK_RUNS_PORT:-$_DEF_PORT} RCT_EP_BK_RUNS_PATH=${RCT_EP_BK_RUNS_PATH:-/api/runs?filter[definitions]=PHYSICS} ### data passes RCT_EP_ML_DP_RAW_PROT=$_DEF_ML_PROT RCT_EP_ML_DP_RAW_HOST=${RCT_EP_ML_DP_RAW_HOST:-$_DEF_ML_HOST} -RCT_EP_ML_DP_RAW_PORT=${RCT_EP_ML_DP_RAW_PORT:-$_DEF_PORT} RCT_EP_ML_DP_RAW_PATH=${RCT_EP_ML_DP_RAW_PATH:-/production/raw.jsp?res_path=json} RCT_EP_ML_DP_DET_PROT=$_DEF_ML_PROT RCT_EP_ML_DP_DET_HOST=${RCT_EP_ML_DP_DET_HOST:-$_DEF_ML_HOST} -RCT_EP_ML_DP_DET_PORT=${RCT_EP_ML_DP_DET_PORT:-$_DEF_PORT} RCT_EP_ML_DP_DET_PATH=${RCT_EP_ML_DP_DET_PATH:-/raw/raw_details.jsp?timesel=0&res_path=json} ### simulation passes RCT_EP_ML_MC_RAW_PROT=$_DEF_ML_PROT RCT_EP_ML_MC_RAW_HOST=${RCT_EP_ML_MC_RAW_HOST:-$_DEF_ML_HOST} -RCT_EP_ML_MC_RAW_PORT=${RCT_EP_ML_MC_RAW_PORT:-$_DEF_PORT} RCT_EP_ML_MC_RAW_PATH=${RCT_EP_ML_MC_RAW_PATH:-/MC/?res_path=json} RCT_EP_ML_MC_DET_PROT=$_DEF_ML_PROT RCT_EP_ML_MC_DET_HOST=${RCT_EP_ML_MC_DET_HOST:-$_DEF_ML_HOST} -RCT_EP_ML_MC_DET_PORT=${RCT_EP_ML_MC_DET_PORT:-$_DEF_PORT} RCT_EP_ML_MC_DET_PATH=${RCT_EP_ML_MC_DET_PATH:-/job_events.jsp?timesel=0&res_path=json} RCT_EP_ML_MC_TAG_PROT=$_DEF_ML_PROT RCT_EP_ML_MC_TAG_HOST=${RCT_EP_ML_MC_TAG_HOST:-$_DEF_ML_HOST} -RCT_EP_ML_MC_TAG_PORT=${RCT_EP_ML_MC_TAG_PORT:-$_DEF_PORT} RCT_EP_ML_MC_TAG_PATH=${RCT_EP_ML_MC_TAG_PATH:-/MC/prodDetails.jsp?res_path=json}