Record project continuation changes
This commit is contained in:
@@ -2,6 +2,8 @@ package supervisor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
||||
)
|
||||
@@ -17,24 +19,146 @@ type StubSupervisor struct {
|
||||
func (s StubSupervisor) Apply(_ context.Context, desired []client.DesiredWorkload) ([]client.WorkloadStatusRequest, error) {
|
||||
statuses := make([]client.WorkloadStatusRequest, 0, len(desired))
|
||||
for _, workload := range desired {
|
||||
state := "degraded"
|
||||
if workload.DesiredState == "disabled" {
|
||||
state = "stopped"
|
||||
}
|
||||
version := workload.Version
|
||||
if version == "" {
|
||||
version = s.Version
|
||||
}
|
||||
statuses = append(statuses, client.WorkloadStatusRequest{
|
||||
ReportedState: state,
|
||||
RuntimeMode: workload.RuntimeMode,
|
||||
Version: version,
|
||||
StatusPayload: map[string]any{
|
||||
"supervisor": "stub",
|
||||
"desired_state": workload.DesiredState,
|
||||
"service_type": workload.ServiceType,
|
||||
},
|
||||
})
|
||||
statuses = append(statuses, s.applyOne(workload))
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
func (s StubSupervisor) applyOne(workload client.DesiredWorkload) client.WorkloadStatusRequest {
|
||||
serviceType := strings.TrimSpace(workload.ServiceType)
|
||||
desiredState := strings.TrimSpace(strings.ToLower(workload.DesiredState))
|
||||
if desiredState == "" {
|
||||
desiredState = "disabled"
|
||||
}
|
||||
runtimeMode := strings.TrimSpace(strings.ToLower(workload.RuntimeMode))
|
||||
if runtimeMode == "" {
|
||||
runtimeMode = "native"
|
||||
}
|
||||
version := strings.TrimSpace(workload.Version)
|
||||
if version == "" {
|
||||
version = s.Version
|
||||
}
|
||||
payload := map[string]any{
|
||||
"schema_version": "rap.node_agent.workload_supervision.v1",
|
||||
"supervisor": "node-agent-local",
|
||||
"desired_state": desiredState,
|
||||
"service_type": serviceType,
|
||||
"runtime_mode": runtimeMode,
|
||||
"observed_at": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
}
|
||||
if desiredState != "enabled" {
|
||||
payload["reason"] = "desired_state_not_enabled"
|
||||
return client.WorkloadStatusRequest{
|
||||
ReportedState: "stopped",
|
||||
RuntimeMode: runtimeMode,
|
||||
Version: version,
|
||||
StatusPayload: payload,
|
||||
}
|
||||
}
|
||||
if serviceType == "core-mesh" || serviceType == "mesh-listener" {
|
||||
payload["reason"] = "builtin_node_agent_service_ready"
|
||||
payload["execution_mode"] = "builtin"
|
||||
payload["traffic"] = serviceTrafficMode(serviceType)
|
||||
return client.WorkloadStatusRequest{
|
||||
ReportedState: "running",
|
||||
RuntimeMode: runtimeMode,
|
||||
Version: version,
|
||||
StatusPayload: payload,
|
||||
}
|
||||
}
|
||||
if serviceType == "synthetic.echo" && runtimeMode == "native" {
|
||||
payload["reason"] = "internal_synthetic_echo_ready"
|
||||
payload["execution_mode"] = "builtin"
|
||||
payload["traffic"] = "test_service_only"
|
||||
return client.WorkloadStatusRequest{
|
||||
ReportedState: "running",
|
||||
RuntimeMode: runtimeMode,
|
||||
Version: version,
|
||||
StatusPayload: payload,
|
||||
}
|
||||
}
|
||||
if serviceType == "rdp-worker" && runtimeMode == "native" && boolConfig(workload.Config, "adapter_contract_probe") {
|
||||
payload["reason"] = "remote_workspace_adapter_contract_probe_ready"
|
||||
payload["execution_mode"] = "contract_probe"
|
||||
payload["service_class"] = "remote_workspace"
|
||||
payload["fabric_service_channel_required"] = true
|
||||
payload["backend_relay_steady_state"] = false
|
||||
payload["channels"] = remoteWorkspaceAdapterChannels()
|
||||
payload["frame_batch_contract"] = remoteWorkspaceFrameBatchContract()
|
||||
payload["traffic"] = "none"
|
||||
return client.WorkloadStatusRequest{
|
||||
ReportedState: "running",
|
||||
RuntimeMode: runtimeMode,
|
||||
Version: version,
|
||||
StatusPayload: payload,
|
||||
}
|
||||
}
|
||||
payload["reason"] = "service_runtime_not_implemented"
|
||||
payload["traffic"] = "blocked"
|
||||
return client.WorkloadStatusRequest{
|
||||
ReportedState: "degraded",
|
||||
RuntimeMode: runtimeMode,
|
||||
Version: version,
|
||||
StatusPayload: payload,
|
||||
}
|
||||
}
|
||||
|
||||
func boolConfig(values map[string]any, key string) bool {
|
||||
if values == nil {
|
||||
return false
|
||||
}
|
||||
value, ok := values[key]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
switch typed := value.(type) {
|
||||
case bool:
|
||||
return typed
|
||||
case string:
|
||||
return strings.EqualFold(strings.TrimSpace(typed), "true")
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func remoteWorkspaceAdapterChannels() []map[string]any {
|
||||
return []map[string]any{
|
||||
{"name": "input", "direction": "client_to_adapter", "reliability": "reliable_ordered", "priority": "critical", "droppable": true, "may_block_input": false},
|
||||
{"name": "control", "direction": "bidirectional", "reliability": "reliable_ordered", "priority": "high", "droppable": false, "may_block_input": false},
|
||||
{"name": "display", "direction": "adapter_to_client", "reliability": "droppable_latest", "priority": "high", "droppable": true, "may_block_input": false},
|
||||
{"name": "cursor", "direction": "adapter_to_client", "reliability": "droppable_latest", "priority": "high", "droppable": true, "may_block_input": false},
|
||||
{"name": "clipboard", "direction": "bidirectional", "reliability": "reliable_ordered", "priority": "medium", "droppable": false, "may_block_input": false},
|
||||
{"name": "file_transfer", "direction": "bidirectional", "reliability": "reliable_chunked", "priority": "medium", "droppable": false, "may_block_input": false},
|
||||
{"name": "audio", "direction": "adapter_to_client", "reliability": "adaptive_droppable", "priority": "medium", "droppable": true, "may_block_input": false},
|
||||
{"name": "device", "direction": "bidirectional", "reliability": "reliable_ordered", "priority": "medium", "droppable": false, "may_block_input": false},
|
||||
{"name": "telemetry", "direction": "adapter_to_client", "reliability": "sampled_droppable", "priority": "low", "droppable": true, "may_block_input": false},
|
||||
}
|
||||
}
|
||||
|
||||
func remoteWorkspaceFrameBatchContract() map[string]any {
|
||||
return map[string]any{
|
||||
"schema_version": "rap.remote_workspace_frame_batch.v1",
|
||||
"adapter_contract_id": "rap.rdp_worker.remote_workspace_adapter_contract_probe.v1",
|
||||
"probe_only": true,
|
||||
"payload_forwarding": "not_implemented",
|
||||
"service_class": "remote_workspace",
|
||||
"allowed_flow_classes": []string{"control", "interactive", "reliable", "bulk", "droppable"},
|
||||
"allowed_payload_encodings": []string{
|
||||
"none",
|
||||
"base64",
|
||||
},
|
||||
"max_probe_frames": 32,
|
||||
"channels": remoteWorkspaceAdapterChannels(),
|
||||
}
|
||||
}
|
||||
|
||||
func serviceTrafficMode(serviceType string) string {
|
||||
switch serviceType {
|
||||
case "core-mesh":
|
||||
return "fabric_control"
|
||||
case "mesh-listener":
|
||||
return "entry_listener"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,3 +33,101 @@ func TestStubSupervisorReportsStoppedForDisabledWorkload(t *testing.T) {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStubSupervisorRunsInternalSyntheticEchoWorkload(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{ServiceType: "synthetic.echo", DesiredState: "enabled", RuntimeMode: "native"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if statuses[0].ReportedState != "running" {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
if statuses[0].StatusPayload["reason"] != "internal_synthetic_echo_ready" {
|
||||
t.Fatalf("reason = %v", statuses[0].StatusPayload["reason"])
|
||||
}
|
||||
if statuses[0].StatusPayload["execution_mode"] != "builtin" {
|
||||
t.Fatalf("execution_mode = %v", statuses[0].StatusPayload["execution_mode"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestStubSupervisorReportsBuiltinFabricServicesRunning(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{ServiceType: "core-mesh", DesiredState: "enabled", RuntimeMode: "container"},
|
||||
{ServiceType: "mesh-listener", DesiredState: "enabled", RuntimeMode: "container"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if len(statuses) != 2 {
|
||||
t.Fatalf("statuses length = %d", len(statuses))
|
||||
}
|
||||
for _, status := range statuses {
|
||||
if status.ReportedState != "running" {
|
||||
t.Fatalf("ReportedState = %q", status.ReportedState)
|
||||
}
|
||||
if status.StatusPayload["reason"] != "builtin_node_agent_service_ready" {
|
||||
t.Fatalf("reason = %v", status.StatusPayload["reason"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStubSupervisorKeepsUnsupportedEnabledWorkloadDegraded(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{ServiceType: "rdp-worker", DesiredState: "enabled", RuntimeMode: "container"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if statuses[0].ReportedState != "degraded" {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
if statuses[0].StatusPayload["reason"] != "service_runtime_not_implemented" {
|
||||
t.Fatalf("reason = %v", statuses[0].StatusPayload["reason"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestStubSupervisorRunsRDPWorkerAdapterContractProbeOnly(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{
|
||||
ServiceType: "rdp-worker",
|
||||
DesiredState: "enabled",
|
||||
RuntimeMode: "native",
|
||||
Config: map[string]any{
|
||||
"adapter_contract_probe": true,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if statuses[0].ReportedState != "running" {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
if statuses[0].StatusPayload["reason"] != "remote_workspace_adapter_contract_probe_ready" {
|
||||
t.Fatalf("reason = %v", statuses[0].StatusPayload["reason"])
|
||||
}
|
||||
if statuses[0].StatusPayload["service_class"] != "remote_workspace" {
|
||||
t.Fatalf("service_class = %v", statuses[0].StatusPayload["service_class"])
|
||||
}
|
||||
if statuses[0].StatusPayload["backend_relay_steady_state"] != false {
|
||||
t.Fatalf("backend_relay_steady_state = %v", statuses[0].StatusPayload["backend_relay_steady_state"])
|
||||
}
|
||||
channels, ok := statuses[0].StatusPayload["channels"].([]map[string]any)
|
||||
if !ok || len(channels) != 9 {
|
||||
t.Fatalf("channels = %#v", statuses[0].StatusPayload["channels"])
|
||||
}
|
||||
if channels[0]["name"] != "input" || channels[0]["priority"] != "critical" || channels[0]["droppable"] != true || channels[0]["may_block_input"] != false {
|
||||
t.Fatalf("unexpected input channel: %#v", channels[0])
|
||||
}
|
||||
frameBatch, ok := statuses[0].StatusPayload["frame_batch_contract"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("frame_batch_contract = %#v", statuses[0].StatusPayload["frame_batch_contract"])
|
||||
}
|
||||
if frameBatch["schema_version"] != "rap.remote_workspace_frame_batch.v1" ||
|
||||
frameBatch["payload_forwarding"] != "not_implemented" ||
|
||||
frameBatch["service_class"] != "remote_workspace" {
|
||||
t.Fatalf("unexpected frame batch contract: %#v", frameBatch)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user