将 Worker 发现、路由画像、容量与执行传输抽象为平台无关接口,新增 Kubernetes 和静态容量适配器,并以 shadow 模式接入生产配置。 实现网络与容量评分、路由防抖、池队列、同步 Worker 租约、一次性执行令牌,以及提交状态不明时禁止重复分配的安全语义。 新增 0105 兼容迁移、管理接口、指标、OpenAPI 和回归测试。已执行全量 Go 测试、go vet、OpenAPI、迁移安全、Compose 与 Kustomize 验证。
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package runner
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/easyai/easyai-ai-gateway/apps/api/internal/executionpool"
|
|
)
|
|
|
|
// httpExecutionTransport is the first platform-neutral Worker transport
|
|
// adapter. The routing core sees only WorkerDescriptor and executionpool's
|
|
// versioned request/response types; Pod DNS and other orchestrator concepts do
|
|
// not cross this boundary.
|
|
type httpExecutionTransport struct {
|
|
client *http.Client
|
|
}
|
|
|
|
func (transport httpExecutionTransport) Execute(
|
|
ctx context.Context,
|
|
worker executionpool.WorkerDescriptor,
|
|
input executionpool.ExecutionRequest,
|
|
) (executionpool.ExecutionResponse, error) {
|
|
if transport.client == nil {
|
|
return executionpool.ExecutionResponse{}, errors.New("worker HTTP client is required")
|
|
}
|
|
payload, err := json.Marshal(InternalExecutionRequest{
|
|
TaskID: input.TaskID,
|
|
LeaseID: input.LeaseID,
|
|
Stream: input.Stream,
|
|
})
|
|
if err != nil {
|
|
return executionpool.ExecutionResponse{}, err
|
|
}
|
|
request, err := http.NewRequestWithContext(
|
|
ctx,
|
|
http.MethodPost,
|
|
strings.TrimRight(worker.Endpoint, "/")+workerExecutionPath,
|
|
bytes.NewReader(payload),
|
|
)
|
|
if err != nil {
|
|
return executionpool.ExecutionResponse{}, err
|
|
}
|
|
request.Header.Set("Content-Type", "application/json")
|
|
request.Header.Set("Authorization", "Worker "+input.AuthorizationToken)
|
|
response, err := transport.client.Do(request)
|
|
if err != nil {
|
|
return executionpool.ExecutionResponse{}, err
|
|
}
|
|
return executionpool.ExecutionResponse{
|
|
StatusCode: response.StatusCode,
|
|
Headers: response.Header,
|
|
Body: response.Body,
|
|
}, nil
|
|
}
|
|
|
|
var _ executionpool.ExecutionTransport = httpExecutionTransport{}
|