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:
@@ -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)
|
||||
|
||||
// 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.
|
||||
// This is a way to turn a unique string handle into an appropriate
|
||||
// filesystem object that we can interact with.
|
||||
|
||||
@@ -55,6 +55,7 @@ type World struct {
|
||||
MetadataPrefix string // expected metadata prefix
|
||||
StoragePrefix string // storage prefix for etcdfs storage
|
||||
StandaloneFs engine.Fs // store an fs here for local usage
|
||||
GetURI func() string
|
||||
Debug bool
|
||||
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...)
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
|
||||
@@ -77,6 +77,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
|
||||
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.
|
||||
func (obj *GAPI) Graph() (*pgraph.Graph, error) {
|
||||
if !obj.initialized {
|
||||
|
||||
10
gapi/gapi.go
10
gapi/gapi.go
@@ -120,6 +120,13 @@ type Next struct {
|
||||
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
|
||||
// the frontend interface that needs to be implemented to use the engine.
|
||||
type GAPI interface {
|
||||
@@ -132,6 +139,9 @@ type GAPI interface {
|
||||
// Init initializes the GAPI and passes in some useful data.
|
||||
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
|
||||
// every event from Next().
|
||||
Graph() (*pgraph.Graph, error)
|
||||
|
||||
@@ -554,6 +554,13 @@ func (obj *GAPI) LangClose() error {
|
||||
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.
|
||||
func (obj *GAPI) Graph() (*pgraph.Graph, error) {
|
||||
if !obj.initialized {
|
||||
|
||||
12
lib/main.go
12
lib/main.go
@@ -592,6 +592,8 @@ func (obj *Main) Run() error {
|
||||
},
|
||||
}).Init()
|
||||
|
||||
var gapiInfoResult *gapi.InfoResult
|
||||
|
||||
// implementation of the World API (alternatives can be substituted in)
|
||||
// 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
|
||||
@@ -606,6 +608,12 @@ func (obj *Main) Run() error {
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
obj.Logf("world: etcd: "+format, v...)
|
||||
},
|
||||
GetURI: func() string {
|
||||
if gapiInfoResult == nil {
|
||||
return ""
|
||||
}
|
||||
return gapiInfoResult.URI
|
||||
},
|
||||
}
|
||||
|
||||
obj.ge = &graph.Engine{
|
||||
@@ -727,6 +735,7 @@ func (obj *Main) Run() error {
|
||||
}
|
||||
// this must generate at least one event for it to work
|
||||
gapiChan = gapiImpl.Next() // stream of graph switch events!
|
||||
gapiInfoResult = gapiImpl.Info()
|
||||
}
|
||||
continue
|
||||
|
||||
@@ -790,6 +799,9 @@ func (obj *Main) Run() error {
|
||||
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
|
||||
if err := obj.ge.Apply(func(graph *pgraph.Graph) error {
|
||||
var err error
|
||||
|
||||
@@ -244,6 +244,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
|
||||
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.
|
||||
func (obj *GAPI) Graph() (*pgraph.Graph, error) {
|
||||
if !obj.initialized {
|
||||
|
||||
@@ -187,6 +187,12 @@ func (obj *GAPI) Init(data *gapi.Data) error {
|
||||
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.
|
||||
func (obj *GAPI) Graph() (*pgraph.Graph, error) {
|
||||
if !obj.initialized {
|
||||
|
||||
@@ -114,6 +114,13 @@ func (obj *GAPI) Init(data *gapi.Data) error {
|
||||
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.
|
||||
func (obj *GAPI) Graph() (*pgraph.Graph, error) {
|
||||
if !obj.initialized {
|
||||
|
||||
Reference in New Issue
Block a user