prjmanager

package
v0.0.0-...-c2c6062 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package prjmanager implements public API for Project Manager.

The Project Manager keeps track of the LUCI Project config, incomplete Runs, and CLs in flight, and notifies Runs when the project config changes.

Index

Constants

View Source
const (
	// ProjectKind is the Datastore entity kind for Project.
	ProjectKind = "Project"
	// ProjectLogKind is the Datastore entity kind for ProjectLog.
	ProjectLogKind = "ProjectLog"
)

Variables

This section is empty.

Functions

func EventboxRecipient

func EventboxRecipient(ctx context.Context, luciProject string) eventbox.Recipient

EventboxRecipient returns eventbox.Recipient for a given LUCI project.

Types

type Notifier

type Notifier struct {
	// TasksBinding are used to register handlers of Project Manager Implementation & CL Purger to
	// avoid circular dependency.
	TasksBinding prjpb.TasksBinding
}

Notifier notifies Project Manager.

func NewNotifier

func NewNotifier(tqd *tq.Dispatcher) *Notifier

NewNotifier creates a new Project Manager notifier and registers it in the provided tq.Dispatcher.

func (*Notifier) NotifyCLsUpdated

func (n *Notifier) NotifyCLsUpdated(ctx context.Context, luciProject string, cls *changelist.CLUpdatedEvents) error

NotifyCLsUpdated tells Project Manager to check latest versions of the given CLs.

func (*Notifier) NotifyPurgeCompleted

func (n *Notifier) NotifyPurgeCompleted(ctx context.Context, luciProject string, purgingCL *prjpb.PurgingCL) error

NotifyPurgeCompleted tells Project Manager that a CL purge has completed.

The ultimate result of CL purge is the updated state of a CL itself, thus no information is provided here.

func (*Notifier) NotifyRunCreated

func (n *Notifier) NotifyRunCreated(ctx context.Context, runID common.RunID) error

NotifyRunCreated is sent by Project Manager to itself within a Run creation transaction.

Unlike other event-sending of Notifier, this one only creates an event and doesn't create a task. This is fine because:

  • if Run creation transaction fails, then this event isn't actually created anyways.
  • if Project Manager observes the Run creation success, then it'll act as if this event was received in the upcoming state transition. Yes, it won't process this event immediately, but at this point the event is a noop, so it'll be cleared out from the eventbox upon next invocation of Project Manager. So there is no need to create a TQ task.
  • else, namely Run creation succeeds but Project Manager sees it as a failure OR Project Manager fails at any point before it can act on RunCreation, then the existing TQ task running Project Manager will be retried. So once again there is no need to create a TQ task.

func (*Notifier) NotifyRunFinished

func (n *Notifier) NotifyRunFinished(ctx context.Context, runID common.RunID, status run.Status) error

NotifyRunFinished tells Project Manager that a run has finalized its state.

func (*Notifier) NotifyTriggeringCLDepsCompleted

func (n *Notifier) NotifyTriggeringCLDepsCompleted(ctx context.Context, luciProject string, event *prjpb.TriggeringCLDepsCompleted) error

NotifyTriggeringCLDepsCompleted tells Project Manager CL deps trigger completion.

func (*Notifier) Poke

func (n *Notifier) Poke(ctx context.Context, luciProject string) error

Poke tells Project Manager to poke all downstream actors and check its own state.

func (*Notifier) SendNow

func (n *Notifier) SendNow(ctx context.Context, luciProject string, e *prjpb.Event) error

SendNow sends the event to Project's eventbox and invokes Project Manager immediately.

func (*Notifier) UpdateConfig

func (n *Notifier) UpdateConfig(ctx context.Context, luciProject string) error

UpdateConfig tells Project Manager to read and update to newest ProjectConfig by fetching it from Datatstore.

Results in stopping Project Manager if ProjectConfig got disabled or deleted.

type Project

type Project struct {

	// ID is LUCI project name.
	ID string `gae:"$id"`

	// EVersion is entity version. Every update should increment it by 1.
	EVersion int64 `gae:",noindex"`
	// UpdateTime is exact time of when this entity was last updated.
	//
	// It's not indexed to avoid hot areas in the index.
	UpdateTime time.Time `gae:",noindex"`

	// State serializes internal Project Manager state.
	//
	// The `LuciProject` field isn't set as it duplicates Project.ID.
	State *prjpb.PState
	// contains filtered or unexported fields
}

Project is an entity per LUCI Project in Datastore.

func Load

func Load(ctx context.Context, luciProject string) (*Project, error)

Load loads LUCI project state from Datastore.

If project doesn't exist in Datastore, returns nil, nil.

func (*Project) ConfigHash

func (p *Project) ConfigHash() string

ConfigHash returns Project's Config hash.

func (*Project) IncompleteRuns

func (p *Project) IncompleteRuns() (ids common.RunIDs)

IncompleteRuns are IDs of Runs which aren't yet completed.

func (*Project) Status

func (p *Project) Status() prjpb.Status

Status returns Project Manager status.

type ProjectLog

type ProjectLog struct {
	Project *datastore.Key `gae:"$parent"`
	// EVersion and other fields are the same as the Project & ProjectStateOffload
	// entities written at the same time.
	EVersion   int64        `gae:"$id"`
	Status     prjpb.Status `gae:",noindex"`
	ConfigHash string       `gae:",noindex"`
	UpdateTime time.Time    `gae:",noindex"`
	State      *prjpb.PState

	// Reasons records why this Log entity was written.
	//
	// There can be more than one, all of which will be indexed.
	Reasons []prjpb.LogReason `gae:"reason"`
	// contains filtered or unexported fields
}

ProjectLog stores historic state of a project.

type ProjectStateOffload

type ProjectStateOffload struct {
	Project *datastore.Key `gae:"$parent"`
	// ID is alaways the same, set/read only by the datastore ORM.
	ID string `gae:"$id,const"`

	// Status of the project {STARTED, STOPPING, STOPPED (disabled)}.
	Status prjpb.Status `gae:",noindex"`
	// ConfigHash is the latest processed Project Config hash.
	ConfigHash string `gae:",noindex"`

	// UpdateTime is the last time the entity was modifed.
	UpdateTime time.Time `gae:",noindex"`
	// contains filtered or unexported fields
}

ProjectStateOffload stores rarely-changed project state duplicated from the main Project entity for use in transactions creating Runs.

Although this is already stored in the main Project entity, doing so would result in retries of Run creation transactions, since Project entity is frequently modified in busy projects.

On the other hand, ProjectStateOffload is highly likely to remain unchanged by the time Run creation transaction commits, thus avoiding needless retries.

Directories

Path Synopsis
Package clpurger purges CLs with a trigger for which Runs can't be started.
Package clpurger purges CLs with a trigger for which Runs can't be started.
Package cltriggerer implements logic for triggering CLs.
Package cltriggerer implements logic for triggering CLs.
Package copyonwrite providers helpers for modifying slices in Copy-on-Write way.
Package copyonwrite providers helpers for modifying slices in Copy-on-Write way.
Package itriager defines interface of a CL component triage process.
Package itriager defines interface of a CL component triage process.
Package manager implements a ProjectManager.
Package manager implements a ProjectManager.
Package pmtest implements tests for working with Project Manager.
Package pmtest implements tests for working with Project Manager.
Package prjpb stores protos for event processing of ProjectManager.
Package prjpb stores protos for event processing of ProjectManager.
Package state implements state machine of a Project Manager.
Package state implements state machine of a Project Manager.
Package triager proposes concrete actions on a group of related CLs.
Package triager proposes concrete actions on a group of related CLs.

Jump to

Keyboard shortcuts

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