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

Commit f98ab99

Browse files
Merge pull request #9 from topcoder-platform/develop
Prod deployment
2 parents b4c7060 + 47c6a8c commit f98ab99

24 files changed

+4672
-3895
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ builddeploy_steps: &builddeploy_steps
3838
source awsenvconf
3939
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
4040
source buildenvvar
41-
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-global-informix-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
41+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
4242
4343
4444
jobs:
@@ -48,15 +48,15 @@ jobs:
4848
environment:
4949
DEPLOY_ENV: "DEV"
5050
LOGICAL_ENV: "dev"
51-
APPNAME: "legacy-challenge-processor"
51+
APPNAME: "legacy-challenge-processor"
5252
steps: *builddeploy_steps
5353

5454
"build-prod":
5555
<<: *defaults
5656
environment:
5757
DEPLOY_ENV: "PROD"
58-
LOGICAL_ENV: "prod"
59-
APPNAME: "legacy-challenge-processor"
58+
LOGICAL_ENV: "prod"
59+
APPNAME: "legacy-challenge-processor"
6060
steps: *builddeploy_steps
6161

6262
workflows:
@@ -77,4 +77,4 @@ workflows:
7777
context : org-global
7878
filters:
7979
branches:
80-
only: master
80+
only: master

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
2-
.env
2+
.env
3+
.idea
4+
.nyc_output
5+
coverage

ReadMe.md

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

3-
This microservice processes kafka events related to challenges and backfills data in Informix (legacy) DB.
3+
This microservice processes kafka events related to challenges and backfills data via V4 Challenge API.
44

55
### Development deployment status
66
[![CircleCI](https://circleci.com/gh/topcoder-platform/legacy-challenge-processor/tree/develop.svg?style=svg)](https://circleci.com/gh/topcoder-platform/legacy-challenge-processor/tree/develop)
77
### Production deployment status
88
[![CircleCI](https://circleci.com/gh/topcoder-platform/legacy-challenge-processor/tree/master.svg?style=svg)](https://circleci.com/gh/topcoder-platform/legacy-challenge-processor/tree/master)
99

1010
## Intended use
11-
1211
- Processor
1312

1413
## Related repos
1514

1615
- [Challenge API](https://github.com/topcoder-platform/challenge-api)
1716

1817
## Prerequisites
19-
- [NodeJS](https://nodejs.org/en/) (v8)
18+
- [NodeJS](https://nodejs.org/en/) (v12)
2019
- [Docker](https://www.docker.com/)
2120
- [Docker Compose](https://docs.docker.com/compose/)
2221
- [Kafka](https://kafka.apache.org/)
23-
- [Informix](https://www.ibm.com/in-en/products/informix)
2422

2523
## Configuration
2624

@@ -38,10 +36,6 @@ The following parameters can be set in config files or in env variables:
3836
- KAFKA_ERROR_TOPIC: The kafka error topic.
3937
- CREATE_CHALLENGE_TOPIC: the create challenge Kafka message topic, default value is 'challenge.notification.create'
4038
- UPDATE_CHALLENGE_TOPIC: the update challenge Kafka message topic, default value is 'challenge.notification.update'
41-
- 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)
42-
- 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)
43-
- 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)
44-
- BUSAPI_URL: The event bus API URL
4539
- AUTH0_URL: Auth0 URL, used to get TC M2M token
4640
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
4741
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
@@ -50,19 +44,18 @@ The following parameters can be set in config files or in env variables:
5044
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
5145
- V5_CHALLENGE_API_URL: v5 challenge api url, default value is 'http://localhost:4000/v5/challenges'
5246
- V5_CHALLENGE_TYPE_API_URL: v5 challenge type api url, default value is 'http://localhost:4000/v5/challengeTypes'
53-
- INFORMIX: Informix database configuration parameters, refer `config/default.js` for more information
47+
- V4_CHALLENGE_API_URL: v4 challenge api url, default value is 'http://localhost:4000/v4/challenges'
48+
- V4_TECHNOLOGIES_API_URL: v4 technologies api url, default value is 'http://localhost:4000/v4/technologies'
49+
- V4_PLATFORMS_API_URL: v4 platforms api url, default value is 'http://localhost:4000/v4/platforms'
5450

5551
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
5652

5753
Configuration for the tests is at `config/test.js`, only add such new configurations different from `config/default.js`
5854
- MOCK_API_PORT: the mock server port, default is 4000
5955
- WAIT_TIME: wait time used in test, default is 1500 or 1.5 second
60-
- V4_CHALLENGE_API_URL: the v4 challenge api url, used mock v4 challenge api in testing
61-
6256

6357
You can find sample `.env` files inside the `/docker` directory.
6458

65-
## Local Deployment
6659
### Foreman Setup
6760
To install foreman follow this [link](https://theforeman.org/manuals/1.24/#3.InstallingForeman)
6861
To know how to use foreman follow this [link](https://theforeman.org/manuals/1.24/#2.Quickstart)
@@ -91,43 +84,68 @@ You can find sample `.env` files inside the `/docker` directory.
9184
- run the producer and then write some message into the console to send to the `challenge.notification.create` topic:
9285
`bin/kafka-console-producer.sh --broker-list localhost:9092 --topic challenge.notification.create`
9386
in the console, write message, one message per line:
94-
`{ "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"}`
87+
`{"topic":"challenge.notification.create","originator":"challenge-api","timestamp":"2019-05-14T00:00:00.000Z","mime-type":"application/json","payload":{"id":"0fe70d1a-ad3c-4c58-b341-a478145c4747","created":"2020-03-23T13:21:07.729Z","createdBy":"TopcoderService","typeId":"0b2ac310-eaf0-40e3-b66b-37e5e9e09365","track":"DEVELOPMENT","name":"Lets see if this will work 12","description":"test-description","timelineTemplateId":"a93544bc-c165-4af4-b55e-18f3593b457a","phases":[{"phaseId":"a93544bc-c165-4af4-b55e-18f3593b457a","duration":1000000,"id":"607e8f90-1ed6-49a3-b5a2-486b761a3def","name":"Registration","isOpen":false,"scheduledStartDate":"2020-03-14T16:28:39.882Z","scheduledEndDate":"2020-03-26T06:15:19.882Z","actualStartDate":"2020-03-14T16:28:39.882Z","actualEndDate":"2020-03-26T06:15:19.882Z"},{"phaseId":"6950164f-3c5e-4bdc-abc8-22aaf5a1bd49","duration":1000000,"id":"486fc45e-01e1-4a20-bda1-50cff82943db","name":"Submission","isOpen":false,"scheduledStartDate":"2020-03-14T16:28:39.882Z","scheduledEndDate":"2020-03-26T06:15:19.882Z","actualStartDate":"2020-03-14T16:28:39.882Z","actualEndDate":"2020-03-26T06:15:19.882Z"}],"prizeSets":[{"type":"Challenge prizes","description":"desc","prizes":[{"description":"desc-first","type":"first place","value":500},{"description":"desc-second","type":"second place","value":250}]}],"reviewType":"INTERNAL","tags":["Other"],"projectId":8913,"forumId":456,"status":"Draft","startDate":"2020-03-14T16:28:39.882Z","terms":[{"id":"0dedac8f-5a1a-4fe7-936f-e1d04dc65b7d","agreeabilityType":"Electronically-agreeable","title":"Terms & Conditions of Use at TopCoder","url":""}],"endDate":"2020-03-26T06:15:19.882Z","numOfSubmissions":0,"numOfRegistrants":0}}`
9588
- optionally, use another terminal, go to same directory, start a consumer to view the messages:
9689
`bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic challenge.notification.create --from-beginning`
9790
- writing/reading messages to/from other topics are similar
9891

99-
### Topcoder Informix Database Setup
100-
We will use Topcoder Informix database setup on Docker.
92+
### Local deployment without Docker
10193

102-
Go to `docker-ifx` folder and run `docker-compose up`
103-
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`.
94+
Please make sure you installed and configured kafka
10495

105-
**Dev Only Step, DO NOT EXECUTE IN PRODUCTION**
106-
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.
107-
Additionally the above script will do the following :
108-
-- Create two Copilot profiles in the db for users : ksmith and wyzmo
109-
-- Create a TC direct project with id = 3000
110-
-- Assign both copilots (ksmith and wyzmo) to the TC direct project with project_full permissions
111-
-- Add three users ('Hung', 'twight' and 'dok_tester') with project_report, project_read and project_write permissions respectively.
96+
Install all dependencies
11297

113-
### Local deployment without Docker
114-
- Given the fact that the library used to access Informix DB depends on Informix Client SDK.
115-
We will run the application on Docker using a base image with Informix Client SDK installed and properly configured.
116-
For deployment, please refer to next section 'Local Deployment with Docker'
98+
```
99+
npm install
100+
```
101+
102+
Run the lint
103+
104+
```
105+
npm run lint
106+
```
107+
108+
Set environment variables for M2M Token
109+
110+
```
111+
export AUTH0_CLIENT_ID=jGIf2pd3f44B1jqvOai30BIKTZanYBfU
112+
export AUTH0_CLIENT_SECRET=ldzqVaVEbqhwjM5KtZ79sG8djZpAVK8Z7qieVcC3vRjI4NirgcinKSBpPwk6mYYP
113+
```
114+
115+
Mock server will be started by test tool during testing but for completing local setup please run mock server
116+
in a separate terminal after running tests. Shutdown mock-api for running tests.
117+
118+
```
119+
npm run mock-api
120+
```
121+
122+
Run the application
123+
124+
```
125+
npm start
126+
```
127+
128+
We will be using mock version of V4 and V5 APIs for local development and testing. You can also configure
129+
corresponding environment variables and point processor to topcoder-dev environment.
117130

118131
### Local Deployment with Docker
119132

120-
1. Make sure that Kafka, mock server and Informix are running as per instructions above.
133+
1. Make sure that Kafka, mock server are running as per instructions above.
121134

122135
2. Go to `docker` folder
123136

124-
3. Rename the file `sample.api.env` to `api.env` And properly update the IP addresses to match your environment for the variables : KAFKA_URL, INFORMIX_HOST and V5_CHALLENGE_TYPE_API_URL( make sure to use IP address instead of hostname ( i.e localhost will not work)).Here is an example:
137+
3. Rename the file `sample.api.env` to `api.env` And properly update the IP addresses to match below environment for the variables ( make sure to use IP address instead of hostname ( i.e localhost will not work)).Here is an example:
138+
Please see that 192.168.1.3 is the IP of host machine for docker where we run all the dependencies
139+
125140
```
126-
KAFKA_URL=192.168.31.8:9092
127-
INFORMIX_HOST=192.168.31.8
128-
V5_CHALLENGE_TYPE_API_URL=http://192.168.31.8:4000/v5/challengeTypes
129-
AUTH0_CLIENT_ID=8QovDh27SrDu1XSs68m21A1NBP8isvOt
130-
AUTH0_CLIENT_SECRET=3QVxxu20QnagdH-McWhVz0WfsQzA1F8taDdGDI4XphgpEYZPcMTF4lX3aeOIeCzh
141+
KAFKA_URL=192.168.1.3:9092
142+
V5_CHALLENGE_API_URL=http://192.168.1.3:4000/v5/challenges
143+
V5_CHALLENGE_TYPE_API_URL=http://192.168.1.3:4000/v5/challengeTypes
144+
V4_CHALLENGE_API_URL=http://192.168.1.3:4000/v4/challenges
145+
V4_TECHNOLOGIES_API_URL=http://192.168.1.3:4000/v4/technologies
146+
V4_PLATFORMS_API_URL=http://192.168.1.3:4000/v4/platforms
147+
AUTH0_CLIENT_ID=jGIf2pd3f44B1jqvOai30BIKTZanYBfU
148+
AUTH0_CLIENT_SECRET=ldzqVaVEbqhwjM5KtZ79sG8djZpAVK8Z7qieVcC3vRjI4NirgcinKSBpPwk6mYYP
131149
AUTH0_URL=https://topcoder-dev.auth0.com/oauth/token
132150
AUTH0_AUDIENCE=https://m2m.topcoder-dev.com/
133151
```
@@ -141,7 +159,6 @@ docker-compose up
141159
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
142160

143161

144-
145162
## Production Deployment
146163

147164
- TBD
@@ -153,9 +170,15 @@ docker-compose up
153170
Test configuration is at `config/test.js`. You don't need to change them.
154171
The following test parameters can be set in config file or in env variables:
155172

156-
- MOCK_API_PORT: port of mock api
173+
- MOCK_API_PORT: port of mock api (Default value conflicts with mock api server. So, please shutdown mock api before running tests)
157174
- WAIT_TIME: wait time used in test, default is 1000 or one second
158-
- V4_CHALLENGE_API_URL: url of challenge api v4
175+
176+
Set environment variables for M2M Token
177+
178+
```
179+
export AUTH0_CLIENT_ID=jGIf2pd3f44B1jqvOai30BIKTZanYBfU
180+
export AUTH0_CLIENT_SECRET=ldzqVaVEbqhwjM5KtZ79sG8djZpAVK8Z7qieVcC3vRjI4NirgcinKSBpPwk6mYYP
181+
```
159182

160183
### Prepare
161184
- Start Local services.
@@ -182,5 +205,10 @@ npm run e2e
182205
Refer to the verification document `Verification.md`
183206

184207
## Notes
185-
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).
186-
In Production, a dedicated user should be created for the legacy-challenge-processor and this value should be properly updated in constants.js.
208+
209+
Application is configured to use local mock APs for development and you can point application
210+
to topcoder dev environment for verification purposes. But, please be aware that you need to use correct
211+
kafka message values for verification.
212+
213+
There are some critical issues in dependencies which come from Topcoder and no-kafka libraries. We use latest
214+
versions as of now but these issues should be addressed.

0 commit comments

Comments
 (0)