From f5dff41edf56b7fac5b699249e9e776ee3d3fb6d Mon Sep 17 00:00:00 2001 From: George Raduta Date: Tue, 27 Jan 2026 16:03:11 +0100 Subject: [PATCH] [OGUI-1880] Use transition status now that is provided by ECS --- .../common/ecsOperationAndStepStatus.enum.js | 4 ++++ .../environment/EnvironmentCache.service.js | 13 ++++------ .../mocha-environment-cache.service.test.js | 24 ++++++++++++++++++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Control/lib/common/ecsOperationAndStepStatus.enum.js b/Control/lib/common/ecsOperationAndStepStatus.enum.js index 4b38f9db8..3ab4e2eb6 100644 --- a/Control/lib/common/ecsOperationAndStepStatus.enum.js +++ b/Control/lib/common/ecsOperationAndStepStatus.enum.js @@ -14,11 +14,15 @@ /** * Available ECS Statuses of operations for Kafka Events + * https://github.com/AliceO2Group/Control/blob/master/core/protos/o2control.proto#L228 * These operations can be under the label: * * operationStatus * * operationStepStatus */ const EcsOperationAndStepStatus = Object.freeze({ + NULL: 'NULL', + STARTED: 'STARTED', + ONGOING: 'ONGOING', DONE_OK: 'DONE_OK', DONE_ERROR: 'DONE_ERROR', DONE_TIMEOUT: 'DONE_TIMEOUT', diff --git a/Control/lib/services/environment/EnvironmentCache.service.js b/Control/lib/services/environment/EnvironmentCache.service.js index e09a7413b..36d059c0f 100644 --- a/Control/lib/services/environment/EnvironmentCache.service.js +++ b/Control/lib/services/environment/EnvironmentCache.service.js @@ -24,11 +24,9 @@ const { const { EnvironmentState } = require('../../common/environmentState.enum.js'); const { TaskState } = require('../../common/taskState.enum.js'); const { EnvironmentTransitionType } = require('../../common/environmentTransitionType.enum.js'); +const { EcsOperationAndStepStatus } = require('../../common/ecsOperationAndStepStatus.enum.js'); const EPN_PATH_IN_ENVIRONMENT_INFO = 'hardware.epn.info'; -const ECS_TRANSITION_DONE_MESSAGE = 'transition completed successfully'; -const ECS_DESTROY_TRANSITION_DONE_MESSAGE = 'environment teardown complete'; - /** * @class * EnvironmentCacheService class is designed to store in-memory information and allow users to also broadcast new information to the all or registered clients. @@ -219,7 +217,7 @@ class EnvironmentCacheService { * @returns {void} */ _handleEnvironmentEvent(environmentEvent) { - const { id, state, transition = {}, message, error, runNumber } = environmentEvent; + const { id, state, transition = {}, error, runNumber } = environmentEvent; const cachedEnvironment = this._environments.has(id) ? this._environments.get(id) : { id, events: [] }; @@ -238,8 +236,7 @@ class EnvironmentCacheService { if ( state === EnvironmentState.CONFIGURED && - message === ECS_TRANSITION_DONE_MESSAGE - // OCTRL-1038 - currently comparing to hardcoded string, but this should be replaced with transition status + transition?.status === EcsOperationAndStepStatus.DONE_OK ) { // Once the environment is configured and ongoing transition is done, we can set the isDeploying to false // This can happen when the environment also goes form RUNNING to CONFIGURED but it is already marked as not deploying anymore @@ -256,9 +253,9 @@ class EnvironmentCacheService { this.addOrUpdateEnvironment(cachedEnvironment, false); if ( - transition?.name === EnvironmentTransitionType.DESTROY && + transition?.name === EnvironmentTransitionType.DESTROY && + transition?.status === EcsOperationAndStepStatus.DONE_OK && state === EnvironmentState.DONE && - message === ECS_DESTROY_TRANSITION_DONE_MESSAGE && !cachedEnvironment.deploymentError ) { // That is, if the environment successfully ended the DESTROY transition diff --git a/Control/test/lib/services/environment/mocha-environment-cache.service.test.js b/Control/test/lib/services/environment/mocha-environment-cache.service.test.js index a009f00ff..5f7cda0ed 100644 --- a/Control/test/lib/services/environment/mocha-environment-cache.service.test.js +++ b/Control/test/lib/services/environment/mocha-environment-cache.service.test.js @@ -23,6 +23,7 @@ EmitterKeys} = require('../../../../lib/common/emitterKeys.enum.js'); const { BroadcastKeys: {ENVIRONMENT_EVENTS, ENVIRONMENTS_OVERVIEW} } = require('../../../../lib/common/broadcastKeys.enum.js'); const { EnvironmentState } = require('../../../../lib/common/environmentState.enum.js'); const { EnvironmentTransitionType } = require('../../../../lib/common/environmentTransitionType.enum.js'); +const { EcsOperationAndStepStatus } = require('../../../../lib/common/ecsOperationAndStepStatus.enum.js'); describe(`'EnvironmentCacheService' - test suite`, () => { let broadcastServiceMock; @@ -376,8 +377,8 @@ describe(`'EnvironmentCacheService' - test suite`, () => { id: 'env1', transition: { name: EnvironmentTransitionType.DESTROY, + status: EcsOperationAndStepStatus.DONE_OK }, - message: 'environment teardown complete', state: EnvironmentState.DONE }); @@ -385,5 +386,26 @@ describe(`'EnvironmentCacheService' - test suite`, () => { assert.ok(!env, 'Environment "env1" should be removed from the cache'); assert.strictEqual(broadcastServiceMock.broadcast.callCount, 2, 'Broadcast (event and overview) should be made when environment is removed'); }); + + it('should successfully remove isDeploying flag on CONFIGURED state after deployment', () => { + const initialEnvironment = { + id: 'env1', + isDeploying: true, + state: EnvironmentState.DEPLOYED + }; + environmentCacheService.addOrUpdateEnvironment(initialEnvironment); + + eventEmitter.emit(EmitterKeys.ENVIRONMENTS_TRACK, { + id: 'env1', + transition: { + name: EnvironmentTransitionType.CONFIGURE, + status: EcsOperationAndStepStatus.DONE_OK + }, + state: EnvironmentState.CONFIGURED + }); + const env = environmentCacheService._environments.get('env1'); + assert.ok(env, 'Environment "env1" should exist in the cache without isDeploying flag'); + assert.strictEqual(env.isDeploying, false, 'isDeploying flag should be removed after successful deployment'); + }); }); });