Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.query(`
UPDATE environments_history_items
SET status = 'DONE'
WHERE status = 'DESTROYED'
`),

// The DESTROYED status is deprecated: the rows converted by `up` cannot be told apart from the ones that were already DONE
down: async () => {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getHistoryDistributionQuery = ({ from, to }) => `
WHERE e.updated_at >= '${timestampToMysql(from, true)}'
AND e.created_at < '${timestampToMysql(to, true)}'
GROUP BY e.id
HAVING FIND_IN_SET('DESTROYED', statusHistory) > 0 OR FIND_IN_SET('ERROR', statusHistory) > 0
HAVING FIND_IN_SET('DONE', statusHistory) > 0 OR FIND_IN_SET('ERROR', statusHistory) > 0
) AS statusHistoryByEnvironmentId
GROUP BY statusHistory
ORDER BY count DESC;
Expand Down
8 changes: 4 additions & 4 deletions lib/database/seeders/20220412122043-environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
ctp_readout_host: 'fake-ctp-host',
}),
},
// Destroyed
// Done
{
id: 'TDI59So3d',
created_at: new Date('2019-08-09 16:05:00'),
Expand All @@ -58,19 +58,19 @@ module.exports = {
created_at: new Date('2019-08-09 15:50:00'),
updated_at: new Date('2019-08-09 16:00:00'),
},
// Error then destroyed
// Error then done
{
id: 'KGIS12DS',
created_at: new Date('2019-08-09 14:45:00'),
updated_at: new Date('2019-08-09 15:35:00'),
},
// Destroyed (only state)
// Done (only state)
{
id: 'VODdsO12d',
created_at: new Date('2019-08-09 14:30:00'),
updated_at: new Date('2019-08-09 14:30:00'),
},
// Destroyed
// Done
{
id: 'GIDO1jdkD',
created_at: new Date('2019-08-09 14:00:00'),
Expand Down
14 changes: 7 additions & 7 deletions lib/database/seeders/20230124105627-environment-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ module.exports = {
},
{
environment_id: 'TDI59So3d',
status: 'DESTROYED',
status_message: 'Environment has been destroyed',
status: 'DONE',
status_message: 'Environment is done',
created_at: new Date('2019-08-09 19:00:00'),
updated_at: new Date('2019-08-09 19:00:00'),
},
Expand Down Expand Up @@ -84,15 +84,15 @@ module.exports = {
},
{
environment_id: 'KGIS12DS',
status: 'DESTROYED',
status_message: 'Environment has been destroyed',
status: 'DONE',
status_message: 'Environment is done',
created_at: new Date('2019-08-09 15:35:00'),
updated_at: new Date('2019-08-09 15:35:00'),
},
{
environment_id: 'VODdsO12d',
status: 'DESTROYED',
status_message: 'Environment has been destroyed',
status: 'DONE',
status_message: 'Environment is done',
created_at: new Date('2019-08-09 14:30:00'),
updated_at: new Date('2019-08-09 14:30:00'),
},
Expand All @@ -113,7 +113,7 @@ module.exports = {
{
environment_id: 'GIDO1jdkD',
status: 'DONE',
status_message: 'Environment has been destroyed',
status_message: 'Environment is done',
created_at: new Date('2019-08-09 14:10:00'),
updated_at: new Date('2019-08-09 14:10:00'),
},
Expand Down
1 change: 0 additions & 1 deletion lib/domain/dtos/CreateEnvironmentHistoryItemDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports.CreateEnvironmentHistoryItemDto = Joi.object({
'RUNNING',
'ERROR',
'MIXED',
'DESTROYED',
'DONE',
).required(),
statusMessage: Joi.string().optional(),
Expand Down
1 change: 0 additions & 1 deletion lib/domain/enums/StatusAcronyms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const statusAcronyms = Object.freeze({
CONFIGURED: 'C',
RUNNING: 'R',
ERROR: 'E',
DESTROYED: 'X',
DONE: 'X',
});

Expand Down
1 change: 0 additions & 1 deletion lib/public/domain/enums/statusAcronym.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const StatusAcronym = Object.freeze({
CONFIGURED: 'C',
RUNNING: 'R',
ERROR: 'E',
DESTROYED: 'X',
DONE: 'X',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ const statusToCssClassMapping = {
STANDBY: 'gray-dark',
DEPLOYED: 'gray-dark',
DONE: 'black',
DESTROYED: 'black',
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ exports.getEnvironmentsInPeriod = async ({ from, to }, relations) => {
HAVING e.updated_at >= '${timestampToMysql(from)}'
OR e.updated_at > '${timestampToMysql(lostIfNoNewsSince)}'
AND GROUP_CONCAT(ehi.status) NOT LIKE '%ERROR%'
AND GROUP_CONCAT(ehi.status) NOT LIKE '%DESTROYED%'
AND GROUP_CONCAT(ehi.status) NOT LIKE '%DONE%'
`);
const ids = rows.map(({ id }) => id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.transitionToErrorLostEnvironments = async (activeEnvironmentIds, modific
HAVING e.updated_at >= '${timestampToMysql(modificationTimePeriod.from)}'
AND e.created_at < '${timestampToMysql(modificationTimePeriod.to)}'
AND group_concat(ehi.status) NOT LIKE '%ERROR%'
AND group_concat(ehi.status) NOT LIKE '%DESTROYED%'
AND group_concat(ehi.status) NOT LIKE '%DONE%'
`;
if (activeEnvironmentIds.length > 0) {
selectQuery += ` AND e.id NOT IN (${activeEnvironmentIds.map((id) => `'${id}'`).join(',')})`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MILLISECONDS_IN_ONE_DAY = 24 * 60 * 60 * 1000;
/**
* Handle lost environments and runs
*
* For all environments that has not been destroyed and have not gone to error, check through AliECS GUI if they are still active, and if not,
* For all environments that is not done and have not gone to error, check through AliECS GUI if they are still active, and if not,
* mark them as gone to error. For all runs that do not have timeO2Stop or timeTrgStop, check through AliECS GUI if they are still running, and
* if not, mark them as stopped NOW
*
Expand Down
60 changes: 16 additions & 44 deletions lib/usecases/environment/GetAllEnvironmentsUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,59 +118,31 @@ class GetAllEnvironmentsUseCase {
}

if (statusHistory) {
// Check if status history ends with 'X' and remove it if present to handle the special case later
const containsX = statusHistory.endsWith('X');
const cleanedStatusHistory = containsX ? statusHistory.slice(0, -1) : statusHistory;
const historyItems = cleanedStatusHistory.split('');
// A status history ending with 'X' (done) must match the end of the environment's history
const endsWithDone = statusHistory.endsWith('X');

// Swap the acronyms with the status (=acronym -> status)
const acronymToStatus = {};
for (const status in statusAcronyms) {
acronymToStatus[statusAcronyms[status]] = status;
}

// Create a list of status history with the status acronyms
const statusFilters = [];
for (const historyItem of historyItems) {
// Only add the next status if it is in the acronyms list
if (Object.values(statusAcronyms).includes(historyItem)) {
// Use the acronym to get the status
statusFilters.push(acronymToStatus[historyItem]);
}
}
// Create a list of status history with the status acronyms, ignoring unknown acronyms
const statusFilters = statusHistory
.split('')
.filter((historyItem) => historyItem in acronymToStatus)
.map((historyItem) => acronymToStatus[historyItem]);

if (containsX) {
const statusFiltersWithDestroyed = [...statusFilters, 'DESTROYED'].join(',');
const statusFiltersWithDone = [...statusFilters, 'DONE'].join(',');

/*
* Use OR condition to match subsequences ending with either DESTROYED or DONE
* Filter the environments by using LIKE for subsequence matching
*/
queryBuilder.literalWhere(
`(${ENVIRONMENT_STATUS_HISTORY_SUBQUERY} LIKE :statusFiltersWithDestroyed OR ` +
`${ENVIRONMENT_STATUS_HISTORY_SUBQUERY} LIKE :statusFiltersWithDone)`,
{
statusFiltersWithDestroyed: `%${statusFiltersWithDestroyed}`,
statusFiltersWithDone: `%${statusFiltersWithDone}`,
},
);
// Filter the environments by using LIKE for subsequence matching
queryBuilder.literalWhere(
`${ENVIRONMENT_STATUS_HISTORY_SUBQUERY} LIKE :statusFilters`,
{ statusFilters: `%${statusFilters.join(',')}${endsWithDone ? '' : '%'}` },
);

queryBuilder.includeAttribute({
query: ENVIRONMENT_STATUS_HISTORY_SUBQUERY,
alias: 'statusHistory',
});
} else {
queryBuilder.literalWhere(
`${ENVIRONMENT_STATUS_HISTORY_SUBQUERY} LIKE :statusFilters`,
{ statusFilters: `%${statusFilters.join(',')}%` },
);

queryBuilder.includeAttribute({
query: ENVIRONMENT_STATUS_HISTORY_SUBQUERY,
alias: 'statusHistory',
});
}
queryBuilder.includeAttribute({
query: ENVIRONMENT_STATUS_HISTORY_SUBQUERY,
alias: 'statusHistory',
});
}

if (runNumbersExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = () => {
{ id: 'A-NEW-NEW-ENVIRONMENT' },
{ status: 'DO-NOT-EXIST', timestamp: new Date(), timestampNano: 0 },
),
new BadParameterError('"status" must be one of [PENDING, STANDBY, DEPLOYED, CONFIGURED, RUNNING, ERROR, MIXED, DESTROYED, DONE]'),
new BadParameterError('"status" must be one of [PENDING, STANDBY, DEPLOYED, CONFIGURED, RUNNING, ERROR, MIXED, DONE]'),
);

await assert.rejects(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = () => {
expect(environments.map(({ id }) => id)).to.eql(['Dxi029djX', 'KGIS12DS', 'EIDO13i3D', 'TDI59So3d', 'CmCvjNbg']);
expect(environments.every((environment) => environment.createdAt.getTime() < period.to && (
environment.updatedAt.getTime() >= period.from
|| environment.historyItems.every(({ status }) => !['DESTROYED', 'ERROR', 'DONE'].includes(status))
|| environment.historyItems.every(({ status }) => !['ERROR', 'DONE'].includes(status))
&& environment.updatedAt.getTime() > period.from - ENVIRONMENT_CONSIDERED_LOST_AFTER
))).to.be.true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = () => {

it('should successfully create an environment history item', async () => {
const environmentId = 'EIDO13i3D';
const status = 'DESTROYED';
const statusMessage = 'Environment has been destroyed';
const status = 'DONE';
const statusMessage = 'Environment is done';
const timestamp = new Date('2024-09-06 10:40').getTime();
const timestampNano = 123456789;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = () => {
for (const environment of customizedECSEosReport.typeSpecific.environments) {
await createEnvironment(environment);
await createEnvironmentHistoryItem({
status: 'DESTROYED',
status: 'DONE',
timestamp: environment.createdAt,
timestampNano: 0,
environmentId: environment.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ module.exports = () => {
expect(historyOccurrences).to.lengthOf(3);
expect(historyOccurrences).to.eql([
{ statusHistory: 'STANDBY,ERROR', count: 1 },
{ statusHistory: 'STANDBY,DEPLOYED,ERROR,DESTROYED', count: 1 },
{ statusHistory: 'CONFIGURED,RUNNING,DEPLOYED,DESTROYED', count: 1 },
{ statusHistory: 'STANDBY,DEPLOYED,ERROR,DONE', count: 1 },
{ statusHistory: 'CONFIGURED,RUNNING,DEPLOYED,DONE', count: 1 },
]);
});

Expand All @@ -344,7 +344,7 @@ module.exports = () => {
to: new Date('2019/08/09 14:40:00').getTime(),
});
expect(historyOccurrences).to.lengthOf(1);
expect(historyOccurrences).to.eql([{ statusHistory: 'DESTROYED', count: 1 }]);
expect(historyOccurrences).to.eql([{ statusHistory: 'DONE', count: 1 }]);
}
{
const historyOccurrences = await statisticsService.getHistoryOccurrencesInEnvironments({
Expand All @@ -362,7 +362,7 @@ module.exports = () => {
to: new Date('2019/08/09 14:30:01').getTime(),
});
expect(historyOccurrences).to.lengthOf(1);
expect(historyOccurrences).to.eql([{ statusHistory: 'DESTROYED', count: 1 }]);
expect(historyOccurrences).to.eql([{ statusHistory: 'DONE', count: 1 }]);
}
{
const historyOccurrences = await statisticsService.getHistoryOccurrencesInEnvironments({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = () => {
envId: 'EIDO13i3D',
},
body: {
status: 'DESTROYED',
status: 'DONE',
statusMessage: 'Completely new message',
},
});
Expand All @@ -42,7 +42,7 @@ module.exports = () => {

it('Should be able to update the environment with correct values', async () => {
const { result } = await new UpdateEnvironmentUseCase().execute(updateEnvironmentDto);
expect(result.status).to.equal('DESTROYED');
expect(result.status).to.equal('DONE');
});

it('Should give an error when the id of the environment can not be found', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/public/Filters/filtersToUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = () => {

await fillInput(page, '.runs-filter input', '10', ['change']);
await fillInput(page, '.id-filter input', 'Dxi029djX, TDI59So3d', ['change']);
await pressElement(page, '#checkboxes-checkbox-DESTROYED');
await pressElement(page, '#checkboxes-checkbox-DONE');
await fillInput(page, '.historyItems-filter input', 'C-R-D-X', ['change']);
await fillInput(page, fromDateTimeSelector, '2019-08-09T00:00', ['change']);
await fillInput(page, toDateTimeSelector, '2019-08-10T23:59', ['change']);
Expand All @@ -98,7 +98,7 @@ module.exports = () => {
"filter[created][to]": "1565481540000",
"filter[runNumbers]": "10",
"filter[statusHistory]": "C-R-D-X",
"filter[currentStatus]": "DESTROYED",
"filter[currentStatus]": "DONE",
"filter[ids]": "Dxi029djX, TDI59So3d"
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/public/Filters/urlToFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = () => {

it('should set filters from EnvironmentsOverview to the URL', async () => {
const url = 'http://localhost:4000/?page=env-overview&filter[created][from]=1565301600000&filter[created][to]=1565474340000' +
'&filter[runNumbers]=10&filter[statusHistory]=C-R-D-X&filter[currentStatus]=DESTROYED&filter[ids]=Dxi029djX%2C%20TDI59So3d';
'&filter[runNumbers]=10&filter[statusHistory]=C-R-D-X&filter[currentStatus]=DONE&filter[ids]=Dxi029djX%2C%20TDI59So3d';
await page.goto(url, { waitUntil: 'load' });
await openFilteringPanel(page);

Expand All @@ -71,7 +71,7 @@ module.exports = () => {

await expectInputValue(page, '.runs-filter input', '10');
await expectInputValue(page, '.id-filter input', 'Dxi029djX, TDI59So3d');
await page.waitForSelector('#checkboxes-checkbox-DESTROYED:checked');
await page.waitForSelector('#checkboxes-checkbox-DONE:checked');
await expectInputValue(page, '.historyItems-filter input', 'C-R-D-X');
await expectInputValue(page, fromDateTimeSelector, '2019-08-08T22:00');
await expectInputValue(page, toDateTimeSelector, '2019-08-10T21:59');
Expand Down
4 changes: 2 additions & 2 deletions test/public/envs/detailsPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = () => {
});

it('Should successfully display the current environment\'s status', async () => {
await expectInnerText(page, '#environment-status-badge.badge', 'DESTROYED');
await expectInnerText(page, '#environment-status-badge.badge', 'DONE');
});

it('Should successfully display the creation date of the environment', async () => {
Expand All @@ -74,7 +74,7 @@ module.exports = () => {
it('Should successfully display the history of the environment', async () => {
await page.waitForFunction(() => document.querySelectorAll('.history-item').length === 4);
const historyStatuses = await page.$$eval('.history-item .badge', (badges) => badges.map((badge) => badge.innerText));
expect(historyStatuses).to.eql(['CONFIGURED', 'RUNNING', 'DEPLOYED', 'DESTROYED']);
expect(historyStatuses).to.eql(['CONFIGURED', 'RUNNING', 'DEPLOYED', 'DONE']);
});

it('Should successfully display the runs related to the environment', async () => {
Expand Down
5 changes: 1 addition & 4 deletions test/public/envs/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ module.exports = () => {
case 'DONE':
await page.waitForSelector(`${cellSelector}.black`);
break;
case 'DESTROYED':
await page.waitForSelector(`${cellSelector}.black`);
break;
case 'DEPLOYED':
await page.waitForSelector(`${cellSelector}.gray`);
break;
Expand Down Expand Up @@ -303,7 +300,7 @@ module.exports = () => {
await fillInput(page, '.runs-filter input', '10', ['change']);

await fillInput(page, '.id-filter input', 'Dxi029djX, TDI59So3d', ['change']);
await page.$eval('.status-filter #checkboxes-checkbox-DESTROYED', (element) => element.click());
await page.$eval('.status-filter #checkboxes-checkbox-DONE', (element) => element.click());

await fillInput(page, '.historyItems-filter input', 'C-R-D-X', ['change']);

Expand Down
Loading
Loading