flynn-discovery

command module
v0.0.0-...-0fdc37b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2015 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Flynn Discovery

A cluster peer discovery server.

flynn-discovery provides a simple HTTP interface to create clusters, register cluster members and get cluster members.

To get flynn-discovery run (requires a correctly configured Go environment):

$ go get github.com/flynn/flynn-discovery

To deploy flynn-discovery into a Flynn cluster execute the following steps:

$ cd $GOPATH/src/github.com/flynn/flynn-discovery
$ flynn create flynn-discovery
$ flynn resource add postgres
$ cat schema.sql | flynn pg psql --
$ git push flynn master

At this point you should have a deployed version of flynn-discovery running on your Flynn cluster.

To see the address run flynn route:

$ flynn route
ROUTE                                    SERVICE              ID                                         STICKY
http:flynn-discovery.dev.localflynn.com  flynn-discovery-web  http/5bb8495e-a660-430d-baa3-4995972ab020  false

Export that URL to use in tests:

$ export FLYNN_DISCOVERY_URL=$(flynn route | sed 1d | cut -f 1 -d " " | sed 's/^http://')

Now we can test flynn-discovery.

First we need to create a cluster token. This will uniquely identify the cluster. The normal workflow is to create the cluster token beforehand and give it to each cluster member so they can register themselves as members of that cluster.

$ curl -XPOST $FLYNN_DISCOVERY_URL/clusters -I
HTTP/1.1 201 Created
Location: /clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48
Date: Thu, 26 Nov 2015 12:26:54 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

If the token was created successfully we should get a 201 Created response status. The Location header is the (relative) URL representing the cluster token.

The cluster token is http://$FLYNN_DISCOVERY_URL/clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48.

Next we can add cluster members by using the provided cluster token:

$ curl -XPOST $FLYNN_DISCOVERY_URL/clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48/instances -d '
{
  "data": {
    "name": "instance-2",
    "url": "http://localhost:3333"
  }
}
'
{"data":{"id":"66b52ea9-50b9-41ab-842e-72643b833400","cluster_id":"e99a6a09-bc2b-4dbb-b84e-c70ae176be48","url":"http://localhost:2222","name":"instance-1","created_at":"2015-11-26T12:24:32.580008Z"}}v

Add another cluster member:

$ curl -XPOST $FLYNN_DISCOVERY_URL/clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48/instances -d '
> {
>   "data": {
>     "name": "instance-2",
>     "url": "http://localhost:3333"
>   }
> }
> '
{"data":{"id":"b4b84b79-4ba5-4847-9827-41616e0db056","cluster_id":"e99a6a09-bc2b-4dbb-b84e-c70ae176be48","url":"http://localhost:3333","name":"instance-2","created_at":"2015-11-26T12:25:25.745206Z"}}

List all the cluster members:

$ curl $FLYNN_DISCOVERY_URL/clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48/instances
{"data":[{"id":"66b52ea9-50b9-41ab-842e-72643b833400","cluster_id":"e99a6a09-bc2b-4dbb-b84e-c70ae176be48","url":"http://localhost:2222","name":"instance-1","created_at":"2015-11-26T12:24:32.580008Z"},{"id":"b4b84b79-4ba5-4847-9827-41616e0db056","cluster_id":"e99a6a09-bc2b-4dbb-b84e-c70ae176be48","url":"http://localhost:3333","name":"instance-2","created_at":"2015-11-26T12:25:25.745206Z"}]}

Or pretty printed:

$ curl -sS $FLYNN_DISCOVERY_URL/clusters/e99a6a09-bc2b-4dbb-b84e-c70ae176be48/instances | json_pp
{
   "data" : [
      {
         "url" : "http://localhost:2222",
         "id" : "66b52ea9-50b9-41ab-842e-72643b833400",
         "name" : "instance-1",
         "cluster_id" : "e99a6a09-bc2b-4dbb-b84e-c70ae176be48",
         "created_at" : "2015-11-26T12:24:32.580008Z"
      },
      {
         "cluster_id" : "e99a6a09-bc2b-4dbb-b84e-c70ae176be48",
         "created_at" : "2015-11-26T12:25:25.745206Z",
         "url" : "http://localhost:3333",
         "name" : "instance-2",
         "id" : "b4b84b79-4ba5-4847-9827-41616e0db056"
      }
   ]
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/flynn/flynn/pkg/cors
Package cors provides handlers to enable CORS support.
Package cors provides handlers to enable CORS support.
_workspace/src/github.com/flynn/go-sql
Package sql provides a generic interface around SQL (or SQL-like) databases.
Package sql provides a generic interface around SQL (or SQL-like) databases.
_workspace/src/github.com/flynn/go-sql/driver
Package driver defines interfaces to be implemented by database drivers as used by package sql.
Package driver defines interfaces to be implemented by database drivers as used by package sql.
_workspace/src/github.com/flynn/pq
Package pq is a pure Go Postgres driver for the database/sql package.
Package pq is a pure Go Postgres driver for the database/sql package.
_workspace/src/github.com/flynn/pq/listen_example
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
_workspace/src/github.com/flynn/pq/oid
Package oid contains OID constants as defined by the Postgres server.
Package oid contains OID constants as defined by the Postgres server.
_workspace/src/github.com/jackc/pgx
Package pgx is a PostgreSQL database driver.
Package pgx is a PostgreSQL database driver.
_workspace/src/github.com/jackc/pgx/stdlib
Package stdlib is the compatibility layer from pgx to database/sql.
Package stdlib is the compatibility layer from pgx to database/sql.
_workspace/src/github.com/julienschmidt/httprouter
Package httprouter is a trie based high performance HTTP request router.
Package httprouter is a trie based high performance HTTP request router.
_workspace/src/github.com/wadey/cryptorand
Package cryptorand provides a math/rand.Source implementation of crypto/rand
Package cryptorand provides a math/rand.Source implementation of crypto/rand
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
_workspace/src/gopkg.in/inconshreveable/log15.v2
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable.
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable.
_workspace/src/gopkg.in/inconshreveable/log15.v2/stack
Package stack implements utilities to capture, manipulate, and format call stacks.
Package stack implements utilities to capture, manipulate, and format call stacks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL