2022-01-18 06:44:12 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gravitl/netmaker/logger"
|
|
|
|
"github.com/gravitl/netmaker/logic"
|
2022-02-01 03:01:09 +08:00
|
|
|
"github.com/gravitl/netmaker/models"
|
|
|
|
"github.com/gravitl/netmaker/mq"
|
2022-01-19 23:44:00 +08:00
|
|
|
"github.com/gravitl/netmaker/servercfg"
|
2022-01-18 06:44:12 +08:00
|
|
|
)
|
|
|
|
|
2022-02-01 03:01:09 +08:00
|
|
|
func runServerPeerUpdate(node *models.Node, ifaceDelta bool) error {
|
|
|
|
|
2022-01-26 00:00:56 +08:00
|
|
|
err := logic.TimerCheckpoint()
|
|
|
|
if err != nil {
|
|
|
|
logger.Log(3, "error occurred on timer,", err.Error())
|
2022-01-21 06:50:42 +08:00
|
|
|
}
|
2022-02-01 03:01:09 +08:00
|
|
|
if servercfg.IsMessageQueueBackend() {
|
|
|
|
if err := mq.PublishPeerUpdate(node); err != nil {
|
|
|
|
logger.Log(0, "failed to inform peers of new node ", err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 23:44:00 +08:00
|
|
|
if servercfg.IsClientMode() != "on" {
|
|
|
|
return nil
|
|
|
|
}
|
2022-02-03 00:56:39 +08:00
|
|
|
var currentServerNode, getErr = logic.GetNetworkServerLeader(node.Network)
|
2022-01-18 22:27:24 +08:00
|
|
|
if err != nil {
|
2022-01-26 00:00:56 +08:00
|
|
|
return getErr
|
2022-01-18 22:27:24 +08:00
|
|
|
}
|
2022-01-31 09:31:11 +08:00
|
|
|
if err = logic.ServerUpdate(¤tServerNode, ifaceDelta); err != nil {
|
2022-01-18 23:55:02 +08:00
|
|
|
logger.Log(1, "server node:", currentServerNode.ID, "failed update")
|
2022-01-18 23:14:27 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-01-18 06:44:12 +08:00
|
|
|
return nil
|
|
|
|
}
|