Example #1
0
File: docker.go Project: 4eek/tsuru
func buildClusterStorage() (cluster.Storage, error) {
	mongoUrl, _ := config.GetString("docker:cluster:mongo-url")
	mongoDatabase, _ := config.GetString("docker:cluster:mongo-database")
	if mongoUrl == "" || mongoDatabase == "" {
		return nil, fmt.Errorf("Cluster Storage: docker:cluster:{mongo-url,mongo-database} must be set.")
	}
	storage, err := mongodb.Mongodb(mongoUrl, mongoDatabase)
	if err != nil {
		return nil, fmt.Errorf("Cluster Storage: Unable to connect to mongodb: %s (docker:cluster:mongo-url = %q; docker:cluster:mongo-database = %q)",
			err.Error(), mongoUrl, mongoDatabase)
	}
	return storage, nil
}
func TestUpdateNodeDoesNotExist(t *testing.T) {
	mongo, err := mongodb.Mongodb("mongodb://localhost:27017", "test-docker-node-update")
	if err != nil {
		t.Fatal(err)
	}
	clu, err := cluster.New(nil, mongo)
	if err != nil {
		t.Fatal(err)
	}
	node := cluster.Node{Address: "http://localhost:4243"}
	err = clu.Register(node)
	defer clu.Unregister("http://localhost:4243")
	nodeUpd := cluster.Node{Address: "http://localhost:4223"}
	nodeUpd.Metadata = map[string]string{"k1": "v1", "k2": "v2"}
	nodeUpd, err = clu.UpdateNode(nodeUpd)
	if err != storage.ErrNoSuchNode {
		t.Error("Expected: No such node in storage, got: ", err)
	}
}
Example #3
0
func buildClusterStorage() (cluster.Storage, error) {
	storageName, _ := config.GetString("docker:cluster:storage")
	if storageName == "redis" {
		redisServer, _ := config.GetString("docker:cluster:redis-server")
		prefix, _ := config.GetString("docker:cluster:redis-prefix")
		if password, err := config.GetString("docker:cluster:redis-password"); err == nil {
			return redis.AuthenticatedRedis(redisServer, password, prefix), nil
		} else {
			return redis.Redis(redisServer, prefix), nil
		}
	} else if storageName == "mongodb" {
		mongoUrl, _ := config.GetString("docker:cluster:mongo-url")
		mongoDatabase, _ := config.GetString("docker:cluster:mongo-database")
		storage, err := mongodb.Mongodb(mongoUrl, mongoDatabase)
		if err != nil {
			return nil, fmt.Errorf("Cluster Storage: Unable to connnect to mongodb: %s", err.Error())
		}
		return storage, nil
	}
	return nil, fmt.Errorf("Cluster Storage: Invalid value for docker:cluster:storage: %s", storageName)
}