41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package supervisor
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
|
)
|
|
|
|
type Supervisor interface {
|
|
Apply(ctx context.Context, desired []client.DesiredWorkload) ([]client.WorkloadStatusRequest, error)
|
|
}
|
|
|
|
type StubSupervisor struct {
|
|
Version string
|
|
}
|
|
|
|
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,
|
|
},
|
|
})
|
|
}
|
|
return statuses, nil
|
|
}
|