Skip to content

Commit

Permalink
🥅 Add extra condition before deleting indices from a given release
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj committed May 14, 2024
1 parent 8bfb201 commit f3d7e86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 14 additions & 0 deletions admin/deleteClinicalIndicesFromRelease.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import assert from 'node:assert/strict';
import readline from 'readline';
import { Client } from '@elastic/elasticsearch';
import { esHost } from '../dist/src/env.js';
import { cbKeepClinicalIndicesOnly } from './utils.mjs';

const args = process.argv.slice(2);
const releaseArgument = args.find(a => a.startsWith('release:')) ?? '';
Expand Down Expand Up @@ -67,6 +68,19 @@ assert(
)} only. Terminating`,
);

const rAllAliases = await client.cat.aliases({
h: 'alias,index',
format: 'json',
});

assert(rAllAliases.statusCode === 200);

const allAliases = rAllAliases.body;
const clinicalAliases = allAliases.filter(cbKeepClinicalIndicesOnly);

const isAliased = clinicalAliases.some(x => x.index.includes(releaseTag));
assert(!isAliased, `${releaseTag} is aliased`);

const displayIndicesQuestion = () =>
new Promise(resolve => {
userReadline.question(
Expand Down
8 changes: 3 additions & 5 deletions admin/findClinicalIndicesUsage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import assert from 'node:assert/strict';
import { Client } from '@elastic/elasticsearch';
import { esHost } from '../dist/src/env.js';
import { cbKeepClinicalIndicesOnly } from './utils.mjs';

const client = new Client({ node: esHost });

Expand All @@ -18,9 +19,6 @@ if (catIndicesResponse.statusCode !== 200) {
process.exit(1);
}

const cbKeepClinicalIndicesOnly = x =>
['file', 'biospecimen', 'participant', 'study'].some(stem => x.index.includes(stem));

const clinicalIndices = catIndicesResponse.body.filter(cbKeepClinicalIndicesOnly);
assert(Array.isArray(clinicalIndices) && clinicalIndices.length > 0, 'No index found. Terminating');

Expand All @@ -43,8 +41,8 @@ const clinicalIndicesNotAliased = clinicalIndices.filter(x => clinicalAliases.ev
const unaliasedClinicalIndicesWithCreationDate = makeReleaseToCreationDate(clinicalIndicesNotAliased);

// Make sure that no aliased index contains previously found unaliased releases.
const unaliasedReleases = unaliasedClinicalIndicesWithCreationDate.map(x => x.release)
assert(clinicalAliases.every(x => !unaliasedReleases.includes(`re_${x.index.split('re_')[1]}`)))
const unaliasedReleases = unaliasedClinicalIndicesWithCreationDate.map(x => x.release);
assert(clinicalAliases.every(x => !unaliasedReleases.includes(`re_${x.index.split('re_')[1]}`)));

console.log(`===== Not Aliased`);

Expand Down
3 changes: 3 additions & 0 deletions admin/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const cbKeepClinicalIndicesOnly = x =>
['file', 'biospecimen', 'participant', 'study'].some(stem => x.index.includes(stem));

0 comments on commit f3d7e86

Please sign in to comment.