コード例 #1
0
ファイル: vulcand.go プロジェクト: albertrdixon/romulus
func (v *vulcan) NewBackend(rsc *kubernetes.Resource) (loadbalancer.Backend, error) {
	s := engine.HTTPBackendSettings{
		Timeouts:  engine.HTTPBackendTimeouts{},
		KeepAlive: engine.HTTPBackendKeepAlive{},
	}
	if val, ok := rsc.GetAnnotation(DailTimeoutKey); ok {
		s.Timeouts.Dial = val
	}
	if val, ok := rsc.GetAnnotation(ReadTimeoutKey); ok {
		s.Timeouts.Read = val
	}
	if val, ok := rsc.GetAnnotation(MaxIdleConnsKey); ok {
		if i, er := strconv.Atoi(val); er == nil {
			s.KeepAlive.MaxIdleConnsPerHost = i
		}
	}
	if val, ok := rsc.GetAnnotation(loadbalancer.BackendSettingsKey); ok {
		if er := json.Unmarshal([]byte(val), &s); er != nil {
			logger.Warnf("Failed to parse settings for frontend %q: %v", rsc.ID, er)
		}
	}

	b, er := engine.NewHTTPBackend(rsc.ID(), s)
	if er != nil {
		return nil, er
	}
	if rsc.IsWebsocket() {
		b.Type = ws
	}
	return newBackend(b), nil
}
コード例 #2
0
ファイル: api_test.go プロジェクト: albertrdixon/romulus
func (s *ApiSuite) TestMiddlewareCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	cl := s.makeConnLimit("c1", 10, "client.ip", 2, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	ms, err := s.client.GetMiddlewares(fk)
	c.Assert(err, IsNil)
	c.Assert(ms[0], DeepEquals, cl)

	cl = s.makeConnLimit("c1", 10, "client.ip", 3, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	mk := engine.MiddlewareKey{Id: cl.Id, FrontendKey: fk}
	v, err := s.client.GetMiddleware(mk)
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, &cl)

	c.Assert(s.client.DeleteMiddleware(mk), IsNil)

	_, err = s.client.GetMiddleware(mk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})

}
コード例 #3
0
ファイル: api_test.go プロジェクト: albertrdixon/romulus
func (s *ApiSuite) TestFrontendCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	fs, err := s.client.GetFrontends()
	c.Assert(err, IsNil)
	c.Assert(fs[0], DeepEquals, *f)

	out, err := s.client.GetFrontend(fk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, f)

	settings := f.HTTPSettings()
	settings.Hostname = `localhost`
	f.Settings = settings
	f.Route = `Path("/v2")`

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	c.Assert(s.client.DeleteFrontend(fk), IsNil)

	out, err = s.client.GetFrontend(fk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}
コード例 #4
0
ファイル: api_test.go プロジェクト: albertrdixon/romulus
func (s *ApiSuite) TestBackendCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	bs, _ := s.ng.GetBackends()
	c.Assert(len(bs), Equals, 1)
	c.Assert(bs[0], DeepEquals, *b)

	bs, err = s.client.GetBackends()
	c.Assert(bs, NotNil)
	c.Assert(err, IsNil)
	c.Assert(bs[0], DeepEquals, *b)

	bk := engine.BackendKey{Id: b.Id}
	out, err := s.client.GetBackend(bk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, b)

	settings := b.HTTPSettings()
	settings.Timeouts.Read = "1s"
	b.Settings = settings
	c.Assert(s.client.UpsertBackend(*b), IsNil)

	out, err = s.client.GetBackend(bk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, b)

	err = s.client.DeleteBackend(bk)
	c.Assert(err, IsNil)

	out, err = s.client.GetBackend(bk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}
コード例 #5
0
ファイル: api_test.go プロジェクト: albertrdixon/romulus
func (s *ApiSuite) TestServerCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	srv1 := engine.Server{Id: "srv1", URL: "http://localhost:5000"}
	srv2 := engine.Server{Id: "srv2", URL: "http://localhost:6000"}

	bk := engine.BackendKey{Id: b.Id}
	c.Assert(s.client.UpsertServer(bk, srv1, 0), IsNil)
	c.Assert(s.client.UpsertServer(bk, srv2, 0), IsNil)

	srvs, _ := s.ng.GetServers(bk)
	c.Assert(len(srvs), Equals, 2)
	c.Assert(srvs[0], DeepEquals, srv1)
	c.Assert(srvs[1], DeepEquals, srv2)

	srvs, err = s.client.GetServers(bk)
	c.Assert(srvs, NotNil)
	c.Assert(len(srvs), Equals, 2)
	c.Assert(srvs[0], DeepEquals, srv1)
	c.Assert(srvs[1], DeepEquals, srv2)

	sk := engine.ServerKey{Id: srv1.Id, BackendKey: bk}
	out, err := s.client.GetServer(sk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &srv1)

	srv1.URL = "http://localhost:5001"
	c.Assert(s.client.UpsertServer(bk, srv1, 0), IsNil)

	out, err = s.client.GetServer(sk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, &srv1)

	err = s.client.DeleteServer(sk)
	c.Assert(err, IsNil)

	out, err = s.client.GetServer(sk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}