judger

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateContest added in v0.5.0

func CreateContest(baseDir string, contest *Contest) error

CreateContest creates a new contest directory and its configuration files. baseDir is the root directory where all contests are stored (e.g., "contests/").

func CreateProblem added in v0.5.0

func CreateProblem(contest *Contest, problem *Problem) error

CreateProblem creates a new problem directory and files within a contest. It also updates the parent contest's YAML file.

func DeleteContest added in v0.5.0

func DeleteContest(contest *Contest) error

DeleteContest removes the entire directory for a contest.

func DeleteProblem added in v0.5.0

func DeleteProblem(contest *Contest, problemID string) error

DeleteProblem removes a problem's directory and updates the parent contest's YAML.

func FindContestDirs added in v0.5.0

func FindContestDirs(rootPath string) ([]string, error)

FindContestDirs scans a root directory and returns a slice of all its immediate subdirectories.

func LoadAllContestsAndProblems

func LoadAllContestsAndProblems(contestDirs []string) (map[string]*Contest, map[string]*Problem, error)

func RecoverAndCleanup

func RecoverAndCleanup(db *gorm.DB, cfg *config.Config) error

RecoverAndCleanup handles the recovery process on application startup. It finds submissions and containers that were in a 'Running' state and cleans up their associated Docker containers before marking them as 'Failed' in the database.

func RequeuePendingSubmissions

func RequeuePendingSubmissions(db *gorm.DB, s *Scheduler, appState *AppState) error

RequeuePendingSubmissions loads submissions with 'Queued' status from the DB and adds them back to the scheduler's queue on startup.

func UpdateContest added in v0.5.0

func UpdateContest(contest *Contest) error

UpdateContest updates an existing contest's configuration files.

func UpdateProblem added in v0.5.0

func UpdateProblem(problem *Problem) error

UpdateProblem updates an existing problem's configuration files.

Types

type Announcement added in v0.5.0

type Announcement struct {
	ID          string    `yaml:"id" json:"id"`
	Title       string    `yaml:"title" json:"title"`
	CreatedAt   time.Time `yaml:"created_at" json:"created_at"`
	UpdatedAt   time.Time `yaml:"updated_at" json:"updated_at"`
	Description string    `yaml:"description" json:"description"`
}

type AppState

type AppState struct {
	sync.RWMutex
	Contests            map[string]*Contest
	Problems            map[string]*Problem
	ProblemToContestMap map[string]*Contest
}

AppState holds the shared, reloadable state of contests and problems.

type ClusterState

type ClusterState struct {
	sync.Mutex
	*config.Cluster
	Nodes map[string]*NodeState `json:"nodes"`
}

type Contest

type Contest struct {
	ID            string          `yaml:"id" json:"id"`
	Name          string          `yaml:"name" json:"name"`
	StartTime     time.Time       `yaml:"starttime" json:"starttime"`
	EndTime       time.Time       `yaml:"endtime" json:"endtime"`
	ProblemDirs   []string        `yaml:"problems" json:"-"` // Renamed from ProblemDirs to problems in YAML, hide from JSON
	ProblemIDs    []string        `yaml:"-" json:"problem_ids"`
	Description   string          `yaml:"-" json:"description"`
	BasePath      string          `yaml:"-" json:"-"`             // Store the base path to find assets, hide from both
	Announcements []*Announcement `yaml:"-" json:"announcements"` // Loaded from announcements.yaml, hidden from contest.yaml
}

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(cfg *config.Config, db *gorm.DB, scheduler *Scheduler, appState *AppState) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(sub *models.Submission, prob *Problem, node *NodeState, allocatedCores []int)

type DockerManager

type DockerManager struct {
	// contains filtered or unexported fields
}

func NewDockerManager

func NewDockerManager(cfg config.DockerConfig) (*DockerManager, error)

func (*DockerManager) CleanupContainer

func (m *DockerManager) CleanupContainer(containerID string)

func (*DockerManager) CopyToContainer

func (m *DockerManager) CopyToContainer(containerID string, srcDir string, dstDir string) error

func (*DockerManager) CreateContainer

func (m *DockerManager) CreateContainer(image, volumeName string, cpu int, cpusetCpus string, memory int64, asRoot bool, customMounts []Mount, networkEnabled bool, name string, envs []string) (string, error)

func (*DockerManager) CreateVolume added in v0.6.0

func (m *DockerManager) CreateVolume(name string) error

func (*DockerManager) ExecInContainer

func (m *DockerManager) ExecInContainer(ctx context.Context, containerID string, cmd []string, outputCallback func(streamType string, data []byte)) (ExecResult, error)

func (*DockerManager) RemoveVolume added in v0.6.0

func (m *DockerManager) RemoveVolume(name string) error

func (*DockerManager) StartContainer

func (m *DockerManager) StartContainer(containerID string) error

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type JudgeResult

type JudgeResult struct {
	Score       int                    `json:"score"`
	Performance float64                `json:"performance"`
	Info        map[string]interface{} `json:"info"`
}

type Mount

type Mount struct {
	Type        string       `yaml:"type" json:"type"`
	Source      string       `yaml:"source" json:"source"`
	Target      string       `yaml:"target" json:"target"`
	ReadOnly    *bool        `yaml:"readonly" json:"readonly"`
	TmpfsOption TmpfsOptions `yaml:"tmpfs_options" json:"tmpfs_options,omitempty"`
}

type NodeDetail

type NodeDetail struct {
	*config.Node
	UsedMemory int64  `json:"used_memory"`
	UsedCores  []bool `json:"used_cores"`
	IsPaused   bool   `json:"is_paused"`
}

type NodeState

type NodeState struct {
	sync.Mutex
	*config.Node
	UsedMemory int64  `json:"used_memory"`
	UsedCores  []bool `json:"used_cores"`
	IsPaused   bool   `json:"is_paused"`
}

type Problem

type Problem struct {
	ID             string         `yaml:"id" json:"id"`
	Name           string         `yaml:"name" json:"name"`
	Level          string         `yaml:"level" json:"level"`
	StartTime      time.Time      `yaml:"starttime" json:"starttime"`
	EndTime        time.Time      `yaml:"endtime" json:"endtime"`
	MaxSubmissions int            `yaml:"max_submissions" json:"max_submissions"`
	Cluster        string         `yaml:"cluster" json:"cluster"`
	CPU            int            `yaml:"cpu" json:"cpu"`
	Memory         int64          `yaml:"memory" json:"memory"`
	Upload         UploadLimit    `yaml:"upload" json:"upload"`
	Workflow       []WorkflowStep `yaml:"workflow" json:"workflow"`
	Score          ScoreConfig    `yaml:"score" json:"score"`
	Description    string         `json:"description"`
	BasePath       string         `yaml:"-" json:"-"` // Store the base path to find assets, hide from both
}

type QueuedSubmission

type QueuedSubmission struct {
	Submission *models.Submission
	Problem    *Problem
}

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(cfg *config.Config, db *gorm.DB, appState *AppState) *Scheduler

func (*Scheduler) GetClusterStates

func (s *Scheduler) GetClusterStates() map[string]ClusterState

func (*Scheduler) GetNodeDetails

func (s *Scheduler) GetNodeDetails(clusterName, nodeName string) (*NodeDetail, error)

func (*Scheduler) GetQueueLengths

func (s *Scheduler) GetQueueLengths() map[string]int

func (*Scheduler) PauseNode

func (s *Scheduler) PauseNode(clusterName, nodeName string) error

func (*Scheduler) ReleaseResources

func (s *Scheduler) ReleaseResources(clusterName, nodeName string, coresToRelease []int, memory int64)

func (*Scheduler) ResumeNode

func (s *Scheduler) ResumeNode(clusterName, nodeName string) error

func (*Scheduler) Run

func (s *Scheduler) Run()

func (*Scheduler) Submit

func (s *Scheduler) Submit(submission *models.Submission, problem *Problem)

type ScoreConfig

type ScoreConfig struct {
	Mode                string `yaml:"mode" json:"mode"`
	MaxPerformanceScore int    `yaml:"max_performance_score" json:"max_performance_score"`
}

type TmpfsOptions added in v0.6.0

type TmpfsOptions struct {
	SizeBytes int64       `yaml:"size_bytes" json:"size_bytes,omitempty"`
	Mode      os.FileMode `yaml:"mode,omitempty" json:"mode,omitempty"`
	Options   [][]string  `yaml:"options,omitempty" json:"options,omitempty"`
}

type UploadLimit

type UploadLimit struct {
	MaxNum      int      `yaml:"maxnum" json:"max_num"`
	MaxSize     int      `yaml:"maxsize" json:"max_size"`
	UploadForm  bool     `yaml:"upload_form" json:"upload_form"`
	UploadFiles []string `yaml:"upload_files" json:"upload_files"`
	Editor      bool     `yaml:"editor" json:"editor"`
	EditorFiles []string `yaml:"editor_files" json:"editor_files"`
}

type WorkflowStep

type WorkflowStep struct {
	Name    string     `yaml:"name" json:"name"`
	Image   string     `yaml:"image" json:"image"`
	Root    bool       `yaml:"root" json:"root"`
	Timeout int        `yaml:"timeout" json:"timeout"`
	Show    bool       `yaml:"show" json:"show"`
	Steps   [][]string `yaml:"steps" json:"steps"`
	Mounts  []Mount    `yaml:"mounts" json:"mounts"`
	Network bool       `yaml:"network" json:"network"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL