operation

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultOperatorWorkerCount is how many workers to run. The number of
	// parallel operations is limited to the number of workers.
	DefaultOperatorWorkerCount int32 = 4
	// DefaultOperatorMaxOperationQueue is default maximum number of queued
	// operations.
	DefaultOperatorMaxOperationQueue = 10000
	// DefaultOperatorMaxOperationEventQueue is the maximum number of events
	// that can be queued before being persisted in the state by the event
	// handler.
	DefaultOperatorMaxOperationEventQueue = 1000
)

Functions

func EventDebugArgs

func EventDebugArgs(event *pb.Operation_Event) []any

EventDebugArgs takes a reference to an operation event and returns a slice of arguments that can be passed ton an hclog.Logger instance for debugging.

func EventTypeString

func EventTypeString(event *pb.Operation_Event) string

EventTypeString takes a reference to an operation event and returns the type of event as a string.

func NewEventFromResponse

func NewEventFromResponse(res *pb.Operation_Response) (*pb.Operation_Event, error)

NewEventFromResponse takes a reference to an operation response and returns a reference to a new operation event. If an error is encountered it will return an event that contains diagnostics of the error as well as an error if possible.

func NewReferenceFromRequest

func NewReferenceFromRequest(op *pb.Operation_Request) (*pb.Ref_Operation, error)

NewReferenceFromRequest takes a reference to an operation request and returns a new reference to the associated operation.

func NewResponseFromRequest

func NewResponseFromRequest(op *pb.Operation_Request) (*pb.Operation_Response, error)

NewResponseFromRequest takes a reference for an operation request and returns a reference to a new operation response.

func ReferenceDebugArgs

func ReferenceDebugArgs(ref *pb.Ref_Operation) []any

ReferenceDebugArgs takes a reference to an operation reference and returns a slice of arguments that can be passed ton an hclog.Logger instance for debugging.

func RequestDebugArgs

func RequestDebugArgs(req *pb.Operation_Request) []any

RequestDebugArgs takes a reference to an operation request and returns a slice of arguments that can be passed ton an hclog.Logger instance for debugging.

func RequestTypeString

func RequestTypeString(op *pb.Operation_Request) string

RequestTypeString takes a reference to an operation request and returns the type of request as a string.

func ResponseDebugArgs

func ResponseDebugArgs(res *pb.Operation_Response) []any

ResponseDebugArgs takes a reference to an operation response and returns a slice of arguments that can be passed ton an hclog.Logger instance for debugging.

func ResponseTypeString

func ResponseTypeString(op *pb.Operation_Response) string

ResponseTypeString takes a reference to an operation response and returns the type of response as a string.

Types

type EventSender

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

func NewEventSender

func NewEventSender(events chan *pb.Operation_Event) *EventSender

func (*EventSender) Publish

func (e *EventSender) Publish(event *pb.Operation_Event) error

func (*EventSender) PublishResponse

func (e *EventSender) PublishResponse(res *pb.Operation_Response) error

type LocalOperator

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

LocalOperator is an in-memory implementation of the server Operator.

func NewLocalOperator

func NewLocalOperator(opts ...LocalOperatorOpt) *LocalOperator

NewLocalOperator returns a new instance of a LocalOperator.

func (*LocalOperator) Dispatch

func (o *LocalOperator) Dispatch(
	req *pb.Operation_Request,
) (
	*pb.Ref_Operation,
	[]*pb.Diagnostic,
)

Dispatch takes an operation request and attempts to dispatch it for execution by the operators worker pool. If the request is successfully converted into a work operation and queued it will return a reference for the operation to the caller.

func (*LocalOperator) Response

Response takes a reference to an operation and returns the response. If no response is found nil will be returned.

func (*LocalOperator) Start

func (o *LocalOperator) Start(ctx context.Context) error

Start starts the operator.

func (*LocalOperator) State

func (o *LocalOperator) State() state.State

State returns the operators state.

func (*LocalOperator) Stop

func (o *LocalOperator) Stop() error

Stop stops the operator. It attempts to gracefully terminate all operations.

func (*LocalOperator) Stream

Stream takes a reference to an operation and returns an event subscriber for the operation, an unsubscriber function, and an error. The subscriber can be used to publish and receive events from the event stream. When the unsubscriber function is called the operators event handler will stop publishing events to the subscriber.

type LocalOperatorOpt

type LocalOperatorOpt func(*LocalOperator)

LocalOperatorOpt is a functional option to configure a new LocalOperator.

func WithLocalOperatorConfig

func WithLocalOperatorConfig(cfg *pb.Operator_Config) LocalOperatorOpt

WithLocalOperatorConfig takes the operator configuration and sets it on the local operator.

func WithLocalOperatorLog

func WithLocalOperatorLog(log hclog.Logger) LocalOperatorOpt

WithLocalOperatorLog is a log setter for a new LocalOperator.

func WithLocalOperatorState

func WithLocalOperatorState(s state.State) LocalOperatorOpt

WithLocalOperatorState is a state setter for a new LocalOperator.

type Operator

type Operator interface {
	Dispatch(req *pb.Operation_Request) (*pb.Ref_Operation, []*pb.Diagnostic)
	Stream(ref *pb.Ref_Operation) (*Subscriber, Unsubscriber, error)
	Response(ref *pb.Ref_Operation) (*pb.Operation_Response, error)
	Stop() error
	Start(ctx context.Context) error
	State() state.State
}

Operator is the server operation handler.

type Publisher

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

Publisher is the operation event publisher.

func NewPublisher

func NewPublisher(opts ...PublisherOpt) *Publisher

NewPublisher returns a new instance of the publisher.

func (*Publisher) Publish

func (p *Publisher) Publish(event *pb.Operation_Event) error

Publish publishes an operation event to listeners for the operationID.

func (*Publisher) Stop

func (p *Publisher) Stop()

Stop closes all subscribers and removes and clears the subscribers list.

func (*Publisher) Subscribe

func (p *Publisher) Subscribe(s *Subscriber) Unsubscriber

Subscribe adds a new subscribers for the operation and returns a closer function.

func (*Publisher) Unsubscribe

func (p *Publisher) Unsubscribe(s *Subscriber)

Unsubscribe unsubscribes a subscriber.

type PublisherOpt

type PublisherOpt func(*Publisher)

PublisherOpt is a NewPublisher option.

func WithPublisherLog

func WithPublisherLog(log hclog.Logger) PublisherOpt

WithPublisherLog sets the logger on the publisher.

type Runner

type Runner struct {
	TFConfig *terraform.Config
	Module   *pb.Terraform_Module
	// contains filtered or unexported fields
}

Runner is a Terraform command runner.

func NewRunner

func NewRunner(opts ...RunnerOpt) *Runner

NewRunner takes options and returns a new validated generator.

type RunnerOpt

type RunnerOpt func(*Runner)

RunnerOpt is a validate module option.

func WithLogger

func WithLogger(log hclog.Logger) RunnerOpt

WithLogger sets the logger.

func WithRunnerTerraformConfig

func WithRunnerTerraformConfig(cfg *pb.Terraform_Runner_Config) RunnerOpt

WithRunnerTerraformConfig configures the Runner with RunnerConfig passed over the wire.

type Subscriber

type Subscriber struct {
	ID string

	Events chan *pb.Operation_Event
	// contains filtered or unexported fields
}

Subscriber is an event subscriber.

func NewSubscriber

func NewSubscriber(
	ref *pb.Ref_Operation,
	opts ...SubscriberOpt,
) (
	*Subscriber,
	error,
)

NewSubscriber takes an operation request and returns a new subscriber instance.

func (*Subscriber) Close

func (s *Subscriber) Close()

Close closes the subscribers.

func (*Subscriber) Send

func (s *Subscriber) Send(event *pb.Operation_Event)

Send sends an event to the subscribers event channel. Send will block until something pulls from the events channel.

type SubscriberOpt

type SubscriberOpt func(*Subscriber)

SubscriberOpt is a new subscriber option.

func WithSubscriberLog

func WithSubscriberLog(log hclog.Logger) SubscriberOpt

WithSubscriberLog sets the subscriber logger.

type Subscribers

type Subscribers map[string]*Subscriber

Subscribers are operation event subscribers.

type TextOutput

type TextOutput struct {
	Stdout io.Writer
	Stderr *strings.Builder
}

TextOutput is a terraform text output collector.

func NewTextOutput

func NewTextOutput() *TextOutput

NewTextOutput returns a new TextOutput.

type Unsubscriber

type Unsubscriber func()

Unsubscriber is a func that unsubscribes that subscriber from the publisher.

type WorkFunc

type WorkFunc func(
	context.Context,
	chan *pb.Operation_Event,
	hclog.Logger,
) *pb.Operation_Response

WorkFunc is a function that a worker can run.

func CheckScenario

func CheckScenario(req *pb.Operation_Request) WorkFunc

CheckScenario takes an operation request for check and returns a worker function to checks a scenario terraform module.

func DestroyScenario

func DestroyScenario(req *pb.Operation_Request) WorkFunc

func DestroyScenario takes an operation request for generate and returns a worker function to generate a terraform module for a scenario.

func ExecScenario

func ExecScenario(req *pb.Operation_Request) WorkFunc

func ExecScenario takes an operation request for generate and returns a worker function to generate a terraform module for a scenario.

func GenerateScenario

func GenerateScenario(req *pb.Operation_Request) WorkFunc

GenerateScenario takes an operation request for generate and returns a worker function to generate a terraform module for a scenario.

func LaunchScenario

func LaunchScenario(req *pb.Operation_Request) WorkFunc

LaunchScenario takes an operation request for check and returns a worker function to checks a scenario terraform module.

func OutputScenario

func OutputScenario(req *pb.Operation_Request) WorkFunc

func OutputScenario takes an operation request for generate and returns a worker function to generate a terraform module for a scenario.

func RunScenario

func RunScenario(req *pb.Operation_Request) WorkFunc

RunScenario takes an operation request for generate and returns a worker function to generate a terraform module for a scenario.

func UnknownWorkFunc

func UnknownWorkFunc(req *pb.Operation_Request) (WorkFunc, error)

UnknownWorkFunc takes an operation request and returns a work func that will fail because it is unknown.

Directories

Path Synopsis
format
Package format provides functions for formatting Terraform and cty as text.
Package format provides functions for formatting Terraform and cty as text.

Jump to

Keyboard shortcuts

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