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.
59 lines
1.4 KiB
59 lines
1.4 KiB
package hal
|
|
|
|
import (
|
|
"context"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
type Cluster struct {
|
|
modules []*Module
|
|
}
|
|
|
|
func (c *Cluster) Run(ctx context.Context) error {
|
|
errs, _ := errgroup.WithContext(ctx)
|
|
for _, module := range c.modules {
|
|
errs.Go(module.Run)
|
|
}
|
|
return errs.Wait()
|
|
}
|
|
|
|
func (config *ClusterConfig) BuildCluster(modules map[string]*Module) (*Cluster, error) {
|
|
// We assume all modules in the connection config exist
|
|
for _, c := range config.Connections {
|
|
conn := NewMultiThreadedIO()
|
|
modules[c.SourceNode].IO[c.SourcePort] = conn
|
|
modules[c.DestNode].IO[c.DestPort] = conn
|
|
}
|
|
|
|
// for host, client := range mapping {
|
|
// modules[host.Module] = struct{}{}
|
|
// modules[client.Module] = struct{}{}
|
|
// host.Module.IO[host.IOPort] = NewMultiThreadedIO(&client)
|
|
// }
|
|
|
|
cluster := &Cluster{modules: make([]*Module, len(modules), len(modules))}
|
|
var index int64
|
|
for _, module := range modules {
|
|
cluster.modules[index] = module
|
|
index++
|
|
}
|
|
return cluster, nil
|
|
}
|
|
|
|
type ClusterConnection struct {
|
|
SourcePort int64 `yaml:"source_port"`
|
|
SourceNode string `yaml:"source_node"`
|
|
DestPort int64 `yaml:"dest_port"`
|
|
DestNode string `yaml:"dest_node"`
|
|
}
|
|
|
|
type ClusterNode struct {
|
|
Name string `yaml:"name"`
|
|
// Path to the hal program
|
|
Program string `yaml:"program"`
|
|
}
|
|
|
|
type ClusterConfig struct {
|
|
Nodes []*ClusterNode `yaml:"nodes"`
|
|
Connections []*ClusterConnection `yaml:"connections"`
|
|
}
|
|
|