Skip to content

Commit

Permalink
ADD: reconcile loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaspeters committed Nov 22, 2022
1 parent fe03fb7 commit d977693
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/AVENTER-UG/mesos-compose
go 1.17

require (
github.com/AVENTER-UG/mesos-util v0.0.42
github.com/AVENTER-UG/mesos-util v0.0.43
github.com/AVENTER-UG/util v0.5.2
github.com/Showmax/go-fqdn v1.0.0
github.com/go-redis/redis/v8 v8.11.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/AVENTER-UG/mesos-util v0.0.41 h1:SU9qpdTmUEtHqFPYvd1aJPcbyS7piL69DMLw
github.com/AVENTER-UG/mesos-util v0.0.41/go.mod h1:70fymV+AZKb3VQtUtprpJVXtp+mEAsYk7/NEg3s5JQ8=
github.com/AVENTER-UG/mesos-util v0.0.42 h1:CeZg+DXe09wuY5g/TFpv0ByJNCRqSgDZowfZg3pIWII=
github.com/AVENTER-UG/mesos-util v0.0.42/go.mod h1:70fymV+AZKb3VQtUtprpJVXtp+mEAsYk7/NEg3s5JQ8=
github.com/AVENTER-UG/mesos-util v0.0.43 h1:cOluIYkqQAuU+cHCOIJW2EiSI/mqfZbcYko/n9GQ9r4=
github.com/AVENTER-UG/mesos-util v0.0.43/go.mod h1:70fymV+AZKb3VQtUtprpJVXtp+mEAsYk7/NEg3s5JQ8=
github.com/AVENTER-UG/util v0.3.0 h1:wtUC7e6LMx37BRGBKKBZ4BUM8q4lkLjgBinS09luv6A=
github.com/AVENTER-UG/util v0.3.0/go.mod h1:8mh50Bes+U3D6ZP3psP4K8LSPNwpeuM5vRNb/vU/sS0=
github.com/AVENTER-UG/util v0.4.2 h1:jqSZ10mdHRrpFFT7Zsw7Z0DzatqV9PuxrM5b8xhTrC4=
Expand Down
1 change: 1 addition & 0 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
config.Credentials.Username = util.Getenv("AUTH_USERNAME", "")
config.Credentials.Password = util.Getenv("AUTH_PASSWORD", "")
config.AppName = "Mesos Compose Framework"
config.ReconcileLoopTime, _ = time.ParseDuration(util.Getenv("RECONCILE_WAIT", "10m"))
config.RedisServer = util.Getenv("REDIS_SERVER", "127.0.0.1:6379")
config.RedisPassword = util.Getenv("REDIS_PASSWORD", "")
config.RedisDB, _ = strconv.Atoi(util.Getenv("REDIS_DB", "1"))
Expand Down
20 changes: 6 additions & 14 deletions mesos/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

mesosutil "github.com/AVENTER-UG/mesos-util"
mesosproto "github.com/AVENTER-UG/mesos-util/proto"

"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -89,18 +88,11 @@ func (e *Scheduler) HeartbeatLoop() {
}
}

func (e *Scheduler) changeDockerPorts(cmd mesosutil.Command) []mesosproto.ContainerInfo_DockerInfo_PortMapping {
var ret []mesosproto.ContainerInfo_DockerInfo_PortMapping
for _, port := range cmd.DockerPortMappings {
port.HostPort = e.API.GetRandomHostPort()
ret = append(ret, port)
}
return ret
}

func (e *Scheduler) changeDiscoveryInfo(cmd mesosutil.Command) mesosproto.DiscoveryInfo {
for i, port := range cmd.DockerPortMappings {
cmd.Discovery.Ports.Ports[i].Number = port.HostPort
// ReconcileLoop - The reconcile loop to check periodicly the task state
func (e *Scheduler) ReconcileLoop() {
ticker := time.NewTicker(e.Config.ReconcileLoopTime)
defer ticker.Stop()
for ; true; <-ticker.C {
go e.Reconcile()
}
return cmd.Discovery
}
17 changes: 17 additions & 0 deletions mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (e *Scheduler) EventLoop() {
_ = strings.TrimSuffix(line, "\n")

go e.HeartbeatLoop()
go e.ReconcileLoop()

for {
// Read line from Mesos
Expand Down Expand Up @@ -171,3 +172,19 @@ func (e *Scheduler) Reconcile() {
logrus.Debug("Reconcile Error: ", err)
}
}

func (e *Scheduler) changeDockerPorts(cmd mesosutil.Command) []mesosproto.ContainerInfo_DockerInfo_PortMapping {
var ret []mesosproto.ContainerInfo_DockerInfo_PortMapping
for _, port := range cmd.DockerPortMappings {
port.HostPort = e.API.GetRandomHostPort()
ret = append(ret, port)
}
return ret
}

func (e *Scheduler) changeDiscoveryInfo(cmd mesosutil.Command) mesosproto.DiscoveryInfo {
for i, port := range cmd.DockerPortMappings {
cmd.Discovery.Ports.Ports[i].Number = port.HostPort
}
return cmd.Discovery
}
51 changes: 26 additions & 25 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@ import (

// Config is a struct of the framework configuration
type Config struct {
Principal string
LogLevel string
MinVersion string
AppName string
EnableSyslog bool
Hostname string
Listen string
Domain string
Credentials UserCredentials
PrefixHostname string
PrefixTaskName string
CPU float64
Memory float64
Disk float64
RedisServer string
RedisPassword string
RedisDB int
SkipSSL bool
SSLKey string
SSLCrt string
Suppress bool
EventLoopTime time.Duration
VaultToken string
VaultURL string
VaultTimeout time.Duration
Principal string
LogLevel string
MinVersion string
AppName string
EnableSyslog bool
Hostname string
Listen string
Domain string
Credentials UserCredentials
PrefixHostname string
PrefixTaskName string
CPU float64
Memory float64
Disk float64
RedisServer string
RedisPassword string
RedisDB int
SkipSSL bool
SSLKey string
SSLCrt string
Suppress bool
EventLoopTime time.Duration
ReconcileLoopTime time.Duration
VaultToken string
VaultURL string
VaultTimeout time.Duration
}

// UserCredentials - The Username and Password to authenticate against this framework
Expand Down

0 comments on commit d977693

Please sign in to comment.