Skip to content

Commit

Permalink
feat: store persistent cache host by announce host api
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Nov 11, 2024
1 parent 10062d7 commit e2fe79d
Showing 1 changed file with 165 additions and 0 deletions.
165 changes: 165 additions & 0 deletions scheduler/service/service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ func (v *V2) AnnounceHost(ctx context.Context, req *schedulerv2.AnnounceHostRequ
}
}

// Handle standard host.
host, loaded := v.resource.HostManager().Load(req.Host.GetId())
if !loaded {
options := []standard.HostOption{
Expand Down Expand Up @@ -703,6 +704,170 @@ func (v *V2) AnnounceHost(ctx context.Context, req *schedulerv2.AnnounceHostRequ
host.AnnounceInterval = req.GetInterval().AsDuration()
}

// Handle the persistent cache host.
persistentCacheHost, loaded := v.persistentCacheResource.HostManager().Load(ctx, req.Host.GetId())
if !loaded {
persistentCacheHost = persistentcache.NewHost(req.Host.GetId(), req.Host.GetHostname(), req.Host.GetIp(), req.Host.GetOs(),
req.Host.GetPlatform(), req.Host.GetPlatformFamily(), req.Host.GetPlatformVersion(), req.Host.GetKernelVersion(), req.Host.GetPort(),
req.Host.GetDownloadPort(), concurrentUploadLimit, 0, 0, 0, req.Host.GetDisableShared(), types.HostType(req.Host.GetType()),
persistentcache.CPU{
LogicalCount: req.Host.Cpu.GetLogicalCount(),
PhysicalCount: req.Host.Cpu.GetPhysicalCount(),
Percent: req.Host.Cpu.GetPercent(),
ProcessPercent: req.Host.Cpu.GetProcessPercent(),
Times: persistentcache.CPUTimes{
User: req.Host.Cpu.Times.GetUser(),
System: req.Host.Cpu.Times.GetSystem(),
Idle: req.Host.Cpu.Times.GetIdle(),
Nice: req.Host.Cpu.Times.GetNice(),
Iowait: req.Host.Cpu.Times.GetIowait(),
Irq: req.Host.Cpu.Times.GetIrq(),
Softirq: req.Host.Cpu.Times.GetSoftirq(),
Steal: req.Host.Cpu.Times.GetSteal(),
Guest: req.Host.Cpu.Times.GetGuest(),
GuestNice: req.Host.Cpu.Times.GetGuestNice(),
},
},
persistentcache.Memory{
Total: req.Host.Memory.GetTotal(),
Available: req.Host.Memory.GetAvailable(),
Used: req.Host.Memory.GetUsed(),
UsedPercent: req.Host.Memory.GetUsedPercent(),
ProcessUsedPercent: req.Host.Memory.GetProcessUsedPercent(),
Free: req.Host.Memory.GetFree(),
},
persistentcache.Network{
TCPConnectionCount: req.Host.Network.GetTcpConnectionCount(),
UploadTCPConnectionCount: req.Host.Network.GetUploadTcpConnectionCount(),
Location: req.Host.Network.GetLocation(),
IDC: req.Host.Network.GetIdc(),
DownloadRate: req.Host.Network.GetDownloadRate(),
DownloadRateLimit: req.Host.Network.GetDownloadRateLimit(),
UploadRate: req.Host.Network.GetUploadRate(),
UploadRateLimit: req.Host.Network.GetUploadRateLimit(),
},
persistentcache.Disk{
Total: req.Host.Disk.GetTotal(),
Free: req.Host.Disk.GetFree(),
Used: req.Host.Disk.GetUsed(),
UsedPercent: req.Host.Disk.GetUsedPercent(),
InodesTotal: req.Host.Disk.GetInodesTotal(),
InodesUsed: req.Host.Disk.GetInodesUsed(),
InodesFree: req.Host.Disk.GetInodesFree(),
InodesUsedPercent: req.Host.Disk.GetInodesUsedPercent(),
},
persistentcache.Build{
GitVersion: req.Host.Build.GetGitVersion(),
GitCommit: req.Host.Build.GetGitCommit(),
GoVersion: req.Host.Build.GetGoVersion(),
Platform: req.Host.Build.GetPlatform(),
},
req.GetInterval().AsDuration(),
time.Now(),
time.Now(),
logger.WithHostID(req.Host.GetId()),
)

persistentCacheHost.Log.Infof("announce new persistent cache host: %#v", req)
if err := v.persistentCacheResource.HostManager().Store(ctx, persistentCacheHost); err != nil {
persistentCacheHost.Log.Errorf("store persistent cache host failed: %s", err)
}

return nil
}

// persistentCacheHost already exists and updates properties.
persistentCacheHost.Port = req.Host.GetPort()
persistentCacheHost.DownloadPort = req.Host.GetDownloadPort()
persistentCacheHost.Type = types.HostType(req.Host.GetType())
persistentCacheHost.DisableShared = req.Host.GetDisableShared()
persistentCacheHost.OS = req.Host.GetOs()
persistentCacheHost.Platform = req.Host.GetPlatform()
persistentCacheHost.PlatformFamily = req.Host.GetPlatformFamily()
persistentCacheHost.PlatformVersion = req.Host.GetPlatformVersion()
persistentCacheHost.KernelVersion = req.Host.GetKernelVersion()
persistentCacheHost.UpdatedAt = time.Now()

if concurrentUploadLimit > 0 {
persistentCacheHost.ConcurrentUploadLimit = concurrentUploadLimit
}

if req.Host.GetCpu() != nil {
persistentCacheHost.CPU = persistentcache.CPU{
LogicalCount: req.Host.Cpu.GetLogicalCount(),
PhysicalCount: req.Host.Cpu.GetPhysicalCount(),
Percent: req.Host.Cpu.GetPercent(),
ProcessPercent: req.Host.Cpu.GetProcessPercent(),
Times: persistentcache.CPUTimes{
User: req.Host.Cpu.Times.GetUser(),
System: req.Host.Cpu.Times.GetSystem(),
Idle: req.Host.Cpu.Times.GetIdle(),
Nice: req.Host.Cpu.Times.GetNice(),
Iowait: req.Host.Cpu.Times.GetIowait(),
Irq: req.Host.Cpu.Times.GetIrq(),
Softirq: req.Host.Cpu.Times.GetSoftirq(),
Steal: req.Host.Cpu.Times.GetSteal(),
Guest: req.Host.Cpu.Times.GetGuest(),
GuestNice: req.Host.Cpu.Times.GetGuestNice(),
},
}
}

if req.Host.GetMemory() != nil {
persistentCacheHost.Memory = persistentcache.Memory{
Total: req.Host.Memory.GetTotal(),
Available: req.Host.Memory.GetAvailable(),
Used: req.Host.Memory.GetUsed(),
UsedPercent: req.Host.Memory.GetUsedPercent(),
ProcessUsedPercent: req.Host.Memory.GetProcessUsedPercent(),
Free: req.Host.Memory.GetFree(),
}
}

if req.Host.GetNetwork() != nil {
persistentCacheHost.Network = persistentcache.Network{
TCPConnectionCount: req.Host.Network.GetTcpConnectionCount(),
UploadTCPConnectionCount: req.Host.Network.GetUploadTcpConnectionCount(),
Location: req.Host.Network.GetLocation(),
IDC: req.Host.Network.GetIdc(),
DownloadRate: req.Host.Network.GetDownloadRate(),
DownloadRateLimit: req.Host.Network.GetDownloadRateLimit(),
UploadRate: req.Host.Network.GetUploadRate(),
UploadRateLimit: req.Host.Network.GetUploadRateLimit(),
}
}

if req.Host.GetDisk() != nil {
persistentCacheHost.Disk = persistentcache.Disk{
Total: req.Host.Disk.GetTotal(),
Free: req.Host.Disk.GetFree(),
Used: req.Host.Disk.GetUsed(),
UsedPercent: req.Host.Disk.GetUsedPercent(),
InodesTotal: req.Host.Disk.GetInodesTotal(),
InodesUsed: req.Host.Disk.GetInodesUsed(),
InodesFree: req.Host.Disk.GetInodesFree(),
InodesUsedPercent: req.Host.Disk.GetInodesUsedPercent(),
}
}

if req.Host.GetBuild() != nil {
persistentCacheHost.Build = persistentcache.Build{
GitVersion: req.Host.Build.GetGitVersion(),
GitCommit: req.Host.Build.GetGitCommit(),
GoVersion: req.Host.Build.GetGoVersion(),
Platform: req.Host.Build.GetPlatform(),
}
}

if req.GetInterval() != nil {
persistentCacheHost.AnnounceInterval = req.GetInterval().AsDuration()
}

persistentCacheHost.Log.Infof("update persistent cache host: %#v", req)
if err := v.persistentCacheResource.HostManager().Store(ctx, persistentCacheHost); err != nil {
persistentCacheHost.Log.Errorf("store persistent cache host failed: %s", err)
}

return nil
}

Expand Down

0 comments on commit e2fe79d

Please sign in to comment.