mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
improve the init by failing in case the app are not running (#6591)
This commit is contained in:
parent
a5e41e8492
commit
cfe1eabc2d
@ -31,7 +31,8 @@ let alfrescoJsApiModeler: any;
|
|||||||
let alfrescoJsApiDevops: any;
|
let alfrescoJsApiDevops: any;
|
||||||
let args: ConfigArgs;
|
let args: ConfigArgs;
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
|
const absentApps: any [] = [];
|
||||||
|
const failingApps: any [] = [];
|
||||||
export interface ConfigArgs {
|
export interface ConfigArgs {
|
||||||
modelerUsername: string;
|
modelerUsername: string;
|
||||||
modelerPassword: string;
|
modelerPassword: string;
|
||||||
@ -62,7 +63,8 @@ async function healthCheck(nameService: string) {
|
|||||||
logger.error(`${nameService} is DOWN `);
|
logger.error(`${nameService} is DOWN `);
|
||||||
isValid = false;
|
isValid = false;
|
||||||
} else {
|
} else {
|
||||||
logger.info(`${nameService} is UP!`);
|
const reset = '\x1b[0m', green = '\x1b[32m';
|
||||||
|
logger.info(`${green}${nameService} is UP!${reset}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`${nameService} is not reachable error: `, error);
|
logger.error(`${nameService} is not reachable error: `, error);
|
||||||
@ -242,24 +244,32 @@ function getAlfrescoJsApiInstance(configArgs: ConfigArgs) {
|
|||||||
|
|
||||||
async function deployMissingApps() {
|
async function deployMissingApps() {
|
||||||
const deployedApps = await getApplicationByStatus('');
|
const deployedApps = await getApplicationByStatus('');
|
||||||
const absentApps = findMissingApps(deployedApps.list.entries);
|
findMissingApps(deployedApps.list.entries);
|
||||||
|
findFailingApps(deployedApps.list.entries);
|
||||||
|
|
||||||
if (absentApps.length > 0) {
|
if (failingApps.length > 0) {
|
||||||
|
failingApps.forEach( app => {
|
||||||
|
const reset = '\x1b[0m', bright = '\x1b[1m', red = '\x1b[31m';
|
||||||
|
logger.error(`${red}${bright}ERROR: App ${app.entry.name} down or inaccessible ${reset}${red} with status ${app.entry.status}${reset}`);
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
} else if (absentApps.length > 0) {
|
||||||
logger.warn(`Missing apps: ${JSON.stringify(absentApps)}`);
|
logger.warn(`Missing apps: ${JSON.stringify(absentApps)}`);
|
||||||
await checkIfAppIsReleased(absentApps);
|
await checkIfAppIsReleased(absentApps);
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`All the apps are correctly deployed`);
|
const reset = '\x1b[0m', green = '\x1b[32m';
|
||||||
|
logger.info(`${green}All the apps are correctly deployed${reset}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkIfAppIsReleased(absentApps: any []) {
|
async function checkIfAppIsReleased(missingApps: any []) {
|
||||||
const projectList = await getProjects();
|
const projectList = await getProjects();
|
||||||
let TIME = 5000;
|
let TIME = 5000;
|
||||||
let noError = true;
|
let noError = true;
|
||||||
|
|
||||||
for (let i = 0; i < absentApps.length; i++) {
|
for (let i = 0; i < missingApps.length; i++) {
|
||||||
noError = true;
|
noError = true;
|
||||||
const currentAbsentApp = absentApps[i];
|
const currentAbsentApp = missingApps[i];
|
||||||
const project = projectList.list.entries.find((currentApp: any) => {
|
const project = projectList.list.entries.find((currentApp: any) => {
|
||||||
return currentAbsentApp.name === currentApp.entry.name;
|
return currentAbsentApp.name === currentApp.entry.name;
|
||||||
});
|
});
|
||||||
@ -349,7 +359,7 @@ async function importProjectAndRelease(app: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findMissingApps(deployedApps: any []) {
|
function findMissingApps(deployedApps: any []) {
|
||||||
const absentApps: any [] = [];
|
|
||||||
Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => {
|
Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => {
|
||||||
const isPresent = deployedApps.find((currentApp: any) => {
|
const isPresent = deployedApps.find((currentApp: any) => {
|
||||||
return ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name;
|
return ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name;
|
||||||
@ -359,7 +369,19 @@ function findMissingApps(deployedApps: any []) {
|
|||||||
absentApps.push(ACTIVITI_CLOUD_APPS[key]);
|
absentApps.push(ACTIVITI_CLOUD_APPS[key]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return absentApps;
|
}
|
||||||
|
|
||||||
|
function findFailingApps(deployedApps: any []) {
|
||||||
|
|
||||||
|
Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => {
|
||||||
|
const failingApp = deployedApps.filter((currentApp: any) => {
|
||||||
|
return ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name && 'Running' !== currentApp.entry.status;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (failingApp?.length > 0) {
|
||||||
|
failingApps.push(...failingApp);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFileFromRemote(url: string, name: string) {
|
async function getFileFromRemote(url: string, name: string) {
|
||||||
@ -423,25 +445,27 @@ async function main(configArgs: ConfigArgs) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await alfrescoJsApiModeler.login(args.modelerUsername, args.modelerPassword).then(() => {
|
await alfrescoJsApiModeler.login(args.modelerUsername, args.modelerPassword).then(() => {
|
||||||
logger.info('login SSO ok');
|
const reset = '\x1b[0m', green = '\x1b[32m';
|
||||||
|
logger.info(`${green}login SSO ok${reset}`);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
logger.info(`login SSO error ${JSON.stringify(error)} ${args.modelerUsername}`);
|
logger.error(`login SSO error ${JSON.stringify(error)} ${args.modelerUsername}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
logger.error('The environment is up and running');
|
const reset = '\x1b[0m', green = '\x1b[32m';
|
||||||
|
logger.info(`${green}The environment is up and running ${reset}`);
|
||||||
alfrescoJsApiDevops = getAlfrescoJsApiInstance(args);
|
alfrescoJsApiDevops = getAlfrescoJsApiInstance(args);
|
||||||
await alfrescoJsApiDevops.login(args.devopsUsername, args.devopsPassword).then(() => {
|
await alfrescoJsApiDevops.login(args.devopsUsername, args.devopsPassword).then(() => {
|
||||||
logger.info('login SSO ok devopsUsername');
|
logger.info('login SSO ok devopsUsername');
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
logger.info(`login SSO error ${JSON.stringify(error)} ${args.devopsUsername}`);
|
logger.error(`login SSO error ${JSON.stringify(error)} ${args.devopsUsername}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
await deployMissingApps();
|
await deployMissingApps();
|
||||||
} else {
|
} else {
|
||||||
logger.info('The environment is not up');
|
logger.error('The environment is not up');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user