snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
174
server/pkg/envoy/builder.go
Normal file
174
server/pkg/envoy/builder.go
Normal file
@@ -0,0 +1,174 @@
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
|
||||
)
|
||||
|
||||
type (
|
||||
builder struct {
|
||||
pp []Preparer
|
||||
|
||||
reportMissingRefs bool
|
||||
}
|
||||
|
||||
Stream struct {
|
||||
Source io.Reader
|
||||
Resource string
|
||||
Identifier string
|
||||
}
|
||||
|
||||
Preparer interface {
|
||||
Prepare(ctx context.Context, ee ...*ResourceState) error
|
||||
}
|
||||
|
||||
// Encoder encodes all resources provided by the Rc until nil is passed
|
||||
//
|
||||
// Encoding errors are passed via Ec.
|
||||
Encoder interface {
|
||||
Encode(ctx context.Context, p Provider) error
|
||||
}
|
||||
|
||||
// Streamer provides a set of streams of encoded documents
|
||||
Streamer interface {
|
||||
Stream() []*Stream
|
||||
}
|
||||
|
||||
PrepareEncoder interface {
|
||||
Preparer
|
||||
Encoder
|
||||
}
|
||||
PrepareEncodeStreamer interface {
|
||||
Preparer
|
||||
Encoder
|
||||
Streamer
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
BuilderErrUnresolvedReferences = fmt.Errorf("builder error: unresolved references")
|
||||
)
|
||||
|
||||
func NewBuilder(pp ...Preparer) *builder {
|
||||
return &builder{
|
||||
pp: pp,
|
||||
}
|
||||
}
|
||||
|
||||
func NewSafeBuilder(pp ...Preparer) *builder {
|
||||
return &builder{
|
||||
pp: pp,
|
||||
reportMissingRefs: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Build builds the graph that is used for structured data processing
|
||||
//
|
||||
// Outline:
|
||||
// 1. Build an initial graph so that we can do some structured preprocessing.
|
||||
// 2. Preprocess the resources based on the initial graph. The initial graph
|
||||
// should remain unchanged. Preprocessing can request additional references and
|
||||
// constraints.
|
||||
// 3. Build a final graph based on the preprocessing modifications.
|
||||
func (b *builder) Build(ctx context.Context, rr ...resource.Interface) (*graph, error) {
|
||||
var err error
|
||||
|
||||
g := b.buildGraph(rr)
|
||||
if len(g.missingRefs) > 0 {
|
||||
return g, BuilderErrUnresolvedReferences
|
||||
}
|
||||
|
||||
// Do any dep. related preprocessing
|
||||
var state *ResourceState
|
||||
err = func() error {
|
||||
for {
|
||||
state, err = g.NextInverted(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if state == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, p := range b.pp {
|
||||
err = p.Prepare(ctx, state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g = b.buildGraph(rr)
|
||||
if len(g.missingRefs) > 0 {
|
||||
return g, BuilderErrUnresolvedReferences
|
||||
}
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (b *builder) buildGraph(rr []resource.Interface) *graph {
|
||||
g := newGraph()
|
||||
|
||||
// Prepare nodes for all resources
|
||||
nn := make(nodeSet, 0, len(rr))
|
||||
for _, r := range rr {
|
||||
nn = nn.add(newNode(r))
|
||||
}
|
||||
|
||||
// Index all resources for nicer lookups
|
||||
nIndex := make(nodeIndex)
|
||||
nIndex.Add(nn...)
|
||||
|
||||
// Build the graph
|
||||
for _, cNode := range nn {
|
||||
refs := cNode.res.Refs()
|
||||
|
||||
// Attempt to connect all available nodes
|
||||
for _, ref := range refs {
|
||||
// Handle wildcard references
|
||||
if ref.IsWildcard() {
|
||||
nn := nIndex.GetResourceType(ref.ResourceType)
|
||||
// Connect the nodes
|
||||
for _, n := range nn {
|
||||
g.addChild(cNode, n)
|
||||
g.addParent(n, cNode)
|
||||
}
|
||||
} else {
|
||||
// Handle regular references
|
||||
rNode := nIndex.GetRef(ref)
|
||||
|
||||
if rNode == nil {
|
||||
if !resource.IgnoreDepResolution(ref) {
|
||||
cNode.missing = append(cNode.missing, ref)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// The resource is available; we can connect the two
|
||||
g.addChild(cNode, rNode)
|
||||
g.addParent(rNode, cNode)
|
||||
}
|
||||
}
|
||||
|
||||
g.addNode(cNode)
|
||||
}
|
||||
|
||||
if b.reportMissingRefs {
|
||||
missing := make(resource.RefSet, 0, 10)
|
||||
for _, n := range g.nn {
|
||||
missing = append(missing, n.missing...)
|
||||
}
|
||||
|
||||
if len(missing) > 0 {
|
||||
g.missingRefs = missing
|
||||
}
|
||||
}
|
||||
|
||||
return g
|
||||
}
|
||||
Reference in New Issue
Block a user