strawberry

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultActive                 = false
	DefaultFamily                 = "none"
	DefaultStage                  = "production"
	DefaultRestartOnSpecletChange = true
	DefaultMinIncarnationIndex    = -1
)
View Source
const AccessControlNamespacesPath = ypath.Path("//sys/access_control_object_namespaces")
View Source
const (
	StageUntracked = "untracked"
)

Variables

View Source
var CypressStateAttributes = []string{
	"strawberry_persistent_state",
	"strawberry_info_state",
	"revision",
	"creation_time",
	"modification_time",
	"value",
}

Functions

func ExecuteTemplate added in v0.0.2

func ExecuteTemplate(templateString string, data any) string

func GetOpBriefAttributes added in v0.0.4

func GetOpBriefAttributes(briefInfo OpletBriefInfo) map[string]any

GetOpBriefAttributes returns map with strawberry attributes, which can be requested from API.

func ToYsonURL

func ToYsonURL(value any) any

Types

type AgentInfo

type AgentInfo struct {
	StrawberryRoot     ypath.Path
	Hostname           string
	Stage              string
	Proxy              string
	Family             string
	OperationNamespace string
	// RobotUsername is needed for a temporary workaround to add the robot to the operation acl.
	//
	// TODO(dakovalkov): remove after YT-17557
	RobotUsername         string
	DefaultNetworkProject *string
	ClusterURL            string
}

AgentInfo contains information about the Agent which is needed in Oplet.

type ClusterInitializer

type ClusterInitializer interface {
	// InitializeCluster does all the custom cluster initialization.
	InitializeCluster() error

	// ACONamespace is an identifier for the access control nodes namespace.
	ACONamespace() string
}

type ClusterInitializerFactory

type ClusterInitializerFactory = func(l log.Logger, ytc yt.Client, root ypath.Path) ClusterInitializer

type Controller

type Controller interface {
	// Prepare builds all necessary operation spec fields.
	Prepare(ctx context.Context, oplet *Oplet) (
		spec map[string]any,
		description map[string]any,
		annotation map[string]any,
		err error)

	// Family returns short lowercase_with_underscore identifier which is included to all vanilla
	// operation annotations started by this strawberry controller. This allows efficient operation
	// filtering using YT list_operations API.
	Family() string

	// Root returns path to the cypress directory containing strawberry nodes.
	Root() ypath.Path

	ParseSpeclet(specletYson yson.RawValue) (parsedSpeclet any, err error)

	// UpdateState updates the controller's state.
	// Returns true if the state has been changed and all oplets should be restarted.
	UpdateState() (changed bool, err error)

	// DescribeOptions returns human-readable descriptors for controller-related speclet options.
	// Some options can be missing in the result if they are not intended to be visible through user interfaces.
	//
	// Given speclet should have suitable type for the specific controller.
	// Otherwise, DescribeOptions may panic.
	DescribeOptions(parsedSpeclet any) []OptionGroupDescriptor

	// GetOpBriefAttributes returns map with controller-related speclet options,
	// which can be requested from API.
	//
	// Given speclet should have suitable type for the specific controller.
	// Otherwise, GetOpBriefAttributes may panic.
	GetOpBriefAttributes(parsedSpeclet any) map[string]any
}

Controller encapsulates particular application business logic, in particular: how operations should be started, which files to bring with them, how to check liveness, etc.

type ControllerFactory

type ControllerFactory struct {
	Ctor   func(l log.Logger, ytc yt.Client, root ypath.Path, cluster string, config yson.RawValue) Controller
	Config yson.RawValue
	// TODO(max): extra commands is actually of type []api.CmdDescriptor, but we can't import it here
	// without creating a circular dependency. Come up with a better solution.
	ExtraCommands any
}

type FieldDiff

type FieldDiff struct {
	OldValue any `yson:"old_value" json:"old_value"`
	NewValue any `yson:"new_value" json:"new_value"`
}

type InfoState

type InfoState struct {
	Error      *string `yson:"error,omitempty"`
	Controller struct {
		Address string `yson:"address"`
	} `yson:"controller"`

	YTOpStartTime  yson.Time `yson:"yt_op_start_time,omitempty"`
	YTOpFinishTime yson.Time `yson:"yt_op_finish_time,omitempty"`
}

InfoState contains fields which are useful for understanding the current status of the oplet, but they are not used by an agent itself and so they are not a part of the persistent state.

type Oplet

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

func NewOplet

func NewOplet(options OpletOptions) *Oplet

func (*Oplet) Active

func (oplet *Oplet) Active() bool

func (*Oplet) Alias

func (oplet *Oplet) Alias() string

func (*Oplet) Broken

func (oplet *Oplet) Broken() bool

func (*Oplet) BrokenError added in v0.0.7

func (oplet *Oplet) BrokenError() error

func (*Oplet) BrokenReason added in v0.0.7

func (oplet *Oplet) BrokenReason() string

func (*Oplet) CheckOperationLiveness

func (oplet *Oplet) CheckOperationLiveness(ctx context.Context) error

func (*Oplet) ControllerSpeclet

func (oplet *Oplet) ControllerSpeclet() any

func (*Oplet) CypAnnotation

func (oplet *Oplet) CypAnnotation() string

func (*Oplet) CypressNode

func (oplet *Oplet) CypressNode() ypath.Path

func (*Oplet) EnsureOperationInValidState

func (oplet *Oplet) EnsureOperationInValidState(ctx context.Context) error

func (*Oplet) EnsurePersistentStateFlushed

func (oplet *Oplet) EnsurePersistentStateFlushed(ctx context.Context) (err error)

func (*Oplet) EnsureUpdatedFromCypress

func (oplet *Oplet) EnsureUpdatedFromCypress(ctx context.Context) error

func (*Oplet) GetBriefInfo added in v0.0.7

func (oplet *Oplet) GetBriefInfo() (briefInfo OpletBriefInfo)

GetBriefInfo should work even if oplet is broken.

func (*Oplet) HasYTOperation

func (oplet *Oplet) HasYTOperation() bool

func (*Oplet) Health added in v0.0.7

func (oplet *Oplet) Health() (health OpletHealth, healthReason string)

func (*Oplet) Inappropriate

func (oplet *Oplet) Inappropriate() bool

Inappropriate returns |true| whenever the oplet does not belong to provided agent.

func (*Oplet) LoadFromYsonNode added in v0.0.7

func (oplet *Oplet) LoadFromYsonNode(node yson.RawValue, acl []yt.ACE) error

func (*Oplet) NextIncarnationIndex

func (oplet *Oplet) NextIncarnationIndex() int

func (*Oplet) OnCypressNodeChanged

func (oplet *Oplet) OnCypressNodeChanged()

func (*Oplet) OpAnnotations

func (oplet *Oplet) OpAnnotations() map[string]any

func (*Oplet) OpDescription

func (oplet *Oplet) OpDescription() map[string]any

func (*Oplet) OperationInfo

func (oplet *Oplet) OperationInfo() (yt.OperationID, yt.OperationState)

func (*Oplet) Pass

func (oplet *Oplet) Pass(ctx context.Context) error

func (*Oplet) SetACL

func (oplet *Oplet) SetACL(acl []yt.ACE)

func (*Oplet) SetPendingRestart

func (oplet *Oplet) SetPendingRestart(reason string)

TODO(dakovalkov): eliminate this.

func (*Oplet) State added in v0.0.7

func (oplet *Oplet) State() OpletState

func (*Oplet) StrawberrySpeclet

func (oplet *Oplet) StrawberrySpeclet() Speclet

func (*Oplet) Untracked added in v0.0.7

func (oplet *Oplet) Untracked() bool

func (*Oplet) UpToDateWithCypress

func (oplet *Oplet) UpToDateWithCypress() bool

func (*Oplet) UpdateACLFromNode

func (oplet *Oplet) UpdateACLFromNode(ctx context.Context) error

type OpletBriefInfo added in v0.0.7

type OpletBriefInfo struct {
	State                           OpletState           `yson:"state" json:"state"`
	Health                          OpletHealth          `yson:"health" json:"health"`
	HealthReason                    string               `yson:"health_reason" json:"health_reason"`
	SpecletDiff                     map[string]FieldDiff `yson:"speclet_diff,omitempty" json:"speclet_diff,omitempty"`
	YTOperation                     YTOperationBriefInfo `yson:"yt_operation,omitempty" json:"yt_operation,omitempty"`
	Creator                         string               `yson:"creator,omitempty" json:"creator,omitempty"`
	Pool                            string               `yson:"pool,omitempty" json:"pool,omitempty"`
	Stage                           string               `yson:"stage" json:"stage"`
	CreationTime                    *yson.Time           `yson:"creation_time,omitempty" json:"creation_time,omitempty"`
	StrawberryStateModificationTime *yson.Time           `yson:"strawberry_state_modification_time,omitempty" json:"strawberry_state_modification_time,omitempty"`
	SpecletModificationTime         *yson.Time           `yson:"speclet_modification_time,omitempty" json:"speclet_modification_time,omitempty"`
	IncarnationIndex                int                  `yson:"incarnation_index" json:"incarnation_index"`
	CtlAttributes                   map[string]any       `yson:"ctl_attributes" json:"ctl_attributes"`
	Error                           string               `yson:"error,omitempty" json:"error,omitempty"`
}

type OpletHealth added in v0.0.7

type OpletHealth string
const (
	OpletHealthGood    OpletHealth = "good"
	OpletHealthPending OpletHealth = "pending"
	OpletHealthFailed  OpletHealth = "failed"
)

type OpletOptions

type OpletOptions struct {
	AgentInfo
	Alias        string
	Controller   Controller
	Logger       log.Logger
	UserClient   yt.Client
	SystemClient yt.Client
}

type OpletState

type OpletState string
const (
	OpletStateActive    OpletState = "active"
	OpletStateInactive  OpletState = "inactive"
	OpletStateUntracked OpletState = "untracked"
)

type OptionDescriptor added in v0.0.4

type OptionDescriptor struct {
	Title        string     `yson:"title" json:"title"`
	Name         string     `yson:"name" json:"name"`
	Type         OptionType `yson:"type" json:"type"`
	CurrentValue any        `yson:"current_value,omitempty" json:"current_value,omitempty"`
	DefaultValue any        `yson:"default_value,omitempty" json:"default_value,omitempty"`
	MinValue     any        `yson:"min_value,omitempty" json:"min_value,omitempty"`
	MaxValue     any        `yson:"max_value,omitempty" json:"max_value,omitempty"`
	Choices      []any      `yson:"choices,omitempty" json:"choices,omitempty"`
	Description  string     `yson:"description,omitempty" json:"description,omitempty"`
}

type OptionGroupDescriptor added in v0.0.4

type OptionGroupDescriptor struct {
	Title   string             `yson:"title" json:"title"`
	Options []OptionDescriptor `yson:"options" json:"options"`

	// Hidden indicates that the option group consists of non-important or rarely used options
	// and these options should be hidden in UI if possible (e.g. under a cut element).
	Hidden bool `yson:"hidden" json:"hidden"`
}

func DescribeOptions added in v0.0.4

func DescribeOptions(a AgentInfo, speclet Speclet) []OptionGroupDescriptor

type OptionType added in v0.0.4

type OptionType string
const (
	TypeBool      OptionType = "bool"
	TypeString    OptionType = "string"
	TypeInt64     OptionType = "int64"
	TypeYson      OptionType = "yson"
	TypePath      OptionType = "path"
	TypePool      OptionType = "pool"
	TypeByteCount OptionType = "byte_count"
)

type PersistentState

type PersistentState struct {
	YTOpID    yt.OperationID    `yson:"yt_operation_id"`
	YTOpState yt.OperationState `yson:"yt_operation_state"`

	IncarnationIndex int `yson:"incarnation_index"`

	// YTOpSpeclet is an unparsed speclet with which current yt operation is started.
	YTOpSpeclet yson.RawValue `yson:"yt_op_strawberry_speclet,omitempty"`
	// YTOpSpecletRevision is a revision of the speclet node with which current yt operation is started.
	YTOpSpecletRevision yt.Revision `yson:"yt_op_speclet_revision,omitempty"`
	// YTOpACL is the last set ACL of the current yt operation.
	YTOpACL []yt.ACE `yson:"yt_op_acl,omitempty"`
	// YTOpPool is the last set pool of the current yt operation.
	YTOpPool *string `yson:"yt_op_pool,omitempty"`

	// SpecletRevision is a revision of the last seen speclet node.
	SpecletRevision yt.Revision `yson:"speclet_revision"`

	// BackoffDuration is a duration during which oplet passes will be skipped after a failed pass.
	// It is increased after every failed pass and is reset after an successful pass.
	BackoffDuration time.Duration `yson:"backoff_duration"`
	// BackoffUntil is a time point until which oplet passes will be skipped due to previously failed passes.
	BackoffUntil time.Time `yson:"backoff_until"`

	// Creator is a user who created the strawberry operation.
	// Creator will automatically gain access to the strawberry operation when the access control object is created.
	Creator string `yson:"creator"`
}

PersistentState contains a part of agent's state which should be persistent in a cypress. It is written to the cypress when changed and is read from the cypress when the cypress revision is changed. The persistence of the state is needed for fault tolerance.

type RestartRequiredOptions

type RestartRequiredOptions struct {
	Stage          *string      `yson:"stage"`
	NetworkProject *string      `yson:"network_project"`
	PreemptionMode *string      `yson:"preemption_mode"`
	LayerPaths     []ypath.Path `yson:"layer_paths"`
}

Change of these parameters leads to operation restart.

type Speclet

type Speclet struct {
	RestartRequiredOptions
	Active                 *bool   `yson:"active"`
	Family                 *string `yson:"family"`
	RestartOnSpecletChange *bool   `yson:"restart_on_speclet_change"`
	// MinSpecletRevision is a minimum speclet revision with which an operation does not require a force restart.
	// If the speclet revision of the running yt operation is less than that,
	// it will be restarted despite the RestartOnSpecletChange option.
	MinSpecletRevision yt.Revision `yson:"min_speclet_revision"`

	Pool *string `yson:"pool"`
}

func ParseSpeclet added in v0.0.4

func ParseSpeclet(specletYson yson.RawValue) (Speclet, error)

func (*Speclet) ActiveOrDefault

func (speclet *Speclet) ActiveOrDefault() bool

func (*Speclet) FamilyOrDefault

func (speclet *Speclet) FamilyOrDefault() string

func (*Speclet) RestartOnSpecletChangeOrDefault

func (speclet *Speclet) RestartOnSpecletChangeOrDefault() bool

func (*Speclet) StageOrDefault

func (speclet *Speclet) StageOrDefault() string

type YTOperationBriefInfo added in v0.0.7

type YTOperationBriefInfo struct {
	ID         yt.OperationID    `yson:"id,omitempty" json:"id,omitempty"`
	URL        string            `yson:"url,omitempty" json:"url,omitempty"`
	State      yt.OperationState `yson:"state,omitempty" json:"state,omitempty"`
	StartTime  *yson.Time        `yson:"start_time,omitempty" json:"start_time,omitempty"`
	FinishTime *yson.Time        `yson:"finish_time,omitempty" json:"finish_time,omitempty"`
}

Jump to

Keyboard shortcuts

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