nus-ncl / OctoBot

"Orchestrator for Traffic Generator Bot" is a unique open source orchestration system or tool to be used to emulate a human for generating random and various traffic (e.g., web browsing, email, file transfer, and so on) which is modular or flexible implementation, scalable for tremendous number client/service, and simple/lightweight execution through CLI (command-line interface) or API (application programming interface).
Other
16 stars 12 forks source link

[Octo-App] Provide simple API calls (GET & POST) #31

Closed ariscahyadi closed 3 years ago

ariscahyadi commented 3 years ago

It is to allow REST API call to the orchestrator from a third-party program or web application/interface. It is mentioned in issue #23

ariscahyadi commented 3 years ago

The server has been tested with this following logs:

ubuntu@octobot-o:~/OctoBot/Octo-App/api-server$ ./start.sh 
Collecting flask (from -r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from flask->-r requirements.txt (line 1))
  Using cached 
...
...
...
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, click, flask
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 itsdangerous-1.1.0
 * Serving Flask app "server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8081/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: <ommitted>
Success with status code 200,                 parsing response...
127.0.0.1 - - [08/Dec/2020 09:20:35] "GET /api/v1/nodes/all HTTP/1.1" 200 -
Success with status code 200,                 parsing response...
127.0.0.1 - - [08/Dec/2020 09:20:39] "GET /api/v1/bots/all HTTP/1.1" 200 -
PING <ommitted> (<ommitted>): 56 data bytes
64 bytes from <ommitted>: seq=0 ttl=63 time=0.404 ms
64 bytes from <ommitted>: seq=1 ttl=63 time=0.346 ms
64 bytes from <ommitted>: seq=2 ttl=63 time=0.345 ms

--- <ommitted> ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.345/0.365/0.404 ms
127.0.0.1 - - [08/Dec/2020 09:21:20] "POST /api/v1/bot/run HTTP/1.1" 200 -

. . The client can access with this following output:

ubuntu@octobot-o:~$ curl http://127.0.0.1:8081/api/v1/nodes/all
{
  "nodes": [
    {
      "nodename": "k8s-master"
    }, 
    {
      "nodename": "octobot-wk-1"
    }, 
    {
      "nodename": "octobot-wk-2"
    }
  ]
}
ubuntu@octobot-o:~$ curl http://127.0.0.1:8081/api/v1/bots/all
{
  "bots": [
    {
      "executor": "worker-1", 
      "image": "busybox", 
      "name": "test-bot-1", 
      "node": "octobot-wk-1", 
      "task": [
        "ping", 
        "<ommitted>"
      ]
    }, 
...
...
...
ubuntu@octobot-o:~$ curl -H "Content-type: application/json" -X POST http://localhost:8081/api/v1/bot/run -d '{"bot":"test-bot-1", "executor":"worker-1", "task":"ping -c 3 <ommitted>"}'
{
  "message": "Task ping -c 3 <ommited> is successfully run by worker-1 in bot test-bot-1"
}