mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-07 08:01:13 +08:00
Go: align with EE (#17882)
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -43,6 +43,7 @@ const (
|
||||
CodeLicenseTimeRollback ErrorCode = 324
|
||||
CodeLicenseNotFound ErrorCode = 325
|
||||
CodeLicenseUnexpectedError ErrorCode = 326
|
||||
CodeLicenseNotValidYet ErrorCode = 327
|
||||
CodeBadRequest ErrorCode = 400
|
||||
CodeUnauthorized ErrorCode = 401
|
||||
CodeForbidden ErrorCode = 403
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"ragflow/internal/common"
|
||||
"ragflow/internal/server"
|
||||
"ragflow/internal/utility"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var licenseStatusCode common.ErrorCode
|
||||
var AdminServiceClient *AdminClient
|
||||
|
||||
// AdminClient is responsible for sending heartbeat reports to the admin server
|
||||
@@ -41,10 +43,12 @@ type AdminClient struct {
|
||||
version string
|
||||
lastSuccess bool
|
||||
attemptCount int
|
||||
clusterInfo *utility.ClusterInfo
|
||||
}
|
||||
|
||||
// NewAdminClient creates a new heartbeat service instance
|
||||
func NewAdminClient(logger *zap.Logger, serverType common.ServerType, serverName, host string, port int) *AdminClient {
|
||||
licenseStatusCode = common.CodeSuccess
|
||||
return &AdminClient{
|
||||
logger: logger,
|
||||
serverType: serverType,
|
||||
@@ -76,6 +80,11 @@ func (h *AdminClient) InitHTTPClient() error {
|
||||
zap.Int("admin_port", adminConfig.HTTPPort),
|
||||
)
|
||||
|
||||
err := h.InitHTTPClientEE()
|
||||
if err != nil {
|
||||
h.logger.Fatal(fmt.Sprintf("Fail to init enterprise service: %v", err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,6 +119,8 @@ func (h *AdminClient) SendHeartbeat() error {
|
||||
Ext: nil,
|
||||
}
|
||||
|
||||
message.Ext = h.clusterInfo
|
||||
|
||||
jsonData, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to marshal heartbeat message", zap.Error(err))
|
||||
@@ -122,22 +133,31 @@ func (h *AdminClient) SendHeartbeat() error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
// extract the Code and Message field of the response
|
||||
var responseBody map[string]interface{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&responseBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code, ok := responseBody["code"].(float64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected heartbeat response (status %d): missing or non-numeric \"code\" field", resp.StatusCode)
|
||||
}
|
||||
responseCode := common.ErrorCode(code)
|
||||
if responseCode != common.CodeLicenseValid {
|
||||
return errors.New(responseCode.Message())
|
||||
}
|
||||
// extract the Code and Message field of the response
|
||||
var responseBody map[string]interface{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&responseBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code, ok := responseBody["code"].(float64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected heartbeat response (status %d): missing or non-numeric \"code\" field", resp.StatusCode)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("error HTTP status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
responseCode := common.ErrorCode(code)
|
||||
if responseCode != common.CodeLicenseValid {
|
||||
if responseCode != licenseStatusCode {
|
||||
licenseStatusCode = responseCode
|
||||
h.logger.Warn(fmt.Sprintf("Heartbeat response error: %s, code: %d", responseCode.Message(), responseCode))
|
||||
}
|
||||
|
||||
return errors.New(responseCode.Message())
|
||||
}
|
||||
licenseStatusCode = responseCode
|
||||
|
||||
h.logger.Debug("Heartbeat sent successfully",
|
||||
zap.String("server_id", h.serverName),
|
||||
|
||||
20
internal/service/admin_client_ee.go
Normal file
20
internal/service/admin_client_ee.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package service
|
||||
|
||||
func (h *AdminClient) InitHTTPClientEE() error {
|
||||
return nil
|
||||
}
|
||||
20
internal/utility/fingerprint_ee.go
Normal file
20
internal/utility/fingerprint_ee.go
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package utility
|
||||
|
||||
type ClusterInfo struct {
|
||||
}
|
||||
Reference in New Issue
Block a user