diff --git a/.github/workflows/build-core.yml b/.github/workflows/build-core.yml index 3a4087a9..27f96216 100644 --- a/.github/workflows/build-core.yml +++ b/.github/workflows/build-core.yml @@ -99,4 +99,3 @@ jobs: - name: '[Prep 7] deploy' uses: zowe-actions/zlux-builds/core/deploy@v2.x/main - diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 18dca22f..f46f49ef 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -53,6 +53,8 @@ const APP_SERVER_COMP_ID = 'app-server'; const AGENT_COMP_ID = 'zss'; +const APIML_GATEWAY_COMP_ID = 'gateway'; + const compsToCheck = { [APP_SERVER_COMP_ID]: { name: "App server", @@ -72,6 +74,15 @@ const compsToCheck = { cpu: true, version: true, endpoints: true + }, + [APIML_GATEWAY_COMP_ID]: { + name: "Gateway", + id: APIML_GATEWAY_COMP_ID, + + os: true, + cpu: false, + version: true, + endpoints: false } }; @@ -883,6 +894,7 @@ PluginLoader.prototype = { return new Promise((complete, fail)=> { let appServerComp = {}; let agentComp = {}; + let gatewayComp = {}; const requestOptions = zluxUtil.getAgentRequestOptions(config, this.tlsOptions, false); appServerComp.os = process.platform; // Operating system @@ -928,9 +940,9 @@ PluginLoader.prototype = { resolve(); }); - }).then(() => { /* Obtains and stores the endpoints exposed by the agent */ + }).then(() => { requestOptions.path = '/server/agent/services'; - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { httpApi.get(requestOptions, (res) => { const { statusCode } = res; // TODO: Check status code for bad status const contentType = res.headers['content-type']; @@ -959,12 +971,64 @@ PluginLoader.prototype = { bootstrapLogger.severe(e.message); resolve(); // We don't want to reject here. Error gets caught down stream }); - }).then(() => { + }) + }).then(() => { /* Obtains and stores the endpoints exposed by the agent */ + requestOptions.path = '/application/info'; + if(config.node.mediationLayer && + config.node.mediationLayer.enabled && + config.node.mediationLayer.server){ + requestOptions.host = config.node.mediationLayer.server.gatewayHostname + requestOptions.port = config.node.mediationLayer.server.gatewayPort + } + let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 1200000; + const GATEWAY_CHECK_RECONNECT_DELAY = 10000; + const end = Date.now() + timer; + return new Promise((resolve, reject) => { + + const gatewayCheck = () => { + if (Date.now() > end) { + bootstrapLogger.warn(`ZWED0045`, this.apimlHost, this.apimlPort); + return reject(new Error(`Call timeout when fetching gateway status from APIML`)); + } + + let req = httpApi.request(requestOptions, (res) => { + res.setEncoding('utf8'); + let rawData = ''; + res.on('data', (chunk) => { rawData += chunk; }); + res.on('end', () => { + try { + const parsedData = JSON.parse(rawData); + if (parsedData.build) { + gatewayComp.os = parsedData.build.operatingSystem; + gatewayComp.version = parsedData.build.version; + } else { + setTimeout(gatewayCheck, GATEWAY_CHECK_RECONNECT_DELAY); + } + resolve(); + } catch (e) { + bootstrapLogger.severe(e.message); + resolve(); // We don't want to reject here. Error gets caught down stream + } + }); + }).on('error', (e) => { + bootstrapLogger.severe(e.message); + setTimeout(gatewayCheck, GATEWAY_CHECK_RECONNECT_DELAY); + resolve(); // We don't want to reject here. Error gets caught down stream + }); + req.setTimeout(timer, () => { + reject(new Error(`Call timeout when fetching gateway status from APIML`)); + }) + req.end(); + } + gatewayCheck(); + }) + .then(() => { /* TODO: before checking if dependencies are met, we must learn about the components that exist. doing this is not formalized currently, so we currently have a block per component to learn about their capabilities, version, environment, etc. perhaps in the future zowe components could have metadata files and/or expected URLs for querying.*/ envComps[AGENT_COMP_ID] = agentComp; envComps[APP_SERVER_COMP_ID] = appServerComp; + envComps[APIML_GATEWAY_COMP_ID] = gatewayComp; complete(); }).catch((e)=> {fail(e);}); }).catch((e)=>{fail(e);}); diff --git a/lib/util.js b/lib/util.js index d59a581e..548a1cc2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -402,14 +402,15 @@ module.exports.getRemoteIframeTemplate = function(remoteUrl) { module.exports.makeRemoteUrl = function(destination, req, serverConfig) { let referer = req.get('Referer'); + let hostname = referer === '' ? '' : new URL(referer).hostname; loggers.utilLogger.debug(`referer: ${referer}`); let zoweExternalHost; let zoweExternalPort; - + if(destination.includes('ZOWE_EXTERNAL_HOST') || destination.includes('ZWE_EXTERNAL_HOST')) { - if( referer > '') { - zoweExternalHost = referer.split(':')[1].substring(2); + if( hostname > '') { + zoweExternalHost = hostname; } else if (process.env.ZWE_EXTERNAL_HOST) { zoweExternalHost = process.env.ZWE_EXTERNAL_HOST; } else if (process.env.ZOWE_EXTERNAL_HOST) {