mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
move scripts check env in cli (#5889)
* move scripts check env in cli * rmeove logs dep * move scripts check env in cli * build all
This commit is contained in:
116
lib/cli/scripts/check-cs-env.ts
Executable file
116
lib/cli/scripts/check-cs-env.ts
Executable file
@@ -0,0 +1,116 @@
|
||||
const alfrescoApi = require('@alfresco/js-api');
|
||||
const program = require('commander');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const MAX_RETRY = 10;
|
||||
const TIMEOUT = 60000;
|
||||
let counter = 0;
|
||||
|
||||
export default async function main(_args: string[]) {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.description('Check Content service is up ')
|
||||
.usage('check-cs-env [options]')
|
||||
.option('--host [type]', 'Remote environment host adf.lab.com ')
|
||||
.option('-p, --password [type]', 'password ')
|
||||
.option('-u, --username [type]', 'username ')
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
await checkEnv();
|
||||
await checkDiskSpaceFullEnv();
|
||||
}
|
||||
|
||||
async function checkEnv() {
|
||||
try {
|
||||
const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
|
||||
provider: 'ECM',
|
||||
hostEcm: program.host
|
||||
});
|
||||
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
} catch (e) {
|
||||
console.log('Login error environment down or inaccessible');
|
||||
counter++;
|
||||
if (MAX_RETRY === counter) {
|
||||
console.log('Give up');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
checkEnv();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDiskSpaceFullEnv() {
|
||||
try {
|
||||
|
||||
const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
|
||||
provider: 'ECM',
|
||||
hostEcm: program.host
|
||||
});
|
||||
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
|
||||
let folder;
|
||||
|
||||
try {
|
||||
folder = await alfrescoJsApi.nodes.addNode('-my-', {
|
||||
'name': `try-env`,
|
||||
'relativePath': `Builds`,
|
||||
'nodeType': 'cm:folder'
|
||||
}, {}, {
|
||||
'overwrite': true
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
folder = await alfrescoJsApi.nodes.getNode('-my-', {
|
||||
'relativePath': `Builds/try-env`,
|
||||
'nodeType': 'cm:folder'
|
||||
}, {}, {
|
||||
'overwrite': true
|
||||
});
|
||||
}
|
||||
|
||||
let pathFile = path.join(__dirname, '../../', 'README.md');
|
||||
let file = fs.createReadStream(pathFile);
|
||||
|
||||
let uploadedFile = await alfrescoJsApi.upload.uploadFile(
|
||||
file,
|
||||
'',
|
||||
folder.entry.id,
|
||||
null,
|
||||
{
|
||||
'name': 'README.md',
|
||||
'nodeType': 'cm:content',
|
||||
'autoRename': true
|
||||
}
|
||||
);
|
||||
|
||||
alfrescoJsApi.node.deleteNode(uploadedFile.entry.id, {permanent: true});
|
||||
} catch (error) {
|
||||
counter++;
|
||||
|
||||
if (MAX_RETRY === counter) {
|
||||
console.log('=============================================================');
|
||||
console.log('================ Not able to upload a file ==================');
|
||||
console.log('================ Possible cause CS is full ==================');
|
||||
console.log('=============================================================');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
checkDiskSpaceFullEnv();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sleep(delay) {
|
||||
var start = new Date().getTime();
|
||||
while (new Date().getTime() < start + delay) ;
|
||||
}
|
50
lib/cli/scripts/check-ps-env.ts
Executable file
50
lib/cli/scripts/check-ps-env.ts
Executable file
@@ -0,0 +1,50 @@
|
||||
const alfrescoApi = require('@alfresco/js-api');
|
||||
const program = require('commander');
|
||||
|
||||
const MAX_RETRY = 10;
|
||||
const TIMEOUT = 60000;
|
||||
let counter = 0;
|
||||
|
||||
export default async function main(_args: string[]) {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.description('Check Process service is up ')
|
||||
.usage('check-ps-env [options]')
|
||||
.option('--host [type]', 'Remote environment host adf.lab.com ')
|
||||
.option('-p, --password [type]', 'password ')
|
||||
.option('-u, --username [type]', 'username ')
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
await checkEnv();
|
||||
}
|
||||
|
||||
async function checkEnv() {
|
||||
try {
|
||||
const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
|
||||
provider: 'BPM',
|
||||
hostBpm: program.host
|
||||
});
|
||||
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
} catch (e) {
|
||||
console.log('Login error environment down or inaccessible');
|
||||
counter++;
|
||||
if (MAX_RETRY === counter) {
|
||||
console.log('Give up');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
checkEnv();
|
||||
}
|
||||
}
|
||||
console.log('ok');
|
||||
}
|
||||
|
||||
|
||||
function sleep(delay) {
|
||||
var start = new Date().getTime();
|
||||
while (new Date().getTime() < start + delay) ;
|
||||
}
|
@@ -17,36 +17,18 @@
|
||||
|
||||
/* tslint:disable */
|
||||
let log = null;
|
||||
try {
|
||||
log = new (require('@angular-devkit/core').logging.IndentLogger)('root');
|
||||
const { bold, gray, red, yellow, white } = require('@angular-devkit/core').terminal;
|
||||
const filter = require('rxjs/operators').filter;
|
||||
|
||||
log
|
||||
.pipe(filter(entry => (entry.level !== 'debug')))
|
||||
.subscribe(entry => {
|
||||
let color = gray;
|
||||
let output = process.stdout;
|
||||
switch (entry.level) {
|
||||
case 'info': color = white; break;
|
||||
case 'warn': color = yellow; break;
|
||||
case 'error': color = red; output = process.stderr; break;
|
||||
case 'fatal': color = x => bold(red(x)); output = process.stderr; break;
|
||||
}
|
||||
|
||||
output.write(color(entry.message) + '\n');
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Reverting to manual console logging.\nReason: ${e.message}.`);
|
||||
log = {
|
||||
debug: console.log.bind(console),
|
||||
info: console.log.bind(console),
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console),
|
||||
fatal: x => { console.error(x); process.exit(100); },
|
||||
createChild: () => log
|
||||
};
|
||||
}
|
||||
log = {
|
||||
debug: console.log.bind(console),
|
||||
info: console.log.bind(console),
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console),
|
||||
fatal: x => {
|
||||
console.error(x);
|
||||
process.exit(100);
|
||||
},
|
||||
createChild: () => log
|
||||
};
|
||||
|
||||
export let logger = log;
|
||||
/* tslint:enable */
|
||||
|
Reference in New Issue
Block a user