From d0d82a64a720b1c6b41e4857133d04bceedcd171 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Tue, 5 Apr 2022 02:23:41 -0400 Subject: [PATCH 01/11] Retrieve gateway info on startup Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 18dca22f..3df39c7b 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 @@ -929,7 +941,13 @@ PluginLoader.prototype = { }); }).then(() => { /* Obtains and stores the endpoints exposed by the agent */ - requestOptions.path = '/server/agent/services'; + requestOptions.path = '/application/info'; + if(config.node.mediationLayer && + config.node.mediationLayer.enabled && + config.node.mediationLayer.server){ + requestOptions.host = config.node.mediationLayer.server.hostname + requestOptions.port = config.node.mediationLayer.server.gatewayPort + } return new Promise((resolve, reject) => { httpApi.get(requestOptions, (res) => { const { statusCode } = res; // TODO: Check status code for bad status @@ -941,13 +959,9 @@ PluginLoader.prototype = { res.on('end', () => { try { const parsedData = JSON.parse(rawData); - if (parsedData.services) { - agentComp.endpoints = []; - for (let i = 0; i < parsedData.services.length; i++) { - if (parsedData.services[i].urlMask) { - agentComp.endpoints.push(parsedData.services[i].urlMask); - } - } + if (parsedData.build) { + gatewayComp.os = parsedData.build.operatingSystem; + gatewayComp.version = parsedData.build.version; } resolve(); } catch (e) { @@ -965,6 +979,7 @@ PluginLoader.prototype = { 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);}); From e48d9229f85f5b499bf0fdac499e42c430a8ae8a Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Tue, 5 Apr 2022 02:31:19 -0400 Subject: [PATCH 02/11] add accidently removed call Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 3df39c7b..350d496e 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -940,6 +940,38 @@ PluginLoader.prototype = { resolve(); }); + }).then(() => { + requestOptions.path = '/server/agent/services'; + 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']; + + res.setEncoding('utf8'); + let rawData = ''; + res.on('data', (chunk) => { rawData += chunk; }); + res.on('end', () => { + try { + const parsedData = JSON.parse(rawData); + if (parsedData.services) { + agentComp.endpoints = []; + for (let i = 0; i < parsedData.services.length; i++) { + if (parsedData.services[i].urlMask) { + agentComp.endpoints.push(parsedData.services[i].urlMask); + } + } + } + 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); + resolve(); // We don't want to reject here. Error gets caught down stream + }); + }) }).then(() => { /* Obtains and stores the endpoints exposed by the agent */ requestOptions.path = '/application/info'; if(config.node.mediationLayer && From 607642b878aef43aadd2b3f6edd0cc0e5b7aa683 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 6 Apr 2022 09:33:24 -0400 Subject: [PATCH 03/11] fix route Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 350d496e..1c8e038b 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -977,7 +977,7 @@ PluginLoader.prototype = { if(config.node.mediationLayer && config.node.mediationLayer.enabled && config.node.mediationLayer.server){ - requestOptions.host = config.node.mediationLayer.server.hostname + requestOptions.host = config.node.mediationLayer.server.gatewayHostname requestOptions.port = config.node.mediationLayer.server.gatewayPort } return new Promise((resolve, reject) => { From 8802b2a53f1cc8d25170a0b4c2931edbb1519c36 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 6 Apr 2022 18:41:06 -0400 Subject: [PATCH 04/11] Add timeout for gateway check Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 63 ++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 1c8e038b..19b4ee64 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -981,30 +981,49 @@ PluginLoader.prototype = { requestOptions.port = config.node.mediationLayer.server.gatewayPort } 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']; - - 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; - } - resolve(); - } catch (e) { + let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; + const end = Date.now() + GATEWAY_TIMEOUT_MILLIS; + return new Promise((resolve, reject) => { + + const gatewayCheck = () => { + if (Date.now() > end) { + log.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.services) { + agentComp.endpoints = []; + for (let i = 0; i < parsedData.services.length; i++) { + if (parsedData.services[i].urlMask) { + agentComp.endpoints.push(parsedData.services[i].urlMask); + } + } + } else { + setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); + } + 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_TIMEOUT_MILLIS); resolve(); // We don't want to reject here. Error gets caught down stream - } - }); - }).on('error', (e) => { - bootstrapLogger.severe(e.message); - 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(); + } }) }).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 From 99a1287a33211f4a8d40572e2cb0c1b857b04f23 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 6 Apr 2022 18:43:40 -0400 Subject: [PATCH 05/11] i think this branch is a lil messed up lol Signed-off-by: Timothy Gerstel --- lib/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) { From 5f0e6b2751f6e2cc5e0510ea18ea43ed8b3658a6 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 6 Apr 2022 21:21:40 -0400 Subject: [PATCH 06/11] Add correct code... Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 83 +++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 19b4ee64..28a70481 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -979,52 +979,49 @@ PluginLoader.prototype = { config.node.mediationLayer.server){ requestOptions.host = config.node.mediationLayer.server.gatewayHostname requestOptions.port = config.node.mediationLayer.server.gatewayPort - } - return new Promise((resolve, reject) => { - let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; - const end = Date.now() + GATEWAY_TIMEOUT_MILLIS; - return new Promise((resolve, reject) => { + } + let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; + const end = Date.now() + GATEWAY_TIMEOUT_MILLIS; + return new Promise((resolve, reject) => { - const gatewayCheck = () => { - if (Date.now() > end) { - log.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.services) { - agentComp.endpoints = []; - for (let i = 0; i < parsedData.services.length; i++) { - if (parsedData.services[i].urlMask) { - agentComp.endpoints.push(parsedData.services[i].urlMask); - } - } - } else { - setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); - } - resolve(); - } catch (e) { - bootstrapLogger.severe(e.message); - resolve(); // We don't want to reject here. Error gets caught down stream + const gatewayCheck = () => { + if (Date.now() > end) { + log.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_TIMEOUT_MILLIS); } - }); - }).on('error', (e) => { - bootstrapLogger.severe(e.message); - setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); - resolve(); // We don't want to reject here. Error gets caught down stream + resolve(); + } catch (e) { + bootstrapLogger.severe(e.message); + 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(); - } }) - }).then(() => { + }).on('error', (e) => { + bootstrapLogger.severe(e.message); + setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); + 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.*/ From 4bc93c2b4002674b22e0b3e4b01c97e1d9007ea9 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 6 Apr 2022 21:25:48 -0400 Subject: [PATCH 07/11] 10 sec delay between requests Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 28a70481..9ac95247 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -981,6 +981,7 @@ PluginLoader.prototype = { requestOptions.port = config.node.mediationLayer.server.gatewayPort } let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; + const GATEWAY_CHECK_RECONNECT_DELAY = 10000; const end = Date.now() + GATEWAY_TIMEOUT_MILLIS; return new Promise((resolve, reject) => { @@ -1001,7 +1002,7 @@ PluginLoader.prototype = { gatewayComp.os = parsedData.build.operatingSystem; gatewayComp.version = parsedData.build.version; } else { - setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); + setTimeout(gatewayCheck, GATEWAY_CHECK_RECONNECT_DELAY); } resolve(); } catch (e) { @@ -1011,7 +1012,7 @@ PluginLoader.prototype = { }); }).on('error', (e) => { bootstrapLogger.severe(e.message); - setTimeout(gatewayCheck, GATEWAY_TIMEOUT_MILLIS); + setTimeout(gatewayCheck, GATEWAY_CHECK_RECONNECT_DELAY); resolve(); // We don't want to reject here. Error gets caught down stream }); req.setTimeout(timer, () => { From b909cecf5336f9565193514ac99a25d7ba639a0d Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Tue, 12 Apr 2022 11:14:03 -0400 Subject: [PATCH 08/11] update var Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 9ac95247..04d4c2df 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -982,7 +982,7 @@ PluginLoader.prototype = { } let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; const GATEWAY_CHECK_RECONNECT_DELAY = 10000; - const end = Date.now() + GATEWAY_TIMEOUT_MILLIS; + const end = Date.now() + GATEWAY_CHECK_RECONNECT_DELAY; return new Promise((resolve, reject) => { const gatewayCheck = () => { From 051daaa2385c9836177a5e507dc23e8f1a516a1b Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Wed, 13 Apr 2022 09:47:40 -0400 Subject: [PATCH 09/11] replace log with bootstrap logger Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 04d4c2df..4c6d3657 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -987,7 +987,7 @@ PluginLoader.prototype = { const gatewayCheck = () => { if (Date.now() > end) { - log.warn(`ZWED0045`, this.apimlHost, this.apimlPort); + bootstrapLogger.warn(`ZWED0045`, this.apimlHost, this.apimlPort); return reject(new Error(`Call timeout when fetching gateway status from APIML`)); } From 732c7da862063a62248c1963c75b494046cd96a7 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Thu, 14 Apr 2022 20:23:01 -0400 Subject: [PATCH 10/11] Per seans testing with a v2 pax on zos, 10 minutes was actually insufficient timeout length to connect to the mediation layer Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index 4c6d3657..fbabf5c8 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -980,7 +980,7 @@ PluginLoader.prototype = { requestOptions.host = config.node.mediationLayer.server.gatewayHostname requestOptions.port = config.node.mediationLayer.server.gatewayPort } - let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 600000; + let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 1200000; const GATEWAY_CHECK_RECONNECT_DELAY = 10000; const end = Date.now() + GATEWAY_CHECK_RECONNECT_DELAY; return new Promise((resolve, reject) => { From 7b1e5ff00d76c5c3b1a4ef69e3a1f7255156c7e0 Mon Sep 17 00:00:00 2001 From: Timothy Gerstel Date: Fri, 15 Apr 2022 09:17:08 -0400 Subject: [PATCH 11/11] fix timeout check Signed-off-by: Timothy Gerstel --- lib/plugin-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin-loader.js b/lib/plugin-loader.js index fbabf5c8..f46f49ef 100644 --- a/lib/plugin-loader.js +++ b/lib/plugin-loader.js @@ -982,7 +982,7 @@ PluginLoader.prototype = { } let timer = process.env.APIML_GATEWAY_TIMEOUT_MILLIS || 1200000; const GATEWAY_CHECK_RECONNECT_DELAY = 10000; - const end = Date.now() + GATEWAY_CHECK_RECONNECT_DELAY; + const end = Date.now() + timer; return new Promise((resolve, reject) => { const gatewayCheck = () => {