コード例 #1
0
func (registry *Registry) Register(uri route.Uri, endpoint *route.Endpoint) {
	registry.Lock()
	defer registry.Unlock()

	uri = uri.ToLower()

	key := tableKey{
		addr: endpoint.CanonicalAddr(),
		uri:  uri,
	}

	var endpointToRegister *route.Endpoint

	entry, found := registry.table[key]
	if found {
		endpointToRegister = entry.endpoint
	} else {
		endpointToRegister = endpoint
		entry = &tableEntry{endpoint: endpoint}

		registry.table[key] = entry
	}

	pool, found := registry.byUri[uri]
	if !found {
		pool = route.NewPool()
		registry.byUri[uri] = pool
	}

	pool.Add(endpointToRegister)

	entry.updatedAt = time.Now()

	registry.timeOfLastUpdate = time.Now()
}
コード例 #2
0
ファイル: registry.go プロジェクト: rakutentech/gorouter
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
	t := time.Now()
	data := lager.Data{"uri": uri, "backend": endpoint.CanonicalAddr(), "modification_tag": endpoint.ModificationTag}

	r.reporter.CaptureRegistryMessage(endpoint)

	r.Lock()

	uri = uri.RouteKey()

	pool, found := r.byUri.Find(uri)
	if !found {
		contextPath := parseContextPath(uri)
		pool = route.NewPool(r.dropletStaleThreshold/4, contextPath)
		r.byUri.Insert(uri, pool)
		r.logger.Debug("uri-added", lager.Data{"uri": uri})
	}

	endpointAdded := pool.Put(endpoint)

	r.timeOfLastUpdate = t
	r.Unlock()

	if endpointAdded {
		r.logger.Debug("endpoint-registered", data)
	} else {
		r.logger.Debug("endpoint-not-registered", data)
	}
}
コード例 #3
0
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
	t := time.Now()
	r.Lock()

	uri = uri.ToLower()

	pool, found := r.byUri[uri]
	if !found {
		pool = route.NewPool(r.dropletStaleThreshold / 4)
		r.byUri[uri] = pool
	}

	pool.Put(endpoint)

	r.timeOfLastUpdate = t
	r.Unlock()
}
コード例 #4
0
ファイル: registry.go プロジェクト: shashankmjain/gorouter
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
	t := time.Now()
	r.Lock()

	uri = uri.RouteKey()

	pool, found := r.byUri.Find(uri)
	if !found {
		contextPath := parseContextPath(uri)
		pool = route.NewPool(r.dropletStaleThreshold/4, contextPath)
		r.byUri.Insert(uri, pool)
	}

	pool.Put(endpoint)

	r.timeOfLastUpdate = t
	r.Unlock()
}
コード例 #5
0
ファイル: registry.go プロジェクト: yingkitw/gorouter
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
	t := time.Now()

	r.reporter.CaptureRegistryMessage(endpoint)

	r.Lock()

	uri = uri.RouteKey()

	pool, found := r.byUri.Find(uri)
	if !found {
		contextPath := parseContextPath(uri)
		pool = route.NewPool(r.dropletStaleThreshold/4, contextPath)
		r.byUri.Insert(uri, pool)
		r.logger.Debug("register", lager.Data{"uri": uri})
	}

	pool.Put(endpoint)

	r.timeOfLastUpdate = t
	r.Unlock()
}
コード例 #6
0
package route_test

import (
	"time"

	"github.com/cloudfoundry/gorouter/route"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EndpointIterator", func() {
	var pool *route.Pool

	BeforeEach(func() {
		pool = route.NewPool(2*time.Minute, "")
	})

	Describe("Next", func() {
		It("performs round-robin through the endpoints", func() {
			e1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "")
			e2 := route.NewEndpoint("", "5.6.7.8", 1234, "", nil, -1, "")
			e3 := route.NewEndpoint("", "1.2.7.8", 1234, "", nil, -1, "")
			endpoints := []*route.Endpoint{e1, e2, e3}

			for _, e := range endpoints {
				pool.Put(e)
			}

			counts := make([]int, len(endpoints))

			iter := pool.Endpoints("")
コード例 #7
0
ファイル: trie_test.go プロジェクト: trainchou/gorouter
	. "github.com/onsi/gomega"
)

var _ = Describe("Trie", func() {

	var (
		r *Trie
	)

	BeforeEach(func() {
		r = NewTrie()
	})

	Describe(".Find", func() {
		It("works for the root node", func() {
			p := route.NewPool(42)
			r.Insert("/", p)
			node, ok := r.Find("/")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("finds an exact match to an existing key", func() {
			p := route.NewPool(42)
			r.Insert("/foo/bar", p)
			node, ok := r.Find("/foo/bar")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("returns nil when no exact match is found", func() {
コード例 #8
0
ファイル: pool_test.go プロジェクト: rakutentech/gorouter
import (
	"fmt"
	"time"

	"github.com/cloudfoundry-incubator/routing-api/models"
	"github.com/cloudfoundry/gorouter/route"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Pool", func() {
	var pool *route.Pool
	var modTag models.ModificationTag

	BeforeEach(func() {
		pool = route.NewPool(2*time.Minute, "")
		modTag = models.ModificationTag{}
	})

	Context("Put", func() {
		It("adds endpoints", func() {
			endpoint := &route.Endpoint{}

			b := pool.Put(endpoint)
			Expect(b).To(BeTrue())
		})

		It("handles duplicate endpoints", func() {
			endpoint := &route.Endpoint{}

			pool.Put(endpoint)
コード例 #9
0
ファイル: trie_test.go プロジェクト: yingkitw/gorouter
	. "github.com/onsi/gomega"
)

var _ = Describe("Trie", func() {

	var (
		r *container.Trie
	)

	BeforeEach(func() {
		r = container.NewTrie()
	})

	Describe(".Find", func() {
		It("works for the root node", func() {
			p := route.NewPool(42, "")
			r.Insert("/", p)
			node, ok := r.Find("/")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("finds an exact match to an existing key", func() {
			p := route.NewPool(42, "")
			r.Insert("/foo/bar", p)
			node, ok := r.Find("/foo/bar")
			Expect(node).To(Equal(p))
			Expect(ok).To(BeTrue())
		})

		It("returns nil when no exact match is found", func() {