Files
fn-serverless/api/runnerpool/runner_pool.go
Tolga Ceylan 74a5379dec fn: lb & pure-runner slot hash id communication (#1007)
* fn: lb & pure-runner slot hash id communication

With this change, LB can pre-calculate the slot hash
key and pass it to runners. If LB knows/calculates
the slot hash ids, then it can also make better
estimates on which runner can successfully execute
it especially when status messages from runner
include a small summary of idle slots for a given
slot hash id. (TODO)

* fn: fix mock test
2018-05-25 14:12:48 -07:00

51 lines
1.3 KiB
Go

package runnerpool
import (
"context"
"io"
"net/http"
"time"
"github.com/fnproject/fn/api/models"
)
// Placer implements a placement strategy for calls that are load-balanced
// across runners in a pool
type Placer interface {
PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall) error
}
// RunnerPool is the abstraction for getting an ordered list of runners to try for a call
type RunnerPool interface {
Runners(call RunnerCall) ([]Runner, error)
Shutdown(ctx context.Context) error
}
// PKIData encapsulates TLS certificate data
type PKIData struct {
Ca string
Key string
Cert string
}
// MTLSRunnerFactory represents a factory method for constructing runners using mTLS
type MTLSRunnerFactory func(addr, certCommonName string, pki *PKIData) (Runner, error)
// Runner is the interface to invoke the execution of a function call on a specific runner
type Runner interface {
TryExec(ctx context.Context, call RunnerCall) (bool, error)
Close(ctx context.Context) error
Address() string
}
// RunnerCall provides access to the necessary details of request in order for it to be
// processed by a RunnerPool
type RunnerCall interface {
SlotHashId() string
LbDeadline() time.Time
RequestBody() io.ReadCloser
ResponseWriter() http.ResponseWriter
StdErr() io.ReadWriteCloser
Model() *models.Call
}