Skip to content

Commit

Permalink
update service discovery example
Browse files Browse the repository at this point in the history
  • Loading branch information
linhsolar committed Dec 20, 2023
1 parent 475b5fd commit 4acad02
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 120 deletions.
309 changes: 214 additions & 95 deletions tutorials/dms/package-lock.json

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions tutorials/dms/simple_rest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"name":"simplerest",
"tags":["bdp","nothing","aalto"],
"port": 3000,
"address":"192.168.2.14",
"check": {
"id": "checksimplerest",
"name": "Simple Status",
"args": ["curl","http://localhost:3000/health"],
"interval": "20s",
"timeout": "10s"
}
}
"name": "simplerest",
"tags": [
"bdp",
"nothing",
"aalto"
],
"port": 3000,
"address": "192.168.8.106",
"check": {
"id": "checksimplerest",
"name": "Simple Status",
"args": [
"curl",
"http://192.168.8.106:3000/health"
],
"interval": "20s",
"timeout": "10s"
}
}
15 changes: 12 additions & 3 deletions tutorials/servicediscovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ We use [consul](https://www.consul.io/) for service discovery.
>You can also use ZooKeeper and etcd to study. But then you need to adapt the code for them
## Practices

> change the code to fix it into your setting, especially, we have some specific paths/urls in the code
### Running consul

* Make sure that you have consul installed in your machine.
* using consul-server.sh to run a consul server for testing
```
$sh consul-server.sh aaltocs aaltosea /tmp/consul 0.0.0.0
$bash consul-server.sh aaltocs aaltosea /tmp/consul 0.0.0.0
```
Meaning that we run a consul server with:
* -datacenter=aaltocs: to indicate the data center
* -node=aaltosea: to indicate the name of the agent
* -data-dir=/tmp/consul: to indicate the place where the data is stored
* -bind=0.0.0.0: to indicate the network interface for the internal cluster communication
You should see consul running

You should see consul running: for example check http://localhost:8500/

### Run some services

Expand Down Expand Up @@ -47,5 +50,11 @@ In principle, services will publish their information into consul. We just make
```
the simple_rest.json can be obtained by calling simple_rest **curl -X GET http://localhost:3000/self**.

* check consul service using http://localhost:8500/ui to see if services are alive or not
* check your consul service, e.g., using http://localhost:8500/ui to see if services are alive or not

You should see consul running: for example check http://localhost:8500/
![Consul UI: services are up](consului.png)

* start and stop simple_rest.js and mongodb container and then go to the consul UI to see if the services are alive or not

![Consul UI: simpleret is down](consuluidown.png)
2 changes: 1 addition & 1 deletion tutorials/servicediscovery/consul-server.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#example: -datacenter=aaltocs -data-dir=/tmp/consul -bind=0.0.0.0 -
#example: -datacenter=aaltocs -node=cse4640 -data-dir=/tmp/consul -bind=0.0.0.0 -
/opt/consul/consul agent -enable-script-checks -datacenter=$1 -node $2 -data-dir=$3 -bind=$4 -server -dev
Binary file added tutorials/servicediscovery/consului.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/servicediscovery/consuluidown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions tutorials/servicediscovery/mongocheck.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/python3
import argparse
from pymongo import MongoClient
import sys
## Just hardcode
client = MongoClient(sys.argv[1])
result=client.db_name.command('ping')
if result is None:
print("Problem")
sys.exit(2)
sys.exit (0)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--service_url', default='mongodb://localhost:27017',help='URL of the server')
args = parser.parse_args()
url =args.service_url
if url:
client = MongoClient(url)
result=client.db_name.command('ping')
if result is None:
print("Problem")
sys.exit(2)
4 changes: 2 additions & 2 deletions tutorials/servicediscovery/mongoservice.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name":"mongodb",
"tags":["bdp","sensordata","aalto"],
"port": 27017,
"address":"192.168.0.14",
"address":"192.168.8.106",
"check": {
"id": "checkmongdo",
"name": "Mongodb Status",
"args": ["/home/truong/myprojects/mygit/cs-e4640/tutorials/servicediscovery/mongocheck.py","mongodb://192.168.0.14:27017"],
"args": ["/home/truong/myprojects/mygit/bigdataplatforms/tutorials/servicediscovery/mongocheck.py","--service_url", "mongodb://192.168.8.106:27017"],
"interval": "20s",
"timeout": "5s"
}
Expand Down

0 comments on commit 4acad02

Please sign in to comment.