84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/google/uuid"
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/RyanCopley/skybridge/faas/internal/domain"
|
|
"github.com/RyanCopley/skybridge/faas/internal/runtime"
|
|
)
|
|
|
|
type SimpleDockerRuntime struct {
|
|
logger *zap.Logger
|
|
}
|
|
|
|
func NewSimpleDockerRuntime(logger *zap.Logger) *SimpleDockerRuntime {
|
|
return &SimpleDockerRuntime{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) Execute(ctx context.Context, function *domain.FunctionDefinition, input json.RawMessage) (*domain.ExecutionResult, error) {
|
|
s.logger.Info("Mock function execution",
|
|
zap.String("function_id", function.ID.String()),
|
|
zap.String("name", function.Name))
|
|
|
|
// Mock execution result
|
|
result := &domain.ExecutionResult{
|
|
Output: json.RawMessage(`{"result": "Hello from FaaS!", "function": "` + function.Name + `"}`),
|
|
Duration: function.Timeout.Duration / 10, // Simulate quick execution
|
|
MemoryUsed: function.Memory / 2, // Simulate partial memory usage
|
|
Logs: []string{"Function started", "Processing input", "Function completed"},
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) Deploy(ctx context.Context, function *domain.FunctionDefinition) error {
|
|
s.logger.Info("Mock function deployment",
|
|
zap.String("function_id", function.ID.String()),
|
|
zap.String("image", function.Image))
|
|
return nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) Remove(ctx context.Context, functionID uuid.UUID) error {
|
|
s.logger.Info("Mock function removal", zap.String("function_id", functionID.String()))
|
|
return nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) GetLogs(ctx context.Context, executionID uuid.UUID) ([]string, error) {
|
|
return []string{
|
|
"Function execution started",
|
|
"Processing request",
|
|
"Function execution completed",
|
|
}, nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) HealthCheck(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) GetInfo(ctx context.Context) (*runtime.RuntimeInfo, error) {
|
|
return &runtime.RuntimeInfo{
|
|
Type: "simple-docker",
|
|
Version: "mock-1.0",
|
|
Available: true,
|
|
Endpoint: "mock://docker",
|
|
Metadata: map[string]string{
|
|
"containers": "0",
|
|
"images": "0",
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) ListContainers(ctx context.Context) ([]runtime.ContainerInfo, error) {
|
|
return []runtime.ContainerInfo{}, nil
|
|
}
|
|
|
|
func (s *SimpleDockerRuntime) StopExecution(ctx context.Context, executionID uuid.UUID) error {
|
|
s.logger.Info("Mock execution stop", zap.String("execution_id", executionID.String()))
|
|
return nil
|
|
} |