Skip to content

Commit 092b319

Browse files
author
Dushyant Bhalgami
authored
Merge pull request #24 from topcoder-platform/develop
Develop
2 parents 4e31fc8 + 493c875 commit 092b319

32 files changed

+1123
-3995
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2018
4+
},
5+
"env": {
6+
"mocha": true,
7+
"node": true,
8+
"es6": true
9+
},
10+
"extends": "eslint:recommended",
11+
"rules": {
12+
"no-trailing-spaces": "error"
13+
}
14+
}

README.md

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Topcoder - Submission Legacy Processor Application
1+
# Topcoder - Legacy Submission Processor Application
22
----------------------
33

44
## Requirements
@@ -29,81 +29,14 @@ You can update the configuration file or set values to the corresponding environ
2929
- `AUTH0_URL` auth0 url
3030
- `AUTH0_AUDIENCE` auth0 audience
3131
- `TOKEN_CACHE_TIME` auth0 token cache time
32+
- `AUTH0_PROXY_SERVER_URL` auth0 proxy server url
3233
- `AUTH0_CLIENT_ID` auth0 client id
3334
- `AUTH0_CLIENT_SECRET` auth0 client secret
3435
- `CHALLENGE_INFO_API` The challenge info api template with {cid} gets replaced with challenge id
35-
- `CHALLENGE_SUBTRACK` The sub track of marathon match challenge
36+
- `MM_CHALLENGE_SUBTRACK` The sub track of marathon match challenge
3637

37-
`./config/production.js`, `./config/staging.js`, `./config/test.js` will use same configuration variables as `./config/default.js` except `./config/test.js` will have new configurations for test only.
38-
- `MOCK_SUBMISSION_API_PORT` The mock submission api port
39-
- `MOCK_SERVER_PORT` The mock server port for challenge api
40-
41-
`./config/mock.js` will use same configuration variables as `./config/default.js` except
42-
- `MOCK_SERVER_PORT` The mock server port for challenge api
43-
44-
`./test/test_files/sqlParams.json` will load necessary sql params used in test, it will only work if you run `./test/sql/test.sql`.
45-
46-
> NOTE: ALL COMMANDS BELOW EXECUTE UNDER ```<legacy-sub-procecssor>``` directory
38+
`./config/production.js`, `./config/staging.js`, `./config/test.js` will use same configuration variables as `./config/default.js` except `./config/test.js` will have new configurations for test only:
39+
- `MOCK_API_PORT` The mock server port for submission && challenge api
4740

48-
To build the application you must set the `DB_SERVER_NAME` environment variable. This variable holds the database hostname.
49-
50-
## Build Application Docker Image
51-
We only need to do this once
52-
```bash
53-
export DB_SERVER_NAME=informix
54-
docker-compose build lsp-app
55-
```
56-
57-
## Run Kafka and Create Topic (if running kafka locally)
58-
59-
Build Kafka image:
60-
```bash
61-
docker-compose build kafka
62-
```
63-
64-
Run Kafka server:
65-
```bash
66-
docker-compose up -d kafka
67-
docker exec -ti kafka bash -c "kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.create"
68-
docker exec -ti kafka bash -c "kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.update"
69-
```
70-
71-
## Install App Requirements
72-
```bash
73-
export DB_SERVER_NAME=informix
74-
docker-compose up lsp-app-install
75-
```
76-
77-
## Deployment
78-
```bash
79-
export DB_SERVER_NAME=informix
80-
docker-compose up lsp-app
81-
```
82-
83-
## Running Test
84-
- Make sure you're running a clean database (you can take down tc-informix container and then up it again)
85-
- Stop `legacy-sub-processor` application if it was running
86-
- Install test data and you may start service `tc-informix` with command `docker-compose up tc-informix` if not started
87-
```bash
88-
docker cp test/sql/test.sql iif_innovator_c:/
89-
docker exec -ti iif_innovator_c bash -c "source /home/informix/ifx_informixoltp_tcp.env && dbaccess - /test.sql"
90-
```
91-
- Run kafka container (and create topic if you haven't do this before)
92-
- Run (you can use `docker-compose run lsp-app-test` too and it is more suitable for test command)
93-
```bash
94-
docker-compose up lsp-app-test
95-
```
96-
97-
## Docker Build
98-
99-
```bash
100-
heroku login
101-
heroku create
102-
heroku container:push web --arg servername=<DATABASE_SERVER>
103-
heroku container:release web
104-
```
105-
106-
## Standard Code Style
107-
108-
- Check code style `npm run lint`
109-
- Check code style with option to fix the errors `npm run lint:fix`
41+
## Validation
42+
Follow the steps in [Validation.md](Validation.md)

Validation.md

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,103 @@
1-
# Topcoder - Submission Legacy Processor Application - Verification
1+
# Topcoder - Legacy Submission Processor Application - Verification
22
------------
3+
> NOTE: ALL COMMANDS BELOW EXECUTE UNDER ```<legacy-sub-procecssor>``` directory
34
4-
Please check [docs/Validation.md](/docs/Validation.md) and [docs/Verification_with_DB.md](/docs/Verification_with_DB.md).
5-
6-
Please note currently you have to verify application with database or please check [docs/Verification_with_DB.md](/docs/Verification_with_DB.md) only.
7-
8-
I would recommend you to verify and test with docker otherwise you need to check related Dockerfile to have better understanding about how to setup environment properly(not recommend).
5+
## Run Kafka and Create Topic
96

7+
Build Kafka image:
8+
```bash
9+
docker-compose build kafka
10+
```
1011

11-
## Topcoder - Marathon Match - Legacy Processor
12-
Please verify under linux or osx and I test under Ubuntu 18.04 and OSX 12 and windows may have issues to verify with docker.
12+
Run Kafka server:
13+
```bash
14+
docker-compose up -d kafka
15+
docker exec -ti kafka bash -c "kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.create"
16+
docker exec -ti kafka bash -c "kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic submission.notification.update"
17+
```
1318

14-
Please check README.md and ensure you could run tests in docker environment successfully and you can check coverage folder to ensure
15-
`src/services/MarathonSubmissionService.js`,`src/services/NonMarathonSubmissionService.js`,`src/services/LegacySubmissionIdService.js` are fully tested.
19+
## Run Informix and Insert Test Data
20+
Make sure you're running a clean database (you can take down and remove iif_innovator_c container and then up it again)
21+
```bash
22+
export DB_SERVER_NAME=informix
1623

17-
## Setup data in direct
18-
Only necessary MM challenge related test data updated in `./test/sql/test.sql` and you can also setup complete test data using direct application.
24+
docker kill iif_innovator_c
25+
docker rm iif_innovator_c
1926

20-
You can follow [docs/Verification_with_DB.md](/docs/Verification_with_DB.md) to setup MM challenge in direct app, choose Marathon Match under Data menu during creating challenge and create new project with billing account if error to save mm challenge, in last step you have to create as draft challenge,add user as Submitter and get match submission phase id.
27+
docker-compose up -d tc-informix
2128

22-
Currently tc-direct have [issue to save Match Round ID](https://github.com/appirio-tech/direct-app/issues/341) or you may see such logs from command `docker-compose logs tc-direct` if you want to save in page and refresh page.
23-
```bash
24-
| 07:48:37,097 ERROR [ExceptionMappingInterceptor] Invalid action class configuration that references an unknown class named [saveDraftContestAction]
25-
tc-direct_1 | java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [saveDraftContestAction]
29+
docker logs iif_innovator_c
30+
# When you see log like following then informix is started:
31+
# starting rest listener on port 27018
32+
# starting mongo listener on port 27017
2633
```
2734

28-
So you have to run such sql and replace <mm challenge id> with your new created mm challenge id.
35+
**Then insert test data (which will be used by Unit Tests step and Verification step)**:
2936
```bash
30-
database tcs_catalog;
31-
INSERT INTO informix.project_info
32-
(project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
33-
VALUES(<mm challenge id>, 56, 2001, '132456', current, '132456', current);
37+
docker cp test/sql/test.sql iif_innovator_c:/
38+
docker exec -ti iif_innovator_c bash -c "source /home/informix/ifx_informixoltp_tcp.env && dbaccess - /test.sql"
3439
```
3540

36-
Even you run sql direct app will still fail to show details page with such error
37-
```bash
38-
java.lang.NullPointerException
39-
tc-direct_1 | at com.topcoder.direct.services.view.action.analytics.longcontest.MarathonMatchHelper.getMarathonMatchDetails(MarathonMatchHelper.java:115)
40-
tc-direct_1 | at com.topcoder.direct.services.view.action.contest.launch.GetContestAction.executeAction(GetContestAction.java:476)
41-
tc-direct_1 | at com.topcoder.direct.services.view.action.BaseDirectStrutsAction.execute(BaseDirectStrutsAction.java:305)
42-
tc-direct_1 | at sun.reflect.GeneratedMethodAccessor553.invoke(Unknown Source)
43-
41+
## Build Application Docker Image
42+
We only need to do this once
43+
```bash
44+
export DB_SERVER_NAME=informix
45+
docker-compose build lsp-app
4446
```
4547

46-
Please check https://github.com/appirio-tech/direct-app/blob/dev/src/java/main/com/topcoder/direct/services/view/action/contest/launch/GetContestAction.java#L502
47-
48-
Even latest direct codes will comment out related codes to solve this issue so just leave direct page there.
49-
50-
## Run Legacy Submission Proc. app
51-
52-
Make sure related services started and test data prepared and start app with `NODE_ENV=mock` to mock challenge api otherwise new created mm challenge will still consider as non mm challenge
48+
## Install App dependencies
5349
```bash
54-
export NODE_ENV=mock
5550
export DB_SERVER_NAME=informix
56-
docker-compose up lsp-app
51+
rm -rf node_modules && docker-compose run lsp-app-install
5752
```
5853

59-
## Send Test data
60-
From previous data setup I got:
61-
- challengeId = 40005570
62-
- memberId = 132458 (user)
63-
- submissionPhaseId = 100024
64-
65-
Let's send mm submission with example = 0 event to kafka:
54+
**Note**, if the ***legacy-processor-module*** is changed locally (e.g. during local dev and not pushed to git yet), then you need to delete it from *node_modules* and copy the local changed one to *node_modules*:
6655

6756
```bash
68-
docker exec -ti lsp-app bash -c "npm run produce-test-event mm 40005570 132458 100024 0"
57+
rm -rf ./node_modules/legacy-processor-module
58+
cp -rf <path/to/legacy-processor-module> ./node_modules
59+
# e.g cp -rf ../legacy-processor-module ./node_modules
6960
```
7061

71-
Let's send mm submission with example = 1 event to kafka:
62+
## Standard Code Style
63+
64+
- Check code style `npm run lint`
65+
- Check code style with option to fix the errors `npm run lint:fix`
7266

67+
## Run Unit Tests
68+
- Stop `legacy-sub-processor` application if it was running: `docker stop lsp-app`
69+
- Make sure kafka container running with topic created and informix container running with test data inserted
70+
- Run unit tests:
7371
```bash
74-
docker exec -ti lsp-app bash -c "npm run produce-test-event mm 40005570 132458 100024 1"
72+
docker-compose run lsp-app-test
7573
```
7674

77-
or you can run sample mm submission message directly(valid if run `test/sql/test.sql`)
75+
## Verify with Test Data
76+
Deploy first:
7877
```bash
79-
docker exec -ti lsp-app bash -c "npm run produce-test-event 9"
78+
export DB_SERVER_NAME=informix
79+
docker-compose up lsp-app
8080
```
8181

82-
83-
Please note currently processor will call challenge api to check whether challenge is MM challenge and default server api.topcoder-dev.com may not exist mm challenge created in local direct application.
84-
So when we start app with NODE_ENV=mock it will use mock challenge api configurations and start mock challenge api server.
82+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event different-topic"` and verify that the app doesn't consume this message (no log)
83+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event null-message"` and verify that the app skips this message (log: `Skipped null or empty event`)
84+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event empty-message"` and verify that the app skips this message (log: `Skipped null or empty event`)
85+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event invalid-json"` and verify that the app skips this message (log: `Skipped Invalid message JSON`)
86+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event empty-json"` and verify that the app skips this message (log: `Skipped the message topic "undefined" doesn't match the Kafka topic submission.notification.create`)
87+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event invalid-payload"` and verify that the app skips this message (log: `Skipped invalid event, reasons: "timestamp" must be...`)
88+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event wrong-topic"` and verify that the app skips this message (log: `Skipped the message topic "wrong-topic" doesn't match the Kafka topic submission.notification.create`)
89+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event wrong-originator"` and verify that the app skips this message (log: `Skipped event from topic wrong-originator`)
90+
91+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event submission"` and verify that the app makes call to the Submission API successfully (log: `Successfully processed non MM message - Patched to the Submission API: id 111, patch: {"legacySubmissionId":60000}`) and the Mock API log (`docker logs mock-api`) like `Patch /submissions/111 with {"legacySubmissionId":60000}`.
92+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event final-fix"` and verify that the app has log like `final fix upload, only insert upload`, and it should only insert into `upload` table, but not `submission`/`resource_submission` table.
93+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event not-allow-multiple"` and verify that the app has log like `delete previous submission for challengeId...`.
94+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event update-url"` and verify that the app has log like `Successfully processed non MM message - Submission url updated...`.
95+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event no-challenge-props"` and verify that the app has error log like `Error: null or empty result get challenge properties...`.
96+
- Run `docker exec -ti lsp-app bash -c "npm run produce-test-event mm-submission"` and verify that the app skips this message (log: `Skipped event for subTrack: DEVELOP_MARATHON_MATCH`).
8597

8698
## Verify Database
87-
Open your database explorer (**DBeaver** application, for instance). Connect to database informixoltp
88-
Check table: `long_component_state`, `long_submission` or run below sql
89-
```bash
90-
select lcs.status_id,lcs.points, lcs.example_submission_number,lcs.submission_number,ls.* from informixoltp:long_submission ls, informixoltp:long_component_state lcs where ls.long_component_state_id=lcs.long_component_state_id
91-
```
99+
Open your database explorer (**DBeaver** application, for instance). Connect to database tcs_catalog
100+
Check table: `upload`, `submission` and `resource_submission`
101+
102+
## Cleanup
103+
After verification, run `docker-compose down` to take down and remove containers.

config/default.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ module.exports = {
1212
KAFKA_URL: process.env.KAFKA_URL || 'ssl://kafka-host:9093',
1313

1414
// The client cert, can be (1) the path to the cert file, or (2) the cert content
15-
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT || './test/kafka-ssl/client.crt',
15+
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT || './docker/kafka/kafka-ssl/client.crt',
1616

1717
// The client cert key, can be (1) the path to the cert key file, or (2) the cert key content
18-
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY || './test/kafka-ssl/client.key',
18+
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY || './docker/kafka/kafka-ssl/client.key',
1919

2020
// The topic from which the app consumes events
2121
KAFKA_NEW_SUBMISSION_TOPIC: process.env.KAFKA_NEW_SUBMISSION_TOPIC || 'submission.notification.create',
@@ -27,7 +27,7 @@ module.exports = {
2727
KAFKA_NEW_SUBMISSION_ORIGINATOR: process.env.KAFKA_NEW_SUBMISSION_ORIGINATOR || 'submission-api',
2828

2929
// The Submission API URL
30-
SUBMISSION_API_URL: process.env.SUBMISSION_API_URL || 'http://submission-api-host:3000',
30+
SUBMISSION_API_URL: process.env.SUBMISSION_API_URL || 'http://mock-api-host:3000',
3131

3232
// The Submission API timeout
3333
SUBMISSION_TIMEOUT: process.env.SUBMISSION_TIMEOUT || '10000',
@@ -50,19 +50,19 @@ module.exports = {
5050
// The Informix Submission Table Sequence Name
5151
ID_SEQ_SUBMISSION: process.env.ID_SEQ_SUBMISSION || 'submission_id_seq',
5252

53-
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
53+
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials for Submission Service
5454

55-
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
55+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
5656

5757
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME || '86400000',
5858

5959
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
6060

6161
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
6262

63-
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API || 'https://api.topcoder-dev.com/v4/challenges?filter=id={cid}', // {cid} gets replaced with challenge id
63+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
6464

65-
CHALLENGE_SUBTRACK: process.env.CHALLENGE_SUBTRACK || 'MARATHON_MATCH, DEVELOP_MARATHON_MATCH',
66-
67-
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL
65+
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API || 'http://mock-api-host:3000/challenges?filter=id={cid}', // {cid} gets replaced with challenge id
66+
67+
MM_CHALLENGE_SUBTRACK: process.env.MM_CHALLENGE_SUBTRACK || 'MARATHON_MATCH, DEVELOP_MARATHON_MATCH'
6868
}

config/mock.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

config/production.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ module.exports = {
6060

6161
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
6262

63-
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API
63+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
64+
65+
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API,
66+
67+
MM_CHALLENGE_SUBTRACK: process.env.MM_CHALLENGE_SUBTRACK
6468
}

config/staging.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,19 @@ module.exports = {
5050
// The Informix Submission Table Sequence Name
5151
ID_SEQ_SUBMISSION: process.env.ID_SEQ_SUBMISSION || 'submission_id_seq',
5252

53-
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API
53+
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
54+
55+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
56+
57+
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME || '86400000',
58+
59+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
60+
61+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
62+
63+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
64+
65+
CHALLENGE_INFO_API: process.env.CHALLENGE_INFO_API,
66+
67+
MM_CHALLENGE_SUBTRACK: process.env.MM_CHALLENGE_SUBTRACK
5468
}

0 commit comments

Comments
 (0)