gapi: Move the World interface into resources

This was necessary to fix some "import cycle" errors I was having when
adding the World api to the resource Data struct.

I think this is a good hint that I need to start splitting up existing
packages into sub files, and cleaning up and inter-package problems too.
This commit is contained in:
James Shubin
2017-03-04 19:29:45 -05:00
parent 32aae8f57a
commit 44771a0049
4 changed files with 18 additions and 17 deletions

View File

@@ -23,24 +23,10 @@ import (
"github.com/purpleidea/mgmt/resources" "github.com/purpleidea/mgmt/resources"
) )
// World is an interface to the rest of the different graph state. It allows
// the GAPI to store state and exchange information throughout the cluster. It
// is the interface each machine uses to communicate with the rest of the world.
type World interface { // TODO: is there a better name for this interface?
ResExport([]resources.Res) error
// FIXME: should this method take a "filter" data struct instead of many args?
ResCollect(hostnameFilter, kindFilter []string) ([]resources.Res, error)
StrWatch(namespace string) chan error
StrGet(namespace string) (map[string]string, error)
StrSet(namespace, value string) error
StrDel(namespace string) error
}
// Data is the set of input values passed into the GAPI structs via Init. // Data is the set of input values passed into the GAPI structs via Init.
type Data struct { type Data struct {
Hostname string // uuid for the host, required for GAPI Hostname string // uuid for the host, required for GAPI
World World World resources.World
Noop bool Noop bool
NoWatch bool NoWatch bool
// NOTE: we can add more fields here if needed by GAPI endpoints // NOTE: we can add more fields here if needed by GAPI endpoints

View File

@@ -443,6 +443,7 @@ func (obj *Main) Run() error {
Hostname: hostname, Hostname: hostname,
Converger: converger, Converger: converger,
Prometheus: prom, Prometheus: prom,
World: world,
Prefix: pgraphPrefix, Prefix: pgraphPrefix,
Debug: obj.Flags.Debug, Debug: obj.Flags.Debug,
}) })

View File

@@ -56,12 +56,27 @@ const (
const refreshPathToken = "refresh" const refreshPathToken = "refresh"
// World is an interface to the rest of the different graph state. It allows
// the GAPI to store state and exchange information throughout the cluster. It
// is the interface each machine uses to communicate with the rest of the world.
type World interface { // TODO: is there a better name for this interface?
ResExport([]Res) error
// FIXME: should this method take a "filter" data struct instead of many args?
ResCollect(hostnameFilter, kindFilter []string) ([]Res, error)
StrWatch(namespace string) chan error
StrGet(namespace string) (map[string]string, error)
StrSet(namespace, value string) error
StrDel(namespace string) error
}
// Data is the set of input values passed into the pgraph for the resources. // Data is the set of input values passed into the pgraph for the resources.
type Data struct { type Data struct {
Hostname string // uuid for the host Hostname string // uuid for the host
//Noop bool //Noop bool
Converger converger.Converger Converger converger.Converger
Prometheus *prometheus.Prometheus Prometheus *prometheus.Prometheus
World World
Prefix string // the prefix to be used for the pgraph namespace Prefix string // the prefix to be used for the pgraph namespace
Debug bool Debug bool
// NOTE: we can add more fields here if needed for the resources. // NOTE: we can add more fields here if needed for the resources.

View File

@@ -26,7 +26,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/purpleidea/mgmt/gapi"
"github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/pgraph"
"github.com/purpleidea/mgmt/resources" "github.com/purpleidea/mgmt/resources"
"github.com/purpleidea/mgmt/util" "github.com/purpleidea/mgmt/util"
@@ -93,7 +92,7 @@ func (c *GraphConfig) Parse(data []byte) error {
// NewGraphFromConfig transforms a GraphConfig struct into a new graph. // NewGraphFromConfig transforms a GraphConfig struct into a new graph.
// FIXME: remove any possibly left over, now obsolete graph diff code from here! // FIXME: remove any possibly left over, now obsolete graph diff code from here!
func (c *GraphConfig) NewGraphFromConfig(hostname string, world gapi.World, noop bool) (*pgraph.Graph, error) { func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World, noop bool) (*pgraph.Graph, error) {
// hostname is the uuid for the host // hostname is the uuid for the host
var graph *pgraph.Graph // new graph to return var graph *pgraph.Graph // new graph to return