Skip to content

Commit

Permalink
Making gripper mapping look like regular graph
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Jul 19, 2021
1 parent 92f033f commit 8d3ea5c
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ 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 conformance/run_conformance.py http://localhost:18201 --readOnly swapi
24 changes: 24 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 @@ -165,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
42 changes: 30 additions & 12 deletions gripper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ import (
type Config struct {
Graph string
ConfigFile string
Mapping *GraphConfig
}

type GraphConfig struct {
Vertices map[string]VertexConfig `json:"vertices"`
Edges map[string]EdgeConfig `json:"edges"`
//path string
}

type ElementConfig struct {
Source string `json:"source"`
Collection string `json:"collection"`
FieldToID *FieldToIDConfig `json:"fieldToID"`
FieldToField *FieldToFieldConfig `json:"fieldToField"`
EdgeTable *EdgeTableConfig `json:"edgeTable"`
}

type VertexConfig struct {
Source string `json:"source"`
Collection string `json:"collection"`
Label string `json:"label"`
Gid string `json:"gid"`
Label string `json:"label"`
Data ElementConfig `json:"data"`
}

type FieldToIDConfig struct {
Expand All @@ -46,12 +54,11 @@ type EdgeTableConfig struct {
}

type EdgeConfig struct {
ToVertex string `json:"toVertex"`
FromVertex string `json:"fromVertex"`
Label string `json:"label"`
FieldToID *FieldToIDConfig `json:"fieldToID"`
FieldToField *FieldToFieldConfig `json:"fieldToField"`
EdgeTable *EdgeTableConfig `json:"edgeTable"`
Gid string `json:"gid"`
To string `json:"to"`
From string `json:"from"`
Label string `json:"label"`
Data ElementConfig `json:"data"`
}

func LoadConfig(path string) (*GraphConfig, error) {
Expand Down Expand Up @@ -82,18 +89,29 @@ func GraphToConfig(graph *gripql.Graph) (*GraphConfig, error) {
s, _ := json.Marshal(d)
vc := VertexConfig{}
json.Unmarshal(s, &vc)
vc.Gid = vert.Gid
vc.Label = vert.Label
vc.Data = dataToElementConfig(vert.Data.AsMap())
out.Vertices[vert.Gid] = vc
}
for _, edge := range graph.Edges {
d := edge.Data.AsMap()
s, _ := json.Marshal(d)
ec := EdgeConfig{}
json.Unmarshal(s, &ec)
ec.Gid = edge.Gid
ec.Label = edge.Label
ec.ToVertex = edge.To
ec.FromVertex = edge.From
ec.To = edge.To
ec.From = edge.From
ec.Data = dataToElementConfig(edge.Data.AsMap())
out.Edges[edge.Gid] = ec
}
return &out, nil
}

func dataToElementConfig(s map[string]interface{}) ElementConfig {
e := ElementConfig{}
o, _ := json.Marshal(s)
json.Unmarshal(o, &e)
return e
}
Loading

0 comments on commit 8d3ea5c

Please sign in to comment.