GithubHelp home page GithubHelp logo

matttproud-soundcloud / visor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matttproud/visor

0.0 0.0 0.0 3.37 MB

Client to bazooka's application registry

License: BSD 2-Clause "Simplified" License

Go 100.00%

visor's Introduction

Visor

Visor is a library which provides an abstraction over a global process state.

Visor uses doozerd.

Usage

To understand how Visor works, we need to understand how it works with time. Each of the Visor data-types App, Revision, Proctype and Instance are snapshots of a specific point in time in the coordinator. When a mutating operation is successfully performed on one of these data-types, a new snapshot is returned, representing the state of the coordinator after the operation. If the operation would fail, the old snapshot is returned with an error.

With the new snapshot, we can perform an operation on this new state, and so on with every new snapshot.

package main

import "github.com/soundcloud/visor"
import "log"

func main() {
    snapshot, err := visor.DialUri("doozer:?ca=localhost:8046", "/")

    name  := "rocket"
    stack := "HEAD" // Runtime stack revision
    repo  := "http://github.com/bazooka/rocket"

    app   := visor.NewApp(name, repo, stack, snapshot)

    _, err := app.Register()
    if err != nil {
        log.Fatalf("error registering app: %s", err)
    }

    rev := visor.NewRevision(app, "f84e19", snapshot)
    rev.ArchiveUrl = "http://artifacts/rocket/f84e19.img"

    _, err = rev.Register()
    if err != nil {
        log.Fatalf("error registering revision: %s", err)
    }
}

Working with snapshots

// Get a snapshot of the latest coordinator state
snapshot, err := visor.DialUri("doozer:?ca=localhost:8046", "/")

// Get the list of applications at snapshot
apps, _ := visor.Apps(snapshot)
app := apps[0] // app.Rev == snapshot.Rev == 1

// Set some environment vars on *app*. Every time state is
// changed in the coordinator, a new App snapshot is returned.
app, _ = app.SetEnvironmentVar("cow", "moo")  // app.Rev == 2
app, _ = app.SetEnvironmentVar("cat", "meow") // app.Rev == 3

// Attempt to get a recently set environment var from an old snapshot (apps[0].Rev == 1)
apps[0].GetEnvironmentVar("cat") // "", ErrKeyNotFound

// Get a recently set environment var from the latest snapshot (app.Rev == 3)
app.GetEnvironmentVar("cat")     // "meow", nil

Watching for events

package main

import "soundcloud/visor"

func main() {
  snapshot, err := visor.DialUri("doozer:?ca=localhost:8046", "/")
  if err != nil {
    panic(err)
  }

  c := make(chan *visor.Event)

  go visor.WatchEvent(snapshot, c)

  // Read one event from the channel
  fmt.Println(<-c)
}

Development

Setup

Dependencies

  • Go (go1)

  • doozer (implicit)

    go get github.com/soundcloud/doozer
    

    if you run in trouble with the protobuf, do a:

    cd src/pkg/code.google.com/p/goprotobuf
    hg pull
    hg update 
    make install
    
  • doozerd (testing)

    go get github.com/ha/doozerd
    

    if this fails, do the following

    cd $GOROOT/src/pkg/github.com/soundcloud/doozerd
    git remote add soundcloud [email protected]:soundcloud/doozerd
    git pull soundcloud master
    ./make.sh
    go install
    

Testing

First start doozerd with default configuration. Then run:

go test

Conventions

This repository follows the code conventions dictated by gofmt. To automate the formatting process install this pre-commit hook, which runs gofmt and adds the files. Don't forget to make the file executable: chmod +x .git/hooks/pre-commit.

Branching

See Guide.

Versioning

This project is versioned with the help of the Semantic Versioning Specification using 0.0.0 as the initial version. Please make sure you have read the guidelines before increasing a version number either for a release or a hotfix.

visor's People

Contributors

cloudhead avatar fronx avatar grobie avatar kesselborn avatar matttproud-soundcloud avatar pje avatar xla avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.