[AAE-4295] Add retry api calls for delete descriptor and application

This commit is contained in:
Roxana Diacenco 2021-01-14 10:28:07 +02:00 committed by GitHub
parent 36580f690b
commit f259b7c940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 9 deletions

View File

@ -19,6 +19,7 @@ import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper';
import { Logger } from '../../core/utils/logger'; import { Logger } from '../../core/utils/logger';
import { ResultSetPaging } from '@alfresco/js-api'; import { ResultSetPaging } from '@alfresco/js-api';
import { ApiService } from '../../core/actions/api.service'; import { ApiService } from '../../core/actions/api.service';
import { ApiUtil } from '../../core/actions/api.util';
export class Application { export class Application {
@ -40,8 +41,25 @@ export class Application {
} }
async undeploy(applicationName: string): Promise<any> { async undeploy(applicationName: string): Promise<any> {
await this.requestApiHelper.delete(`${this.endPoint}${applicationName}`); const isApplicationUndeployed = (response: any) => {
Logger.info(`[Application] Application ${applicationName} was undeployed successfully.`); if (JSON.stringify(response) === '{}') {
Logger.info(`[Application] Application was undeployed successfully`);
return true;
} else {
Logger.warn(`[Application] Application was not undeployed`);
return false;
}
};
const apiCall = async () => {
try {
Logger.info(`[Application] Undeploy application ${applicationName} ...`);
return this.requestApiHelper.delete(`${this.endPoint}${applicationName}`);
} catch (error) {
Logger.error(`[Application] Undeploy application ${applicationName} failed with error: ${error.message}`);
}
};
return ApiUtil.waitForApi(apiCall, isApplicationUndeployed, 10, 3000);
} }
async deleteDescriptor(name: string): Promise<void> { async deleteDescriptor(name: string): Promise<void> {

View File

@ -44,13 +44,26 @@ export class Descriptor {
} }
async delete(name: string): Promise<void> { async delete(name: string): Promise<void> {
try { const isDescriptorDeleted = (response: any) => {
await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`); if (JSON.stringify(response) === '{}') {
await this.requestApiHelper.delete(`${this.endPoint}${name}`); Logger.info(`[Descriptor] Descriptor was deleted successfully`);
Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`); return true;
} catch (error) { } else {
Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`); Logger.warn(`[Descriptor] Descriptor was not deleted`);
} return false;
}
};
const apiCall = async () => {
try {
await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`);
Logger.info(`[Descriptor] Deleting descriptor ${name} ...`);
return this.requestApiHelper.delete(`${this.endPoint}${name}`);
} catch (error) {
Logger.error(`[Descriptor] Delete descriptor ${name} failed with error: ${error.message}`);
}
};
return ApiUtil.waitForApi(apiCall, isDescriptorDeleted, 10, 3000);
} }
async get(name: string): Promise<any> { async get(name: string): Promise<any> {
@ -64,8 +77,10 @@ export class Descriptor {
async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise<any> { async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise<any> {
const predicate = (result: { status: string }) => { const predicate = (result: { status: string }) => {
Logger.info(`[Descriptor] Descriptor ${name} status is: ${result.status}`);
return result.status === expectedStatus; return result.status === expectedStatus;
}; };
const apiCall = async () => this.get(name); const apiCall = async () => this.get(name);
return ApiUtil.waitForApi(apiCall, predicate); return ApiUtil.waitForApi(apiCall, predicate);