Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Latest commit

 

History

History
725 lines (626 loc) · 13.5 KB

webapi.md

File metadata and controls

725 lines (626 loc) · 13.5 KB

JSON/Web API

Notice:
This is a pre-release! We can't guarantee that something you build today will work in the next release.

Queue

GET /v1/queue

Request:

GET /v1/queue HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "id": "bridged-webapp.715a2ddb-02f0-11e5-835c-a268d739d527_TASK_RUNNING",
        "data": {
            "taskId": "bridged-webapp.715a2ddb-02f0-11e5-835c-a268d739d527",
            "taskStatus": "TASK_RUNNING",
            "appId": "/bridged-webapp",
            "host": "slave1.dev",
            "ports": [
                31006,
                31007
            ],
            "eventType": "status_update_event",
            "timestamp": "2015-05-25T15:12:23.338Z"
        },
        "moduleState": [
            {
                "name": "HelloWorld",
                "state": "started",
                "runtime": 0
            }
        ],
        "runtime": 0.8,
        "active": true
    }
]

POST /v1/queue

Request:

POST /v1/queue HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "eventType": "status_update_event",
    "timestamp": "2015-05-25T15:12:24.140Z",
    "slaveId": "20150516-151938-1029963786-5050-2012-S1",
    "taskId": "bridged-webapp.7455ba9d-02f0-11e5-835c-a268d739d527",
    "taskStatus": "TASK_RUNNING",
    "appId": "/bridged-webapp",
    "host": "slave1.dev",
    "ports": [
        31004,31005
    ],
    "version": "2015-05-25T15:12:19.075Z"
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "leader": "http://slave1.dev:31999",
    "taskId": "bridged-webapp.7455ba9d-02f0-11e5-835c-a268d739d527_TASK_RUNNING"
}

Modules

GET /v1/module/inventory/{moduleId}

Request:

GET /v1/module/inventory/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "id": "bridged-webapp.28aa2a14-2157-11e5-9e08-56847afe9799",
        "data": {
            "customData": "Moin, Moin",
            "taskData": {
                "taskId": "bridged-webapp.28aa2a14-2157-11e5-9e08-56847afe9799",
                "taskStatus": "TASK_RUNNING",
                "appId": "/bridged-webapp",
                "host": "slave1.dev",
                "ports": [
                    31002,
                    31003
                ],
                "timestamp": 1435909578085
            }
        }
    }
]

GET /v1/module/list

Request:

GET /v1/module/list HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "HelloWorld": {
        "name": "HelloWorld",
        "queue": {
            "tasks": [
                {
                    "data": {
                        "activeModules": [],
                        "taskId": "bridged-webapp.28aa2a14-2157-11e5-9e08-56847afe9799",
                        "taskStatus": "TASK_KILLED",
                        "appId": "/bridged-webapp",
                        "host": "slave1.dev",
                        "ports": [
                            31023
                        ],
                        "timestamp": 1435909542992,
                        "cleanup": true,
                        "state": "idle"
                    }
                }
            ],
            "concurrency": 1,
            "payload": 1,
            "started": true,
            "paused": false
        },
        "logger": {
            "context": "Module.HelloWorld"
        },
        "presets": [
            {
                "appId": "/bridged-webapp",
                "moduleName": "HelloWorld",
                "status": "enabled",
                "options": {
                    "actions": {
                        "add": "Moin, Moin",
                        "remove": "Tschues"
                    }
                },
                "lastEdit": false
            }
        ],
        "folder": "HelloWorld",
        "options": {},
        "timeout": 60000,
        "syncInProgress": false,
        "activeTask": {
            "activeModules": [],
            "taskId": "bridged-webapp.67bb4g14-2157-11e5-9e08-56847afe9799",
            "taskStatus": "TASK_KILLED",
            "appId": "/bridged-webapp",
            "host": "slave1.dev",
            "ports": [
                31019
            ],
            "timestamp": 1435909558026,
            "cleanup": true,
            "state": "started",
            "start": 1435914049725
        }
    }
}

GET /v1/module/list/{moduleId}

Request:

GET /v1/module/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "name": "HelloWorld",
    "queue": {
        "tasks": [],
        "concurrency": 1,
        "payload": 1,
        "started": true,
        "paused": false
    },
    "logger": {
        "context": "Module.HelloWorld"
    },
    "presets": [
        {
            "appId": "/bridged-webapp",
            "moduleName": "HelloWorld",
            "status": "enabled",
            "options": {
                "actions": {
                    "add": "Moin, Moin",
                    "remove": "Tschues"
                }
            },
            "lastEdit": false
        }
    ],
    "folder": "HelloWorld",
    "options": {},
    "timeout": 60000,
    "syncInProgress": false,
    "activeTask": {
        "activeModules": [],
        "taskId": "bridged-webapp.28aa2a14-2157-11e5-9e08-56847afe9799",
        "taskStatus": "TASK_RUNNING",
        "appId": "/bridged-webapp",
        "host": "slave1.dev",
        "ports": [
            31004
        ],
        "cleanup": true,
        "state": "finished",
        "start": 1435914144910,
        "timestamp": 1435914149916,
        "stop": 1435914149920
    }
}

GET /v1/module/queue/list/{moduleId}

Request:

GET /v1/module/queue/list/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "id": "bridged-webapp.2a7414a6-2157-11e5-9e08-56847afe9799_TASK_KILLED",
        "data": {
            "taskId": "bridged-webapp.2a7414a6-2157-11e5-9e08-56847afe9799",
            "taskStatus": "TASK_KILLED",
            "appId": "/bridged-webapp",
            "host": "slave1.dev",
            "ports": [
                31614,
                31615
            ],
            "timestamp": 1435909588111
        },
        "cleanup": true,
        "moduleState": [],
        "runtime": 0.8,
        "state": "started"
    }
]

POST /v1/module/queue/pause/{moduleId}

Request:

POST /v1/module/queue/pause/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "name": "HelloWorld",
    "queue": {
        "tasks": [],
        "concurrency": 1,
        "saturated": null,
        "empty": null,
        "drain": null,
        "started": true,
        "paused": true
    },
    "logger": {
        "context": "MconnModule.HelloWorld"
    },
    "folder": "HelloWorld",
    "options": {},
    "timeout": 60000,
    "currentJob": null
}

POST /v1/module/queue/resume/{moduleId}

Request:

POST /v1/module/queue/resume/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "name": "HelloWorld",
    "queue": {
        "tasks": [],
        "concurrency": 1,
        "saturated": null,
        "empty": null,
        "drain": null,
        "started": true,
        "paused": false
    },
    "logger": {
        "context": "MconnModule.HelloWorld"
    },
    "folder": "HelloWorld",
    "options": {},
    "timeout": 60000,
    "currentJob": null
}

GET /v1/module/preset

Request:

GET /v1/module/preset HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "HelloWorld": [
        {
            "appId": "/bridged-webapp",
            "moduleName": "HelloWorld",
            "status": "enabled",
            "options": {
                "actions": {
                    "add": "Moin, Moin",
                    "remove": "Tschues"
                }
            },
            "lastEdit": false
        }
    ]
}

GET /v1/module/preset/{moduleId}

Request:

GET /v1/module/preset/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "appId": "/bridged-webapp",
        "moduleName": "HelloWorld",
        "status": "enabled",
        "options": {
            "actions": {
                "add": "Moin, Moin",
                "remove": "Tschues"
            }
        },
        "lastEdit": false
    }
]

POST /v1/module/preset

Request:

POST /v1/module/preset HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "appId": "/bridged-webapp",
    "moduleName": "HelloWorld",
    "status": "enabled",
    "options": {
        "actions": {
            "add": "Moin, Moin",
            "remove": "Tschues"
        }
    }
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "ok",
    "message": "AppId for module HelloWorld created: /bridged-webapp"
}

PUT /v1/module/preset

Request:

PUT /v1/module/preset HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "appId": "/bridged-webapp",
    "moduleName": "HelloWorld",
    "status": "enabled",
    "options": {
        "actions": {
            "add": "Hello, hello",
            "remove": "Bye"
        }
    }
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "ok",
    "message": "AppId for module HelloWorld modified: /bridged-webapp"
}

DELETE /v1/module/preset

Request:

DELETE /v1/module/preset HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "appId": "/bridged-webapp",
    "moduleName": "HelloWorld"
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "ok",
    "message": "AppId for module HelloWorld deleted: /bridged-webapp"
}

POST /v1/module/sync

Request:

POST  /v1/module/sync HTTP/1.1
Accept: */*

Response:

ok

POST /v1/module/sync/{moduleId}

Request:

POST  /v1/module/HelloWorld HTTP/1.1
Accept: */*

Response:

ok

System

GET /v1/info

Request:

GET /v1/info HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "leader": "slave3.dev:31999",
    "env": {
        "MCONN_LOGGER_LEVEL": "3",
        "MCONN_HOST": "slave1.dev",
        "MCONN_PORT": "31999",
        "MCONN_PATH": "/application",
        "MCONN_QUEUE_TIMEOUT": "60000",
        "MCONN_MODULE_PATH": "/mnt/mesos/sandbox",
        "MCONN_MODULE_PREPARE": "true",
        "MCONN_MODULE_START": "HelloWorld",
        "MCONN_MODULE_SYNC_TIME": "600000",
        "MCONN_ZK_HOSTS": "leader.mesos:2181",
        "MCONN_ZK_PATH": "/mconn",
        "MCONN_ZK_SESSION_TIMEOUT": "1000",
        "MCONN_ZK_SPIN_DELAY": "3000",
        "MCONN_ZK_RETRIES": "10",
        "MCONN_MARATHON_HOSTS": "leader.mesos:8080",
        "MCONN_MARATHON_SSL": "false"
    }
}

GET /v1/leader

Request:

GET /v1/leader HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "leader": "slave3.dev:31999"
}

GET /v1/ping

Request:

GET /v1/ping HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: text/plain

pong

POST /v1/exit/leader

Request:

POST /v1/exit/leader HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "ok"
    "message": "Exit leader: slave3.dev:31999"
}

POST /v1/exit/node

Request:

POST /v1/exit/node HTTP/1.1
Accept: */*

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "ok"
    "message": "Exit node"
}

Error-Handling

Example to detect errors:

if body?.status? and body.status = "error" then 

Example for "URI not found"

Request:

GET /v1/undefined HTTP/1.1
Accept: */*

Response:

HTTP/1.1 404 Not found
Content-Type: application/json

{
    "status": "error"
    "message": "URI not found: /v1/u9ihio"
}

Example for "Module not found"

Request:

POST /v1/module/sync/HelloWorld HTTP/1.1
Accept: */*

Response:

HTTP/1.1 404 Not found
Content-Type: application/json

{
    "status": "error"
    "message": "Module not found: HelloWorld"
}

Response:

HTTP/1.1 500 Internal Server Error
Content-Type: application/json

{
    "status": "error"
    "message": "Marathon is unreachable"
}