Beispiel #1
0
func NewController(container, image string) (*Controller, error) {
	endpoint := os.Getenv("DOCKER_HOST")
	if endpoint == "" {
		endpoint = config.Get().DockerEndpoint
	}

	var client *docker.Client
	var e error

	certpath := os.Getenv("DOCKER_CERT_PATH")
	if certpath == "" {
		client, e = docker.NewClient(endpoint)
		if e != nil {
			return nil, e
		}

	} else {
		client, e = docker.NewTLSClient(endpoint,
			certpath+"/cert.pem",
			certpath+"/key.pem",
			certpath+"/ca.pem")

		if e != nil {
			return nil, e
		}
	}

	return &Controller{client, container, image}, nil
}
Beispiel #2
0
func NewSession(l *log.Logger, containers ...string) (*Session, error) {
	if l == nil {
		l = log.New(os.Stderr, "[session] ", log.LstdFlags)
	}

	etcd, e := data.NewETCDClient(config.Get().ETCDEndpoint)
	if e != nil {
		return nil, e
	}

	// initial configuration becomes "known defaults"
	resp, e := etcd.Get(context.Background(), data.ETCDDataSourceKey, nil)
	if e != nil {
		return nil, e
	}

	sources := []*data.Source{}
	if e := json.Unmarshal([]byte(resp.Node.Value), &sources); e != nil {
		return nil, e
	}

	client := &client.APIClient{Host: config.Get().APIEndpoint}
	controllers := map[string]*Controller{}
	for _, container := range containers {
		controller, e := NewController(container, "")
		if e != nil {
			return nil, e
		}

		controllers[container] = controller
	}

	// special filler controller
	controller, e := NewController("filler", "hyperworks/disk-filler")
	if e != nil {
		return nil, e
	}

	controllers["filler"] = controller

	return &Session{l, controllers, sources, etcd, client, nil}, nil
}
Beispiel #3
0
func DefaultServices() (*Services, error) {
	cfg := config.Get()
	logger := log.New(os.Stderr, "[chaostesting] ", log.LstdFlags)

	provider, e := data.NewETCDProvider(logger, cfg.ETCDEndpoint)
	if e != nil {
		return nil, e
	}

	srv := &Services{
		Logger: logger,
		DB:     provider,
	}

	srv.Handlers = &Handlers{srv}
	return srv, nil
}
Beispiel #4
0
package main

import "time"
import "strings"
import "log"
import "app/config"
import "app/data"
import "app/client"

var api = &client.APIClient{Host: config.Get().APIEndpoint}

func main() {
	_ = time.Sleep

	for {
		listTodos()
		completeTodo(2)
		completeTodo(4)
		listTodos()
		restartTodo(2)
		restartTodo(4)
		// time.Sleep(1 * time.Second)

		listTodos()
		completeTodo(1)
		completeTodo(3)
		listTodos()
		restartTodo(1)
		restartTodo(3)
		// time.Sleep(2 * time.Second)
	}