state

package
v0.0.0-...-a81527e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

type State struct {
	*domain.StateBase
}

State represents the persistence layer for opened ports.

func NewState

func NewState(factory database.TxnRunnerFactory) *State

NewState returns a new state reference.

func (*State) FilterUnitUUIDsForApplication

func (st *State) FilterUnitUUIDsForApplication(ctx context.Context, units []unit.UUID, app coreapplication.ID) (set.Strings, error)

func (*State) GetAllOpenedPorts

func (s *State) GetAllOpenedPorts(ctx context.Context) (port.UnitGroupedPortRanges, error)

GetAllOpenedPorts returns the opened ports in the model, grouped by unit name.

NOTE: We do not group by endpoint here. It is not needed. Instead, we just group by unit name

func (*State) GetApplicationOpenedPorts

func (st *State) GetApplicationOpenedPorts(ctx context.Context, application coreapplication.ID) (port.UnitEndpointPortRanges, error)

GetApplicationOpenedPorts returns the opened ports for all the units of the given application. We return opened ports paired with the unit UUIDs, grouped by endpoint. This is because some consumers do not care about the unit.

func (*State) GetMachineNamesForUnits

func (st *State) GetMachineNamesForUnits(ctx context.Context, units []unit.UUID) ([]coremachine.Name, error)

GetMachineNamesForUnits returns a slice of machine names that host the provided units.

func (*State) GetMachineOpenedPorts

func (st *State) GetMachineOpenedPorts(ctx context.Context, machine string) (map[coreunit.Name]network.GroupedPortRanges, error)

GetMachineOpenedPorts returns the opened ports for all the units on the given machine. Opened ports are grouped first by unit and then by endpoint.

NOTE: In the ddl machines and units both share 1-to-1 relations with net_nodes. So to join units to machines we go via their net_nodes.

TODO: Once we have a core static machine uuid type, use it here.

func (*State) GetUnitOpenedPorts

func (st *State) GetUnitOpenedPorts(ctx context.Context, unit coreunit.UUID) (network.GroupedPortRanges, error)

GetUnitOpenedPorts returns the opened ports for a given unit uuid, grouped by endpoint.

func (*State) GetUnitUUID

func (st *State) GetUnitUUID(ctx context.Context, unitName coreunit.Name) (coreunit.UUID, error)

GetUnitUUID returns the UUID of the unit with the given name, returning an error satisfying porterrors.UnitNotFound if the unit does not exist.

func (*State) InitialWatchMachineOpenedPortsStatement

func (st *State) InitialWatchMachineOpenedPortsStatement() string

InitialWatchMachineOpenedPortsStatement returns the query to load the initial event for the WatchOpenedPorts watcher

func (*State) UpdateUnitPorts

func (st *State) UpdateUnitPorts(
	ctx context.Context, unit coreunit.UUID, openPorts, closePorts network.GroupedPortRanges,
) error

UpdateUnitPorts opens and closes ports for the endpoints of a given unit. The service layer must ensure that opened and closed ports for the same endpoints must not conflict.

func (*State) WatchOpenedPortsTable

func (st *State) WatchOpenedPortsTable() string

WatchOpenedPortsTable returns the name of the table that should be watched

Jump to

Keyboard shortcuts

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