[AAE-16884] init aae script fixes (#8957)

* [ci:force] init aae script fixes

* [ci:force] improved typings

* [ci:force] switch to http and remove useless test

* [ci:force] simple change to trigger tests

* [ci:force] remove debug logs
This commit is contained in:
Denys Vuika
2023-10-02 16:04:12 +01:00
committed by GitHub
parent e21ad3ca02
commit 94baaf7d33
3 changed files with 30 additions and 50 deletions

View File

@@ -18,7 +18,7 @@
*/
import program from 'commander';
import https from 'https';
import http from 'node:http';
import * as fs from 'fs';
import { logger } from './logger';
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
@@ -29,8 +29,6 @@ let alfrescoJsApiModeler: AlfrescoApi;
let alfrescoJsApiDevops: AlfrescoApi;
let args: ConfigArgs;
let isValid = true;
const absentApps: any[] = [];
const failingApps: any[] = [];
export interface ConfigArgs {
modelerUsername: string;
modelerPassword: string;
@@ -91,15 +89,14 @@ async function healthCheck(nameService: string) {
}
/**
* Get deployed application by status
* Get deployed application
*
* @param status application status
*/
async function getApplicationByStatus(status: string) {
async function getApplications(): Promise<{ list: { entries: any[] } }> {
const url = `${args.host}/deployment-service/v1/applications`;
const pathParams = {};
const queryParams = { status };
const queryParams = {};
const headerParams = {};
const formParams = {};
const bodyParam = {};
@@ -461,9 +458,9 @@ function getAlfrescoJsApiInstance(configArgs: ConfigArgs): AlfrescoApi {
* @param envs environments
*/
async function deployMissingApps(tag?: string, envs?: string[]) {
const deployedApps = await getApplicationByStatus('');
findMissingApps(deployedApps.list.entries);
findFailingApps(deployedApps.list.entries);
const deployedApps = await getApplications();
const failingApps = findFailingApps(deployedApps.list.entries);
const missingApps = findMissingApps(deployedApps.list.entries);
if (failingApps.length > 0) {
failingApps.forEach((app) => {
@@ -473,9 +470,9 @@ async function deployMissingApps(tag?: string, envs?: string[]) {
logger.error(`${red}${bright}ERROR: App ${app.entry.name} down or inaccessible ${reset}${red} with status ${app.entry.status}${reset}`);
});
exit(1);
} else if (absentApps.length > 0) {
logger.warn(`Missing apps: ${JSON.stringify(absentApps)}`);
await checkIfAppIsReleased(absentApps, tag, envs);
} else if (missingApps.length > 0) {
logger.warn(`Missing apps: ${JSON.stringify(missingApps)}`);
await checkIfAppIsReleased(missingApps, tag, envs);
} else {
const reset = '\x1b[0m';
const green = '\x1b[32m';
@@ -564,7 +561,7 @@ async function checkIfAppIsReleased(missingApps: any[], tag?: string, envs?: str
* @param projectRelease project release
* @param envId environment id
*/
async function deployWithPayload(currentAbsentApp: any, projectRelease: any, envId?: string) {
async function deployWithPayload(currentAbsentApp: any, projectRelease: any, envId?: string): Promise<void> {
const deployPayload = {
name: currentAbsentApp.name,
releaseId: projectRelease.entry.id,
@@ -608,10 +605,13 @@ async function checkDescriptorExist(name: string): Promise<boolean> {
*/
async function importProjectAndRelease(app: any, tag?: string) {
const appLocationReplaced = app.file_location(tag);
logger.warn('App fileLocation ' + appLocationReplaced);
await getFileFromRemote(appLocationReplaced, app.name);
logger.warn('Project imported ' + app.name);
const projectRelease = await importAndReleaseProject(`${app.name}.zip`);
await deleteLocalFile(`${app.name}`);
return projectRelease;
}
@@ -620,32 +620,42 @@ async function importProjectAndRelease(app: any, tag?: string) {
* Find missing applications
*
* @param deployedApps applications
* @returns list of missing apps
*/
function findMissingApps(deployedApps: any[]) {
function findMissingApps(deployedApps: any[]): any[] {
const result = [];
Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => {
const isPresent = deployedApps.find((currentApp: any) => ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name);
if (!isPresent) {
absentApps.push(ACTIVITI_CLOUD_APPS[key]);
result.push(ACTIVITI_CLOUD_APPS[key]);
}
});
return result;
}
/**
* Find failing applications
*
* @param deployedApps applications
* @returns list of failing apps
*/
function findFailingApps(deployedApps: any[]) {
function findFailingApps(deployedApps: any[]): any[] {
const result = [];
Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => {
const failingApp = deployedApps.filter(
(currentApp: any) => ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name && 'Running' !== currentApp.entry.status
);
if (failingApp?.length > 0) {
failingApps.push(...failingApp);
result.push(...failingApp);
}
});
return result;
}
/**
@@ -656,7 +666,7 @@ function findFailingApps(deployedApps: any[]) {
*/
async function getFileFromRemote(url: string, name: string) {
return new Promise<void>((resolve, reject) => {
https.get(url, (response) => {
http.get(url, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`HTTP error! Status: ${response.statusCode}`));
return;