muxer

package module
v0.0.0-...-18a6489 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const SchemaVersion int32 = 0

The version expected to be specified by GetSchema

Variables

This section is empty.

Functions

This section is empty.

Types

type DispatchTable

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

func MergeSchemasAndComputeDispatchTable

func MergeSchemasAndComputeDispatchTable(schemas []schema.PackageSpec) (DispatchTable, schema.PackageSpec, error)

type Endpoint

type Endpoint struct {
	Server func(*provider.HostClient) (rpc.ResourceProviderServer, error)
}

type GetMappingArgs

type GetMappingArgs interface {
	Fetch() []GetMappingResponse
}

type GetMappingResponse

type GetMappingResponse struct {
	Provider string
	Data     []byte
}

type Main

type Main struct {
	Servers []Endpoint

	// An optional pre-computed mapping of functions/resources to servers.
	DispatchTable DispatchTable

	// An optional pre-computed schema. If not provided, then the schema will be
	// derived from layering underlying server schemas.
	//
	// If set, DispatchTable must also be set.
	Schema string

	GetMappingHandler map[string]MultiMappingHandler
}

Mux multiple rpc servers into a single server by routing based on request type and urn.

Most rpc methods are resolved via a schema lookup based precomputed mapping created when the Muxer is initialized, with earlier servers getting priority.

For example:

Given server s1 serving resources r1, r2 and server s2 serving r1, r3, the muxer
m1 := Mux(host, s1, s2) will dispatch r1 and r2 to s1. m1 will dispatch only r3 to
s2.  If we swap the order of of creation: m2 := Mux(host, s2, s1) we see different
prioritization. m2 will serve r1 and r3 to s2, only serving r2 to s1.

Most methods are fully dispatch based:

  • Create, Read, Update, Delete, Check, Diff: The type is extracted from the URN associated with the request. The server who's schema provided the resource is routed the whole request.

  • Construct: The type token is passed directly. The server who's schema provided the resource is routed the whole request.

  • Invoke, StreamInvoke, Call: The type token is passed directly. The server who's schema provided the function is routed the whole request.

Each provider specifies in it's schema what options it accepts as configuration. Config based endpoints filter the schema so each provider is only shown keys that it expects to see. It is possible for multiple subsidiary providers to accept the same key.

  • CheckConfig: Broadcast to each server. Any diffs between returned results errors.

  • DiffConfig: Broadcast to each server. Results are then merged with the most drastic action dominating.

  • Configure: Broadcast to each server for individual configuration. When computing the returned set of capabilities, each option is set to the AND of the subsidiary servers. This means that the Muxed server is only as capable as the least capable of its subsidiaries.

A dispatch strategy doesn't make sense for methods related to the provider as a whole. The following methods are broadcast to all providers:

  • Cancel: Each server receives a cancel request.

The remaining methods are treated specially by the Muxed server:

  • GetSchema: When Mux is called, GetSchema is called once on each server. The muxer merges each schema with earlier servers overriding later servers. The origin of each resource and function in the presented schema is remembered and used to route later resource and function requests.

  • Attach: `Attach` is never called on Muxed providers. Instead the host passed into `Mux` is replaced. If subsidiary servers where constructed with the same `host` as passed to `Mux`, then they will observe the new `host` spurred by `Attach`.

  • GetMapping: `GetMapping` dispatches on all underlerver Servers. If zero or 1 server responds with a non-empty data section, we call GetMappingHandler[Key] to merge the data sections, where Key is the key given in the GetMappingRequest.

func (Main) Server

func (m Main) Server(host *provider.HostClient, module, version string) (pulumirpc.ResourceProviderServer, error)

type MultiMappingHandler

type MultiMappingHandler = func(GetMappingArgs) (GetMappingResponse, error)

Jump to

Keyboard shortcuts

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