try delete apps 3 times when are failing

This commit is contained in:
eromano
2023-07-03 16:14:11 +02:00
parent 3b3fd5ab9a
commit 4b302e1cb3
+59 -21
View File
@@ -22,7 +22,10 @@ import request = require('request');
import * as fs from 'fs';
import { logger } from './logger';
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
const ACTIVITI_CLOUD_APPS = require('./resources').ACTIVITI_CLOUD_APPS;
const MAX_RETRY = 3;
let retry = 0;
let alfrescoJsApiModeler: any;
let alfrescoJsApiDevops: any;
@@ -30,6 +33,7 @@ let args: ConfigArgs;
let isValid = true;
const absentApps: any [] = [];
const failingApps: any [] = [];
export interface ConfigArgs {
modelerUsername: string;
modelerPassword: string;
@@ -228,27 +232,6 @@ async function importAndReleaseProject(absoluteFilePath: string) {
}
}
function deleteDescriptor(name: string) {
const url = `${args.host}/deployment-service/v1/descriptors/${name}`;
const pathParams = {};
const queryParams = {};
const headerParams = {};
const formParams = {};
const bodyParam = {};
const contentTypes = ['application/json'];
const accepts = ['application/json'];
try {
return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'DELETE', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts);
} catch (error) {
logger.error('Delete descriptor' + error.status);
isValid = false;
}
}
function deploy(model: any) {
const url = `${args.host}/deployment-service/v1/applications`;
@@ -309,7 +292,16 @@ async function deployMissingApps(tag?: string, envs?: string[]) {
const red = '\x1b[31m';
logger.error(`${red}${bright}ERROR: App ${app.entry.name} down or inaccessible ${reset}${red} with status ${app.entry.status}${reset}`);
});
if (retry < MAX_RETRY) {
retry++;
await forceUndeployFailedApps(failingApps, environmentId)
await sleep(TIME);
await deployMissingApps(tag);
} else {
process.exit(1);
}
} else if (absentApps.length > 0) {
logger.warn(`Missing apps: ${JSON.stringify(absentApps)}`);
await checkIfAppIsReleased(absentApps, tag, envs);
@@ -406,6 +398,52 @@ async function deployWithPayload(currentAbsentApp: any, projectRelease: any, env
}
async function deleteDescriptor(appName: any [], environmentId?: string) {
const url = `${args.host}/deployment-service/v1/descriptors/${appName}`;
const pathParams = {};
const queryParams = {status};
const headerParams = {};
const formParams = {};
const bodyParam = {
environmentId: environmentId
};
const contentTypes = ['application/json'];
const accepts = ['application/json'];
await alfrescoJsApiDevops.login(args.devopsUsername, args.devopsPassword);
return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'DELETE', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts).on('error', (error) => {
logger.error(`Delete descriptor ${error} `);
});
}
async function forceUndeployFailedApps(failedApps: any [], environmentId?: string) {
for (const appName in failedApps) {
logger.error(`Force undeploy app in failed status ${appName}`);
const url = `${args.host}/deployment-service/v1/applications/${appName}`;
const pathParams = {};
const queryParams = {status};
const headerParams = {};
const formParams = {};
const bodyParam = {
environmentId: environmentId
};
const contentTypes = ['application/json'];
const accepts = ['application/json'];
return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'DELETE', pathParams, queryParams, headerParams, formParams, bodyParam,
contentTypes, accepts).on('error', (error) => {
logger.error(`Delete application ${appName} ${error} `);
});
}
}
async function checkDescriptorExist(name: string) {
logger.info(`Check descriptor ${name} exist in the list `);
const descriptorList = await getDescriptors();