diff --git a/engine/world.go b/engine/world.go index 8db5866f..c57d2f94 100644 --- a/engine/world.go +++ b/engine/world.go @@ -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. diff --git a/etcd/world.go b/etcd/world.go index 260526fc..015759ba 100644 --- a/etcd/world.go +++ b/etcd/world.go @@ -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 diff --git a/gapi/empty/empty.go b/gapi/empty/empty.go index 911d525c..9c7b7418 100644 --- a/gapi/empty/empty.go +++ b/gapi/empty/empty.go @@ -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 { diff --git a/gapi/gapi.go b/gapi/gapi.go index ddf21125..eb03780b 100644 --- a/gapi/gapi.go +++ b/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) diff --git a/lang/gapi/gapi.go b/lang/gapi/gapi.go index 23c2d2f4..9dd3acb5 100644 --- a/lang/gapi/gapi.go +++ b/lang/gapi/gapi.go @@ -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 { diff --git a/lib/main.go b/lib/main.go index f2c48ea0..14a228c6 100644 --- a/lib/main.go +++ b/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 diff --git a/puppet/gapi.go b/puppet/gapi.go index 4aa74429..0f9cedea 100644 --- a/puppet/gapi.go +++ b/puppet/gapi.go @@ -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 { diff --git a/puppet/langpuppet/gapi.go b/puppet/langpuppet/gapi.go index ca061892..6bc45c8c 100644 --- a/puppet/langpuppet/gapi.go +++ b/puppet/langpuppet/gapi.go @@ -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 { diff --git a/yamlgraph/gapi.go b/yamlgraph/gapi.go index 0e67af6c..dce28601 100644 --- a/yamlgraph/gapi.go +++ b/yamlgraph/gapi.go @@ -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 {