Skip to content

ES to OS migration to aid with OpenSearch consolidation #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 7, 2025
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ install_dependency: &install_dependency
sudo apt update
sudo apt install python3-pip
sudo pip3 install awscli --upgrade
sudo pip3 install docker==6.1.3
sudo pip3 install docker-compose
# sudo pip3 install docker==6.1.3
# sudo pip3 install docker-compose

install_deploysuite: &install_deploysuite
name: Installation of install_deploysuite.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/submissions-api/tree

## Related repos

- [ES Processor](https://github.com/topcoder-platform/submission-processor-es) - Updates data in ElasticSearch
- [ES Processor](https://github.com/topcoder-platform/submission-processor-es) - Updates data in Opensearch

## Pre-requisites

Expand Down Expand Up @@ -179,8 +179,8 @@ npm run start
```

This command will do 2 things:
- Import the data to the database and index it to ElasticSearch
- Note, to migrate the existing data from DynamoDB to ES, run the following script
- Import the data to the database and index it to OpenSearch
- Note, to migrate the existing data from DynamoDB to OS, run the following script
```
npm run db-to-es
```
Expand Down
17 changes: 16 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,20 @@ set -eo pipefail
#sed -i='' "s|submissions-api:latest|$TAG|" docker/docker-compose.yml
echo "" > docker/api.env
docker-compose -f docker/docker-compose.yml build submissions-api
docker images
#docker images
docker create --name app submissions-api:latest
if [ -d node_modules ]
then
mv package-lock.json old-package-lock.json
docker cp app:/submissions-api/package-lock.json package-lock.json
set +eo pipefail
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
set -eo pipefail
else
UPDATE_CACHE=1
fi

if [ "$UPDATE_CACHE" == 1 ]
then
docker cp app:/submissions-api/node_modules .
fi
9 changes: 4 additions & 5 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ module.exports = {
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
esConfig: {
HOST: process.env.ES_HOST || 'localhost:9200',
API_VERSION: process.env.ES_API_VERSION || '6.3',
ES_INDEX: process.env.ES_INDEX || 'submission',
ES_TYPE: process.env.ES_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
osConfig: {
HOST: process.env.OS_HOST || 'localhost:9200',
OS_INDEX: process.env.OS_INDEX || 'submission-api',
OS_TYPE: process.env.OS_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
},
PAGE_SIZE: process.env.PAGE_SIZE || 20,
MAX_PAGE_SIZE: parseInt(process.env.MAX_PAGE_SIZE) || 100,
Expand Down
6 changes: 3 additions & 3 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module.exports = {
BUSAPI_EVENTS_URL: 'https://api.topcoder-dev.com/v5/bus/events',
BUSAPI_URL: 'https://api.topcoder-dev.com/v5',
CHALLENGEAPI_V5_URL: 'https://api.topcoder-dev.com/v5/challenges',
esConfig: {
ES_INDEX: process.env.ES_INDEX_TEST || 'submission-test',
ES_TYPE: process.env.ES_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
osConfig: {
OS_INDEX: process.env.OS_INDEX_TEST || 'submission-test',
OS_TYPE: process.env.OS_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
},
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
Expand Down
74 changes: 24 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"local:init": "npm run init-db && npm run init-es"
},
"dependencies": {
"@elastic/elasticsearch": "^6.8.8",
"@opensearch-project/opensearch": "^2.11.0",
"amazon-s3-uri": "0.1.1",
"aws-sdk": "^2.265.1",
"axios": "^1.4.0",
Expand Down
55 changes: 25 additions & 30 deletions scripts/ESloadHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,102 @@ const submissions = require('./data/Submissions.json')
const reviews = require('./data/Reviews.json')
const reviewSummations = require('./data/ReviewSummations.json')

const esClient = helper.getEsClient()
const osClient = helper.getOsClient()

/*
* Delete all data from ES
* Delete all data from OS
*/
function deleteDatafromES () {
logger.info('Clear data from ES if any')
function deleteDatafromOS () {
logger.info('Clear data from OS if any')
const filter = {
index: config.get('esConfig.ES_INDEX'),
type: config.get('esConfig.ES_TYPE'),
index: config.get('osConfig.OS_INDEX'),
q: '*'
}
return esClient.deleteByQuery(filter)
return osClient.deleteByQuery(filter)
}

/*
* Load Review Types from JSON into ES
* Load Review Types from JSON into OS
*/
async function loadReviewTypes () {
const promises = []
reviewTypes.forEach((reviewType) => {
const record = {
index: config.get('esConfig.ES_INDEX'),
type: config.get('esConfig.ES_TYPE'),
index: config.get('osConfig.OS_INDEX'),
id: reviewType.id,
body: _.extend({ resource: 'reviewType' }, reviewType)
}
promises.push(esClient.create(record))
promises.push(osClient.index(record))
})
await Promise.all(promises)
}

/*
* Load Submissions from JSON into ES
* Load Submissions from JSON into OS
*/
async function loadSubmissions () {
const promises = []
submissions.forEach((submission) => {
const record = {
index: config.get('esConfig.ES_INDEX'),
type: config.get('esConfig.ES_TYPE'),
index: config.get('osConfig.OS_INDEX'),
id: submission.id,
body: _.extend({ resource: 'submission' }, submission)
}
promises.push(esClient.create(record))
promises.push(osClient.index(record))
})
await Promise.all(promises)
}

/*
* Load Reviews from JSON into ES
* Load Reviews from JSON into OS
*/
async function loadReviews () {
const promises = []
reviews.forEach((review) => {
const record = {
index: config.get('esConfig.ES_INDEX'),
type: config.get('esConfig.ES_TYPE'),
index: config.get('osConfig.OS_INDEX'),
id: review.id,
body: _.extend({ resource: 'review' }, review)
}
promises.push(esClient.create(record))
promises.push(osClient.index(record))
})
await Promise.all(promises)
}

/*
* Load Review Summations from JSON into ES
* Load Review Summations from JSON into OS
*/
async function loadReviewSummations () {
const promises = []
reviewSummations.forEach((reviewSummation) => {
const record = {
index: config.get('esConfig.ES_INDEX'),
type: config.get('esConfig.ES_TYPE'),
index: config.get('osConfig.OS_INDEX'),
id: reviewSummation.id,
body: _.extend({ resource: 'reviewSummation' }, reviewSummation)
}
promises.push(esClient.create(record))
promises.push(osClient.index(record))
})
await Promise.all(promises)
}

/*
* Load data into ES after removing existing data
* Load data into OS after removing existing data
*/
async function loadES () {
await deleteDatafromES()
logger.info('ES Loading started!')
async function loadOS () {
await deleteDatafromOS()
logger.info('OS Loading started!')
await loadReviewTypes()
await loadSubmissions()
await loadReviews()
await loadReviewSummations()
logger.info('ES Loading succeeded!')
logger.info('OS Loading succeeded!')
}

module.exports = {
deleteDatafromES,
deleteDatafromOS,
loadReviewTypes,
loadSubmissions,
loadReviews,
loadReviewSummations,
loadES
loadOS
}
Loading