Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: topcoder-platform/submissions-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.7
Choose a base ref
...
head repository: topcoder-platform/submissions-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Loading
Showing with 17,115 additions and 6,834 deletions.
  1. +18 −18 .circleci/config.yml
  2. +8 −0 .eslintrc.yml
  3. +5 −5 README.md
  4. +9 −8 app.js
  5. +16 −1 build.sh
  6. +23 −6 config/default.js
  7. +5 −4 config/test.js
  8. +4 −2 docker/Dockerfile
  9. +2 −1 docker/sample.api.env
  10. +15,539 −0 package-lock.json
  11. +31 −25 package.json
  12. +37 −42 scripts/ESloadHelper.js
  13. +10 −9 scripts/createIndex.js
  14. +7 −7 scripts/createTables.js
  15. +10 −9 scripts/deleteIndex.js
  16. +5 −4 scripts/importData.js
  17. +5 −4 scripts/loadES.js
  18. +14 −16 scripts/migrateFromDBToES.js
  19. +12 −11 scripts/updateToV5ChallengeId.js
  20. +16 −16 scripts/updateToV5ChallengeIdSmallChunk.js
  21. +12 −11 scripts/updateToV5ChallengeIdV2.js
  22. +1 −1 src/bootstrap.js
  23. +1 −1 src/common/ErrorMiddleware.js
  24. +33 −0 src/common/axiosInstance.js
  25. +16 −16 src/common/dbhelper.js
  26. +333 −224 src/common/helper.js
  27. +124 −0 src/common/informixHelper.js
  28. +34 −48 src/common/logger.js
  29. +16 −0 src/common/m2mHelper.js
  30. +18 −0 src/constants/index.js
  31. +8 −8 src/controllers/ArtifactController.js
  32. +2 −2 src/controllers/HealthCheckController.js
  33. +12 −12 src/controllers/ReviewController.js
  34. +12 −12 src/controllers/ReviewSummationController.js
  35. +12 −12 src/controllers/ReviewTypeController.js
  36. +25 −15 src/controllers/SubmissionController.js
  37. +12 −2 src/routes/SubmissionRoutes.js
  38. +52 −33 src/services/ArtifactService.js
  39. +5 −7 src/services/HealthCheckService.js
  40. +29 −6 src/services/HelperService.js
  41. +52 −57 src/services/ReviewService.js
  42. +47 −47 src/services/ReviewSummationService.js
  43. +43 −43 src/services/ReviewTypeService.js
  44. +266 −119 src/services/SubmissionService.js
  45. +156 −156 test/common/testData.js
  46. +3 −3 test/e2e/ReviewService.test.js
  47. +2 −2 test/e2e/ReviewSummationService.test.js
  48. +3 −3 test/e2e/prepare.js
  49. +10 −10 test/unit/prepare.js
  50. +0 −5,796 yarn.lock
36 changes: 18 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
version: 2
version: 2.1
defaults: &defaults
docker:
- image: cimg/python:3.11.0-browsers
docker:
- image: cimg/python:3.13.2-browsers
install_dependency: &install_dependency
name: Installation of build and deployment dependencies.
command: |
sudo apt install jq
sudo apt update
sudo apt install python3-pip
sudo pip3 install awscli --upgrade
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.
command: |
git clone --branch v1.4.15 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
cp ./../buildscript/master_deploy.sh .
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .
name: Installation of install_deploysuite.
command: |
git clone --branch v1.4.17 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
cp ./../buildscript/master_deploy.sh .
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .
run_build: &run_build
name: Installation of build dependencies.
command: ./build.sh
name: Installation of build dependencies.
command: ./build.sh

jobs:
# Build & Deploy against development backend
@@ -40,7 +40,7 @@ jobs:
source awsenvconf
./buildenv.sh -e DEV -b dev-submissions-api-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-submissions-api-appvar -i submissions-api
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-submissions-api-appvar -i submissions-api -p FARGATE
"build-prod":
<<: *defaults
@@ -58,20 +58,20 @@ jobs:
source awsenvconf
./buildenv.sh -e PROD -b prod-submissions-api-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-submissions-api-appvar -i submissions-api
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-submissions-api-appvar -i submissions-api -p FARGATE
workflows:
version: 2
build:
jobs:
# Development builds are executed on "develop" branch only.
- "build-dev":
context : org-global
context: org-global
filters:
branches:
only: ['develop']
only: ["develop", "PM-809_artifact-endpoint-update"]
- "build-prod":
context : org-global
context: org-global
filters:
branches:
only:
8 changes: 8 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
env:
browser: true
commonjs: true
es2021: true
extends: standard
parserOptions:
ecmaVersion: latest
rules: {}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

@@ -71,7 +71,7 @@ e.g.

```
export AWS_REGION="<AWS Region>"
export S3_BUCKET="<S3 Bucket Name>"
export DMZ_BUCKET="<S3 Bucket Name>"
export ARTIFACT_BUCKET="<Artifact S3 Bucket Name>"
export ES_HOST="<ES Endpoint>"
export AUTH0_URL="<Auth0 URL>"
@@ -135,7 +135,7 @@ npm run start
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
S3_BUCKET=
DMZ_BUCKET=
ARTIFACT_BUCKET=

# Auth0 config
@@ -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
```
17 changes: 9 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ const cors = require('cors')
const bodyParser = require('body-parser')
const httpStatus = require('http-status')
const _ = require('lodash')
const winston = require('winston')
const logger = require('./src/common/logger')
const helper = require('./src/common/helper')
const errorMiddleware = require('./src/common/ErrorMiddleware')
const routes = require('./src/routes')
@@ -25,10 +25,12 @@ const http = require('http').Server(app)

app.set('port', config.WEB_SERVER_PORT)

app.use(bodyParser.json({ limit: '150mb' }))
app.use(bodyParser.urlencoded({ limit: '150mb', extended: true }))
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }))
app.use(cors())
app.use(fileUpload())
app.use(fileUpload({
limits: { fileSize: 150 * 1024 * 1024 }
}))

const apiRouter = express.Router()

@@ -63,7 +65,6 @@ function checkIfExists (source, term) {
return false
}

/* eslint-disable no-param-reassign */
_.each(routes, (verbs, url) => {
_.each(verbs, (def, verb) => {
let actions = [
@@ -72,7 +73,7 @@ _.each(routes, (verbs, url) => {
next()
}
]
const method = require(`./src/controllers/${def.controller}`)[ def.method ]; // eslint-disable-line
const method = require(`./src/controllers/${def.controller}`)[def.method]

if (!method) {
throw new Error(`${def.method} is undefined, for controller ${def.controller}`)
@@ -127,7 +128,7 @@ _.each(routes, (verbs, url) => {
}

actions.push(method)
winston.info(`API : ${verb.toLocaleUpperCase()} ${config.API_VERSION}${url}`)
logger.info(`API : ${verb.toLocaleUpperCase()} ${config.API_VERSION}${url}`)
apiRouter[verb](`${config.API_VERSION}${url}`, helper.autoWrapExpress(actions))
})
})
@@ -152,7 +153,7 @@ app.use('*', (req, res) => {
})

http.listen(app.get('port'), () => {
winston.info(`Express server listening on port ${app.get('port')}`)
logger.info(`Express server listening on port ${app.get('port')}`)
})

module.exports = app
17 changes: 16 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 23 additions & 6 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ module.exports = {
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used by the application
AWS_READ_UNITS: process.env.AWS_READ_UNITS || 5,
AWS_WRITE_UNITS: process.env.AWS_WRITE_UNITS || 5,
S3_BUCKET: process.env.S3_BUCKET || 'tc-testing-submissions', // S3 Bucket to which submissions need to be uploaded
DMZ_BUCKET: process.env.AWS_DMZ_BUCKET || 'tc-testing-submissions', // S3 Bucket to which submissions need to be uploaded
QUARANTINE_BUCKET: process.env.AWS_QUARANTINE_BUCKET,
ARTIFACT_BUCKET: process.env.ARTIFACT_BUCKET || 'tc-testing-submissions' // S3 bucket to which artifacts need to be uploaded
},
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
@@ -28,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,
@@ -52,5 +52,22 @@ module.exports = {
'c56a4180-65aa-42ec-a945-5fd21dec0505': 987123456,
'9ecc88e5-a4ee-44a4-8ec1-70bd98022510': 123789456,
'd6d31f34-8ee5-4589-ae65-45652fcc01a6': 30000720
},

INTERNAL_CACHE_TTL: process.env.INTERNAL_CACHE_TTL || 1800,
INFORMIX: {
SERVER: process.env.INFORMIX_SERVER || 'informixoltp_tcp', // informix server
DATABASE: process.env.INFORMIX_DATABASE || 'tcs_catalog', // informix database
HOST: process.env.INFORMIX_HOST || 'localhost', // host
PROTOCOL: process.env.INFORMIX_PROTOCOL || 'onsoctcp',
PORT: process.env.INFORMIX_PORT || '2021', // port
DB_LOCALE: process.env.INFORMIX_DB_LOCALE || 'en_US.57372',
USER: process.env.INFORMIX_USER || 'informix', // user
PASSWORD: process.env.INFORMIX_PASSWORD || '1nf0rm1x', // password
POOL_MAX_SIZE: parseInt(process.env.MAXPOOL, 10) || 60,
maxsize: parseInt(process.env.MAXSIZE) || 0,
minpool: parseInt(process.env.MINPOOL, 10) || 1,
idleTimeout: parseInt(process.env.IDLETIMEOUT, 10) || 3600,
timeout: parseInt(process.env.TIMEOUT, 10) || 30000
}
}
9 changes: 5 additions & 4 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -13,14 +13,15 @@ module.exports = {
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used by the application
AWS_READ_UNITS: process.env.AWS_READ_UNITS || 5,
AWS_WRITE_UNITS: process.env.AWS_WRITE_UNITS || 5,
S3_BUCKET: process.env.S3_BUCKET_TEST || 'tc-testing-submissions' // S3 Bucket to which submissions need to be uploaded
DMZ_BUCKET: process.env.AWS_DMZ_BUCKET_TEST || 'tc-testing-submissions', // S3 Bucket to which submissions need to be uploaded
QUARANTINE_BUCKET: process.env.AWS_QUARANTINE_BUCKET_TEST
},
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,
6 changes: 4 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the base image with Node.js
FROM node:12.22.12-buster
FROM node:14.21.3

# Copy the current directory into the Docker image
COPY . /submissions-api
@@ -8,5 +8,7 @@ COPY . /submissions-api
WORKDIR /submissions-api

# Install the dependencies from package.json
RUN yarn install
RUN npm install
ENV INFORMIXDIR=/submissions-api/node_modules/informixdb/installer/onedb-odbc-driver
ENV LD_LIBRARY_PATH=${INFORMIXDIR}/lib:${INFORMIXDIR}/lib/esql:${INFORMIXDIR}/lib/cli
ENTRYPOINT node app.js
3 changes: 2 additions & 1 deletion docker/sample.api.env
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ AUTH0_CLIENT_ID=<Auth0 Client ID>
AUTH0_CLIENT_SECRET=<Auth0 Client Secret>
AWS_ACCESS_KEY_ID=<AWS Access Key ID>
AWS_SECRET_ACCESS_KEY=<AWS Secret Access Key>
S3_BUCKET=<AWS S3 Bucket>
DMZ_BUCKET=<AWS S3 Bucket>
QUARANTINE_BUCKET=<AWS S3 Quarantine Bucket>
ARTIFACT_BUCKET=<AWS S3 Artifact Bucket>
ES_HOST=<ES Host Endpoint>
Loading