refactored 'share.tail' for new subordinate boot protocol (#789)

This commit is contained in:
Michael Quigley 2024-11-13 11:18:52 -05:00
parent f4fa04e687
commit 85a22950a7
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 49 additions and 32 deletions

View File

@ -63,12 +63,14 @@ func (a *access) tail(data []byte) {
} }
} }
a.booted = true a.booted = true
} else {
a.bootErr = errors.New(line)
} }
} else { } else {
a.bootErr = errors.New(line) a.bootErr = errors.New(line)
} }
} else { } else {
logrus.Warn(line) a.bootErr = errors.New(line)
} }
} else { } else {
a.bootErr = errors.New(line) a.bootErr = errors.New(line)

View File

@ -54,43 +54,58 @@ func (s *share) tail(data []byte) {
if line, err := s.readBuffer.ReadString('\n'); err == nil { if line, err := s.readBuffer.ReadString('\n'); err == nil {
line = strings.Trim(line, "\n") line = strings.Trim(line, "\n")
if !s.booted { if !s.booted {
in := make(map[string]interface{}) if strings.HasPrefix(line, "{") {
if err := json.Unmarshal([]byte(line), &in); err == nil { in := make(map[string]interface{})
if v, found := in["token"]; found { if err := json.Unmarshal([]byte(line), &in); err == nil {
if str, ok := v.(string); ok { if v, found := in["message"]; found {
s.token = str if str, ok := v.(string); ok {
} if str == "boot" {
} if v, found := in["token"]; found {
if v, found := in["backend_mode"]; found { if str, ok := v.(string); ok {
if str, ok := v.(string); ok { s.token = str
s.backendMode = sdk.BackendMode(str) }
} }
} if v, found := in["backend_mode"]; found {
if v, found := in["share_mode"]; found { if str, ok := v.(string); ok {
if str, ok := v.(string); ok { s.backendMode = sdk.BackendMode(str)
s.shareMode = sdk.ShareMode(str) }
} }
} if v, found := in["share_mode"]; found {
if v, found := in["frontend_endpoints"]; found { if str, ok := v.(string); ok {
if vArr, ok := v.([]interface{}); ok { s.shareMode = sdk.ShareMode(str)
for _, v := range vArr { }
if str, ok := v.(string); ok { }
s.frontendEndpoints = append(s.frontendEndpoints, 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 { close(s.bootComplete)
if str, ok := v.(string); ok {
s.target = str
}
}
s.booted = true
} else { } else {
s.bootErr = errors.New(line) logrus.Warn(line)
} }
close(s.bootComplete)
} else { } else {
if strings.HasPrefix(line, "{") { if strings.HasPrefix(line, "{") {
in := make(map[string]interface{}) in := make(map[string]interface{})