Beispiel #1
0
func (s *ApiSuite) SetUpTest(c *C) {
	s.backend = membackend.NewMemBackend(registry.GetRegistry())

	muxRouter := mux.NewRouter()
	hostRouter := hostroute.NewHostRouter()
	proxy, err := vulcan.NewProxy(hostRouter)
	configurator := configure.NewConfigurator(proxy)
	c.Assert(err, IsNil)

	InitProxyController(s.backend, adapter.NewAdapter(proxy), configurator.GetConnWatcher(), muxRouter)
	s.testServer = httptest.NewServer(muxRouter)
	s.client = NewClient(s.testServer.URL, registry.GetRegistry())
}
Beispiel #2
0
func (s *ApiSuite) SetUpTest(c *C) {
	newProxy := func(id int) (proxy.Proxy, error) {
		return proxy.New(id, stapler.New(), proxy.Options{})
	}

	s.ng = memng.New(registry.GetRegistry())

	sv := supervisor.New(newProxy, s.ng, make(chan error), supervisor.Options{})

	app := scroll.NewApp()
	InitProxyController(s.ng, sv, app)
	s.testServer = httptest.NewServer(app.GetHandler())
	s.client = NewClient(s.testServer.URL, registry.GetRegistry())
}
func (s *BackendSuite) TestHostsFromJson(c *C) {
	h, err := NewHost("localhost")
	c.Assert(err, IsNil)

	up, err := NewUpstream("up1")
	c.Assert(err, IsNil)

	e, err := NewEndpoint("u1", "e1", "http://localhost")
	c.Assert(err, IsNil)

	l, err := NewLocation("localhost", "loc1", "/path", "up1")
	c.Assert(err, IsNil)

	cl, err := connlimit.NewConnLimit(10, "client.ip")
	c.Assert(err, IsNil)

	i := &MiddlewareInstance{Id: "c1", Type: "connlimit", Middleware: cl}

	up.Endpoints = []*Endpoint{e}
	l.Upstream = up
	l.Middlewares = []*MiddlewareInstance{i}
	h.Locations = []*Location{l}
	hosts := []*Host{h}

	bytes, err := json.Marshal(map[string]interface{}{"Hosts": hosts})

	out, err := HostsFromJson(bytes, registry.GetRegistry().GetSpec)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)

	c.Assert(out, DeepEquals, hosts)
}
Beispiel #4
0
func (s *MemSuite) SetUpTest(c *C) {
	engine := New(registry.GetRegistry())

	s.suite.ChangesC = make(chan interface{})
	s.stopC = make(chan bool)
	go engine.Subscribe(s.suite.ChangesC, s.stopC)
	s.suite.Engine = engine
}
Beispiel #5
0
func main() {
	log.InitWithConfig(log.Config{Name: "console"})

	cmd := command.NewCommand(registry.GetRegistry())
	err := cmd.Run(os.Args)
	if err != nil {
		log.Errorf("error: %s\n", err)
	}
}
Beispiel #6
0
func (s *CmdSuite) run(params ...string) string {
	args := []string{"vctl"}
	args = append(args, params...)
	args = append(args, fmt.Sprintf("--vulcan=%s", s.testServer.URL))
	s.out = &bytes.Buffer{}
	s.cmd = &Command{registry: registry.GetRegistry(), out: s.out, vulcanUrl: s.testServer.URL}
	s.cmd.Run(args)
	return strings.Replace(s.out.String(), "\n", " ", -1)
}
Beispiel #7
0
func (s *CmdSuite) SetUpTest(c *C) {
	s.ng = memng.New(registry.GetRegistry())

	newProxy := func(id int) (proxy.Proxy, error) {
		return proxy.New(id, stapler.New(), proxy.Options{})
	}

	sv := supervisor.New(newProxy, s.ng, make(chan error), supervisor.Options{})
	sv.Start()
	s.sv = sv

	app := scroll.NewApp()
	api.InitProxyController(s.ng, sv, app)
	s.testServer = httptest.NewServer(app.GetHandler())

	s.out = &bytes.Buffer{}
	s.cmd = &Command{registry: registry.GetRegistry(), out: s.out, vulcanUrl: s.testServer.URL}
}
Beispiel #8
0
func main() {
	log.Init([]*log.LogConfig{&log.LogConfig{Name: "console"}})

	cmd := command.NewCommand(registry.GetRegistry())
	err := cmd.Run(os.Args)
	if err != nil {
		log.Errorf("Error: %s\n", err)
	}
}
Beispiel #9
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	if err := service.Run(registry.GetRegistry()); err != nil {
		fmt.Printf("Service exited with error: %s\n", err)
		os.Exit(255)
	} else {
		fmt.Println("Service exited gracefully")
	}
}
Beispiel #10
0
func (s *S) SetUpTest(c *check.C) {
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	dbtest.ClearAllCollections(s.conn.Collection("router_vulcand_tests").Database)
	s.engine = memng.New(registry.GetRegistry())
	scrollApp := scroll.NewApp()
	api.InitProxyController(s.engine, &supervisor.Supervisor{}, scrollApp)
	s.vulcandServer = httptest.NewServer(scrollApp.GetHandler())
	config.Set("routers:vulcand:api-url", s.vulcandServer.URL)
}
Beispiel #11
0
func (s *SupervisorSuite) SetUpTest(c *C) {
	s.ng = memng.New(registry.GetRegistry()).(*memng.Mem)

	s.errorC = make(chan error)

	s.clock = &timetools.FreezedTime{
		CurrentTime: time.Date(2012, 3, 4, 5, 6, 7, 0, time.UTC),
	}

	s.sv = New(newProxy, s.ng, s.errorC, Options{Clock: s.clock})
}
Beispiel #12
0
func (s *ApiSuite) TestMiddlewareCRUD(c *C) {
	_, err := s.client.AddUpstream("up1")
	c.Assert(err, IsNil)

	_, err = s.client.AddHost("localhost")
	c.Assert(err, IsNil)

	loc, err := s.client.AddLocation("localhost", "la", "/home", "up1")
	c.Assert(err, IsNil)
	c.Assert(loc, NotNil)

	cl := s.makeConnLimit("c1", 10, "client.ip", 2, loc)
	out, err := s.client.AddMiddleware(registry.GetRegistry().GetSpec(cl.Type), loc.Hostname, loc.Id, cl)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)
	c.Assert(out.Id, Equals, cl.Id)
	c.Assert(out.Priority, Equals, cl.Priority)

	hosts, err := s.client.GetHosts()
	c.Assert(err, IsNil)
	m := hosts[0].Locations[0].Middlewares[0]
	c.Assert(m.Id, Equals, cl.Id)
	c.Assert(m.Type, Equals, cl.Type)
	c.Assert(m.Priority, Equals, cl.Priority)

	cl2 := s.makeConnLimit("c1", 10, "client.ip", 3, loc)
	out, err = s.client.UpdateMiddleware(registry.GetRegistry().GetSpec(cl.Type), loc.Hostname, loc.Id, cl2)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)
	c.Assert(out.Id, Equals, cl2.Id)
	c.Assert(out.Priority, Equals, cl2.Priority)

	status, err := s.client.DeleteMiddleware(registry.GetRegistry().GetSpec(cl.Type), loc.Hostname, loc.Id, cl.Id)
	c.Assert(err, IsNil)
	c.Assert(status, NotNil)
}
/**
Initialize an etcd API client
*/
func newVulcandClient(vulcandAdminURLString string) (*vulcandAPI.Client, error) {
	var u *url.URL
	var err error
	if u, err = url.Parse(os.ExpandEnv(vulcandAdminURLString)); err != nil {
		return nil, fmt.Errorf("Could not parse Vulcand admin URL: %v. Error: %v", vulcandAdminURLString, err)
	}
	if u.Scheme == "" || u.Host == "" || u.Host == ":" || u.Path != "" {
		return nil, fmt.Errorf("Invalid URL provided for Vulcand API server: %v.", u)
	}

	c := vulcandAPI.NewClient(vulcandAdminURLString, vulcandRegistry.GetRegistry())
	if c == nil {
		return nil, fmt.Errorf("Could not initialize Vulcand API client")
	}
	return c, nil
}
Beispiel #14
0
func createRouter(prefix string) (router.Router, error) {
	vURL, err := config.GetString(prefix + ":api-url")
	if err != nil {
		return nil, err
	}
	domain, err := config.GetString(prefix + ":domain")
	if err != nil {
		return nil, err
	}
	client := api.NewClient(vURL, registry.GetRegistry())
	vRouter := &vulcandRouter{
		client: client,
		prefix: prefix,
		domain: domain,
	}
	return vRouter, nil
}
Beispiel #15
0
func (s *EtcdSuite) SetUpTest(c *C) {
	// Initiate a backend with a registry

	key, err := secret.KeyFromString(s.key)
	c.Assert(err, IsNil)

	box, err := secret.NewBox(key)
	c.Assert(err, IsNil)

	engine, err := New(
		s.nodes,
		s.etcdPrefix,
		registry.GetRegistry(),
		Options{
			EtcdConsistency: s.consistency,
			Box:             box,
		})
	c.Assert(err, IsNil)
	s.ng = engine.(*ng)
	s.client = s.ng.client

	// Delete all values under the given prefix
	_, err = s.client.Get(s.etcdPrefix, false, false)
	if err != nil {
		// There's no key like this
		if !notFound(err) {
			// We haven't expected this error, oops
			c.Assert(err, IsNil)
		}
	} else {
		_, err = s.ng.client.Delete(s.etcdPrefix, true)
		c.Assert(err, IsNil)
	}

	s.changesC = make(chan interface{})
	s.stopC = make(chan bool)
	go s.ng.Subscribe(s.changesC, s.stopC)

	s.suite.ChangesC = s.changesC
	s.suite.Engine = engine
}