From 1f95941545a2175bc3ddd1819e17bf35ec93f758 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 17:46:01 +0200 Subject: [PATCH 1/7] modified producer ready function to be sync --- clinic/src/producers/AppointmentProducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clinic/src/producers/AppointmentProducer.js b/clinic/src/producers/AppointmentProducer.js index be55114f..48d31d37 100644 --- a/clinic/src/producers/AppointmentProducer.js +++ b/clinic/src/producers/AppointmentProducer.js @@ -10,7 +10,7 @@ export const appointmentProducer = (app) => { const producer = new KafkaNode.Producer(client); const kafka_topic = 'notifications'; - producer.on('ready', async function () { + producer.on('ready', function () { console.log('Appointment Producer is ready'); }); From f5a5e1c581cc97cae25e5f0e6377f8658f757487 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 18:00:56 +0200 Subject: [PATCH 2/7] restored POST /admin/:request endpoint --- authentication/src/api/user.js | 21 ++----------------- .../tests/api-tests/AuthenticationAPI.test.js | 2 -- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/authentication/src/api/user.js b/authentication/src/api/user.js index 00d280c3..449a19dd 100644 --- a/authentication/src/api/user.js +++ b/authentication/src/api/user.js @@ -102,9 +102,6 @@ export const user = (app) => { } }); - // - - // app.delete('/users/:id', async (req, res) => { try { const userId = req.params.id; @@ -173,8 +170,9 @@ export const user = (app) => { } }); - app.post('/check-admin/:request', async (req, res) => { + app.post('/admins/:request', async (req, res) => { try { + let signupData = null; const requestFrom = req.params.request; // clinic, pharmacy const userName = req.body.userName; const email = req.body.email; @@ -203,21 +201,6 @@ export const user = (app) => { throw new Error('invalid system'); } - res.status(OK_REQUEST_CODE_200).end(); - } catch (error) { - if (error.response) { - res - .status(BAD_REQUEST_CODE_400) - .send({ message: error.response.data.errMessage }); - } else { - res.status(ERROR_STATUS_CODE).send({ message: error.message }); - } - } - }); - - app.post('/admins/:request', async (req, res) => { - try { - let signupData = null; switch (requestFrom) { case CLINIC_REQ: signupData = await axios.post(ADMIN_Clinic_SIGNUP_URL, req.body); diff --git a/authentication/src/tests/api-tests/AuthenticationAPI.test.js b/authentication/src/tests/api-tests/AuthenticationAPI.test.js index 94fe4304..bab7ba1c 100644 --- a/authentication/src/tests/api-tests/AuthenticationAPI.test.js +++ b/authentication/src/tests/api-tests/AuthenticationAPI.test.js @@ -173,8 +173,6 @@ describe('POST /admins/:request', () => { const type = PHARMACY_ADMIN_ENUM; const email = faker.internet.email(); - // const userId = faker.database.mongodbObjectId(); - // const userName = faker.internet.userName(); const user = new User(generateUser(userId, email, userName, type)); await user.save(); const res = await request(app).post(`/admins/${PHARMACY_REQ}`).send({ userId: userId, type: type, email: email, userName: userName, password: faker.internet.password() }); From 74595a74cf9147eafad7030c654550149a78f015 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 18:14:34 +0200 Subject: [PATCH 3/7] fix: removed producer ready functions --- clinic/src/producers/AppointmentProducer.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/clinic/src/producers/AppointmentProducer.js b/clinic/src/producers/AppointmentProducer.js index 48d31d37..57bd4d95 100644 --- a/clinic/src/producers/AppointmentProducer.js +++ b/clinic/src/producers/AppointmentProducer.js @@ -10,15 +10,6 @@ export const appointmentProducer = (app) => { const producer = new KafkaNode.Producer(client); const kafka_topic = 'notifications'; - producer.on('ready', function () { - console.log('Appointment Producer is ready'); - }); - - producer.on('error', function (err) { - console.log('Appointment Producer is in error state'); - console.log(err); - }); - const sendAppointmentNotification = async (userId, appointment) => { const payload = [ { From 315460b3763a172fea1e114ac8d0139950cf9dcd Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 22:46:14 +0200 Subject: [PATCH 4/7] added kafka to ci --- .github/workflows/clinic-microservice-ci.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clinic-microservice-ci.yml b/.github/workflows/clinic-microservice-ci.yml index c081f827..b6d67c56 100644 --- a/.github/workflows/clinic-microservice-ci.yml +++ b/.github/workflows/clinic-microservice-ci.yml @@ -5,9 +5,9 @@ name: Clinic CI on: push: - branches: [ "main" ] + branches: ['main'] pull_request: - branches: [ "main" ] + branches: ['main'] jobs: lint-and-test-clinic: @@ -17,6 +17,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Run Docker + run: docker-compose up -d + + - name: Wait for Kafka to be ready + run: npx wait-on tcp:127.0.0.1:${{ secrets.KAFKA_PORT }} && echo "Kafka is ready!" + - name: Setup Node.js uses: actions/setup-node@v2 with: @@ -33,6 +39,9 @@ jobs: - name: Run Tests (Clinic Microservice) run: npm run test working-directory: clinic + env: MONGO_URI_TEST: ${{ secrets.MONGO_URI_TEST }} - + ZOOKEEPER_PORT: ${{ secrets.ZOOKEEPER_PORT }} + KAFKA_PORT: ${{ secrets.KAFKA_PORT }} + ZOOKEEPER_HOST_NAME: ${{ secrets.ZOOKEEPER_HOST_NAME}} From 665033dd83f9ab86f0b9c7b7c0a433b9c745a4a7 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 22:51:50 +0200 Subject: [PATCH 5/7] closed kafka producer after tests finish running --- clinic/src/producers/AppointmentProducer.js | 18 +++++++++++++++--- clinic/src/utils/TestingUtils.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clinic/src/producers/AppointmentProducer.js b/clinic/src/producers/AppointmentProducer.js index 57bd4d95..33c8c38d 100644 --- a/clinic/src/producers/AppointmentProducer.js +++ b/clinic/src/producers/AppointmentProducer.js @@ -5,11 +5,21 @@ import { OK_STATUS_CODE, } from '../utils/Constants.js'; -export const appointmentProducer = (app) => { - const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' }); - const producer = new KafkaNode.Producer(client); +const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' }); +const producer = new KafkaNode.Producer(client); + +const appointmentProducer = (app) => { const kafka_topic = 'notifications'; + producer.on('ready', function () { + console.log('Appointment producer is ready'); + }); + + producer.on('error', function (err) { + console.log('Appointment producer is in error state'); + console.log(err); + }); + const sendAppointmentNotification = async (userId, appointment) => { const payload = [ { @@ -49,3 +59,5 @@ export const appointmentProducer = (app) => { } }); }; + +export { appointmentProducer, producer }; diff --git a/clinic/src/utils/TestingUtils.js b/clinic/src/utils/TestingUtils.js index 81f045b8..aeff9e24 100644 --- a/clinic/src/utils/TestingUtils.js +++ b/clinic/src/utils/TestingUtils.js @@ -1,3 +1,4 @@ +const { producer } = require('../producers/AppointmentProducer.js'); const mongoose = require('mongoose'); const dotenv = require('dotenv'); dotenv.config(); @@ -14,6 +15,7 @@ const connectDBTest = async () => { const disconnectDBTest = async () => { try { + producer.close(); const collections = mongoose.connection.collections; for (const key in collections) { From 6264f469d3f25d1646ae45dfb5075b644ace6473 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 22:53:20 +0200 Subject: [PATCH 6/7] added compose file --- clinic/docker-compose.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 clinic/docker-compose.yaml diff --git a/clinic/docker-compose.yaml b/clinic/docker-compose.yaml new file mode 100644 index 00000000..e2add088 --- /dev/null +++ b/clinic/docker-compose.yaml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - ${ZOOKEEPER_PORT}:${ZOOKEEPER_PORT} + environment: + - ALLOW_ANONYMOUS_LOGIN=yes + + kafka: + image: wurstmeister/kafka + container_name: kafka + ports: + - ${KAFKA_PORT}:${KAFKA_PORT} + volumes: + - ./data/kafka:/var/run/docker.sock + environment: + - KAFKA_BROKER_ID=1 + - KAFKA_LISTENERS=PLAINTEXT://:${KAFKA_PORT} + - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:${KAFKA_PORT} + - KAFKA_ZOOKEEPER_CONNECT=${ZOOKEEPER_HOST_NAME}:${ZOOKEEPER_PORT} + - KAFKA_CREATE_TOPICS=notifications:1:1,out_of_stock:1:1 + - ALLOW_PLAINTEXT_LISTENER=yes + depends_on: + - zookeeper From d85a279edc59c3a5c51ae924c6a26a833a0256ef Mon Sep 17 00:00:00 2001 From: amir-awad Date: Thu, 18 Jan 2024 22:54:22 +0200 Subject: [PATCH 7/7] put compose file in root dir --- clinic/docker-compose.yaml => docker-compose.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clinic/docker-compose.yaml => docker-compose.yaml (100%) diff --git a/clinic/docker-compose.yaml b/docker-compose.yaml similarity index 100% rename from clinic/docker-compose.yaml rename to docker-compose.yaml