Skip to content

Commit

Permalink
Merge pull request #24 from airavata-courses/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
amberramesh authored Feb 8, 2022
2 parents 6965cd4 + 915dc4e commit 3f8b4a3
Show file tree
Hide file tree
Showing 70 changed files with 4,932 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ $RECYCLE.BIN/
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.apdisk
node_modules
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,43 @@ Repository for the course project for CSCI-B 649 Applied Distributed Systems in

The project is in its initial stages of development and the README will be updated as new features are added.

## Core Team
## Team

- Akshat Arvind
- Amber Ramesh
- Ratchahan Anbarasan

## System Architecture

![image](https://user-images.githubusercontent.com/96559018/152918648-57a1ad5e-b9a4-4d73-9b40-77c584aaae17.png)

## Tech Stack

- Spring boot
- Maven
- JPA
- Lombok
- MySQL
- Java 17
- grpc
- kafka
- Python 3
- Flask
- Docker

## Installation Procedure:

### Pre-requisites:

- Docker
- openjdk 17

### Installation Order

1. Kafka and Zookeeper server
2. MySQL Database
3. Mongo Database
4. Services



12 changes: 12 additions & 0 deletions api_gateway/Models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const mongoose = require('mongoose')
const UserSchema = new mongoose.Schema({
email: {
type: String,
required: true,
},
password: {
type: String,
required: true,
}
})
module.exports = mongoose.model('User',UserSchema)
25 changes: 25 additions & 0 deletions api_gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Vulcan

## API Gateway

Below are the steps to run the API Gateway Service. Inside the api_gateway folder run -

```
docker-compose up -d
```

This will spin up the mongoDB server inside a docker container.

```
npm install
```

To install all the node dependencies.

```
node index.js
```

This will run the api-gateway server on port 3000.

For detailed information on this service, visit [LINK](https://github.com/airavata-courses/vulcan/wiki/API-GATEWAY-WIKI)
23 changes: 23 additions & 0 deletions api_gateway/config/kafka-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const kafka = require("kafka-node");
// const Producer = kafka.Producer;
// const Consumer = kafka.Consumer;

var Consumer = kafka.Consumer,
client = new kafka.KafkaClient("localhost:9092"),
consumer = new Consumer(
client, [ { topic: "gateway", partition: 0 } ], { autoCommit: false });


var Producer = kafka.Producer,
// KeyedMessage = kafka.KeyedMessage,
client = new kafka.KafkaClient("localhost:9092"),
producer = new Producer(client)

// const ConsumerGroup = kafka.ConsumerGroup
// const client = new kafka.KafkaClient({ kafkaHost: "kafka-service:9092" });
// let config = require("./config");
// producer = new Producer(client);


module.exports = { producer, consumer };

11 changes: 11 additions & 0 deletions api_gateway/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.7'
services:
mongodb_container:
image: mongo:latest
ports:
- 27017:27017
volumes:
- mongodb_data_container:/data/db

volumes:
mongodb_data_container:
98 changes: 98 additions & 0 deletions api_gateway/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const express = require('express')
const mongoose = require('mongoose')
const passport = require('passport')
const bodyParser = require('body-parser')
const User = require('./Models/User')
const jwt = require('jsonwebtoken');
require('./passport')
const app = express()
const server = require('http').createServer(app);
const cors = require('cors')
const WebSocket = require('ws');
const wss = new WebSocket.Server({ server });
app.use(cors());

genToken = user => {
return jwt.sign({
iss: 'Joan_Louji',
sub: user.id,
iat: new Date().getTime(),
exp: new Date().setDate(new Date().getDate() + 1)
}, 'joanlouji');
}
app.use(bodyParser.json())

const consumer = require('./config/kafka-config').consumer
const producer = require("./config/kafka-config").producer

// This can go inside the post request when user makes the data request or when login is authenticated.
wss.on('connection', function connection(ws) {
console.log('A new client Connection!')
// ws.send('Welcome new Client');
consumer.on("message", function (message) {
console.log('received: %s', message.value);
ws.send(message.value)
})

ws.on('message', function incoming(message) {
msg = new TextDecoder('utf-8').decode(new Uint8Array(message))
console.log(msg)
let payloads = [
{
topic: "ingestor",
messages: msg
}];

producer.send(payloads, function (err, data) {
console.error(err);
});

producer.on('error', function (err) {
console.error(err)
})
});
});




app.post('/register', async function (req, res, next) {
const { email, password } = req.body;

//Check If User Exists
let foundUser = await User.findOne({ email });
if (foundUser) {
return res.status(403).json({ error: 'Email is already in use' });
}

const newUser = new User({ email, password })
await newUser.save()
// Generate JWT token
const token = genToken(newUser)
res.status(200).json({ token })
});


mongoose.connect("mongodb://localhost/27017", { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connection.once('open', function () {
console.log('Connected to Mongo');
}).on('error', function (err) {
console.log('Mongo Error', err);
})


app.post('/login', async (req, res, next) => {
const { email, password } = req.body;
let foundUser = await User.findOne({ email, password });
if (foundUser) {
return res.status(200).json("Login Succesful");
}
return res.status(403).json("Invalid User Name")
})

app.get('/secret', passport.authenticate('jwt', { session: false }), (req, res, next) => {
res.json("Secret Data")
})


server.listen(3000, () => console.log('Listenining on port : 3000'))
Loading

0 comments on commit 3f8b4a3

Please sign in to comment.