mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5008] Add an health checks on the services: (#5267)
* Add an health checks on the services: deployment-service modeling-service dmn-service * Refactoring
This commit is contained in:
committed by
Eugenio Romano
parent
9814e28027
commit
037aab7ae1
@@ -36,6 +36,12 @@ export interface ConfigArgs {
|
|||||||
identityHost: boolean;
|
identityHost: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const AAE_MICROSERVICES = [
|
||||||
|
'deployment-service',
|
||||||
|
'modeling-service',
|
||||||
|
'dmn-service'
|
||||||
|
];
|
||||||
|
|
||||||
async function getDeployedApplicationsByStatus(args: ConfigArgs, apiService: any, status: string) {
|
async function getDeployedApplicationsByStatus(args: ConfigArgs, apiService: any, status: string) {
|
||||||
const url = `${args.host}/deployment-service/v1/applications`;
|
const url = `${args.host}/deployment-service/v1/applications`;
|
||||||
|
|
||||||
@@ -55,6 +61,27 @@ async function getDeployedApplicationsByStatus(args: ConfigArgs, apiService: any
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function healthCheck(args: ConfigArgs, apiService: any, nameService: string, result: any) {
|
||||||
|
const url = `${args.host}/${nameService}/actuator/health`;
|
||||||
|
|
||||||
|
const pathParams = {}, queryParams = {},
|
||||||
|
headerParams = {}, formParams = {}, bodyParam = {},
|
||||||
|
contentTypes = ['application/json'], accepts = ['application/json'];
|
||||||
|
try {
|
||||||
|
const health = await apiService.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam,
|
||||||
|
contentTypes, accepts);
|
||||||
|
if (health.status !== 'UP' ) {
|
||||||
|
logger.error(`${nameService} is DOWN `);
|
||||||
|
result.isValid = false;
|
||||||
|
} else {
|
||||||
|
logger.info(`${nameService} is UP!`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`${nameService} is not reachable ${error.status} `);
|
||||||
|
result.isValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getAlfrescoJsApiInstance(args: ConfigArgs) {
|
function getAlfrescoJsApiInstance(args: ConfigArgs) {
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'BPM',
|
provider: 'BPM',
|
||||||
@@ -75,13 +102,16 @@ function getAlfrescoJsApiInstance(args: ConfigArgs) {
|
|||||||
|
|
||||||
async function login(args: ConfigArgs, alfrescoJsApi: any) {
|
async function login(args: ConfigArgs, alfrescoJsApi: any) {
|
||||||
logger.info(`Perform login...`);
|
logger.info(`Perform login...`);
|
||||||
|
try {
|
||||||
await alfrescoJsApi.login(args.username, args.password);
|
await alfrescoJsApi.login(args.username, args.password);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Not able to login. Credentials ${args.username}:${args.password} are not valid`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
return alfrescoJsApi;
|
return alfrescoJsApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deployMissingApps(args: ConfigArgs) {
|
async function deployMissingApps(args: ConfigArgs, alfrescoJsApi: any) {
|
||||||
const alfrescoJsApi = getAlfrescoJsApiInstance(args);
|
|
||||||
await login(args, alfrescoJsApi);
|
|
||||||
const deployedApps = await getDeployedApplicationsByStatus(args, alfrescoJsApi, '');
|
const deployedApps = await getDeployedApplicationsByStatus(args, alfrescoJsApi, '');
|
||||||
const absentApps = findMissingApps(deployedApps);
|
const absentApps = findMissingApps(deployedApps);
|
||||||
|
|
||||||
@@ -359,5 +389,21 @@ async function main(args) {
|
|||||||
program.outputHelp();
|
program.outputHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
await deployMissingApps(args);
|
const alfrescoJsApi = getAlfrescoJsApiInstance(args);
|
||||||
|
await login(args, alfrescoJsApi);
|
||||||
|
|
||||||
|
const result = { isValid: true };
|
||||||
|
|
||||||
|
AAE_MICROSERVICES.map(async (serviceName) => {
|
||||||
|
await healthCheck(args, alfrescoJsApi, serviceName, result);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.isValid) {
|
||||||
|
logger.error('The envirorment is up and running');
|
||||||
|
await deployMissingApps(args, alfrescoJsApi);
|
||||||
|
} else {
|
||||||
|
logger.error('The envirorment is not up');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user