Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gateway to app server component checking #405

Open
wants to merge 15 commits into
base: v2.x/staging
Choose a base branch
from
70 changes: 67 additions & 3 deletions lib/plugin-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this comment was meant to be on line 945, line 975 can say the same thing except for API ML

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 || 600000;
const GATEWAY_CHECK_RECONNECT_DELAY = 10000;
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2022-04-12 20:34:27.699 <:> me WARN (_zsf.bootstrap,process.js:29) ZWED0036W - Uncaught exception found. Error:
ReferenceError: log is not defined
ZWED0037W - Ending server process due to uncaught exception.
ZWED0050I - Server shutting down, received signal=SIGQUIT

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);});
Expand Down