Skip to content

Commit

Permalink
improvements and add mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
gionapaolini committed Apr 11, 2021
1 parent 8ccbab0 commit 097974b
Show file tree
Hide file tree
Showing 26 changed files with 802 additions and 222 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ node_modules
bin
obj
__pycache__
charts
charts
**/Python/**/modules
**/Python/cache
**/Python/models
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@
"remoteRoot": "/app/Python"
}
]
},
{
"name": "Attach to Service4",
"type": "python",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 8001
},
"pathMappings": [
{
"localRoot": "${workspaceRoot}/Source/Python",
"remoteRoot": "/app/Python"
}
]
}
]
}
7 changes: 6 additions & 1 deletion Scripts/DeploySystem.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
cd $(dirname "$0")
cd ..

sh Scripts/DestroySystem.sh

kubectl create namespace development
kubectl config set-context --current --namespace=development

helm dep update ./SystemCharts/ClusterResources

helm install cluster-resources ./SystemCharts/ClusterResources --namespace development --wait

declare -a kafka_topics=("topic1")
declare -a kafka_topics=("qa-updated", "intents-updated")

for topic in "${kafka_topics[@]}"
do
kubectl exec --stdin --tty cluster-resources-kafka-0 -- /opt/bitnami/kafka/bin/kafka-topics.sh -create --topic $topic --bootstrap-server localhost:9092
done

kubectl apply -f SystemCharts/TestingPod.yaml
kubectl wait --for=condition=Ready --timeout=600s pod tests

for dir in ./Source/*/Services/*/
do
dir_name=$(basename $dir)
Expand Down
2 changes: 2 additions & 0 deletions Scripts/DestroySystem.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
helm uninstall cluster-resources --namespace development

kubectl delete -f SystemCharts/TestingPod.yaml

#Remove all services
for dir in ./Source/*/Services/*/
do
Expand Down
4 changes: 2 additions & 2 deletions Scripts/MergeKubeConfig.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export KUBECONFIG=~/.kube/config:/mnt/c/Users/{USER}/.kube/config
kubectl config view --flatten > /mnt/c/Users/{USER}/.kube/config
export KUBECONFIG=~/.kube/config:/mnt/c/Users/Gio/.kube/config
kubectl config view --flatten > /mnt/c/Users/Gio/.kube/config
42 changes: 39 additions & 3 deletions Source/NodeJS/Services/Service1/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
const express = require('express')
const KafkaProducer = require('../../Tools/KafkaProducer')
var bodyParser = require('body-parser')
const mongoose = require("mongoose");
const { QAModel, IntentProjectData } = require('./models/DataModels');

mongoose.connect(process.env.MONGODB_SERVER_URL, {
useNewUrlParser: true,
dbName: "demoDB",
useUnifiedTopology: true,
useCreateIndex: true,
});

KafkaProducer.connect();

const app = express();
app.use(bodyParser.json())

app.post('/qa/:projectId', async (req, res) => {
const { projectId } = req.params;
const { data } = req.body;
await QAModel.updateOne({projectId}, {data}, { upsert: true });
KafkaProducer.produceMessage("qa-updated", { projectId });
res.status(200).json();
})

app.post('/intents/:projectId', async (req, res) => {
const { projectId } = req.params;
const { data } = req.body;
await IntentProjectData.updateOne({projectId}, {data}, { upsert: true });
KafkaProducer.produceMessage("intents-updated", { projectId });
res.status(200).json();
})

app.get('/qa/:projectId', async (req, res) => {
const { projectId } = req.params;
const data = await QAModel.findOne({projectId});
res.status(200).json(data);
})

app.get('/', (req, res) => {
KafkaProducer.produceMessage("topic1", "Message from service1");
res.send('Nodejs says hello world');
app.get('/intents/:projectId', async (req, res) => {
const { projectId } = req.params;
const data = await IntentProjectData.findOne({projectId});
res.status(200).json(data);
})

app.listen(80, () => {
Expand Down
45 changes: 45 additions & 0 deletions Source/NodeJS/Services/Service1/models/DataModels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const mongoose = require("mongoose");

const QAModelSchema = new mongoose.Schema(
{
projectId: {
type: String,
index: true,
required: true,
unique: true,
},
data: {
type: String,
required: true,
minlength: 10,
maxlength: 1000
}
},
);

const IntentProjectDataSchema = new mongoose.Schema(
{
projectId: {
type: String,
index: true,
required: true,
unique: true,
},
data: [
{
intent: {
type: String,
required: true,
},
sentences: [String]
}
]
},
);

const QAModel = mongoose.model("QAModel", QAModelSchema);
const IntentProjectData = mongoose.model("IntentProjectData", IntentProjectDataSchema);

module.exports = {
QAModel, IntentProjectData
}
4 changes: 3 additions & 1 deletion Source/NodeJS/Services/Service1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"kafkajs": "^1.15.0"
"kafkajs": "^1.15.0",
"mongoose": "^5.12.3"
}
}
Loading

0 comments on commit 097974b

Please sign in to comment.