Skip to content

HTTP API v1

Frank Rosner edited this page Sep 16, 2016 · 22 revisions

Cluster Broccoli provides an RESTful HTTP API for managing templates and instances. It is also used by the Web UI, which utilizes Restangular to submit the API calls.

There are two nouns in Cluster Broccoli: Templates and instances. A template is used to spawn new instances replacing variables with specified values. An instance has a status and a set of services. Cluster Broccoli queries Nomad for getting the status of an instance, while using Consul for discovering services associated with it.

Table of Contents

Templates

A template defines the structure of a Nomad job. It consists of an ID, a description, the Nomad job JSON template including variable parameters.

/api/v1/templates

The general templates endpoint is used to query existing templates. Templates are read-only and will be loaded on application start-up.

GET

Description: Lists all available templates.

Parameters: None.

Example query:

curl 'localhost:9000/api/v1/templates'

Example return value:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
[
  {
    "id": "http-server",
    "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
    "parameters": [
      "id",
      "cpu"
    ],
    "parameterInfos": {
      "cpu": {
        "name": "cpu",
        "default": "100"
      }
    },
    "version": "f88dbbdc8249b8e5075598e165aec527"
  },
  {
    "id": "jupyter",
    "description": "Open source, interactive data science and scientific computing across over 40 programming languages.",
    "parameters": [
      "id"
    ],
    "parameterInfos": {},
    "version": "2c64126e09b72abd1a46f6db5b296221"
  },
  {
    "id": "zeppelin",
    "description": "A web-based notebook that enables interactive data analytics. You can make beautiful data-driven, interactive and collaborative documents with SQL, Scala and more.",
    "parameters": [
      "id"
    ],
    "parameterInfos": {},
    "version": "6f983b4ea4e12344e73f450fa9201243"
  }
]

/api/v1/templates/<templateId>

The specific templates endpoint is used to get more detailed information about a template.

GET

Description: Queries a single template.

Parameters: None.

Example query:

curl 'localhost:9000/api/v1/templates/jupyter'

Example return value:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
{
  "id": "jupyter",
  "description": "Open source, interactive data science and scientific computing across over 40 programming languages.",
  "parameters": [
    "id"
  ],
  "parameterInfos": {},
  "version": "2c64126e09b72abd1a46f6db5b296221"
}

Instances

An instance represents a template with all parameter values being set. It is used to submit a Nomad job to the cluster. It consists of an ID, the template it is derived from, a parameter value mapping, a status, and a set of services.

/api/v1/instances

The general instances endpoint is used to get all created instances, as well as creating new instances.

GET

Description: Lists all created instances.

Parameters: templateId (optional).

Example query:

curl 'localhost:9000/api/v1/instances?templateId=http-server'

Example return value:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
[
  {
    "id": "my-http",
    "parameterValues": {
      "id": "my-http",
      "cpu": "250"
    },
    "status": "stopped",
    "services": {},
    "template": {
      "id": "http-server",
      "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
      "parameters": [
        "id",
        "cpu"
      ],
      "parameterInfos": {
        "cpu": {
          "name": "cpu",
          "default": "100"
        }
      },
      "version": "f88dbbdc8249b8e5075598e165aec527"
    }
  }
]

POST

Description: Creates a new instance.

Parameters: Creation request JSON (templateId, parameters).

Example query:

curl -H 'Content-Type: application/json' \
  -X POST -d '{ "templateId": "http-server", "parameters": { "id": "my-http", "cpu": "250" } }' \
  'http://localhost:9000/api/v1/instances'

Example return value:

< HTTP/1.1 201 Created
< Location: /api/v1/instances/my-http
< Content-Type: application/json; charset=utf-8
{
  "id": "my-http",
  "parameterValues": {
    "id": "my-http",
    "cpu": "250"
  },
  "status": "stopped",
  "services": {},
  "template": {
    "id": "http-server",
    "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
    "parameters": [
      "id",
      "cpu"
    ],
    "parameterInfos": {
      "cpu": {
        "name": "cpu",
        "default": "100"
      }
    },
    "version": "f88dbbdc8249b8e5075598e165aec527"
  }
}

/api/v1/instances/<instanceId>

The specific instances endpoint is used to get details about, change the status of and delete single instances.

GET

Description: Queries a single instance.

Parameters: None.

Example query:

curl 'localhost:9000/api/v1/instances/my-http'

Example return value:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
{
  "id": "my-http",
  "parameterValues": {
    "id": "my-http",
    "cpu": "250"
  },
  "status": "stopped",
  "services": {},
  "template": {
    "id": "http-server",
    "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
    "parameters": [
      "id",
      "cpu"
    ],
    "parameterInfos": {
      "cpu": {
        "name": "cpu",
        "default": "100"
      }
    },
    "version": "f88dbbdc8249b8e5075598e165aec527"
  }
}

POST

Description: Updates an instance. You can either change the status, update the parameter values or select a new template of an instance.

Parameters: status, parameterValues, selectedTemplate.

Example query for status update:

curl -v -H 'Content-Type: application/json' \
  -X POST -d '{ "status": "running" }' \
  'http://localhost:9000/api/v1/instances/my-http'

Example return value for status update:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
{
  "id": "my-http",
  "parameterValues": {
    "id": "my-http",
    "cpu": "250"
  },
  "status": "pending",
  "services": {},
  "template": {
    "id": "http-server",
    "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
    "parameters": [
      "id",
      "cpu"
    ],
    "parameterInfos": {
      "cpu": {
        "name": "cpu",
        "default": "100"
      }
    },
    "version": "f88dbbdc8249b8e5075598e165aec527"
  }
}

Example query for parameter values update:

curl -v -H 'Content-Type: application/json' \
  -X POST -d '{ "parameterValues": { "id": "my-http", "cpu": "50" } }' \
  'http://localhost:9000/api/v1/instances/my-http'

Example return value for parameter values update:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
{
  "id": "my-http",
  "parameterValues": {
    "id": "my-http",
    "cpu": "50"
  },
  "status": "pending",
  "services": {},
  "template": {
    "id": "http-server",
    "description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
    "parameters": [
      "id",
      "cpu"
    ],
    "parameterInfos": {
      "cpu": {
        "name": "cpu",
        "default": "100"
      }
    },
    "version": "f88dbbdc8249b8e5075598e165aec527"
  }
}

DELETE

Description: Stops and deletes an instance.

Parameters: None.

Example query:

curl -X DELETE 'localhost:9000/api/v1/instances/my-http'

Example return value:

< HTTP/1.1 200 OK

About

/api/v1/about

You can query the about endpoint to get some information about your Broccoli deployment.

GET

Description: Returns information about Cluster Broccoli.

Example query:

curl 'localhost:9000/api/v1/about'

Example return value:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
{
  "project": {
    "name": "Cluster Broccoli",
    "version": "0.4.0"
  },
  "scala": {
    "version": "2.10.6"
  },
  "sbt": {
    "version": "0.13.11"
  }
}
Clone this wiki locally