Skip to content

Commit 80b8476

Browse files
authored
Merge pull request #360 from topcoder-platform/develop
ES to OS migration to aid with OpenSearch consolidation
2 parents c81edf1 + da7f555 commit 80b8476

17 files changed

+164
-187
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ install_dependency: &install_dependency
99
sudo apt update
1010
sudo apt install python3-pip
1111
sudo pip3 install awscli --upgrade
12-
sudo pip3 install docker==6.1.3
13-
sudo pip3 install docker-compose
12+
# sudo pip3 install docker==6.1.3
13+
# sudo pip3 install docker-compose
1414
1515
install_deploysuite: &install_deploysuite
1616
name: Installation of install_deploysuite.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/submissions-api/tree
2020

2121
## Related repos
2222

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

2525
## Pre-requisites
2626

@@ -179,8 +179,8 @@ npm run start
179179
```
180180

181181
This command will do 2 things:
182-
- Import the data to the database and index it to ElasticSearch
183-
- Note, to migrate the existing data from DynamoDB to ES, run the following script
182+
- Import the data to the database and index it to OpenSearch
183+
- Note, to migrate the existing data from DynamoDB to OS, run the following script
184184
```
185185
npm run db-to-es
186186
```

build.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,20 @@ set -eo pipefail
1010
#sed -i='' "s|submissions-api:latest|$TAG|" docker/docker-compose.yml
1111
echo "" > docker/api.env
1212
docker-compose -f docker/docker-compose.yml build submissions-api
13-
docker images
13+
#docker images
14+
docker create --name app submissions-api:latest
15+
if [ -d node_modules ]
16+
then
17+
mv package-lock.json old-package-lock.json
18+
docker cp app:/submissions-api/package-lock.json package-lock.json
19+
set +eo pipefail
20+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
21+
set -eo pipefail
22+
else
23+
UPDATE_CACHE=1
24+
fi
1425

26+
if [ "$UPDATE_CACHE" == 1 ]
27+
then
28+
docker cp app:/submissions-api/node_modules .
29+
fi

config/default.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ module.exports = {
2929
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
3030
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
3131
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
32-
esConfig: {
33-
HOST: process.env.ES_HOST || 'localhost:9200',
34-
API_VERSION: process.env.ES_API_VERSION || '6.3',
35-
ES_INDEX: process.env.ES_INDEX || 'submission',
36-
ES_TYPE: process.env.ES_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
32+
osConfig: {
33+
HOST: process.env.OS_HOST || 'localhost:9200',
34+
OS_INDEX: process.env.OS_INDEX || 'submission-api',
35+
OS_TYPE: process.env.OS_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
3736
},
3837
PAGE_SIZE: process.env.PAGE_SIZE || 20,
3938
MAX_PAGE_SIZE: parseInt(process.env.MAX_PAGE_SIZE) || 100,

config/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ module.exports = {
1919
BUSAPI_EVENTS_URL: 'https://api.topcoder-dev.com/v5/bus/events',
2020
BUSAPI_URL: 'https://api.topcoder-dev.com/v5',
2121
CHALLENGEAPI_V5_URL: 'https://api.topcoder-dev.com/v5/challenges',
22-
esConfig: {
23-
ES_INDEX: process.env.ES_INDEX_TEST || 'submission-test',
24-
ES_TYPE: process.env.ES_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
22+
osConfig: {
23+
OS_INDEX: process.env.OS_INDEX_TEST || 'submission-test',
24+
OS_TYPE: process.env.OS_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
2525
},
2626
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
2727
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,

package-lock.json

Lines changed: 24 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"local:init": "npm run init-db && npm run init-es"
2727
},
2828
"dependencies": {
29-
"@elastic/elasticsearch": "^6.8.8",
29+
"@opensearch-project/opensearch": "^2.11.0",
3030
"amazon-s3-uri": "0.1.1",
3131
"aws-sdk": "^2.265.1",
3232
"axios": "^1.4.0",

scripts/ESloadHelper.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,107 +12,102 @@ const submissions = require('./data/Submissions.json')
1212
const reviews = require('./data/Reviews.json')
1313
const reviewSummations = require('./data/ReviewSummations.json')
1414

15-
const esClient = helper.getEsClient()
15+
const osClient = helper.getOsClient()
1616

1717
/*
18-
* Delete all data from ES
18+
* Delete all data from OS
1919
*/
20-
function deleteDatafromES () {
21-
logger.info('Clear data from ES if any')
20+
function deleteDatafromOS () {
21+
logger.info('Clear data from OS if any')
2222
const filter = {
23-
index: config.get('esConfig.ES_INDEX'),
24-
type: config.get('esConfig.ES_TYPE'),
23+
index: config.get('osConfig.OS_INDEX'),
2524
q: '*'
2625
}
27-
return esClient.deleteByQuery(filter)
26+
return osClient.deleteByQuery(filter)
2827
}
2928

3029
/*
31-
* Load Review Types from JSON into ES
30+
* Load Review Types from JSON into OS
3231
*/
3332
async function loadReviewTypes () {
3433
const promises = []
3534
reviewTypes.forEach((reviewType) => {
3635
const record = {
37-
index: config.get('esConfig.ES_INDEX'),
38-
type: config.get('esConfig.ES_TYPE'),
36+
index: config.get('osConfig.OS_INDEX'),
3937
id: reviewType.id,
4038
body: _.extend({ resource: 'reviewType' }, reviewType)
4139
}
42-
promises.push(esClient.create(record))
40+
promises.push(osClient.index(record))
4341
})
4442
await Promise.all(promises)
4543
}
4644

4745
/*
48-
* Load Submissions from JSON into ES
46+
* Load Submissions from JSON into OS
4947
*/
5048
async function loadSubmissions () {
5149
const promises = []
5250
submissions.forEach((submission) => {
5351
const record = {
54-
index: config.get('esConfig.ES_INDEX'),
55-
type: config.get('esConfig.ES_TYPE'),
52+
index: config.get('osConfig.OS_INDEX'),
5653
id: submission.id,
5754
body: _.extend({ resource: 'submission' }, submission)
5855
}
59-
promises.push(esClient.create(record))
56+
promises.push(osClient.index(record))
6057
})
6158
await Promise.all(promises)
6259
}
6360

6461
/*
65-
* Load Reviews from JSON into ES
62+
* Load Reviews from JSON into OS
6663
*/
6764
async function loadReviews () {
6865
const promises = []
6966
reviews.forEach((review) => {
7067
const record = {
71-
index: config.get('esConfig.ES_INDEX'),
72-
type: config.get('esConfig.ES_TYPE'),
68+
index: config.get('osConfig.OS_INDEX'),
7369
id: review.id,
7470
body: _.extend({ resource: 'review' }, review)
7571
}
76-
promises.push(esClient.create(record))
72+
promises.push(osClient.index(record))
7773
})
7874
await Promise.all(promises)
7975
}
8076

8177
/*
82-
* Load Review Summations from JSON into ES
78+
* Load Review Summations from JSON into OS
8379
*/
8480
async function loadReviewSummations () {
8581
const promises = []
8682
reviewSummations.forEach((reviewSummation) => {
8783
const record = {
88-
index: config.get('esConfig.ES_INDEX'),
89-
type: config.get('esConfig.ES_TYPE'),
84+
index: config.get('osConfig.OS_INDEX'),
9085
id: reviewSummation.id,
9186
body: _.extend({ resource: 'reviewSummation' }, reviewSummation)
9287
}
93-
promises.push(esClient.create(record))
88+
promises.push(osClient.index(record))
9489
})
9590
await Promise.all(promises)
9691
}
9792

9893
/*
99-
* Load data into ES after removing existing data
94+
* Load data into OS after removing existing data
10095
*/
101-
async function loadES () {
102-
await deleteDatafromES()
103-
logger.info('ES Loading started!')
96+
async function loadOS () {
97+
await deleteDatafromOS()
98+
logger.info('OS Loading started!')
10499
await loadReviewTypes()
105100
await loadSubmissions()
106101
await loadReviews()
107102
await loadReviewSummations()
108-
logger.info('ES Loading succeeded!')
103+
logger.info('OS Loading succeeded!')
109104
}
110105

111106
module.exports = {
112-
deleteDatafromES,
107+
deleteDatafromOS,
113108
loadReviewTypes,
114109
loadSubmissions,
115110
loadReviews,
116111
loadReviewSummations,
117-
loadES
112+
loadOS
118113
}

0 commit comments

Comments
 (0)