Improve recovery strategy Activiti 7

This commit is contained in:
Eugenio Romano
2019-04-26 18:15:31 +01:00
parent f24245aa23
commit 8231a5a37e
3 changed files with 101 additions and 24 deletions

View File

@@ -527,7 +527,7 @@ exports.ACTIVITI7_APPS = {
} }
}, },
SUB_PROCESS_APP: { SUB_PROCESS_APP: {
name: "subprocess-app", name: "subprocessapp",
file_location: "/resources/activiti7/subProcessApp.zip", file_location: "/resources/activiti7/subprocessapp.zip",
} }
}; };

View File

@@ -63,7 +63,7 @@ async function main() {
if (notRunningSecondAttempt && notRunningSecondAttempt.length > 0) { if (notRunningSecondAttempt && notRunningSecondAttempt.length > 0) {
let notRunningAppAfterWaitSecondAttempt = await waitPossibleStaleApps(this.alfrescoJsApi, notRunningSecondAttempt); let notRunningAppAfterWaitSecondAttempt = await waitPossibleStaleApps(this.alfrescoJsApi, notRunningSecondAttempt);
if (notRunningAppAfterWaitSecondAttempt && notRunningAppAfterWaitSecondAttempt.legnth > 0) { if (notRunningAppAfterWaitSecondAttempt && notRunningAppAfterWaitSecondAttempt.length > 0) {
console.log(`Not possible to recover the following apps in the environment`); console.log(`Not possible to recover the following apps in the environment`);
notRunningAppAfterWaitSecondAttempt.forEach((currentApp) => { notRunningAppAfterWaitSecondAttempt.forEach((currentApp) => {
@@ -89,7 +89,6 @@ async function deleteStaleApps(alfrescoJsApi, notRunningAppAfterWait) {
} }
async function waitPossibleStaleApps(alfrescoJsApi, notRunning) { async function waitPossibleStaleApps(alfrescoJsApi, notRunning) {
do { do {
console.log(`Wait stale app ${TIMEOUT}`); console.log(`Wait stale app ${TIMEOUT}`);
@@ -125,6 +124,7 @@ async function getNotRunningApps(alfrescoJsApi) {
Object.keys(ACTIVITI7_APPS).forEach((key) => { Object.keys(ACTIVITI7_APPS).forEach((key) => {
let isNotRunning = allStatusApps.find((currentApp) => { let isNotRunning = allStatusApps.find((currentApp) => {
//console.log(currentApp.entry.name + ' ' +currentApp.entry.status);
return ACTIVITI7_APPS[key].name === currentApp.entry.name && currentApp.entry.status !== 'Running'; return ACTIVITI7_APPS[key].name === currentApp.entry.name && currentApp.entry.status !== 'Running';
}); });
@@ -146,7 +146,6 @@ async function getNotRunningApps(alfrescoJsApi) {
} }
async function deployAbsentApps(alfrescoJsApi) { async function deployAbsentApps(alfrescoJsApi) {
let deployedApps = await getDeployedApplicationsByStatus(alfrescoJsApi, ''); let deployedApps = await getDeployedApplicationsByStatus(alfrescoJsApi, '');
Object.keys(ACTIVITI7_APPS).forEach((key) => { Object.keys(ACTIVITI7_APPS).forEach((key) => {
@@ -178,37 +177,44 @@ async function checkIfAppIsReleased(apiService, absentApps) {
if (!app) { if (!app) {
let uploadedApp = await importApp(apiService, currentAbsentApp); console.log('Missing project, create the project for ' + currentAbsentApp.name);
let uploadedApp = await importProjectApp(apiService, currentAbsentApp);
console.log('Project uploaded ' + currentAbsentApp.name);
if (uploadedApp) { if (uploadedApp) {
await releaseApp(apiService, uploadedApp); await releaseApp(apiService, uploadedApp);
await deployApp(apiService, uploadedApp); await deployApp(apiService, uploadedApp, currentAbsentApp.name);
} }
} else { } else {
let appRelease = undefined; console.log('Project for ' + currentAbsentApp.name + 'present');
let appReleaseList = await getReleaseAppyProjectId(apiService, app.entry.id);
if (!appReleaseList) { let appRelease = undefined;
let appReleaseList = await getReleaseAppProjectId(apiService, app.entry.id);
if (appReleaseList.list.entries.length === 0) {
console.log('1 ');
appRelease = await releaseApp(apiService, app); appRelease = await releaseApp(apiService, app);
} else { } else {
appRelease = appReleaseList.list.entries.find((currentRelease) => { appRelease = appReleaseList.list.entries.find((currentRelease) => {
return currentRelease.entry.version === 'latest'; return currentRelease.entry.version === 'latest';
}); });
} }
console.log('App to deploy ' + appRelease.entry.projectName + ' app release id ' + JSON.stringify(appRelease.entry.id)); console.log('App to deploy app release id ' + JSON.stringify(appRelease));
await deployApp(apiService, appRelease); await deployApp(apiService, appRelease, currentAbsentApp.name);
} }
} }
} }
async function deployApp(apiService, app) { async function deployApp(apiService, app, name) {
const url = `${config.hostBpm}/alfresco-deployment-service/v1/applications`; const url = `${config.hostBpm}/alfresco-deployment-service/v1/applications`;
const pathParams = {}; const pathParams = {};
const bodyParam = { const bodyParam = {
"name": app.entry.projectName, "name": name,
"releaseId": app.entry.id, "releaseId": app.entry.id,
"version": app.entry.name, "version": app.entry.name,
"security": [{"role": "APS_ADMIN", "groups": [], "users": ["admin.adf"]}, { "security": [{"role": "APS_ADMIN", "groups": [], "users": ["admin.adf"]}, {
@@ -225,12 +231,12 @@ async function deployApp(apiService, app) {
return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts); contentTypes, accepts);
} catch (error) { } catch (error) {
console.log(`Not possible to deploy the project ${app.entry.projectName} status : ${JSON.stringify(error.status)} ${JSON.stringify(error)}`); console.log(`Not possible to deploy the project ${app.entry.projectName} status : ${JSON.stringify(error.status)} ${JSON.stringify(error.response.text)}`);
process.exit(1); process.exit(1);
} }
} }
async function importApp(apiService, app) { async function importProjectApp(apiService, app) {
const pathFile = path.join('./e2e/' + app.file_location); const pathFile = path.join('./e2e/' + app.file_location);
const file = fs.createReadStream(pathFile); const file = fs.createReadStream(pathFile);
@@ -241,18 +247,22 @@ async function importApp(apiService, app) {
contentTypes = ['multipart/form-data'], accepts = ['application/json']; contentTypes = ['multipart/form-data'], accepts = ['application/json'];
try { try {
console.log('import app ' + app.file_location);
return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts); contentTypes, accepts);
} catch (error) { } catch (error) {
if (error.status !== 409) { if (error.status !== 409) {
console.log(`Not possible to upload the project ${app.name} status : ${JSON.stringify(error.status)} ${JSON.stringify(error.text)}`); console.log(`Not possible to upload the project ${app.name} status : ${JSON.stringify(error.status)} ${JSON.stringify(error.response.text)}`);
process.exit(1); process.exit(1);
} else {
console.log(`Not possible to upload the project because inconsistency CS - Modelling try to delete manually the node`);
await deleteSiteByName(app.name);
await importProjectApp(apiService, app);
}
} }
} }
} async function getReleaseAppProjectId(apiService, projectId) {
async function getReleaseAppyProjectId(apiService, projectId) {
const url = `${config.hostBpm}/alfresco-modeling-service/v1/projects/${projectId}/releases`; const url = `${config.hostBpm}/alfresco-modeling-service/v1/projects/${projectId}/releases`;
const pathParams = {}, queryParams = {}, const pathParams = {}, queryParams = {},
@@ -281,7 +291,7 @@ async function releaseApp(apiService, app) {
return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, return await apiService.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts); contentTypes, accepts);
} catch (error) { } catch (error) {
console.log(`Not possible to release the project ${app.entry.name} status : ${JSON.stringify(error.status)} ${JSON.stringify(error.text)}`); console.log(`Not possible to release the project ${app.entry.name} status : $ ${JSON.stringify(error.status)} ${JSON.stringify(error.response.text)}`);
process.exit(1); process.exit(1);
} }
@@ -353,4 +363,71 @@ function sleep(delay) {
while (new Date().getTime() < start + delay) ; while (new Date().getTime() < start + delay) ;
} }
async function deleteChildrenNodeByName(alfrescoJsApi, nameNodeToDelete, nodeId) {
let childrenNodes = await alfrescoJsApi.core.nodesApi.getNodeChildren(nodeId);
let childrenToDelete = childrenNodes.list.entries.find((currentNode) => {
console.log(currentNode.entry.name);
return currentNode.entry.name === nameNodeToDelete;
});
console.log('childrenToDelete ' + childrenToDelete);
if (childrenToDelete) {
await alfrescoJsApi.core.nodesApi.deleteNode(childrenToDelete.entry.id);
}
}
async function deleteSiteByName(name) {
console.log(`====== Delete Site ${name} ${program.host} ======`);
let alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
provider: 'ECM',
hostEcm: `http://${program.host}`
});
await alfrescoJsApi.login(program.username, program.password);
let listSites = [];
try {
listSites = await alfrescoJsApi.core.sitesApi.getSites();
} catch (error) {
console.log('error get list sites' + JSON.stringify(error));
process.exit(1);
}
let apsModelingNodeId;
let apsReleaseNodeId;
if (listSites && listSites.list.entries.length > 0) {
for (let i = 0; i < listSites.list.entries.length; i++) {
if (listSites.list.entries[i].entry.id === name) {
try {
await alfrescoJsApi.core.sitesApi.deleteSite(listSites.list.entries[i].entry.id, {options: {permanent: true}});
} catch (error) {
console.log('error' + JSON.stringify(error));
}
}
if (listSites.list.entries[i].entry.id === 'ApsModeling') {
apsModelingNodeId = listSites.list.entries[i].entry.guid;
}
if (listSites.list.entries[i].entry.id === 'ApsRelease') {
apsReleaseNodeId = listSites.list.entries[i].entry.guid;
}
}
}
console.log(`====== Delete Folder in apsModeling`);
await deleteChildrenNodeByName(alfrescoJsApi, name, apsModelingNodeId);
console.log(`====== Delete Folder in apsRelease`);
await deleteChildrenNodeByName(alfrescoJsApi, name, apsReleaseNodeId);
}
main(); main();