From 94baaf7d338fbdb503f4363f97344f9c2d0ab3b8 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 2 Oct 2023 16:04:12 +0100 Subject: [PATCH] [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 --- lib/cli/scripts/init-aae-env.ts | 48 +++++++++++-------- .../lib/process/process-cloud.module.spec.ts | 30 ------------ .../services/start-process-cloud.service.ts | 2 +- 3 files changed, 30 insertions(+), 50 deletions(-) delete mode 100644 lib/process-services-cloud/src/lib/process/process-cloud.module.spec.ts diff --git a/lib/cli/scripts/init-aae-env.ts b/lib/cli/scripts/init-aae-env.ts index 5f8f7487d5..594acb4937 100755 --- a/lib/cli/scripts/init-aae-env.ts +++ b/lib/cli/scripts/init-aae-env.ts @@ -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 { const deployPayload = { name: currentAbsentApp.name, releaseId: projectRelease.entry.id, @@ -608,10 +605,13 @@ async function checkDescriptorExist(name: string): Promise { */ 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((resolve, reject) => { - https.get(url, (response) => { + http.get(url, (response) => { if (response.statusCode !== 200) { reject(new Error(`HTTP error! Status: ${response.statusCode}`)); return; diff --git a/lib/process-services-cloud/src/lib/process/process-cloud.module.spec.ts b/lib/process-services-cloud/src/lib/process/process-cloud.module.spec.ts deleted file mode 100644 index d185fa4e7d..0000000000 --- a/lib/process-services-cloud/src/lib/process/process-cloud.module.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ProcessCloudModule } from './process-cloud.module'; - -describe('ProcessCloudModule', () => { - let processCloudModule: ProcessCloudModule; - - beforeEach(() => { - processCloudModule = new ProcessCloudModule(); - }); - - it('should create an instance', () => { - expect(processCloudModule).toBeTruthy(); - }); -}); diff --git a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts index 27e156a6be..33fe81bb6b 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts @@ -89,7 +89,7 @@ export class StartProcessCloudService extends BaseCloudService { * Delete an existing process instance * * @param appName name of the Application - * @param processInstanceId process instance to update + * @param processInstanceId the identifier of the process instance to update * @returns Observable */ deleteProcess(appName: string, processInstanceId: string): Observable {