High Availability daemon to share an IP around N servers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zoreide/orchestrator.go

87 lines
1.6 KiB

package main
import (
"fmt"
"log"
"strconv"
"time"
)
func (mip *AbstractMulticast) WriteNumberToMulticast() {
log.Println("Initiating ticker")
bstNumber := fmt.Sprintf("%d", ZoreideBridge.hIerarchyNumber)
for range time.Tick(1 * time.Second) {
_, err := mip.Wconn.Write([]byte(bstNumber))
if err != nil {
log.Println("Cannot write to multicast:" + err.Error())
}
}
}
func (mip *AbstractMulticast) ReadNumberFromMulticast() {
log.Println("Initiating reader")
buffer := make([]byte, mip.MaxDatagramSize)
// Loop forever reading from the socket
for {
_, _, err := mip.Rconn.ReadFromUDP(buffer)
if err != nil {
log.Println("ReadFromUDP failed:", err)
}
BstChannel <- string(buffer)
}
}
func (b *AbstractBridge) BeTheBeta() {
log.Println("Inizializing Descalator")
ownNumber := b.hIerarchyNumber
for bstNumber := range BstChannel {
brdNumber, err := strconv.ParseInt(bstNumber, 10, 64)
if err != nil {
log.Println("Garbage received on multicast: ", bstNumber)
log.Println("Cannot convert to int64:", err.Error())
continue
}
if brdNumber > ownNumber {
log.Println("GULP! There is a bigger one, better descalating")
b.IsAlpha = false
if b.IsActive {
b.removeIPandBridgeInt()
b.IsActive = false
}
}
}
}
func (b *AbstractBridge) WaitForBeAlpha() {
log.Println("Inizializing Escalator")
for range time.Tick(5 * time.Second) {
if b.IsAlpha && !b.IsActive {
log.Println("I'm the ALPHA! Get out my path, losers!")
b.configureIpAndBridgeUp()
b.IsActive = true
}
b.IsAlpha = true
}
}