Skip to content

Commit

Permalink
🔧 Add helper script to check aliases and releases (#127)
Browse files Browse the repository at this point in the history
* 🔧 Add helper script to check aliases and releases

* 🐛 Remove unnessary arg

* 🖊️ Add more details to checkAliasWithRelease script
  • Loading branch information
evans-g-crsj authored Mar 26, 2024
1 parent 45ee5bf commit 9ad703e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions admin/checkAliasWithRelease.mjs
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions admin/findClinicalIndicesUsage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ad703e

Please sign in to comment.