예제 #1
0
// This updates the shard manager to use new shard states.
func (m *BaseShardManager) UpdateShardStates(shardStates []ShardState) {
	newAddrs := set.NewSet()
	for _, state := range shardStates {
		newAddrs.Add(state.Address)
	}

	m.rwMutex.Lock()
	defer m.rwMutex.Unlock()

	oldAddrs := set.NewSet()
	for _, state := range m.shardStates {
		oldAddrs.Add(state.Address)
	}

	for address := range set.Subtract(newAddrs, oldAddrs).Iter() {
		if err := m.pool.Register("tcp", address.(string)); err != nil {
			m.logError(err)
		}
	}

	for address := range set.Subtract(oldAddrs, newAddrs).Iter() {
		if err := m.pool.Unregister("tcp", address.(string)); err != nil {
			m.logError(err)
		}
	}

	m.shardStates = shardStates
}
예제 #2
0
func New(name string) (module *Module) {
	module = &Module{
		name:   name,
		before: set.NewSet(),
		after:  set.NewSet(),
	}
	modules.PushBack(module)
	return
}
예제 #3
0
// Samples 'k' unique ints from the range [0, n)
func SampleInts(n int, k int) (res []int, err error) {
	if k < 0 {
		err = errors.Newf("invalid sample size k")
		return
	}

	if n < k {
		err = errors.Newf("sample size k larger than n")
		return
	}

	picked := set.NewSet()
	for picked.Len() < k {
		i := Intn(n)
		picked.Add(i)
	}

	res = make([]int, k)
	e := 0
	for i := range picked.Iter() {
		res[e] = i.(int)
		e++
	}

	return
}
예제 #4
0
func (c *Oauth2Client) Refresh(db *database.Database) (err error) {
	refreshed, err := c.Check()
	if err != nil {
		return
	}

	if !refreshed {
		return
	}

	coll := db.Accounts()

	c.Account.Oauth2AccTokn = c.AccessToken
	c.Account.Oauth2RefTokn = c.RefreshToken
	c.Account.Oauth2Exp = c.Expiry

	if c.Account.Id == "" {
		return
	}

	fields := set.NewSet("oauth2_acc_tokn", "oauth2_ref_tokn", "oauth2_exp")

	err = coll.CommitFields(c.Account.Id, c.Account, fields)
	if err != nil {
		err = database.ParseError(err)
		return
	}

	return
}
예제 #5
0
파일: utils.go 프로젝트: pacur/pacur
func getTargets(path string) (targets []string, err error) {
	pac, err := parse.File("", "", path)
	if err != nil {
		return
	}

	err = pac.Compile()
	if err != nil {
		return
	}

	tarSet := set.NewSet()
	for _, target := range pac.Targets {
		tarSet.Add(target)
	}

	for _, release := range constants.Releases {
		distro := strings.Split(release, "-")[0]

		if tarSet.Contains("!"+release) || tarSet.Contains("!"+distro) {
			continue
		}

		if tarSet.Contains(release) || tarSet.Contains(distro) {
			targets = append(targets, release)
		}
	}

	return
}
예제 #6
0
func StringSet(items []string) (s set.Set) {
	s = set.NewSet()

	for _, item := range items {
		s.Add(item)
	}

	return
}
func (s *RoundRobinResourcePoolSuite) TestRegisterAndGet(c *C) {
	s.SetupPool(c, 10)

	err := s.pool.Register("foo")
	c.Assert(err, IsNil)
	err = s.pool.Register("bar")
	c.Assert(err, IsNil)
	err = s.pool.Register("abc")
	c.Assert(err, IsNil)
	err = s.pool.Register("zzz")
	c.Assert(err, IsNil)

	locations := make([]string, 0)
	locSet := set.NewSet()

	c1, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c1.ResourceLocation())
	locSet.Add(c1.ResourceLocation())

	c2, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c2.ResourceLocation())
	locSet.Add(c2.ResourceLocation())

	c3, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c3.ResourceLocation())
	locSet.Add(c3.ResourceLocation())

	c4, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c4.ResourceLocation())
	locSet.Add(c4.ResourceLocation())

	expected := set.NewSet("foo", "bar", "abc", "zzz")
	c.Assert(locSet.IsEqual(expected), IsTrue)

	for i := 0; i < 20; i++ {
		h, err := s.pool.Get("")
		c.Assert(err, IsNil)
		c.Assert(h.ResourceLocation(), Equals, locations[i%4])
	}
}
예제 #8
0
파일: redhat.go 프로젝트: pacur/pacur
func (r *Redhat) getFiles() (files []string, err error) {
	backup := set.NewSet()
	paths := set.NewSet()

	for _, path := range r.Pack.Backup {
		if !strings.HasPrefix(path, "/") {
			path = "/" + path
		}
		backup.Add(path)
	}

	rpmPath, err := r.getRpmPath()
	if err != nil {
		return
	}

	output, err := utils.ExecOutput(r.Pack.PackageDir, "rpm", "-qlp", rpmPath)
	if err != nil {
		return
	}

	for _, path := range strings.Split(output, "\n") {
		if len(path) < 1 {
			continue
		}

		paths.Remove(filepath.Dir(path))
		paths.Add(path)
	}

	for pathInf := range paths.Iter() {
		path := pathInf.(string)

		if backup.Contains(path) {
			path = `%config "` + path + `"`
		} else {
			path = `"` + path + `"`
		}

		files = append(files, path)
	}

	return
}
func (s *ManagerSuite) TestRegister(c *C) {
	shardStates := make([]ShardState, 4)
	shardStates[0].Address = "foo"
	shardStates[1].Address = "bar"
	shardStates[2].Address = "baz"
	shardStates[3].Address = "foo"
	s.manager.UpdateShardStates(shardStates)

	expectedRegistered := set.NewSet("foo", "bar", "baz")
	c.Assert(expectedRegistered.IsEqual(s.pool.registered), IsTrue)
}
func (s *RoundRobinResourcePoolSuite) TestInitWithPools(c *C) {
	foo := s.CreateResourceLocationPool("foo")
	bar := s.CreateResourceLocationPool("bar")
	abc := s.CreateResourceLocationPool("abc")
	zzz := s.CreateResourceLocationPool("zzz")

	s.SetupPool(c, 10, foo, bar, abc, zzz)

	locations := make([]string, 0)
	locSet := set.NewSet()

	c1, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c1.ResourceLocation())
	locSet.Add(c1.ResourceLocation())

	c2, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c2.ResourceLocation())
	locSet.Add(c2.ResourceLocation())

	c3, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c3.ResourceLocation())
	locSet.Add(c3.ResourceLocation())

	c4, err := s.pool.Get("")
	c.Assert(err, IsNil)
	locations = append(locations, c4.ResourceLocation())
	locSet.Add(c4.ResourceLocation())

	expected := set.NewSet("foo", "bar", "abc", "zzz")
	c.Assert(locSet.IsEqual(expected), IsTrue)

	for i := 0; i < 20; i++ {
		h, err := s.pool.Get("")
		c.Assert(err, IsNil)
		c.Assert(h.ResourceLocation(), Equals, locations[i%4])
	}
}
예제 #11
0
// Event system for client using web socket.
package event

import (
	"github.com/dropbox/godropbox/container/set"
	"github.com/pritunl/pritunl-client-electron/service/utils"
	"time"
)

var (
	LastAwake = time.Now()
	listeners = set.NewSet()
)

type Event struct {
	Id   string      `json:"id"`
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

func (e *Event) Init() {
	e.Id = utils.Uuid()
	for listInf := range listeners.Iter() {
		list := listInf.(*Listener)

		go func() {
			defer func() {
				recover()
			}()
			list.stream <- e
		}()
예제 #12
0
	"github.com/dropbox/godropbox/container/set"
	"github.com/gin-gonic/gin"
	"github.com/sethgrid/multibar"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"time"
)

const (
	controllerSize = 250
)

var (
	hosts      = set.NewSet()
	hostsLock  = sync.Mutex{}
	bars       []*Bar
	barsWaiter sync.WaitGroup
)

type Bar struct {
	lock   sync.Mutex
	setter multibar.ProgressFunc
	size   int
	count  int
}

func (b *Bar) Incr() {
	b.lock.Lock()
	b.count += 1
예제 #13
0
func init() {
	lockedInterfaces = set.NewSet()
}
예제 #14
0
파일: constants.go 프로젝트: pacur/pacur
		"ubuntu-yakkety": ".yakkety_",
	}
	DistroPack = map[string]string{
		"archlinux": "pacman",
		"fedora":    "redhat",
		"centos":    "redhat",
		"debian":    "debian",
		"ubuntu":    "debian",
	}
	Packagers = [...]string{
		"apt",
		"pacman",
		"yum",
	}

	ReleasesSet    = set.NewSet()
	Distros        = []string{}
	DistrosSet     = set.NewSet()
	DistroPackager = map[string]string{}
	PackagersSet   = set.NewSet()
)

func init() {
	for _, release := range Releases {
		ReleasesSet.Add(release)
		distro := strings.Split(release, "-")[0]
		Distros = append(Distros, distro)
		DistrosSet.Add(distro)
	}

	for _, distro := range Distros {
func newMockPool() *mockPool {
	return &mockPool{
		registered: set.NewSet(),
	}
}