service

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const CacheAcornName = "cache"
View Source
const MapperAcornName = "mapper"
View Source
const OwnersAcornName = "owners"
View Source
const RepositoriesAcornName = "repositories"
View Source
const ServicesAcornName = "services"
View Source
const TriggerAcornName = "trigger"
View Source
const UpdaterAcornName = "updater"

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	IsCache() bool

	// SetOwnerListTimestamp lets you set or update the timestamp for the last full scan of the list of aliases.
	SetOwnerListTimestamp(ctx context.Context, timestamp string)

	// GetOwnerListTimestamp gives you the timestamp of the last full scan of the list of aliases.
	GetOwnerListTimestamp(ctx context.Context) string

	// GetSortedOwnerAliases gives you a time snapshot copy of the slice of sorted owner names.
	//
	// This means you won't mess up the cache if you work with it in any way.
	GetSortedOwnerAliases(ctx context.Context) []string

	// GetOwner gives you a time snapshot deep copy of the owner information.
	//
	// This means you won't mess up the data in the cache if you work with it in any way.
	//
	// Requesting an owner that is not in the cache is an error.
	GetOwner(ctx context.Context, alias string) (openapi.OwnerDto, error)

	// PutOwner creates or replaces the owner cache entry.
	//
	// This is an atomic operation.
	PutOwner(ctx context.Context, alias string, entry openapi.OwnerDto)

	// DeleteOwner deletes the owner cache entry.
	//
	// This is an atomic operation.
	DeleteOwner(ctx context.Context, alias string)

	// SetServiceListTimestamp lets you set or update the timestamp for the last full scan of the list of names.
	SetServiceListTimestamp(ctx context.Context, timestamp string)

	// GetServiceListTimestamp gives you the timestamp of the last full scan of the list of names.
	GetServiceListTimestamp(ctx context.Context) string

	// GetSortedServiceNames gives you a time snapshot copy of the slice of sorted service names.
	//
	// This means you won't mess up the cache if you work with it in any way.
	GetSortedServiceNames(ctx context.Context) []string

	// GetService gives you a time snapshot deep copy of the service information.
	//
	// This means you won't mess up the data in the cache if you work with it in any way.
	//
	// Requesting a service that is not in the cache is an error.
	GetService(ctx context.Context, name string) (openapi.ServiceDto, error)

	// PutService creates or replaces the service cache entry.
	//
	// This is an atomic operation.
	PutService(ctx context.Context, name string, entry openapi.ServiceDto)

	// DeleteService deletes the service cache entry.
	//
	// This is an atomic operation.
	DeleteService(ctx context.Context, name string)

	// SetRepositoryListTimestamp lets you set or update the timestamp for the last full scan of the list of keys.
	SetRepositoryListTimestamp(ctx context.Context, timestamp string)

	// GetRepositoryListTimestamp gives you the timestamp of the last full scan of the list of keys.
	GetRepositoryListTimestamp(ctx context.Context) string

	// GetSortedRepositoryKeys gives you a time snapshot copy of the slice of sorted repository names.
	//
	// This means you won't mess up the cache if you work with it in any way.
	GetSortedRepositoryKeys(ctx context.Context) []string

	// GetRepository gives you a time snapshot deep copy of the repository information.
	//
	// This means you won't mess up the data in the cache if you work with it in any way.
	//
	// Requesting an repository that is not in the cache is an error.
	GetRepository(ctx context.Context, key string) (openapi.RepositoryDto, error)

	// PutRepository creates or replaces the repository cache entry.
	//
	// This is an atomic operation.
	PutRepository(ctx context.Context, key string, entry openapi.RepositoryDto)

	// DeleteRepository deletes the repository cache entry.
	//
	// This is an atomic operation.
	DeleteRepository(ctx context.Context, key string)
}

Cache is the central in-memory metadata cache, present to speed up read access to the current metadata.

type Mapper

type Mapper interface {
	IsMapper() bool

	RefreshMetadata(ctx context.Context) ([]repository.UpdateEvent, error)
	ContainsNewInformation(ctx context.Context, event repository.UpdateEvent) bool

	GetSortedOwnerAliases(ctx context.Context) ([]string, error)
	GetOwner(ctx context.Context, ownerAlias string) (openapi.OwnerDto, error)
	WriteOwner(ctx context.Context, ownerAlias string, owner openapi.OwnerDto) (openapi.OwnerDto, error)
	DeleteOwner(ctx context.Context, ownerAlias string, jiraIssue string) (openapi.OwnerPatchDto, error)
	IsOwnerEmpty(ctx context.Context, ownerAlias string) bool

	GetSortedServiceNames(ctx context.Context) ([]string, error)
	GetService(ctx context.Context, serviceName string) (openapi.ServiceDto, error)
	WriteService(ctx context.Context, serviceName string, service openapi.ServiceDto) (openapi.ServiceDto, error)
	DeleteService(ctx context.Context, serviceName string, jiraIssue string) (openapi.ServicePatchDto, error)

	GetSortedRepositoryKeys(ctx context.Context) ([]string, error)
	GetRepository(ctx context.Context, repoKey string) (openapi.RepositoryDto, error)
	WriteRepository(ctx context.Context, repoKey string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)
	DeleteRepository(ctx context.Context, repoKey string, jiraIssue string) (openapi.RepositoryPatchDto, error)

	// WriteServiceWithChangedOwner groups the whole operation into a single commit.
	//
	// A service takes all its referenced repositories along, but unreferenced repositories will be missed and stay.
	// They can be moved as part of a repository update.
	WriteServiceWithChangedOwner(ctx context.Context, serviceName string, service openapi.ServiceDto) (openapi.ServiceDto, error)

	// WriteRepositoryWithChangedOwner groups the whole operation into a single commit.
	//
	// Note that you MUST NOT call this for a repo that is referenced by a service (needs to be verified before
	// calling this). If referenced, the repo can only change owners together with the service.
	// Use WriteServiceWithChangedOwner.
	WriteRepositoryWithChangedOwner(ctx context.Context, repoKey string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)
}

Mapper translates between the git repo representation (yaml) and the business entities.

It also performs commit workflows for the metadata repository.

It also performs the mapping between commit info and kafka messages for newly pulled commits (because this needs knowledge of the internal commit info structures).

Note that you are expected to hold the lock in Updater when you call any of this, so concurrent updates of the local git tree are avoided.

Anyway, Updater should be the only one making calls here, so this should just work.

type Owners

type Owners interface {
	IsOwners() bool

	GetOwners(ctx context.Context) (openapi.OwnerListDto, error)
	GetOwner(ctx context.Context, ownerAlias string) (openapi.OwnerDto, error)

	GetAllGroupMembers(ctx context.Context, groupOwner string, groupName string) []string

	// CreateOwner returns the owner as it was created, with commit hash and timestamp filled in.
	CreateOwner(ctx context.Context, ownerAlias string, ownerDto openapi.OwnerCreateDto) (openapi.OwnerDto, error)

	// UpdateOwner returns the owner as it was committed, with commit hash and timestamp filled in.
	UpdateOwner(ctx context.Context, ownerAlias string, ownerDto openapi.OwnerDto) (openapi.OwnerDto, error)

	// PatchOwner returns the owner as it was committed, with commit hash and timestamp filled in.
	PatchOwner(ctx context.Context, ownerAlias string, ownerPatchDto openapi.OwnerPatchDto) (openapi.OwnerDto, error)

	DeleteOwner(ctx context.Context, ownerAlias string, deletionInfo openapi.DeletionDto) error
}

Owners provides the business logic for owner metadata.

type Repositories

type Repositories interface {
	IsRepositories() bool

	// ValidRepositoryKey checks validity of a repository key and returns an error describing the problem if invalid
	ValidRepositoryKey(ctx context.Context, repoKey string) apierrors.AnnotatedError

	GetRepositories(ctx context.Context,
		ownerAliasFilter string, serviceNameFilter string,
		nameFilter string, typeFilter string) (openapi.RepositoryListDto, error)
	GetRepository(ctx context.Context, repoKey string) (openapi.RepositoryDto, error)

	// CreateRepository returns the repository as it was created, with commit hash and timestamp filled in.
	CreateRepository(ctx context.Context, key string, repositoryDto openapi.RepositoryCreateDto) (openapi.RepositoryDto, error)

	// UpdateRepository returns the repository as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a repository is supported, unless it's still referenced by its service. In that case,
	// move the whole service (including its repositories).
	UpdateRepository(ctx context.Context, key string, repositoryDto openapi.RepositoryDto) (openapi.RepositoryDto, error)

	// PatchRepository returns the repository as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a repository is supported, unless it's still referenced by its service. In that case,
	// move the whole service (including its repositories).
	PatchRepository(ctx context.Context, key string, repositoryPatchDto openapi.RepositoryPatchDto) (openapi.RepositoryDto, error)

	// DeleteRepository will fail if the repo is still referenced by its service. Delete that one first.
	DeleteRepository(ctx context.Context, key string, deletionInfo openapi.DeletionDto) error
}

Repositories provides the business logic for repository metadata.

type Services

type Services interface {
	IsServices() bool

	GetServices(ctx context.Context, ownerAliasFilter string) (openapi.ServiceListDto, error)
	GetService(ctx context.Context, serviceName string) (openapi.ServiceDto, error)

	// CreateService returns the service as it was created, with commit hash and timestamp filled in.
	CreateService(ctx context.Context, serviceName string, serviceDto openapi.ServiceCreateDto) (openapi.ServiceDto, error)

	// UpdateService returns the service as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a service is supported, and will also move any referenced repositories to the new owner.
	UpdateService(ctx context.Context, serviceName string, serviceDto openapi.ServiceDto) (openapi.ServiceDto, error)

	// PatchService returns the service as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a service is supported, and will also move any referenced repositories to the new owner.
	PatchService(ctx context.Context, serviceName string, servicePatchDto openapi.ServicePatchDto) (openapi.ServiceDto, error)

	// DeleteService deletes a service, but leaves its repositories behind
	//
	// Reason: they still need to be configured by bit-brother.
	DeleteService(ctx context.Context, serviceName string, deletionInfo openapi.DeletionDto) error
}

Services provides the business logic for service metadata.

type Trigger

type Trigger interface {
	IsTrigger() bool
}

Trigger triggers update runs in Updater.

Trigger events occur on initial app startup (before it becomes healthy), and periodically

type Updater

type Updater interface {
	IsUpdater() bool

	// StartReceivingEvents starts receiving events. Called by Trigger after it has initially populated the cache.
	StartReceivingEvents(ctx context.Context) error

	// WithMetadataLock is a convenience function that will obtain the lock on the metadata repo, call
	// the closure, and then free the lock.
	//
	// Note that a child context (!) is passed through to your function, so other methods of Updater can know
	// that you are holding the lock at the moment.
	//
	// Any error closure returns is passed through, and the lock is finally released.
	WithMetadataLock(ctx context.Context, closure func(context.Context) error) error

	// PerformFullUpdate is called by Trigger both for initial cache population and periodic updates.
	//
	// It does not send any kafka events - one situation where it might be called is when an event
	// has been received.
	//
	// Both the git tree and all caches are updated.
	PerformFullUpdate(ctx context.Context) error

	// PerformFullUpdateWithNotifications is called when the webhook is triggered.
	//
	// Unlike PerformFullUpdate this version sends out kafka events for any new commits.
	//
	// Both the git tree and all caches are updated.
	PerformFullUpdateWithNotifications(ctx context.Context) error

	// WriteOwner returns the owner as written, with commit hash and timestamp filled in.
	//
	// Sends a kafka event and updates the cache.
	WriteOwner(ctx context.Context, ownerAlias string, validOwnerDto openapi.OwnerDto) (openapi.OwnerDto, error)

	// DeleteOwner deletes an owner.
	//
	// Sends a kafka event and updates the cache.
	DeleteOwner(ctx context.Context, ownerAlias string, deletionInfo openapi.DeletionDto) error

	CanDeleteOwner(ctx context.Context, ownerAlias string) bool

	// WriteService returns the service as written, with commit hash and timestamp filled in.
	//
	// This supports changing the owner.
	//
	// Assumes up-to-date cache.
	//
	// Sends a kafka event and updates the cache.
	WriteService(ctx context.Context, serviceName string, validServiceDto openapi.ServiceDto) (openapi.ServiceDto, error)

	// DeleteService deletes a service.
	//
	// Sends a kafka event and updates the cache.
	DeleteService(ctx context.Context, serviceName string, deletionInfo openapi.DeletionDto) error

	// WriteRepository returns the repository as written, with commit hash and timestamp filled in.
	//
	// This supports changing the owner, unless the repository is referenced by a service, then you should not call this.
	//
	// Assumes up-to-date cache.
	//
	// Sends a kafka event and updates the cache.
	WriteRepository(ctx context.Context, key string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)

	// DeleteRepository deletes a repository.
	//
	// Sends a kafka event and updates the cache.
	DeleteRepository(ctx context.Context, key string, deletionInfo openapi.DeletionDto) error

	// CanMoveOrDeleteRepository checks that no service still references the repository key.
	//
	// Expects a current cache and you must be holding the lock.
	CanMoveOrDeleteRepository(ctx context.Context, key string) bool
}

Updater is the central orchestrator component that manages information flow.

Jump to

Keyboard shortcuts

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