From 9ad703e5fd0f546a3d49f671b04f1119732f67ab Mon Sep 17 00:00:00 2001 From: Evans Girard <54366437+evans-g-crsj@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:57:42 -0400 Subject: [PATCH] :wrench: Add helper script to check aliases and releases (#127) * :wrench: Add helper script to check aliases and releases * :bug: Remove unnessary arg * :pen: Add more details to checkAliasWithRelease script --- admin/checkAliasWithRelease.mjs | 42 ++++++++++++++++++++++++++++++ admin/findClinicalIndicesUsage.mjs | 5 ++++ 2 files changed, 47 insertions(+) create mode 100644 admin/checkAliasWithRelease.mjs diff --git a/admin/checkAliasWithRelease.mjs b/admin/checkAliasWithRelease.mjs new file mode 100644 index 0000000..da190a0 --- /dev/null +++ b/admin/checkAliasWithRelease.mjs @@ -0,0 +1,42 @@ +import { Client } from '@elastic/elasticsearch'; +import { esHost } from '../dist/src/env.js'; +import assert from 'node:assert/strict'; + +const cbKeepClinicalIndicesOnly = x => + ['file', 'biospecimen', 'participant', 'study'].some(stem => x.index.includes(stem)); + +const client = new Client({ node: esHost }); + +const rAllAliases = await client.cat.aliases({ + h: 'alias,index', + format: 'json', +}); + +assert(rAllAliases.statusCode === 200); + +const allAliases = rAllAliases.body; +const hasNext = allAliases.some(x => x.alias.includes('next_')); +const clinicalAliases = allAliases + .filter(cbKeepClinicalIndicesOnly) + .filter(x => (hasNext ? x.alias.includes('next_') : x)); + +const aliasToReleases = clinicalAliases.reduce((xs, x) => { + const r = 're' + x.index.split('_re_')[1]; + const v = [...new Set(xs[x.alias] ? [...xs[x.alias], r] : [r])]; + return { + ...xs, + [x.alias]: v, + all: v, + }; +}, {}); + +const { all, ...entities } = aliasToReleases; +console.log(`\n`); + +//not the best test but it should suffice +const ok = hasNext ? all.length === 1 : all.length <= 2 +if (!ok) { + console.warn('Check if the clinical aliases are ok - There might be a problem') +} +console.log(`Release(s) found: ${all}`); +console.log(entities); diff --git a/admin/findClinicalIndicesUsage.mjs b/admin/findClinicalIndicesUsage.mjs index e8a9e7a..9f018a5 100644 --- a/admin/findClinicalIndicesUsage.mjs +++ b/admin/findClinicalIndicesUsage.mjs @@ -41,6 +41,11 @@ const makeReleaseToCreationDate = l => const clinicalIndicesNotAliased = clinicalIndices.filter(x => clinicalAliases.every(a => a.index !== x.index)); 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]}`))) + console.log(`===== Not Aliased`); unaliasedClinicalIndicesWithCreationDate.length