Example #1
0
func (t *Topology) AddToSegAutoRoot(seg *capn.Segment) msgs.Topology {
	topology := msgs.AutoNewTopology(seg)
	topology.SetClusterId(t.ClusterId)
	topology.SetVersion(t.Version)
	hosts := seg.NewTextList(len(t.Hosts))
	topology.SetHosts(hosts)
	for idx, host := range t.Hosts {
		hosts.Set(idx, host)
	}
	topology.SetF(t.F)
	topology.SetMaxRMCount(t.MaxRMCount)
	topology.SetAsyncFlush(t.AsyncFlush)
	rms := seg.NewUInt32List(len(t.AllRMs))
	topology.SetRms(rms)
	for idx, rmId := range t.AllRMs {
		rms.Set(idx, uint32(rmId))
	}
	accounts := msgs.NewAccountList(seg, len(t.Accounts))
	topology.SetAccounts(accounts)
	idx := 0
	for un, pw := range t.Accounts {
		account := accounts.At(idx)
		idx++
		account.SetUsername(un)
		account.SetPassword(pw)
	}
	return topology
}
Example #2
0
func (c Conds) AddToSeg(seg *capn.Segment) msgs.ConditionPair_List {
	cap := msgs.NewConditionPairList(seg, len(c))
	idx := 0
	for rmId, condSup := range c {
		condSupCap := msgs.NewConditionPair(seg)
		condSupCap.SetRmId(uint32(rmId))
		condSupCap.SetCondition(condSup.Cond.AddToSeg(seg))
		suppliersCap := seg.NewUInt32List(len(condSup.Suppliers))
		for idx, rmId := range condSup.Suppliers {
			suppliersCap.Set(idx, uint32(rmId))
		}
		condSupCap.SetSuppliers(suppliersCap)
		cap.Set(idx, condSupCap)
		idx++
	}
	return cap
}
Example #3
0
func (config *Configuration) AddToSegAutoRoot(seg *capn.Segment) msgs.Configuration {
	cap := msgs.AutoNewConfiguration(seg)
	cap.SetClusterId(config.ClusterId)
	cap.SetVersion(config.Version)

	hosts := seg.NewTextList(len(config.Hosts))
	cap.SetHosts(hosts)
	for idx, host := range config.Hosts {
		hosts.Set(idx, host)
	}

	cap.SetF(config.F)
	cap.SetMaxRMCount(config.MaxRMCount)
	cap.SetNoSync(config.NoSync)

	rms := seg.NewUInt32List(len(config.rms))
	cap.SetRms(rms)
	for idx, rmId := range config.rms {
		rms.Set(idx, uint32(rmId))
	}

	rmsRemoved := seg.NewUInt32List(len(config.rmsRemoved))
	cap.SetRmsRemoved(rmsRemoved)
	idx := 0
	for rmId := range config.rmsRemoved {
		rmsRemoved.Set(idx, uint32(rmId))
		idx++
	}

	fingerprintsMap := config.fingerprints
	fingerprints := seg.NewDataList(len(fingerprintsMap))
	cap.SetFingerprints(fingerprints)
	idx = 0
	for fingerprint := range fingerprintsMap {
		fingerprints.Set(idx, fingerprint[:])
		idx++
	}

	if config.nextConfiguration == nil {
		cap.SetStable()
	} else {
		nextConfig := config.nextConfiguration
		cap.SetTransitioningTo()
		next := cap.TransitioningTo()
		next.SetConfiguration(nextConfig.Configuration.AddToSegAutoRoot(seg))

		allHostsCap := seg.NewTextList(len(nextConfig.AllHosts))
		for idx, host := range nextConfig.AllHosts {
			allHostsCap.Set(idx, host)
		}
		next.SetAllHosts(allHostsCap)

		newRMIdsCap := seg.NewUInt32List(len(nextConfig.NewRMIds))
		for idx, rmId := range nextConfig.NewRMIds {
			newRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetNewRMIds(newRMIdsCap)

		survivingRMIdsCap := seg.NewUInt32List(len(nextConfig.SurvivingRMIds))
		for idx, rmId := range nextConfig.SurvivingRMIds {
			survivingRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetSurvivingRMIds(survivingRMIdsCap)

		lostRMIdsCap := seg.NewUInt32List(len(nextConfig.LostRMIds))
		for idx, rmId := range nextConfig.LostRMIds {
			lostRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetLostRMIds(lostRMIdsCap)

		barrierReached1Cap := seg.NewUInt32List(len(nextConfig.BarrierReached1))
		for idx, rmId := range nextConfig.BarrierReached1 {
			barrierReached1Cap.Set(idx, uint32(rmId))
		}
		next.SetBarrierReached1(barrierReached1Cap)

		barrierReached2Cap := seg.NewUInt32List(len(nextConfig.BarrierReached2))
		for idx, rmId := range nextConfig.BarrierReached2 {
			barrierReached2Cap.Set(idx, uint32(rmId))
		}
		next.SetBarrierReached2(barrierReached2Cap)

		next.SetInstalledOnNew(nextConfig.InstalledOnNew)

		next.SetPending(nextConfig.Pending.AddToSeg(seg))
	}
	return cap
}