Skip to content

Commit

Permalink
Merge pull request #257 from bmeg/er-framework
Browse files Browse the repository at this point in the history
External Resource Framework
  • Loading branch information
kellrott authored Jul 23, 2021
2 parents c5ee2d9 + 5d0137a commit acac10a
Show file tree
Hide file tree
Showing 43 changed files with 2,547 additions and 1,297 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ jobs:
chmod +x grip
make start-gripper-test
sleep 5
./grip server --rpc-port 18202 --http-port 18201 --config ./gripper/test-graph/config.yaml &
./grip server --rpc-port 18202 --http-port 18201 --config ./gripper/test-graph/config.yaml --er tableServer=localhost:50051 &
sleep 5
python gripper/test-graph/test_gripper.py http://localhost:18201
python conformance/run_conformance.py http://localhost:18201 --readOnly swapi
124 changes: 0 additions & 124 deletions cmd/dig/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/erclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var source = "main"
var dataOnly = false

func getClient() *gripper.GripperClient {
c := map[string]gripper.DriverConfig{source: {Host: host}}
c := map[string]string{source: host}
out := gripper.NewGripperClient(c)
return out
}
Expand Down
34 changes: 28 additions & 6 deletions cmd/list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ var Cmd = &cobra.Command{
Short: "List operations",
}

var listTablesCmd = &cobra.Command{
Use: "tables",
Short: "List tables",
Long: ``,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
conn, err := gripql.Connect(rpc.ConfigWithDefaults(host), true)
if err != nil {
return err
}

resp, err := conn.ListTables()
if err != nil {
return err
}

for g := range resp {
fmt.Printf("%s\t%s\t%s\n", g.Source, g.Name, g.Fields)
}
return nil
},
}

var listGraphsCmd = &cobra.Command{
Use: "graphs",
Short: "List graphs",
Expand All @@ -41,7 +64,7 @@ var listGraphsCmd = &cobra.Command{
}

var listLabelsCmd = &cobra.Command{
Use: "labels <graph>}",
Use: "labels <graph>",
Short: "List the vertex and edge labels in a graph",
Long: ``,
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -73,12 +96,11 @@ var listLabelsCmd = &cobra.Command{
}

func init() {
gflags := listGraphsCmd.Flags()
gflags.StringVar(&host, "host", host, "grip server url")

lflags := listLabelsCmd.Flags()
lflags.StringVar(&host, "host", host, "grip server url")
listGraphsCmd.Flags().StringVar(&host, "host", host, "grip server url")
listLabelsCmd.Flags().StringVar(&host, "host", host, "grip server url")
listTablesCmd.Flags().StringVar(&host, "host", host, "grip server url")

Cmd.AddCommand(listGraphsCmd)
Cmd.AddCommand(listLabelsCmd)
Cmd.AddCommand(listTablesCmd)
}
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"

"github.com/bmeg/grip/cmd/create"
"github.com/bmeg/grip/cmd/dig"
"github.com/bmeg/grip/cmd/drop"
"github.com/bmeg/grip/cmd/dump"
"github.com/bmeg/grip/cmd/erclient"
Expand Down Expand Up @@ -50,7 +49,6 @@ func init() {
RootCmd.PersistentFlags().BoolVar(&enableProf, "pprof", enableProf, "enable pprof on port 6060")
RootCmd.AddCommand(create.Cmd)
RootCmd.AddCommand(drop.Cmd)
RootCmd.AddCommand(dig.Cmd)
RootCmd.AddCommand(dump.Cmd)
RootCmd.AddCommand(genBashCompletionCmd)
RootCmd.AddCommand(info.Cmd)
Expand Down
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ func init() {
flags.StringVar(&conf.Logger.Level, "log-level", conf.Logger.Level, "Log level [info, debug, warn, error]")
flags.StringVar(&conf.Logger.Formatter, "log-format", conf.Logger.Formatter, "Log format [text, json]")
flags.BoolVar(&conf.Server.RequestLogging.Enable, "log-requests", conf.Server.RequestLogging.Enable, "Log all requests")

flags.StringToStringVarP(&conf.Sources, "er", "e", conf.Sources, "GRIPPER source address")
}
27 changes: 27 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/bmeg/grip/elastic"
esql "github.com/bmeg/grip/existing-sql"
"github.com/bmeg/grip/gripper"
"github.com/bmeg/grip/gripql"
"github.com/bmeg/grip/log"
"github.com/bmeg/grip/mongo"
"github.com/bmeg/grip/psql"
Expand Down Expand Up @@ -46,6 +47,7 @@ type Config struct {
Default string
Graphs map[string]string
Drivers map[string]DriverConfig
Sources map[string]string
}

type DriverParams interface {
Expand Down Expand Up @@ -74,6 +76,8 @@ func DefaultConfig() *Config {

c.Drivers = map[string]DriverConfig{}

c.Sources = map[string]string{}

c.Logger = log.DefaultLoggerConfig()
return c
}
Expand Down Expand Up @@ -162,6 +166,29 @@ func ParseConfigFile(relpath string, conf *Config) error {
if err != nil {
return fmt.Errorf("failed to parse config at path %s: \n%v", path, err)
}
for i := range conf.Drivers {
if conf.Drivers[i].Gripper != nil {
if conf.Drivers[i].Gripper.ConfigFile != "" {
gpath := filepath.Join(filepath.Dir(path), conf.Drivers[i].Gripper.ConfigFile)

gsource, err := ioutil.ReadFile(gpath)
if err != nil {
return fmt.Errorf("failed to read graph at path %s: \n%v", gpath, err)
}
// Parse file
data := map[string]interface{}{}
err = yaml.Unmarshal(gsource, &data)
if err != nil {
return fmt.Errorf("failed to parse config at path %s: \n%v", path, err)
}
graph, err := gripql.GraphMapToProto(data)
if err != nil {
return fmt.Errorf("failed to parse config at path %s: \n%v", path, err)
}
conf.Drivers[i].Gripper.Mapping, _ = gripper.GraphToConfig(graph)
}
}
}
return nil
}

Expand Down
Loading

0 comments on commit acac10a

Please sign in to comment.