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
51 changes: 49 additions & 2 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,47 @@ PluginLoader.prototype = {
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 */
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.hostname
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

considering the gateway often starts slower than app-server, i think you need some sort of loop w/ timeout here because it's highly likely to fail on the first request.

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) {
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(() => {
/* 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