Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 8cd7d75

Browse files
Initial commit
0 parents  commit 8cd7d75

File tree

14 files changed

+4040
-0
lines changed

14 files changed

+4040
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
3+
.env

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# UBahn - User Skills Processor
2+
3+
Sync the skills for a user in u-bahn with the skills in members api
4+
5+
## Dependencies
6+
7+
- Nodejs(v12+)
8+
- Kafka
9+
10+
## Configuration
11+
12+
Configuration for the skill record processor is at `config/default.js`.
13+
The following parameters can be set in config files or in env variables:
14+
15+
- LOG_LEVEL: the log level; default value: 'debug'
16+
- KAFKA_URL: comma separated Kafka hosts; default value: 'localhost:9092'
17+
- KAFKA_CLIENT_CERT: Kafka connection certificate, optional; default value is undefined;
18+
if not provided, then SSL connection is not used, direct insecure connection is used;
19+
if provided, it can be either path to certificate file or certificate content
20+
- KAFKA_CLIENT_CERT_KEY: Kafka connection private key, optional; default value is undefined;
21+
if not provided, then SSL connection is not used, direct insecure connection is used;
22+
if provided, it can be either path to private key file or private key content
23+
- KAFKA_GROUP_ID: the Kafka group id, default value is 'skill-record-processor'
24+
- SKILL_SYNC_TOPIC: the sync skill Kafka message topic, default value is 'backgroundjob.sync.user.skills'
25+
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
26+
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'
27+
- AUTH0_URL: The auth0 url, default value: 'https://topcoder-dev.auth0.com/oauth/token'
28+
- AUTH0_UBAHN_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://u-bahn.topcoder-dev.com'
29+
- AUTH0_TOPCODER_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://m2m.topcoder-dev.com/'
30+
- AUTH0_CLIENT_ID: The auth0 client id
31+
- AUTH0_CLIENT_SECRET: The auth0 client secret
32+
- AUTH0_PROXY_SERVER_URL: The auth0 proxy server url
33+
- TOKEN_CACHE_TIME: The token cache time
34+
- SKILL_PROVIDER_NAME: The skill provider name, default value: Topcoder
35+
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
36+
37+
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
38+
39+
## Local Kafka setup
40+
41+
### Install bin
42+
43+
- `http://kafka.apache.org/quickstart` contains details to setup and manage Kafka server,
44+
below provides details to setup Kafka server in Linux/Mac, Windows will use bat commands in bin/windows instead
45+
46+
### Local install with Docker
47+
48+
- Navigate to the directory `docker-kafka`
49+
- Run the command `docker-compose up -d`
50+
51+
## Local deployment
52+
53+
1. Make sure that Kafka is running.
54+
55+
2. From the project root directory, run the following command to install the dependencies
56+
57+
```bash
58+
npm install
59+
```
60+
61+
3. To run linters if required
62+
63+
```bash
64+
npm run lint
65+
```
66+
67+
To fix possible lint errors:
68+
69+
```bash
70+
npm run lint:fix
71+
```
72+
73+
4. Start the processor and health check dropin
74+
75+
```bash
76+
npm start
77+
```
78+
79+
## Local Deployment with Docker
80+
81+
To run the Skill Record Processor using docker, follow the below steps
82+
83+
1. Navigate to the directory `docker`
84+
85+
2. Rename the file `sample.api.env` to `api.env`
86+
87+
3. Set the auth0 config in the file `api.env`
88+
89+
4. Once that is done, run the following command
90+
91+
```bash
92+
docker-compose up
93+
```
94+
95+
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
96+
97+
## Verification
98+
99+
1. config `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`
100+
2. start kafka-console-producer to write messages to `backgroundjob.sync.user.skills`
101+
`docker exec -it skill-record-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic backgroundjob.sync.user.skills`
102+
3. write message:
103+
`{ "topic": "backgroundjob.sync.user.skills", "originator": "backgroundjob.service", "timestamp": "2021-05-08T00:00:00.000Z", "mime-type": "application/json", "payload": {"id":"88774616","handle":"billsedison","firstName":"Sachin1","lastName":"Kumar1"} }`
104+
4. Watch the app console, It will show message successfully handled.
105+
5. write non handle message:
106+
`{ "topic": "backgroundjob.sync.user.skills", "originator": "backgroundjob.service", "timestamp": "2021-05-08T00:00:00.000Z", "mime-type": "application/json", "payload": {"id":"88774616","firstName":"Sachin1","lastName":"Kumar1"} }`
107+
6. watch the app console, it will show the ignoring message

build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
APP_NAME=$1
4+
UPDATE_CACHE=""
5+
echo "" > docker/api.env
6+
docker-compose -f docker/docker-compose.yml build $APP_NAME
7+
docker create --name app $APP_NAME:latest
8+
9+
if [ -d node_modules ]
10+
then
11+
mv package-lock.json old-package-lock.json
12+
docker cp app:/$APP_NAME/package-lock.json package-lock.json
13+
set +eo pipefail
14+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
15+
set -eo pipefail
16+
else
17+
UPDATE_CACHE=1
18+
fi
19+
20+
if [ "$UPDATE_CACHE" == 1 ]
21+
then
22+
docker cp app:/$APP_NAME/node_modules .
23+
fi

config/default.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* The default configuration file.
3+
*/
4+
5+
module.exports = {
6+
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
7+
8+
KAFKA_URL: process.env.KAFKA_URL || 'localhost:9092',
9+
// below are used for secure Kafka connection, they are optional
10+
// for the local Kafka, they are not needed
11+
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT,
12+
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY,
13+
14+
// Kafka group id
15+
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'skill-record-processor',
16+
SKILL_SYNC_TOPIC: process.env.SKILL_SYNC_TOPIC || 'backgroundjob.sync.user.skills',
17+
18+
UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5',
19+
MEMBERS_API_URL: process.env.MEMBERS_API_URL || 'https://api.topcoder-dev.com/v5/members',
20+
21+
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials
22+
AUTH0_UBAHN_AUDIENCE: process.env.AUTH0_UBAHN_AUDIENCE || 'https://u-bahn.topcoder.com',
23+
AUTH0_TOPCODER_AUDIENCE: process.env.AUTH0_TOPCODER_AUDIENCE || 'https://m2m.topcoder-dev.com/',
24+
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
25+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
26+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
27+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
28+
29+
SKILL_PROVIDER_NAME: process.env.SKILL_PROVIDER_NAME || 'Topcoder',
30+
SLEEP_TIME: process.env.SLEEP_TIME ? parseInt(process.env.SLEEP_TIME, 10) : 1000
31+
}

docker-kafka/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
zookeeper:
4+
image: wurstmeister/zookeeper
5+
container_name: skill-record-processor_zookeeper
6+
ports:
7+
- "2181:2181"
8+
kafka:
9+
image: wurstmeister/kafka
10+
container_name: skill-record-processor_kafka
11+
ports:
12+
- "9092:9092"
13+
environment:
14+
KAFKA_ADVERTISED_HOST_NAME: localhost
15+
KAFKA_CREATE_TOPICS: "backgroundjob.sync.user.skills:1:1"
16+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

docker/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Use the base image with Node.js 12.16.3
2+
FROM node:12.16.3
3+
4+
# Copy the current directory into the Docker image
5+
COPY . /ubahn-skill-record-processor
6+
7+
# Set working directory for future use
8+
WORKDIR /ubahn-skill-record-processor
9+
10+
# Install the dependencies from package.json
11+
RUN npm install
12+
CMD npm start

docker/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
services:
3+
ubahn-skill-record-processor:
4+
image: ubahn-skill-record-processor:latest
5+
build:
6+
context: ../
7+
dockerfile: docker/Dockerfile
8+
env_file:
9+
- api.env
10+
network_mode: "host"

docker/sample.api.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AUTH0_CLIENT_ID=<Auth0 Client ID>
2+
AUTH0_CLIENT_SECRET=<Auth0 Client Secret>

0 commit comments

Comments
 (0)