service

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicState

type AtomicState interface {
	domain.AtomicStateBase

	// GetColocatedOpenedPorts returns all the open ports for all units co-located
	// with the given unit. Units are considered co-located if they share the same
	// net-node.
	GetColocatedOpenedPorts(ctx domain.AtomicContext, unitUUID coreunit.UUID) ([]network.PortRange, error)

	// GetEndpointOpenedPorts returns the opened ports for a given endpoint of a
	// given unit.
	GetEndpointOpenedPorts(ctx domain.AtomicContext, unitUUID coreunit.UUID, endpoint string) ([]network.PortRange, error)

	// GetEndpoints returns all the valid relation endpoints for a given unit. This
	// does not include the special wildcard endpoint.
	GetEndpoints(ctx domain.AtomicContext, unitUUID coreunit.UUID) ([]string, error)

	// UpdateUnitPorts opens and closes ports for the endpoints of a given unit.
	// The opened and closed ports for the same endpoints must not conflict.
	UpdateUnitPorts(ctx domain.AtomicContext, unitUUID coreunit.UUID, openPorts, closePorts network.GroupedPortRanges) error
}

AtomicState describes the subset of methods on state that run within an atomic context.

type Service

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

Service provides the API for managing the opened ports for units.

func NewService

func NewService(st State, logger logger.Logger) *Service

NewService returns a new Service for managing opened ports for units.

func (*Service) GetAllOpenedPorts

func (s *Service) 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 (*Service) GetApplicationOpenedPorts

func (s *Service) GetApplicationOpenedPorts(ctx context.Context, applicationUUID coreapplication.ID) (map[coreunit.Name]network.GroupedPortRanges, error)

GetApplicationOpenedPorts returns the opened ports for all the units of the application. Opened ports are grouped first by unit name and then by endpoint.

func (*Service) GetApplicationOpenedPortsByEndpoint

func (s *Service) GetApplicationOpenedPortsByEndpoint(ctx context.Context, applicationUUID coreapplication.ID) (network.GroupedPortRanges, error)

GetApplicationOpenedPortsByEndpoint returns all the opened ports for the given application, across all units, grouped by endpoint.

NOTE: The returned port ranges are atomised, meaning we guarantee that each port range is of unit length. This is useful for down-stream consumers such as k8s, which can only reason with unit-length port ranges.

func (*Service) GetMachineOpenedPorts

func (s *Service) GetMachineOpenedPorts(ctx context.Context, machineUUID string) (map[coreunit.Name]network.GroupedPortRanges, error)

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

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

func (*Service) GetUnitOpenedPorts

func (s *Service) GetUnitOpenedPorts(ctx context.Context, unitUUID coreunit.UUID) (network.GroupedPortRanges, error)

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

func (*Service) GetUnitUUID

func (s *Service) GetUnitUUID(ctx context.Context, unitName coreunit.Name) (coreunit.UUID, error)

GetUnitUUID returns the UUID of the unit with the given name.

func (*Service) UpdateUnitPorts

func (s *Service) UpdateUnitPorts(ctx context.Context, unitUUID coreunit.UUID, openPorts, closePorts network.GroupedPortRanges) error

UpdateUnitPorts opens and closes ports for the endpoints of a given unit.

NOTE: There is a special wildcard endpoint "" that represents all endpoints. Any operations applied to the wildcard endpoint will logically applied to all endpoints.

That is, if we open a port range on the wildcard endpoint, we will open it as usual but as a side effect we close that port range on all other endpoints.

On the other hand, if we close a specific endpoint's port range that is open on the wildcard endpoint, we will close it on the wildcard endpoint and open it on all other endpoints except the targeted endpoint.

type State

type State interface {
	WatcherState
	AtomicState

	// GetUnitOpenedPorts returns the opened ports for a given unit uuid,
	// grouped by endpoint.
	GetUnitOpenedPorts(context.Context, coreunit.UUID) (network.GroupedPortRanges, error)

	// GetAllOpenedPorts returns the opened ports in the model, grouped by unit name.
	GetAllOpenedPorts(context.Context) (port.UnitGroupedPortRanges, error)

	// GetMachineOpenedPorts returns the opened ports for all the units on the
	// given machine. Opened ports are grouped first by unit name and then by endpoint.
	GetMachineOpenedPorts(ctx context.Context, machineUUID string) (map[coreunit.Name]network.GroupedPortRanges, 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.
	GetApplicationOpenedPorts(ctx context.Context, applicationUUID coreapplication.ID) (port.UnitEndpointPortRanges, error)

	// GetUnitUUID returns the UUID of the unit with the given name.
	GetUnitUUID(ctx context.Context, unitName coreunit.Name) (coreunit.UUID, error)
}

State describes the methods that a state implementation must provide to manage opened ports for units.

type WatchableService

type WatchableService struct {
	*Service
	// contains filtered or unexported fields
}

WatchableService provides the API for managing the opened ports for units, as well as the ability to watch for changes to opened ports.

func NewWatchableService

func NewWatchableService(st State, watcherFactory WatcherFactory, logger logger.Logger) *WatchableService

NewWatchableService returns a new Service providing an API to manage the opened ports for units.

func (*WatchableService) WatchMachineOpenedPorts

func (s *WatchableService) WatchMachineOpenedPorts(ctx context.Context) (watcher.StringsWatcher, error)

WatchMachineOpenedPorts returns a strings watcher for opened ports. This watcher emits events for changes to the opened ports table. Each emitted event contains the machine name which is associated with the changed port range.

func (*WatchableService) WatchOpenedPortsForApplication

func (s *WatchableService) WatchOpenedPortsForApplication(ctx context.Context, applicationUUID coreapplication.ID) (watcher.NotifyWatcher, error)

WatchOpenedPortsForApplication returns a notify watcher for opened ports. This watcher emits events for changes to the opened ports table that are associated with the given application

type WatcherFactory

type WatcherFactory interface {
	// NewNamespaceMapperWatcher returns a new namespace watcher
	// for events based on the input change mask and mapper.
	NewNamespaceMapperWatcher(
		namespace string,
		changeMask changestream.ChangeType,
		initialStateQuery eventsource.NamespaceQuery,
		mapper eventsource.Mapper,
	) (watcher.StringsWatcher, error)

	// NewNamespaceNotifyMapperWatcher returns a new namespace notify watcher
	// for events based on the input change mask and mapper.
	NewNamespaceNotifyMapperWatcher(
		namespace string, changeMask changestream.ChangeType, mapper eventsource.Mapper,
	) (watcher.NotifyWatcher, error)
}

WatcherFactory describes methods for creating watchers.

type WatcherState

type WatcherState interface {
	// WatchOpenedPortsTable returns the name of the table that should be watched
	WatchOpenedPortsTable() string

	// InitialWatchMachineOpenedPortsStatement returns the query to load the initial
	// event for the WatchMachineOpenedPorts watcher
	InitialWatchMachineOpenedPortsStatement() string

	// GetMachineNamesForUnits returns map from endpoint uuids to the uuids of
	// the machines which host that endpoint for each provided endpoint uuid.
	GetMachineNamesForUnits(context.Context, []unit.UUID) ([]coremachine.Name, error)

	// FilterEndpointsForApplication returns the subset of provided endpoint uuids
	// that are associated with the provided application.
	FilterUnitUUIDsForApplication(context.Context, []unit.UUID, coreapplication.ID) (set.Strings, error)
}

WatcherState describes the methods that the service needs for its watchers.

Jump to

Keyboard shortcuts

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