state

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerState = serverState{
	Containers:      newOwnershipState(),
	Networks:        newOwnershipState(),
	TemplateRequest: newTemplateRequestState(),
}

ServerState is the singleton server state of the current CTRv2 instance.

Functions

This section is empty.

Types

type OwnershipRecorder

type OwnershipRecorder interface {
	// RecordOwnership declares ownership of a name and the associated ID. The
	// same name can be redeclared to overwrite the existing ID.
	RecordOwnership(name string, id string)
	// HasOwnership checks current ownership.
	HasOwnership(name string, id string) bool
	// RemoveOwnership revokes ownership of a name.
	RemoveOwnership(name string)
	// GetIdsToClearOwnership returns current IDs in reverse order of
	// declarations. The IDs can be used to recycle entities.
	GetIdsToClearOwnership() []string
	// GetMapping returns name to ID mapping.
	GetMapping() *sync.Map
	// Clear reset the state.
	Clear()
	// GetIdForOwner returns a copy of ID mapping to name.
	GetIdForOwner(name string) string
}

OwnershipRecorder is the interface to manage ownership state in the server. If an entity (container/network) is started/created by the server, the server "owns" the entity and is responsible to recycle (stop/remove) at server exit. An ownership is identified by the entity name (supplied by client) and the ID (generated by docker). Ownership with the same name can be redeclared to a different ID; the old ID will be abandoned permanently. Redeclaration may happen due to local development, client bugs, and/or unexpected stop of containers. As long as an action is accepted by the underlying docker commands, the server follows suit and records the state.

type TemplateRequestRecorder

type TemplateRequestRecorder interface {
	// Add container ID to Request mapping to the state.
	Add(containerId string, request *api.StartTemplatedContainerRequest)
	// Exist checks if a container ID exists in the state.
	Exist(containerId string) bool
	// Get Request by container ID from the state.
	Get(containerId string) *api.StartTemplatedContainerRequest
}

TemplateRequestRecorder is the interface to track the state of StartTemplatedContainerRequest.

Jump to

Keyboard shortcuts

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