API: expose runtime representation
Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com> Co-authored-by: Jean-Baptiste Doumenjou <jb.doumenjou@gmail.com>
This commit is contained in:
parent
5cd9396dae
commit
f6df556eb0
50 changed files with 2250 additions and 1158 deletions
|
@ -13,13 +13,13 @@ import (
|
|||
|
||||
// Manager is the TCPHandlers factory
|
||||
type Manager struct {
|
||||
configs map[string]*config.TCPService
|
||||
configs map[string]*config.TCPServiceInfo
|
||||
}
|
||||
|
||||
// NewManager creates a new manager
|
||||
func NewManager(configs map[string]*config.TCPService) *Manager {
|
||||
func NewManager(conf *config.RuntimeConfiguration) *Manager {
|
||||
return &Manager{
|
||||
configs: configs,
|
||||
configs: conf.TCPServices,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,23 +29,23 @@ func (m *Manager) BuildTCP(rootCtx context.Context, serviceName string) (tcp.Han
|
|||
ctx := internal.AddProviderInContext(rootCtx, serviceQualifiedName)
|
||||
ctx = log.With(ctx, log.Str(log.ServiceName, serviceName))
|
||||
|
||||
// FIXME Check if the service is declared multiple times with different types
|
||||
conf, ok := m.configs[serviceQualifiedName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("the service %q does not exits", serviceQualifiedName)
|
||||
return nil, fmt.Errorf("the service %q does not exist", serviceQualifiedName)
|
||||
}
|
||||
|
||||
if conf.LoadBalancer == nil {
|
||||
return nil, fmt.Errorf("the service %q doesn't have any TCP load balancer", serviceQualifiedName)
|
||||
conf.Err = fmt.Errorf("the service %q doesn't have any TCP load balancer", serviceQualifiedName)
|
||||
return nil, conf.Err
|
||||
}
|
||||
|
||||
logger := log.FromContext(ctx)
|
||||
|
||||
// FIXME Check if the service is declared multiple times with different types
|
||||
loadBalancer := tcp.NewRRLoadBalancer()
|
||||
|
||||
for _, server := range conf.LoadBalancer.Servers {
|
||||
if _, err := parseIP(server.Address); err != nil {
|
||||
logger.Errorf("Invalid IP address for a %q server %q: %v", serviceQualifiedName, server.Address, err)
|
||||
if _, _, err := net.SplitHostPort(server.Address); err != nil {
|
||||
logger.Errorf("In service %q: %v", serviceQualifiedName, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -57,20 +57,5 @@ func (m *Manager) BuildTCP(rootCtx context.Context, serviceName string) (tcp.Han
|
|||
|
||||
loadBalancer.AddServer(handler)
|
||||
}
|
||||
|
||||
return loadBalancer, nil
|
||||
}
|
||||
|
||||
func parseIP(s string) (string, error) {
|
||||
ip, _, err := net.SplitHostPort(s)
|
||||
if err == nil {
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
ipNoPort := net.ParseIP(s)
|
||||
if ipNoPort == nil {
|
||||
return "", fmt.Errorf("invalid IP Address %s", ipNoPort)
|
||||
}
|
||||
|
||||
return ipNoPort.String(), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue