Skip to content

Commit 6928fad

Browse files
authored
[OGUI-1880] Use transition status now that is provided by ECS (#3305)
* updates the logic of environment events to use transition status now that ECS is providing it * removes the previous use of hardcoded message string comparison * Extend `EcsOperationAndStepStatus` enum with additional ECS statuses (`NULL/STARTED/ONGOING`).
1 parent fc7b706 commit 6928fad

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

Control/lib/common/ecsOperationAndStepStatus.enum.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414

1515
/**
1616
* Available ECS Statuses of operations for Kafka Events
17+
* https://github.com/AliceO2Group/Control/blob/master/core/protos/o2control.proto#L228
1718
* These operations can be under the label:
1819
* * operationStatus
1920
* * operationStepStatus
2021
*/
2122
const EcsOperationAndStepStatus = Object.freeze({
23+
NULL: 'NULL',
24+
STARTED: 'STARTED',
25+
ONGOING: 'ONGOING',
2226
DONE_OK: 'DONE_OK',
2327
DONE_ERROR: 'DONE_ERROR',
2428
DONE_TIMEOUT: 'DONE_TIMEOUT',

Control/lib/services/environment/EnvironmentCache.service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ const {
2424
const { EnvironmentState } = require('../../common/environmentState.enum.js');
2525
const { TaskState } = require('../../common/taskState.enum.js');
2626
const { EnvironmentTransitionType } = require('../../common/environmentTransitionType.enum.js');
27+
const { EcsOperationAndStepStatus } = require('../../common/ecsOperationAndStepStatus.enum.js');
2728
const EPN_PATH_IN_ENVIRONMENT_INFO = 'hardware.epn.info';
2829

29-
const ECS_TRANSITION_DONE_MESSAGE = 'transition completed successfully';
30-
const ECS_DESTROY_TRANSITION_DONE_MESSAGE = 'environment teardown complete';
31-
3230
/**
3331
* @class
3432
* 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 {
219217
* @returns {void}
220218
*/
221219
_handleEnvironmentEvent(environmentEvent) {
222-
const { id, state, transition = {}, message, error, runNumber } = environmentEvent;
220+
const { id, state, transition = {}, error, runNumber } = environmentEvent;
223221
const cachedEnvironment = this._environments.has(id)
224222
? this._environments.get(id)
225223
: { id, events: [] };
@@ -238,8 +236,7 @@ class EnvironmentCacheService {
238236

239237
if (
240238
state === EnvironmentState.CONFIGURED &&
241-
message === ECS_TRANSITION_DONE_MESSAGE
242-
// OCTRL-1038 - currently comparing to hardcoded string, but this should be replaced with transition status
239+
transition?.status === EcsOperationAndStepStatus.DONE_OK
243240
) {
244241
// Once the environment is configured and ongoing transition is done, we can set the isDeploying to false
245242
// 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 {
256253
this.addOrUpdateEnvironment(cachedEnvironment, false);
257254

258255
if (
259-
transition?.name === EnvironmentTransitionType.DESTROY &&
256+
transition?.name === EnvironmentTransitionType.DESTROY &&
257+
transition?.status === EcsOperationAndStepStatus.DONE_OK &&
260258
state === EnvironmentState.DONE &&
261-
message === ECS_DESTROY_TRANSITION_DONE_MESSAGE &&
262259
!cachedEnvironment.deploymentError
263260
) {
264261
// That is, if the environment successfully ended the DESTROY transition

Control/test/lib/services/environment/mocha-environment-cache.service.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ EmitterKeys} = require('../../../../lib/common/emitterKeys.enum.js');
2323
const { BroadcastKeys: {ENVIRONMENT_EVENTS, ENVIRONMENTS_OVERVIEW} } = require('../../../../lib/common/broadcastKeys.enum.js');
2424
const { EnvironmentState } = require('../../../../lib/common/environmentState.enum.js');
2525
const { EnvironmentTransitionType } = require('../../../../lib/common/environmentTransitionType.enum.js');
26+
const { EcsOperationAndStepStatus } = require('../../../../lib/common/ecsOperationAndStepStatus.enum.js');
2627

2728
describe(`'EnvironmentCacheService' - test suite`, () => {
2829
let broadcastServiceMock;
@@ -376,14 +377,35 @@ describe(`'EnvironmentCacheService' - test suite`, () => {
376377
id: 'env1',
377378
transition: {
378379
name: EnvironmentTransitionType.DESTROY,
380+
status: EcsOperationAndStepStatus.DONE_OK
379381
},
380-
message: 'environment teardown complete',
381382
state: EnvironmentState.DONE
382383
});
383384

384385
const env = environmentCacheService._environments.get('env1');
385386
assert.ok(!env, 'Environment "env1" should be removed from the cache');
386387
assert.strictEqual(broadcastServiceMock.broadcast.callCount, 2, 'Broadcast (event and overview) should be made when environment is removed');
387388
});
389+
390+
it('should successfully remove isDeploying flag on CONFIGURED state after deployment', () => {
391+
const initialEnvironment = {
392+
id: 'env1',
393+
isDeploying: true,
394+
state: EnvironmentState.DEPLOYED
395+
};
396+
environmentCacheService.addOrUpdateEnvironment(initialEnvironment);
397+
398+
eventEmitter.emit(EmitterKeys.ENVIRONMENTS_TRACK, {
399+
id: 'env1',
400+
transition: {
401+
name: EnvironmentTransitionType.CONFIGURE,
402+
status: EcsOperationAndStepStatus.DONE_OK
403+
},
404+
state: EnvironmentState.CONFIGURED
405+
});
406+
const env = environmentCacheService._environments.get('env1');
407+
assert.ok(env, 'Environment "env1" should exist in the cache without isDeploying flag');
408+
assert.strictEqual(env.isDeploying, false, 'isDeploying flag should be removed after successful deployment');
409+
});
388410
});
389411
});

0 commit comments

Comments
 (0)