gapi: Plumb through a URI mechanism

This is at least a stop-gap until we redo the whole filesystem API mess.
I think golang is partly to blame because they don't have proper API's
merged yet.
This commit is contained in:
James Shubin
2024-10-13 16:40:50 -04:00
parent b03fdeccae
commit a8c8f09aa3
9 changed files with 67 additions and 0 deletions

View File

@@ -63,6 +63,10 @@ type World interface { // TODO: is there a better name for this interface?
Scheduler(namespace string, opts ...scheduler.Option) (*scheduler.Result, error) Scheduler(namespace string, opts ...scheduler.Option) (*scheduler.Result, error)
// URI returns the current FS URI.
// TODO: Can we improve this API or deprecate it entirely?
URI() string
// Fs takes a URI and returns the filesystem that corresponds to that. // Fs takes a URI and returns the filesystem that corresponds to that.
// This is a way to turn a unique string handle into an appropriate // This is a way to turn a unique string handle into an appropriate
// filesystem object that we can interact with. // filesystem object that we can interact with.

View File

@@ -55,6 +55,7 @@ type World struct {
MetadataPrefix string // expected metadata prefix MetadataPrefix string // expected metadata prefix
StoragePrefix string // storage prefix for etcdfs storage StoragePrefix string // storage prefix for etcdfs storage
StandaloneFs engine.Fs // store an fs here for local usage StandaloneFs engine.Fs // store an fs here for local usage
GetURI func() string
Debug bool Debug bool
Logf func(format string, v ...interface{}) Logf func(format string, v ...interface{})
} }
@@ -189,6 +190,12 @@ func (obj *World) Scheduler(namespace string, opts ...scheduler.Option) (*schedu
return scheduler.Schedule(obj.Client.GetClient(), path, obj.Hostname, modifiedOpts...) return scheduler.Schedule(obj.Client.GetClient(), path, obj.Hostname, modifiedOpts...)
} }
// URI returns the current FS URI.
// TODO: Can we improve this API or deprecate it entirely?
func (obj *World) URI() string {
return obj.GetURI()
}
// Fs returns a distributed file system from a unique URI. For single host // Fs returns a distributed file system from a unique URI. For single host
// execution that doesn't span more than a single host, this file system might // execution that doesn't span more than a single host, this file system might
// actually be a local or memory backed file system, so actually only // actually be a local or memory backed file system, so actually only

View File

@@ -77,6 +77,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
return nil return nil
} }
// Info returns some data about the GAPI implementation.
func (obj *GAPI) Info() *gapi.InfoResult {
return &gapi.InfoResult{
URI: "",
}
}
// Graph returns a current Graph. // Graph returns a current Graph.
func (obj *GAPI) Graph() (*pgraph.Graph, error) { func (obj *GAPI) Graph() (*pgraph.Graph, error) {
if !obj.initialized { if !obj.initialized {

View File

@@ -120,6 +120,13 @@ type Next struct {
Err error // if something goes wrong (use with or without exit!) Err error // if something goes wrong (use with or without exit!)
} }
// InfoResult is some data that a GAPI can return on request.
type InfoResult struct {
// URI is the FS URI that we pass around everywhere.
// TODO: can this be deprecated?
URI string
}
// GAPI is a Graph API that represents incoming graphs and change streams. It is // GAPI is a Graph API that represents incoming graphs and change streams. It is
// the frontend interface that needs to be implemented to use the engine. // the frontend interface that needs to be implemented to use the engine.
type GAPI interface { type GAPI interface {
@@ -132,6 +139,9 @@ type GAPI interface {
// Init initializes the GAPI and passes in some useful data. // Init initializes the GAPI and passes in some useful data.
Init(*Data) error Init(*Data) error
// Info returns some data about the GAPI implementation.
Info() *InfoResult
// Graph returns the most recent pgraph. This is called by the engine on // Graph returns the most recent pgraph. This is called by the engine on
// every event from Next(). // every event from Next().
Graph() (*pgraph.Graph, error) Graph() (*pgraph.Graph, error)

View File

@@ -554,6 +554,13 @@ func (obj *GAPI) LangClose() error {
return nil return nil
} }
// Info returns some data about the GAPI implementation.
func (obj *GAPI) Info() *gapi.InfoResult {
return &gapi.InfoResult{
URI: obj.InputURI,
}
}
// Graph returns a current Graph. // Graph returns a current Graph.
func (obj *GAPI) Graph() (*pgraph.Graph, error) { func (obj *GAPI) Graph() (*pgraph.Graph, error) {
if !obj.initialized { if !obj.initialized {

View File

@@ -592,6 +592,8 @@ func (obj *Main) Run() error {
}, },
}).Init() }).Init()
var gapiInfoResult *gapi.InfoResult
// implementation of the World API (alternatives can be substituted in) // implementation of the World API (alternatives can be substituted in)
// XXX: The "implementation of the World API" should have more than just // XXX: The "implementation of the World API" should have more than just
// etcd in it, so this could live elsewhere package wise and just have // etcd in it, so this could live elsewhere package wise and just have
@@ -606,6 +608,12 @@ func (obj *Main) Run() error {
Logf: func(format string, v ...interface{}) { Logf: func(format string, v ...interface{}) {
obj.Logf("world: etcd: "+format, v...) obj.Logf("world: etcd: "+format, v...)
}, },
GetURI: func() string {
if gapiInfoResult == nil {
return ""
}
return gapiInfoResult.URI
},
} }
obj.ge = &graph.Engine{ obj.ge = &graph.Engine{
@@ -727,6 +735,7 @@ func (obj *Main) Run() error {
} }
// this must generate at least one event for it to work // this must generate at least one event for it to work
gapiChan = gapiImpl.Next() // stream of graph switch events! gapiChan = gapiImpl.Next() // stream of graph switch events!
gapiInfoResult = gapiImpl.Info()
} }
continue continue
@@ -790,6 +799,9 @@ func (obj *Main) Run() error {
continue continue
} }
// TODO: Apply/push gapiInfoResult into resources and/or
// engine in the future if we decide we need to do that!
// apply the global metaparams to the graph // apply the global metaparams to the graph
if err := obj.ge.Apply(func(graph *pgraph.Graph) error { if err := obj.ge.Apply(func(graph *pgraph.Graph) error {
var err error var err error

View File

@@ -244,6 +244,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
return nil return nil
} }
// Info returns some data about the GAPI implementation.
func (obj *GAPI) Info() *gapi.InfoResult {
return &gapi.InfoResult{
URI: obj.InputURI,
}
}
// Graph returns a current Graph. // Graph returns a current Graph.
func (obj *GAPI) Graph() (*pgraph.Graph, error) { func (obj *GAPI) Graph() (*pgraph.Graph, error) {
if !obj.initialized { if !obj.initialized {

View File

@@ -187,6 +187,12 @@ func (obj *GAPI) Init(data *gapi.Data) error {
return nil return nil
} }
// Info returns some data about the GAPI implementation.
func (obj *GAPI) Info() *gapi.InfoResult {
// XXX: Do we want this or obj.puppetGAPI or something else?
return obj.langGAPI.Info()
}
// Graph returns a current Graph. // Graph returns a current Graph.
func (obj *GAPI) Graph() (*pgraph.Graph, error) { func (obj *GAPI) Graph() (*pgraph.Graph, error) {
if !obj.initialized { if !obj.initialized {

View File

@@ -114,6 +114,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
return nil return nil
} }
// Info returns some data about the GAPI implementation.
func (obj *GAPI) Info() *gapi.InfoResult {
return &gapi.InfoResult{
URI: obj.InputURI,
}
}
// Graph returns a current Graph. // Graph returns a current Graph.
func (obj *GAPI) Graph() (*pgraph.Graph, error) { func (obj *GAPI) Graph() (*pgraph.Graph, error) {
if !obj.initialized { if !obj.initialized {