Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 799f6d1

Browse files
code from 30103353
1 parent aafd91a commit 799f6d1

File tree

12 files changed

+6072
-50
lines changed

12 files changed

+6072
-50
lines changed

.gitignore

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

ReadMe.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Configuration
1111

12-
Configuration for the legacy groups processor is at `config/default.js`.
12+
Configuration for the legacy challenge processor is at `config/default.js`.
1313
The following parameters can be set in config files or in env variables:
1414
- LOG_LEVEL: the log level; default value: 'debug'
1515
- KAFKA_URL: comma separated Kafka hosts; default value: 'localhost:9092'
@@ -20,8 +20,13 @@ The following parameters can be set in config files or in env variables:
2020
if not provided, then SSL connection is not used, direct insecure connection is used;
2121
if provided, it can be either path to private key file or private key content
2222
- KAFKA_GROUP_ID: the Kafka group id, default value is 'legacy-challenge-processor'
23+
- KAFKA_ERROR_TOPIC: The kafka error topic.
2324
- CREATE_CHALLENGE_TOPIC: the create challenge Kafka message topic, default value is 'challenge.notification.create'
2425
- UPDATE_CHALLENGE_TOPIC: the update challenge Kafka message topic, default value is 'challenge.notification.update'
26+
- CREATE_CHALLENGE_RESOURCE_TOPIC : The kafka topic to which to write create challenge resources events, default value is 'challenge.action.resource.create' (This topic exists in https://lauscher.topcoder-dev.com/ and can be used for testing)
27+
- COPILOT_ROLE_UUID: The Copilot role UUID, default value is 'bac822d2-725d-4973-9714-360918a09bc0' ( the same value should be set for the corresponding configuration value in legacy-challenge-resource-processor at https://github.com/topcoder-platform/legacy-challenge-resource-processor/blob/develop/src/common/utils.js#L10)
28+
- OBSERVER_ROLE_UUID: The Observer role UUID, default value is 'bac822d2-725d-4973-9712-360918a09bc0' ( the same value should be set for the corresponding configuration value in legacy-challenge-resource-processor at https://github.com/topcoder-platform/legacy-challenge-resource-processor/blob/develop/src/common/utils.js#L10)
29+
- BUSAPI_URL: The event bus API URL
2530
- AUTH0_URL: Auth0 URL, used to get TC M2M token
2631
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
2732
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
@@ -62,7 +67,7 @@ Configuration for the tests is at `config/test.js`, only add such new configurat
6267
- run the producer and then write some message into the console to send to the `challenge.notification.create` topic:
6368
`bin/kafka-console-producer.sh --broker-list localhost:9092 --topic challenge.notification.create`
6469
in the console, write message, one message per line:
65-
`{ "topic": "challenge.notification.create", "originator": "challenge-api", "timestamp": "2019-05-14T00:00:00.000Z", "mime-type": "application/json", "payload": { "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011", "typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098", "track": "CODE", "name": "test-for-legacy-challenge-processor", "description": "<p>test</p>", "phases": [{ "id": "id-1", "name": "registration", "isActive": true, "duration": 345600000 }, { "id": "id-2", "name": "submission", "isActive": true, "duration": 345600000 }, { "id": "id-3", "name": "checkpoint", "isActive": true, "duration": 172800000 } ], "prizeSets": [{ "type": "Code", "prizes": [{ "type": "first-place", "value": 1000 }, { "type": "second-place", "value": 500 }] }, { "type": "Check Point", "prizes": [{ "type": "first-place", "value": 200 }, { "type": "second-place", "value": 200 }, { "type": "third-place", "value": 200 }] }], "reviewType": "COMMUNITY", "markdown": false, "tags": ["Node.js", "NodeJS", "MongoDB", "AWS"], "projectId": 5087, "forumId": 33059 } }`
70+
`{ "topic": "challenge.notification.create", "originator": "challenge-api", "timestamp": "2019-05-14T00:00:00.000Z", "mime-type": "application/json", "payload": { "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011", "typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098", "track": "CODE", "name": "test-for-legacy-challenge-processor", "description": "<p>test</p>", "phases": [{ "id": "id-1", "name": "registration", "isActive": true, "duration": 345600000 }, { "id": "id-2", "name": "submission", "isActive": true, "duration": 345600000 }, { "id": "id-3", "name": "checkpoint", "isActive": true, "duration": 172800000 } ], "prizeSets": [{ "type": "Code", "prizes": [{ "type": "first-place", "value": 1000 }, { "type": "second-place", "value": 500 }] }, { "type": "Check Point", "prizes": [{ "type": "first-place", "value": 200 }, { "type": "second-place", "value": 200 }, { "type": "third-place", "value": 200 }] }], "reviewType": "COMMUNITY", "markdown": false, "tags": ["Node.js", "NodeJS", "MongoDB", "AWS"], "projectId": 3000, "forumId": 33059 }, "copilotId": 124861, "status": "Active"}`
6671
- optionally, use another terminal, go to same directory, start a consumer to view the messages:
6772
`bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic challenge.notification.create --from-beginning`
6873
- writing/reading messages to/from other topics are similar
@@ -73,8 +78,17 @@ We will use Topcoder Informix database setup on Docker.
7378
Go to `docker-ifx` folder and run `docker-compose up`
7479
After the database has initialized, You can use a database GUI tool(example [DBeaver](https://dbeaver.io)) to run the sql script `docker-ifx/update.sql`.
7580

81+
**Dev Only Step, DO NOT EXECUTE IN PRODUCTION**
82+
For testing the creation of challenge resources, the users need to agree to user terms before adding them as resources, to achieve this : execute the sql script `docker-ifx/devOnly-Updates.sql` this will make all users in the database agree to all terms.
83+
Additionally the above script will do the following :
84+
-- Create two Copilot profiles in the db for users : ksmith and wyzmo
85+
-- Create a TC direct project with id = 3000
86+
-- Assign both copilots (ksmith and wyzmo) to the TC direct project with project_full permissions
87+
-- Add three users ('Hung', 'twight' and 'dok_tester') with project_report, project_read and project_write permissions respectively.
88+
89+
7690
## Mock V5 Challenge API
77-
Mock V5 challenge api is under `test/mock` folder. You can use command `npm run mock-api` to start the server.
91+
Mock V5 challenge api is under `test/mock` folder. You can use command `npm run mock-api` to start the server. (dependencies should be installed prior to running mock-api with `npm install`)
7892

7993
## Local deployment
8094
- Given the fact that the library used to access Informix DB depends on Informix Client SDK.
@@ -92,6 +106,10 @@ For deployment, please refer to next section 'Local Deployment with Docker'
92106
KAFKA_URL=192.168.31.8:9092
93107
INFORMIX_HOST=192.168.31.8
94108
V5_CHALLENGE_TYPE_API_URL=http://192.168.31.8:4000/v5/challengeTypes
109+
AUTH0_CLIENT_ID=8QovDh27SrDu1XSs68m21A1NBP8isvOt
110+
AUTH0_CLIENT_SECRET=3QVxxu20QnagdH-McWhVz0WfsQzA1F8taDdGDI4XphgpEYZPcMTF4lX3aeOIeCzh
111+
AUTH0_URL=https://topcoder-dev.auth0.com/oauth/token
112+
AUTH0_AUDIENCE=https://m2m.topcoder-dev.com/
95113
```
96114

97115
4. Once that is done, go to run the following command
@@ -103,4 +121,8 @@ docker-compose up
103121
5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies
104122

105123
## Verification
106-
Refer `Verification.md`
124+
Refer to `Verification.md`
125+
126+
## Notes :
127+
In constants.js, 'processorUserId' is set to 132456 which is the id of the user 'heffan'. It used to populated auditing fields for the created records (create_user and modify_user).
128+
In Production, a dedicated user should be created for the legacy-challenge-processor and this value should be properly updated in constants.js.

Verification.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
# Topcoder - Legacy Challenge Processor
22

3+
## Prerequisites :
4+
-- If you previously built the legacy-challenge-processor docker image, make sure it is removed before rebuilding the new one using this submission.
5+
-- This verification guides assumes using a fresh Informix database with the updates mentioned in ReadMe.md
6+
37
## Verification
48
start Kafka server, start Informix database, start mock api server and start the processor
59

610
1. start kafka-console-producer to write messages to `challenge.notification.create` topic:
711
`bin/kafka-console-producer.sh --broker-list localhost:9092 --topic challenge.notification.create`
8-
2. write message:
9-
`{ "topic": "challenge.notification.create","originator": "challenge-api","timestamp": "2019-05-14T00:00:00.000Z","mime-type": "application/json","payload": { "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011","typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098","track": "CODE","name": "test-for-legacy-challenge-processor","description": "<p>test</p>","phases": [{ "id": "id-1","name": "registration","isActive": true, "duration": 345600000 }, { "id": "id-2","name": "submission","isActive": true, "duration": 345600000 }, { "id": "id-3","name": "checkpoint","isActive": true, "duration": 172800000 } ], "prizeSets": [{ "type": "Code","prizes": [{ "type": "first-place", "value": 1000 }, { "type": "second-place","value": 500 }] }, { "type": "Check Point", "prizes": [{ "type": "first-place","value": 200 }, { "type": "second-place","value": 200 }, { "type": "third-place","value": 200 }] }],"reviewType": "COMMUNITY","markdown": false,"tags": ["Java","JUnit","MongoDB","AWS"],"projectId": 5087,"forumId": 33059 } }`
10-
3. Use database GUI tool to execute following statements to verify AssetDTO data.
11-
```sql
12-
select * from tcs_catalog:comp_catalog where component_id >= 2010;
13-
select * from tcs_catalog:comp_categories where comp_categories_id >= 2010;
14-
select * from tcs_catalog:comp_versions where comp_vers_id >= 2010;
15-
select * from tcs_catalog:comp_version_dates where comp_version_dates_id >= 3000;
16-
select * from tcs_catalog:comp_technology where comp_tech_id >= 2200;
17-
```
18-
4. Use database GUI tool to insert the following test data(Only AssetDTO data has been persisted right now, so you can't retrieve the corresponding AssetDTO using the legacyId provided by message payload). project_info table will contain component version id of challenge, you can use the comp_vers_id retrieve from step 3 to replace the `value` column.
19-
```sql
20-
insert into tcs_catalog:project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) values(2000, 2, 39, 132456, current, 132456, current);
21-
insert into tcs_catalog:project_info(project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) values(2000, 1, 2020, 132456, current, 132456, current);
22-
```
23-
5. start kafka-console-producer to write messages to `challenge.notification.update` topic:
24-
`bin/kafka-console-producer.sh --broker-list localhost:9092 --topic challenge.notification.update`
25-
6. write message
26-
`{ "topic": "challenge.notification.update","originator": "challenge-api","timestamp": "2019-05-14T00:00:00.000Z","mime-type": "application/json","payload": { "legacyId": 2000, "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011","typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098","track": "CODE","name": "update-for-legacy-challenge-processor","description": "#Title\n##sub title 1\ntext\n##sub title2\nanother text\n","phases": [{ "id": "id-1","name": "registration","isActive": true, "duration": 345600000 }, { "id": "id-2","name": "submission","isActive": true, "duration": 345600000 }], "prizeSets": [{ "type": "Code","prizes": [{ "type": "first-place", "value": 800 }, { "type": "second-place","value": 400 }]}],"reviewType": "COMMUNITY","markdown":true,"tags": ["Node.js","NodeJS", "PostgreSQL"],"projectId": 5087,"forumId": 33059 } }`
27-
7. Use database GUI tool to execute following statements to verify AssetDTO data.
28-
```sql
29-
select * from tcs_catalog:comp_catalog where component_id >= 2010;
30-
select * from tcs_catalog:comp_technology where comp_tech_id >= 2200;
31-
```
32-
8. Try to change track, write the following message
33-
`{ "topic": "challenge.notification.update","originator": "challenge-api","timestamp": "2019-05-14T00:00:00.000Z","mime-type": "application/json","payload": { "legacyId": 2000, "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011","typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098","track": "WEB_DESIGNS","name": "update-for-legacy-challenge-processor","description": "#Title\n##sub title 1\ntext\n##sub title2\nanother text\n","phases": [{ "id": "id-1","name": "registration","isActive": true, "duration": 345600000 }, { "id": "id-2","name": "submission","isActive": true, "duration": 345600000 }], "prizeSets": [{ "type": "Code","prizes": [{ "type": "first-place", "value": 800 }, { "type": "second-place","value": 400 }]}],"reviewType": "COMMUNITY","markdown":true,"tags": ["Node.js","NodeJS", "PostgreSQL"],"projectId": 5087,"forumId": 33059 } }`
34-
9. You would see error message in app console.
35-
36-
## Unit test Coverage
37-
It is not available right now
38-
39-
## E2E test Coverage
40-
It is not available right now
12+
2. write create challenge message:
13+
`{ "topic": "challenge.notification.create","originator": "challenge-api","timestamp": "2019-05-14T00:00:00.000Z","mime-type": "application/json","payload": { "id": "1a4ef3a8-ed35-40d1-b8a6-7371a700d011","typeId": "2f4ef3a8-ed35-40d1-b8a6-7371a700d098","track": "CODE","name": "test-for-legacy-challenge-processor","description": "<p>test</p>","phases": [{ "id": "id-1","name": "registration","isActive": true, "duration": 345600000 }, { "id": "id-2","name": "submission","isActive": true, "duration": 345600000 }, { "id": "id-3","name": "checkpoint","isActive": true, "duration": 172800000 } ], "prizeSets": [{ "type": "Code","prizes": [{ "type": "first-place", "value": 1000 }, { "type": "second-place","value": 500 }] }, { "type": "Check Point", "prizes": [{ "type": "first-place","value": 200 }, { "type": "second-place","value": 200 }, { "type": "third-place","value": 200 }] }],"reviewType": "COMMUNITY","markdown": false,"tags": ["Java","JUnit","MongoDB","AWS"],"projectId": 3000,"forumId": 33059, "copilotId": 124861, "status": "Active"} }`
14+
15+
3. Use databasse GUI tool to execute the following sql statements to get the data of the created Challenge :
16+
```sql
17+
select * from tcs_catalog:project where tc_direct_project_id = 3000;
18+
```
19+
This statement will show an output similar to https://drive.google.com/open?id=11WySjFHRGchK4jiGni05VbMierAJw5zs
20+
21+
The project_id value (30005520) in the output represents the legacyId of the created challenge and this value will be used in the next SQL statement
22+
23+
4. Execute the following SQL statements to check the challenge prizes (replace <legacyId> with the value of project_id column in the previous statement):
24+
```sql
25+
select * from tcs_catalog:prize where project_id = <legacyId>
26+
```
27+
The output should be similar to this one : https://drive.google.com/open?id=1YG5MNT8mYcubZjyJPKJkHJc910Dxe5Qu
28+
29+
5. Open your browser and navigate to https://lauscher.topcoder-dev.com/ , Login as TonyJ/appirio123
30+
31+
6. On the top left of the main page in 'Topic:' dropdown list select the topic that was configured for CREATE_CHALLENGE_RESOURCE_TOPIC in default.js ('challenge.action.resource.create' if using default value) and click on 'View' button.
32+
There should be 5 messages sent to this topic :
33+
-- One message for the Copilot resource :
34+
ksmith, user_id = 124861, challengeId = "1a4ef3a8-ed35-40d1-b8a6-7371a700d011" 'payload.id' from the event message payload and roleId = "bac822d2-725d-4973-9714-360918a09bc0" (The value configured in default.js COPILOT_ROLE_UUID)
35+
36+
https://drive.google.com/open?id=1j7j2k-HtAB2SqbHm8uicPKKzP1dTEo7E
37+
38+
39+
-- The remaining 4 events sent to this topic are for observers , for example for user "wyzmo" (user_id = 124856), who is a Copilot on the TC direct project but is not the copilot of the created challenge :
40+
Check the roleId, it should match the value configured for OBSERVER_ROLE_UUID in default.js
41+
42+
43+
7. Check code styling by running the following commands locally :
44+
-- `npm install`
45+
-- `npm run lint`

config/default.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ module.exports = {
1313

1414
// Kafka group id
1515
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'legacy-challenge-processor',
16+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
1617

1718
CREATE_CHALLENGE_TOPIC: process.env.CREATE_CHALLENGE_TOPIC || 'challenge.notification.create',
1819
UPDATE_CHALLENGE_TOPIC: process.env.UPDATE_CHALLENGE_TOPIC || 'challenge.notification.update',
20+
CREATE_CHALLENGE_RESOURCE_TOPIC: process.env.CREATE_CHALLENGE_RESOURCE_TOPIC || 'challenge.action.resource.create',
21+
22+
OBSERVER_ROLE_UUID: process.env.OBSERVER_ROLE_UUID || 'bac822d2-725d-4973-9712-360918a09bc0',
23+
COPILOT_ROLE_UUID: process.env.COPILOT_ROLE_UUID || 'bac822d2-725d-4973-9714-360918a09bc0',
24+
25+
// bus API config params
26+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
1927

2028
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
2129
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
2230
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME || 90,
23-
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || 'EkE9qU3Ey6hdJwOsF1X0duwskqcDuElW',
24-
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || 'Iq7REiEacFmepPh0UpKoOmc6u74WjuoJriLayeVnt311qeKNBvhRNBe9BZ8WABYk',
31+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '',
32+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '',
2533
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
2634

2735
V5_CHALLENGE_API_URL: process.env.V5_CHALLENGE_API_URL || 'http://localhost:4000/v5/challenges',

docker-ifx/devOnly-Updates.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- THIS SCRIPT SHOULD NOT BE EXECUTED IN PRODUCTION --
2+
DATABASE tcs_catalog;
3+
4+
-- Make sure all users in the db agree to all terms
5+
INSERT INTO user_terms_of_use_xref
6+
SELECT u.user_id, t.terms_of_use_id, CURRENT, CURRENT
7+
FROM user u
8+
JOIN terms_of_use t ON 1=1
9+
LEFT JOIN (SELECT user_id, terms_of_use_id FROM user_terms_of_use_xref) x
10+
ON x.user_id = u.user_id AND x.terms_of_use_id = t.terms_of_use_id
11+
WHERE x.user_id IS NULL;
12+
13+
14+
-- Create some Copilot profiles
15+
16+
-- ksmith
17+
insert into copilot_profile values(1, 124861, 1, 0, 100, current, 't', '132456', current, '132456', current, 't', 't' );
18+
19+
-- wyzmo
20+
insert into copilot_profile values(2, 124856, 1, 0, 100, current, 't', '132456', current, '132456', current, 't', 't' );
21+
22+
23+
-- Create a TC direct project
24+
insert into tc_direct_project(project_id, name, project_status_id, user_id, create_date )
25+
values(3000, 'Test TC Direct Project', 1, 132456, current);
26+
27+
-- Assign two Copilots to TC Direct project (ksmith (id = 124861) and wyzmo (id = 124856))
28+
insert into copilot_project(copilot_project_id, copilot_profile_id, tc_direct_project_id, copilot_type_id, copilot_project_status_id, private_project, create_user, create_date, modify_user, modify_date)
29+
values(6000, 1, 3000, 1, 1, 'N', 132456, current, 132456, current);
30+
31+
insert into copilot_project(copilot_project_id, copilot_profile_id, tc_direct_project_id, copilot_type_id, copilot_project_status_id, private_project, create_user, create_date, modify_user, modify_date)
32+
values(6001, 2, 3000, 1, 1, 'N', 132456, current, 132456, current);
33+
34+
-- Create Copilots permissions ( permission_type_id = 3, means project_full permission)
35+
-- ksmith
36+
insert into user_permission_grant(user_permission_grant_id, user_id, resource_id, permission_type_id)
37+
values(1000, 124861, 3000, 3);
38+
-- wyzmo
39+
insert into user_permission_grant(user_permission_grant_id, user_id, resource_id, permission_type_id)
40+
values(1001, 124856, 3000, 3);
41+
42+
-- Create TC direct permissions for other users
43+
44+
-- handle = 'Hung', Permission type = project_report
45+
insert into user_permission_grant(user_permission_grant_id, user_id, resource_id, permission_type_id)
46+
values(1002, 124764, 3000, 0);
47+
48+
-- handle = 'twight', Permission type = project_read
49+
insert into user_permission_grant(user_permission_grant_id, user_id, resource_id, permission_type_id)
50+
values(1003, 124766, 3000, 1);
51+
52+
-- handle = 'dok_tester', Permission type = project_write
53+
insert into user_permission_grant(user_permission_grant_id, user_id, resource_id, permission_type_id)
54+
values(1004, 20, 3000, 2);

0 commit comments

Comments
 (0)