From 85a22950a7bb7e020ed5bd43ee5997f55614ebdf Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 13 Nov 2024 11:18:52 -0500 Subject: [PATCH] refactored 'share.tail' for new subordinate boot protocol (#789) --- agent/access.go | 4 ++- agent/share.go | 77 +++++++++++++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/agent/access.go b/agent/access.go index 4ea8fe4b..ed7aa2b7 100644 --- a/agent/access.go +++ b/agent/access.go @@ -63,12 +63,14 @@ func (a *access) tail(data []byte) { } } a.booted = true + } else { + a.bootErr = errors.New(line) } } else { a.bootErr = errors.New(line) } } else { - logrus.Warn(line) + a.bootErr = errors.New(line) } } else { a.bootErr = errors.New(line) diff --git a/agent/share.go b/agent/share.go index 2d309748..8c0cc5f2 100644 --- a/agent/share.go +++ b/agent/share.go @@ -54,43 +54,58 @@ func (s *share) tail(data []byte) { if line, err := s.readBuffer.ReadString('\n'); err == nil { line = strings.Trim(line, "\n") if !s.booted { - in := make(map[string]interface{}) - if err := json.Unmarshal([]byte(line), &in); err == nil { - if v, found := in["token"]; found { - if str, ok := v.(string); ok { - s.token = str - } - } - if v, found := in["backend_mode"]; found { - if str, ok := v.(string); ok { - s.backendMode = sdk.BackendMode(str) - } - } - if v, found := in["share_mode"]; found { - if str, ok := v.(string); ok { - s.shareMode = sdk.ShareMode(str) - } - } - if v, found := in["frontend_endpoints"]; found { - if vArr, ok := v.([]interface{}); ok { - for _, v := range vArr { - if str, ok := v.(string); ok { - s.frontendEndpoints = append(s.frontendEndpoints, str) + if strings.HasPrefix(line, "{") { + in := make(map[string]interface{}) + if err := json.Unmarshal([]byte(line), &in); err == nil { + if v, found := in["message"]; found { + if str, ok := v.(string); ok { + if str == "boot" { + if v, found := in["token"]; found { + if str, ok := v.(string); ok { + s.token = str + } + } + if v, found := in["backend_mode"]; found { + if str, ok := v.(string); ok { + s.backendMode = sdk.BackendMode(str) + } + } + if v, found := in["share_mode"]; found { + if str, ok := v.(string); ok { + s.shareMode = sdk.ShareMode(str) + } + } + if v, found := in["frontend_endpoints"]; found { + if vArr, ok := v.([]interface{}); ok { + for _, v := range vArr { + if str, ok := v.(string); ok { + s.frontendEndpoints = append(s.frontendEndpoints, str) + } + } + } + } + if v, found := in["target"]; found { + if str, ok := v.(string); ok { + s.target = str + } + } + s.booted = true + } else { + s.bootErr = errors.New(line) } + } else { + s.bootErr = errors.New(line) } + } else { + s.bootErr = errors.New(line) } + } else { + s.bootErr = errors.New(line) } - if v, found := in["target"]; found { - if str, ok := v.(string); ok { - s.target = str - } - } - s.booted = true + close(s.bootComplete) } else { - s.bootErr = errors.New(line) + logrus.Warn(line) } - close(s.bootComplete) - } else { if strings.HasPrefix(line, "{") { in := make(map[string]interface{})