diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f65c26d..78982114 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/config/config.go b/config/config.go index a7a3e264..ff558058 100644 --- a/config/config.go +++ b/config/config.go @@ -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" @@ -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 } diff --git a/gripper/config.go b/gripper/config.go index 57ed24d9..2e18cf50 100644 --- a/gripper/config.go +++ b/gripper/config.go @@ -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 { @@ -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) { @@ -82,7 +89,9 @@ 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 { @@ -90,10 +99,19 @@ func GraphToConfig(graph *gripql.Graph) (*GraphConfig, error) { 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 +} diff --git a/gripper/graph.go b/gripper/graph.go index 99b5037c..4a59b411 100644 --- a/gripper/graph.go +++ b/gripper/graph.go @@ -54,71 +54,71 @@ func NewTabularGraph(conf GraphConfig, sources map[string]string) (*TabularGraph //Check if vertex mapping match to sources for _, v := range conf.Vertices { - _, err := out.client.GetCollectionInfo(context.Background(), v.Source, v.Collection) + _, err := out.client.GetCollectionInfo(context.Background(), v.Data.Source, v.Data.Collection) if err != nil { - return nil, fmt.Errorf("Unable to get collection information %s : %s", v.Source, v.Collection) + return nil, fmt.Errorf("Unable to get collection information %s : %s", v.Data.Source, v.Data.Collection) } } //Check if edges match sources for _, e := range conf.Edges { - if _, ok := conf.Vertices[e.ToVertex]; !ok { + if _, ok := conf.Vertices[e.To]; !ok { return nil, fmt.Errorf("Edge ToVertex not found") } - if _, ok := conf.Vertices[e.FromVertex]; !ok { + if _, ok := conf.Vertices[e.From]; !ok { return nil, fmt.Errorf("Edge ToVertex not found") } - if e.EdgeTable != nil { + if e.Data.EdgeTable != nil { eTable, err := out.client.GetCollectionInfo(context.Background(), - e.EdgeTable.Source, e.EdgeTable.Collection) + e.Data.EdgeTable.Source, e.Data.EdgeTable.Collection) if err != nil { return nil, fmt.Errorf("Unable to get collection information %s : %s", - e.EdgeTable.Source, e.EdgeTable.Collection) + e.Data.EdgeTable.Source, e.Data.EdgeTable.Collection) } - if !setcmp.ContainsString(eTable.SearchFields, e.EdgeTable.ToField) { + if !setcmp.ContainsString(eTable.SearchFields, e.Data.EdgeTable.ToField) { return nil, fmt.Errorf("Edge 'To' Field not indexed: %s %s", - e.EdgeTable.Collection, - e.EdgeTable.ToField) + e.Data.EdgeTable.Collection, + e.Data.EdgeTable.ToField) } - if !setcmp.ContainsString(eTable.SearchFields, e.EdgeTable.FromField) { + if !setcmp.ContainsString(eTable.SearchFields, e.Data.EdgeTable.FromField) { return nil, fmt.Errorf("Edge 'From' Field not indexed: %s %s", - e.EdgeTable.Collection, - e.EdgeTable.FromField) + e.Data.EdgeTable.Collection, + e.Data.EdgeTable.FromField) } - if !strings.HasPrefix(e.EdgeTable.ToField, "$.") { - return nil, fmt.Errorf("Edge 'To' Field does not start with JSONPath prefix ($.) = %s", e.EdgeTable.ToField) + if !strings.HasPrefix(e.Data.EdgeTable.ToField, "$.") { + return nil, fmt.Errorf("Edge 'To' Field does not start with JSONPath prefix ($.) = %s", e.Data.EdgeTable.ToField) } - if !strings.HasPrefix(e.EdgeTable.FromField, "$.") { - return nil, fmt.Errorf("Edge 'From' Field does not start with JSONPath prefix ($.) = %s", e.EdgeTable.FromField) + if !strings.HasPrefix(e.Data.EdgeTable.FromField, "$.") { + return nil, fmt.Errorf("Edge 'From' Field does not start with JSONPath prefix ($.) = %s", e.Data.EdgeTable.FromField) } - } else if e.FieldToID != nil { + } else if e.Data.FieldToID != nil { //return nil, fmt.Errorf("Not supported yet") - } else if e.FieldToField != nil { - vTo := conf.Vertices[e.ToVertex] - vFrom := conf.Vertices[e.FromVertex] + } else if e.Data.FieldToField != nil { + vTo := conf.Vertices[e.To] + vFrom := conf.Vertices[e.From] - if !strings.HasPrefix(e.FieldToField.ToField, "$.") { - return nil, fmt.Errorf("Edge 'To' Field does not start with JSONPath prefix ($.) = %s", e.FieldToField.ToField) + if !strings.HasPrefix(e.Data.FieldToField.ToField, "$.") { + return nil, fmt.Errorf("Edge 'To' Field does not start with JSONPath prefix ($.) = %s", e.Data.FieldToField.ToField) } - if !strings.HasPrefix(e.FieldToField.FromField, "$.") { - return nil, fmt.Errorf("Edge 'From' Field does not start with JSONPath prefix ($.) = %s", e.FieldToField.FromField) + if !strings.HasPrefix(e.Data.FieldToField.FromField, "$.") { + return nil, fmt.Errorf("Edge 'From' Field does not start with JSONPath prefix ($.) = %s", e.Data.FieldToField.FromField) } if iTo, err := out.client.GetCollectionInfo(context.Background(), - vTo.Source, vTo.Collection); err == nil { - if !setcmp.ContainsString(iTo.SearchFields, e.FieldToField.ToField) { + vTo.Data.Source, vTo.Data.Collection); err == nil { + if !setcmp.ContainsString(iTo.SearchFields, e.Data.FieldToField.ToField) { return nil, fmt.Errorf("Edge 'To' Field not indexed: %s %s", - vTo.Collection, - e.FieldToField.ToField) + vTo.Data.Collection, + e.Data.FieldToField.ToField) } } if iFrom, err := out.client.GetCollectionInfo(context.Background(), - vFrom.Source, vFrom.Collection); err == nil { - if !setcmp.ContainsString(iFrom.SearchFields, e.FieldToField.FromField) { + vFrom.Data.Source, vFrom.Data.Collection); err == nil { + if !setcmp.ContainsString(iFrom.SearchFields, e.Data.FieldToField.FromField) { return nil, fmt.Errorf("Edge 'From' Field not indexed: %s %s", - vFrom.Collection, - e.FieldToField.FromField) + vFrom.Data.Collection, + e.Data.FieldToField.FromField) } } } else { @@ -139,42 +139,42 @@ func NewTabularGraph(conf GraphConfig, sources map[string]string) (*TabularGraph oConf := EdgeConfig{} iConf := EdgeConfig{} - if e.EdgeTable != nil { + if e.Data.EdgeTable != nil { oConf = e //copy the edge config, but flip the field requests for the incoming edges - iConf.FromVertex = oConf.ToVertex - iConf.ToVertex = oConf.FromVertex + iConf.From = oConf.To + iConf.To = oConf.From iConf.Label = oConf.Label - iConf.EdgeTable = &EdgeTableConfig{} - iConf.EdgeTable.Source = oConf.EdgeTable.Source - iConf.EdgeTable.Collection = oConf.EdgeTable.Collection - iConf.EdgeTable.FromField = oConf.EdgeTable.ToField - iConf.EdgeTable.ToField = oConf.EdgeTable.FromField - } else if e.FieldToID != nil { + iConf.Data.EdgeTable = &EdgeTableConfig{} + iConf.Data.EdgeTable.Source = oConf.Data.EdgeTable.Source + iConf.Data.EdgeTable.Collection = oConf.Data.EdgeTable.Collection + iConf.Data.EdgeTable.ToField = oConf.Data.EdgeTable.FromField + iConf.Data.EdgeTable.FromField = oConf.Data.EdgeTable.ToField + } else if e.Data.FieldToID != nil { //do something here - } else if e.FieldToField != nil { + } else if e.Data.FieldToField != nil { oConf = e //copy the edge config, but flip the field requests for the incoming edges - iConf.FromVertex = oConf.ToVertex - iConf.ToVertex = oConf.FromVertex + iConf.From = oConf.To + iConf.To = oConf.From iConf.Label = oConf.Label - iConf.FieldToField = &FieldToFieldConfig{} - iConf.FieldToField.FromField = oConf.FieldToField.ToField - iConf.FieldToField.ToField = oConf.FieldToField.FromField + iConf.Data.FieldToField = &FieldToFieldConfig{} + iConf.Data.FieldToField.FromField = oConf.Data.FieldToField.ToField + iConf.Data.FieldToField.ToField = oConf.Data.FieldToField.FromField } - out.inEdges[e.ToVertex] = append(out.inEdges[e.ToVertex], &EdgeSource{ + out.inEdges[e.To] = append(out.inEdges[e.To], &EdgeSource{ prefix: ePrefix, config: &iConf, - fromVertex: out.vertices[e.ToVertex], - toVertex: out.vertices[e.FromVertex], + fromVertex: out.vertices[e.To], + toVertex: out.vertices[e.From], reverse: true, }) - out.outEdges[e.FromVertex] = append(out.outEdges[e.FromVertex], &EdgeSource{ + out.outEdges[e.From] = append(out.outEdges[e.From], &EdgeSource{ prefix: ePrefix, config: &oConf, - fromVertex: out.vertices[e.FromVertex], - toVertex: out.vertices[e.ToVertex], + fromVertex: out.vertices[e.From], + toVertex: out.vertices[e.To], reverse: false, }) } @@ -248,7 +248,7 @@ func (t *TabularGraph) GetVertex(key string, load bool) *gdbi.Vertex { c := make(chan *RowRequest, 1) c <- &RowRequest{Id: id, RequestID: 0} close(c) - if rowChan, err := t.client.GetRowsByID(context.Background(), v.config.Source, v.config.Collection, c); err == nil { + if rowChan, err := t.client.GetRowsByID(context.Background(), v.config.Data.Source, v.config.Data.Collection, c); err == nil { var row *Row for i := range rowChan { row = i @@ -275,26 +275,26 @@ func (t *TabularGraph) GetEdge(key string, load bool) *gdbi.Edge { for _, edge := range edgeList { if edge.config.Label == label { if strings.HasPrefix(src, edge.fromVertex.prefix) && strings.HasPrefix(dst, edge.toVertex.prefix) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { srcID := strings.TrimPrefix(src, edge.fromVertex.prefix) dstID := strings.TrimPrefix(dst, edge.toVertex.prefix) res, err := t.client.GetRowsByField(context.Background(), - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection, - edge.config.EdgeTable.FromField, srcID) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection, + edge.config.Data.EdgeTable.FromField, srcID) if err == nil { var out *gdbi.Edge for row := range res { data := row.Data.AsMap() - if rowDst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if rowDst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if rowdDstStr, ok := rowDst.(string); ok { if dstID == rowdDstStr { o := gdbi.Edge{ ID: edge.GenID(srcID, dstID), //edge.prefix + row.Id, - To: edge.config.ToVertex + dstID, - From: edge.config.FromVertex + srcID, + To: edge.config.To + dstID, + From: edge.config.From + srcID, Label: edge.config.Label, Data: row.Data.AsMap(), Loaded: true, @@ -307,25 +307,25 @@ func (t *TabularGraph) GetEdge(key string, load bool) *gdbi.Edge { return out } log.Errorf("Row Error: %s", err) - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("GetEdge.FieldToID not yet implemented") - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { srcID := strings.TrimPrefix(src, edge.fromVertex.prefix) dstID := strings.TrimPrefix(dst, edge.toVertex.prefix) - srcRow := t.getRow(edge.fromVertex.config.Source, edge.fromVertex.config.Collection, srcID) + srcRow := t.getRow(edge.fromVertex.config.Data.Source, edge.fromVertex.config.Data.Collection, srcID) if srcRow != nil { - dstRow := t.getRow(edge.toVertex.config.Source, edge.toVertex.config.Collection, dstID) + dstRow := t.getRow(edge.toVertex.config.Data.Source, edge.toVertex.config.Data.Collection, dstID) if dstRow != nil { srcData := srcRow.Data.AsMap() dstData := dstRow.Data.AsMap() - if srcField, err := jsonpath.JsonPathLookup(srcData, edge.config.FieldToField.FromField); err == nil { - if dstField, err := jsonpath.JsonPathLookup(dstData, edge.config.FieldToField.ToField); err == nil { + if srcField, err := jsonpath.JsonPathLookup(srcData, edge.config.Data.FieldToField.FromField); err == nil { + if dstField, err := jsonpath.JsonPathLookup(dstData, edge.config.Data.FieldToField.ToField); err == nil { if srcField == dstField { o := gdbi.Edge{ ID: edge.GenID(srcID, dstID), //edge.prefix + row.Id, - To: edge.config.ToVertex + dstID, - From: edge.config.FromVertex + srcID, + To: edge.config.To + dstID, + From: edge.config.From + srcID, Label: edge.config.Label, Loaded: true, } @@ -359,7 +359,7 @@ func (t *TabularGraph) VertexLabelScan(ctx context.Context, label string) chan s for _, source := range t.vertexSourceOrder { v := t.vertices[source] if v.config.Label == label { - for n := range t.client.GetIDs(ctx, v.config.Source, v.config.Collection) { + for n := range t.client.GetIDs(ctx, v.config.Data.Source, v.config.Data.Collection) { out <- v.prefix + n } } @@ -416,7 +416,7 @@ func (t *TabularGraph) GetVertexList(ctx context.Context, load bool) <-chan *gdb for _, source := range t.vertexSourceOrder { c := t.vertices[source] //log.Infof("Getting vertices from table: %s", c.config.Label) - for row := range t.client.GetRows(ctx, c.config.Source, c.config.Collection) { + for row := range t.client.GetRows(ctx, c.config.Data.Source, c.config.Data.Collection) { v := gdbi.Vertex{ ID: c.prefix + row.Id, Label: c.config.Label, @@ -442,15 +442,15 @@ func (t *TabularGraph) GetEdgeList(ctx context.Context, load bool) <-chan *gdbi. if ctx.Err() == context.Canceled { return } - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { res := t.client.GetRows(ctx, - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection) for row := range res { data := row.Data.AsMap() - if dst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if dst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if dstStr, ok := dst.(string); ok { - if src, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.FromField); err == nil { + if src, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.FromField); err == nil { if srcStr, ok := src.(string); ok { e := gdbi.Edge{ ID: edge.GenID(srcStr, dstStr), @@ -466,21 +466,21 @@ func (t *TabularGraph) GetEdgeList(ctx context.Context, load bool) <-chan *gdbi. } } } - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("GetEdgeList.FieldToID not yet implemented") - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { srcRes := t.client.GetRows(ctx, - edge.fromVertex.config.Source, - edge.fromVertex.config.Collection) + edge.fromVertex.config.Data.Source, + edge.fromVertex.config.Data.Collection) for srcRow := range srcRes { srcData := srcRow.Data.AsMap() - if field, err := jsonpath.JsonPathLookup(srcData, edge.config.FieldToField.FromField); err == nil { + if field, err := jsonpath.JsonPathLookup(srcData, edge.config.Data.FieldToField.FromField); err == nil { if fValue, ok := field.(string); ok { if fValue != "" { dstRes, err := t.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { for dstRow := range dstRes { o := gdbi.Edge{ @@ -579,7 +579,7 @@ func (t *TabularGraph) GetVertexChannel(ctx context.Context, req chan gdbi.Eleme if x, ok := prefixMap[v.prefix]; ok { mux.Put(x, r) } else { - in, out := rowRequestVertexPipeline(ctx, v.prefix, v.config.Label, t.client, v.config.Source, v.config.Collection) + in, out := rowRequestVertexPipeline(ctx, v.prefix, v.config.Label, t.client, v.config.Data.Source, v.config.Data.Collection) x, _ := mux.AddPipeline(in, out) prefixMap[v.prefix] = x mux.Put(x, r) @@ -610,17 +610,17 @@ func (t *TabularGraph) GetOutChannel(ctx context.Context, req chan gdbi.ElementL id := r.ID[len(vPrefix):len(r.ID)] for _, edge := range edgeList { if len(edgeLabels) == 0 || setcmp.ContainsString(edgeLabels, edge.config.Label) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { res, err := t.client.GetRowsByField(ctx, - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection, - edge.config.EdgeTable.FromField, id) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection, + edge.config.Data.EdgeTable.FromField, id) if err == nil { for row := range res { data := row.Data.AsMap() - if dst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if dst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if dstStr, ok := dst.(string); ok { - dstID := edge.config.ToVertex + dstStr + dstID := edge.config.To + dstStr nReq := gdbi.ElementLookup{ID: dstID, Ref: r.Ref} vReqs <- nReq } else { @@ -635,14 +635,14 @@ func (t *TabularGraph) GetOutChannel(ctx context.Context, req chan gdbi.ElementL log.Errorf("Row Error: %s\n", err) } } - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("GetOutChannel.FieldToID not yet implemented") - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { //log.Infof("FieldToField lookup %#v", edge.config.FieldToField) cur := r.Ref.GetCurrent() fValue := "" if cur != nil && cur.ID == r.ID { - if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.FieldToField.FromField); err == nil { + if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.Data.FieldToField.FromField); err == nil { if vStr, ok := v.(string); ok { fValue = vStr } @@ -654,9 +654,9 @@ func (t *TabularGraph) GetOutChannel(ctx context.Context, req chan gdbi.ElementL } if fValue != "" { res, err := t.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { //log.Infof("Searching %s : %s == %s", edge.toVertex.config.Collection, edge.config.FieldToField.ToField, fValue ) for row := range res { @@ -697,19 +697,19 @@ func (t *TabularGraph) GetInChannel(ctx context.Context, req chan gdbi.ElementLo id := r.ID[len(vPrefix):len(r.ID)] for _, edge := range edgeList { if len(edgeLabels) == 0 || setcmp.ContainsString(edgeLabels, edge.config.Label) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { //log.Infof("Using EdgeTable %s:%s to find %s", edge.config.EdgeTable.Collection, edge.config.EdgeTable.FromField, id) res, err := t.client.GetRowsByField(ctx, - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection, - edge.config.EdgeTable.FromField, id) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection, + edge.config.Data.EdgeTable.FromField, id) if err == nil { for row := range res { //log.Infof("Found %s", row) data := row.Data.AsMap() - if dst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if dst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if dstStr, ok := dst.(string); ok { - dstID := edge.config.ToVertex + dstStr + dstID := edge.config.To + dstStr nReq := gdbi.ElementLookup{ID: dstID, Ref: r.Ref} vReqs <- nReq } @@ -720,11 +720,11 @@ func (t *TabularGraph) GetInChannel(ctx context.Context, req chan gdbi.ElementLo log.Errorf("Row Error: %s", err) } } - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { cur := r.Ref.GetCurrent() fValue := "" if cur != nil && cur.ID == r.ID { - if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.FieldToField.FromField); err == nil { + if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.Data.FieldToField.FromField); err == nil { if vStr, ok := v.(string); ok { fValue = vStr } @@ -738,9 +738,9 @@ func (t *TabularGraph) GetInChannel(ctx context.Context, req chan gdbi.ElementLo } if fValue != "" { res, err := t.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { for row := range res { o := gdbi.Vertex{ @@ -758,7 +758,7 @@ func (t *TabularGraph) GetInChannel(ctx context.Context, req chan gdbi.ElementLo } } } - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("Need to implement FieldToID") } } @@ -787,21 +787,21 @@ func (t *TabularGraph) GetOutEdgeChannel(ctx context.Context, req chan gdbi.Elem id := r.ID[len(vPrefix):len(r.ID)] for _, edge := range edgeList { if len(edgeLabels) == 0 || setcmp.ContainsString(edgeLabels, edge.config.Label) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { //log.Infof("Using EdgeTable %s", *edge.config.EdgeTable) res, err := t.client.GetRowsByField(ctx, - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection, - edge.config.EdgeTable.FromField, id) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection, + edge.config.Data.EdgeTable.FromField, id) if err == nil { for row := range res { data := row.Data.AsMap() - if dst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if dst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if dstStr, ok := dst.(string); ok { o := gdbi.Edge{ ID: edge.GenID(id, dstStr), - From: edge.config.FromVertex + id, - To: edge.config.ToVertex + dstStr, + From: edge.config.From + id, + To: edge.config.To + dstStr, Label: edge.config.Label, Data: row.Data.AsMap(), Loaded: true, @@ -815,11 +815,11 @@ func (t *TabularGraph) GetOutEdgeChannel(ctx context.Context, req chan gdbi.Elem log.Errorf("Row Error: %s", err) } } - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { cur := r.Ref.GetCurrent() fValue := "" if cur != nil && cur.ID == r.ID { - if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.FieldToField.FromField); err == nil { + if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.Data.FieldToField.FromField); err == nil { if vStr, ok := v.(string); ok { fValue = vStr } @@ -833,9 +833,9 @@ func (t *TabularGraph) GetOutEdgeChannel(ctx context.Context, req chan gdbi.Elem } if fValue != "" { res, err := t.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { for row := range res { o := gdbi.Edge{ @@ -856,7 +856,7 @@ func (t *TabularGraph) GetOutEdgeChannel(ctx context.Context, req chan gdbi.Elem } } - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("Need to implement FieldToID") } } @@ -885,16 +885,16 @@ func (t *TabularGraph) GetInEdgeChannel(ctx context.Context, req chan gdbi.Eleme id := r.ID[len(vPrefix):len(r.ID)] for _, edge := range edgeList { if len(edgeLabels) == 0 || setcmp.ContainsString(edgeLabels, edge.config.Label) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { //log.Printf("Using EdgeTable %s", *edge.config.EdgeTable) res, err := t.client.GetRowsByField(ctx, - edge.config.EdgeTable.Source, - edge.config.EdgeTable.Collection, - edge.config.EdgeTable.FromField, id) + edge.config.Data.EdgeTable.Source, + edge.config.Data.EdgeTable.Collection, + edge.config.Data.EdgeTable.FromField, id) if err == nil { for row := range res { data := row.Data.AsMap() - if dst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if dst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if dstStr, ok := dst.(string); ok { o := gdbi.Edge{ ID: edge.GenID(dstStr, id), @@ -913,11 +913,11 @@ func (t *TabularGraph) GetInEdgeChannel(ctx context.Context, req chan gdbi.Eleme log.Errorf("Row Error: %s", err) } } - } else if edge.config.FieldToField != nil { + } else if edge.config.Data.FieldToField != nil { cur := r.Ref.GetCurrent() fValue := "" if cur != nil && cur.ID == r.ID { - if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.FieldToField.FromField); err == nil { + if v, err := jsonpath.JsonPathLookup(cur.Data, edge.config.Data.FieldToField.FromField); err == nil { if vStr, ok := v.(string); ok { fValue = vStr } @@ -931,9 +931,9 @@ func (t *TabularGraph) GetInEdgeChannel(ctx context.Context, req chan gdbi.Eleme } if fValue != "" { res, err := t.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { for row := range res { o := gdbi.Edge{ @@ -953,7 +953,7 @@ func (t *TabularGraph) GetInEdgeChannel(ctx context.Context, req chan gdbi.Eleme } } } - } else if edge.config.FieldToID != nil { + } else if edge.config.Data.FieldToID != nil { log.Errorf("Need to implement FieldToID") } else { log.Errorf("No Edge plan configured") diff --git a/gripper/graphdb.go b/gripper/graphdb.go index 8ceb3252..4acf0682 100644 --- a/gripper/graphdb.go +++ b/gripper/graphdb.go @@ -4,7 +4,8 @@ import ( "context" "fmt" "log" - "path/filepath" + + //"path/filepath" "github.com/bmeg/grip/gdbi" "github.com/bmeg/grip/gripql" @@ -14,6 +15,7 @@ type TabularGDB struct { graphs map[string]*TabularGraph } +/* func NewGDB(conf Config, configPath string, sources map[string]string) (*TabularGDB, error) { out := TabularGDB{map[string]*TabularGraph{}} fPath := filepath.Join(filepath.Dir(configPath), conf.ConfigFile) @@ -29,6 +31,7 @@ func NewGDB(conf Config, configPath string, sources map[string]string) (*Tabular } return &out, nil } +*/ func NewGDBFromGraph(graph *gripql.Graph, sources map[string]string) (*TabularGDB, error) { out := TabularGDB{map[string]*TabularGraph{}} @@ -45,6 +48,17 @@ func NewGDBFromGraph(graph *gripql.Graph, sources map[string]string) (*TabularGD return &out, nil } +func NewGDBFromConfig(name string, conf *GraphConfig, sources map[string]string) (*TabularGDB, error) { + out := TabularGDB{map[string]*TabularGraph{}} + o, err := NewTabularGraph(*conf, sources) + if err == nil { + out.graphs[name] = o + } else { + log.Printf("Error loading graph config: %s", err) + } + return &out, nil +} + func (g *TabularGDB) AddGraph(string) error { return fmt.Errorf("AddGraph not implemented") } diff --git a/gripper/optimize.go b/gripper/optimize.go index 50eb678f..469c68e3 100644 --- a/gripper/optimize.go +++ b/gripper/optimize.go @@ -55,7 +55,7 @@ func (t *tabularHasLabelProc) Process(ctx context.Context, man gdbi.Manager, in default: } if setcmp.ContainsString(t.labels, table.config.Label) { - for row := range t.graph.client.GetRows(ctx, table.config.Source, table.config.Collection) { + for row := range t.graph.client.GetRows(ctx, table.config.Data.Source, table.config.Data.Collection) { out <- i.AddCurrent(&gdbi.DataElement{ ID: table.prefix + row.Id, Label: table.config.Label, @@ -103,19 +103,19 @@ func (t *tabularEdgeHasLabelProc) Process(ctx context.Context, man gdbi.Manager, default: } if setcmp.ContainsString(t.labels, edge.config.Label) { - if edge.config.EdgeTable != nil { + if edge.config.Data.EdgeTable != nil { //srcID := strings.TrimPrefix(src, edge.fromVertex.prefix) //dstID := strings.TrimPrefix(dst, edge.toVertex.prefix) - for row := range t.graph.client.GetRows(ctx, edge.config.EdgeTable.Source, edge.config.EdgeTable.Collection) { + for row := range t.graph.client.GetRows(ctx, edge.config.Data.EdgeTable.Source, edge.config.Data.EdgeTable.Collection) { data := row.Data.AsMap() - if rowSrc, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.FromField); err == nil { + if rowSrc, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.FromField); err == nil { if rowSrcStr, ok := rowSrc.(string); ok { - if rowDst, err := jsonpath.JsonPathLookup(data, edge.config.EdgeTable.ToField); err == nil { + if rowDst, err := jsonpath.JsonPathLookup(data, edge.config.Data.EdgeTable.ToField); err == nil { if rowDstStr, ok := rowDst.(string); ok { o := gdbi.Edge{ ID: edge.GenID(rowSrcStr, rowDstStr), //edge.prefix + row.Id, - To: edge.config.ToVertex + rowDstStr, - From: edge.config.FromVertex + rowSrcStr, + To: edge.config.To + rowDstStr, + From: edge.config.From + rowSrcStr, Label: edge.config.Label, Data: row.Data.AsMap(), Loaded: true, @@ -126,16 +126,16 @@ func (t *tabularEdgeHasLabelProc) Process(ctx context.Context, man gdbi.Manager, } } } - } else if edge.config.FieldToField != nil { - for srcRow := range t.graph.client.GetRows(ctx, edge.fromVertex.config.Source, edge.fromVertex.config.Collection) { + } else if edge.config.Data.FieldToField != nil { + for srcRow := range t.graph.client.GetRows(ctx, edge.fromVertex.config.Data.Source, edge.fromVertex.config.Data.Collection) { srcData := srcRow.Data.AsMap() - if srcField, err := jsonpath.JsonPathLookup(srcData, edge.config.FieldToField.FromField); err == nil { + if srcField, err := jsonpath.JsonPathLookup(srcData, edge.config.Data.FieldToField.FromField); err == nil { if fValue, ok := srcField.(string); ok { if fValue != "" { dstRes, err := t.graph.client.GetRowsByField(ctx, - edge.toVertex.config.Source, - edge.toVertex.config.Collection, - edge.config.FieldToField.ToField, fValue) + edge.toVertex.config.Data.Source, + edge.toVertex.config.Data.Collection, + edge.config.Data.FieldToField.ToField, fValue) if err == nil { for dstRow := range dstRes { o := gdbi.Edge{ diff --git a/gripper/test-graph/swapi.yaml b/gripper/test-graph/swapi.yaml index 2a54d832..00951be1 100644 --- a/gripper/test-graph/swapi.yaml +++ b/gripper/test-graph/swapi.yaml @@ -1,193 +1,210 @@ -sources: - tableServer: - host: localhost:50051 - vertices: - "Character:" : - source: tableServer + - gid: "Character:" label: Character - collection: Character + data: + source: tableServer + collection: Character - "Planet:" : - source: tableServer + - gid: "Planet:" label: Planet - collection: Planet + data: + collection: Planet + source: tableServer - "Film:" : - source: tableServer + - gid: "Film:" label: Film - collection: Film + data: + collection: Film + source: tableServer - "Species:" : - source: tableServer + - gid: "Species:" label: Species - collection: Species + data: + source: tableServer + collection: Species - "Starship:" : - source: tableServer + - gid: "Starship:" label: Starship - collection: Starship + data: + source: tableServer + collection: Starship - "Vehicle:" : - source: tableServer + - gid: "Vehicle:" label: Vehicle - collection: Vehicle + data: + source: tableServer + collection: Vehicle edges: - homeworld: - fromVertex: "Character:" - toVertex: "Planet:" + - gid: "homeworld" + from: "Character:" + to: "Planet:" label: homeworld - fieldToField: - fromField: $.homeworld - toField: $.id - - species: - fromVertex: "Character:" - toVertex: "Species:" + data: + fieldToField: + fromField: $.homeworld + toField: $.id + + - gid: species + from: "Character:" + to: "Species:" label: species - fieldToField: - fromField: $.species - toField: $.id - - people: - fromVertex: "Species:" - toVertex: "Character:" + data: + fieldToField: + fromField: $.species + toField: $.id + + - gid: people + from: "Species:" + to: "Character:" label: people - edgeTable: - source: tableServer - collection: speciesCharacter - fromField: $.from - toField: $.to - - - residents: - fromVertex: "Planet:" - toVertex: "Character:" + data: + edgeTable: + source: tableServer + collection: speciesCharacter + fromField: $.from + toField: $.to + + - gid: residents + from: "Planet:" + to: "Character:" label: residents - edgeTable: - source: tableServer - collection: planetCharacter - fromField: $.from - toField: $.to - - filmVehicles: - fromVertex: "Film:" - toVertex: "Vehicle:" + data: + edgeTable: + source: tableServer + collection: planetCharacter + fromField: $.from + toField: $.to + + - gid: filmVehicles + from: "Film:" + to: "Vehicle:" label: "vehicles" - edgeTable: - source: tableServer - collection: filmVehicles - fromField: "$.from" - toField: "$.to" - - vehicleFilms: - toVertex: "Film:" - fromVertex: "Vehicle:" + data: + edgeTable: + source: tableServer + collection: filmVehicles + fromField: "$.from" + toField: "$.to" + + - gid: vehicleFilms + to: "Film:" + from: "Vehicle:" label: "films" - edgeTable: - source: tableServer - collection: filmVehicles - toField: "$.from" - fromField: "$.to" - - filmStarships: - fromVertex: "Film:" - toVertex: "Starship:" + data: + edgeTable: + source: tableServer + collection: filmVehicles + toField: "$.from" + fromField: "$.to" + + - gid: filmStarships + from: "Film:" + to: "Starship:" label: "starships" - edgeTable: - source: tableServer - collection: filmStarships - fromField: "$.from" - toField: "$.to" - - starshipFilms: - toVertex: "Film:" - fromVertex: "Starship:" + data: + edgeTable: + source: tableServer + collection: filmStarships + fromField: "$.from" + toField: "$.to" + + - gid: starshipFilms + to: "Film:" + from: "Starship:" label: "films" - edgeTable: - source: tableServer - collection: filmStarships - toField: "$.from" - fromField: "$.to" - - filmPlanets: - fromVertex: "Film:" - toVertex: "Planet:" + data: + edgeTable: + source: tableServer + collection: filmStarships + toField: "$.from" + fromField: "$.to" + + - gid: filmPlanets + from: "Film:" + to: "Planet:" label: "planets" - edgeTable: - source: tableServer - collection: filmPlanets - fromField: "$.from" - toField: "$.to" - - planetFilms: - toVertex: "Film:" - fromVertex: "Planet:" + data: + edgeTable: + source: tableServer + collection: filmPlanets + fromField: "$.from" + toField: "$.to" + + - gid: planetFilms + to: "Film:" + from: "Planet:" label: "films" - edgeTable: - source: tableServer - collection: filmPlanets - toField: "$.from" - fromField: "$.to" - - filmSpecies: - fromVertex: "Film:" - toVertex: "Species:" + data: + edgeTable: + source: tableServer + collection: filmPlanets + toField: "$.from" + fromField: "$.to" + + - gid: filmSpecies + from: "Film:" + to: "Species:" label: "species" - edgeTable: - source: tableServer - collection: filmSpecies - fromField: "$.from" - toField: "$.to" - - speciesFilms: - toVertex: "Film:" - fromVertex: "Species:" + data: + edgeTable: + source: tableServer + collection: filmSpecies + fromField: "$.from" + toField: "$.to" + + - gid: speciesFilms + to: "Film:" + from: "Species:" label: "films" - edgeTable: - source: tableServer - collection: filmSpecies - toField: "$.from" - fromField: "$.to" - - filmCharacters: - fromVertex: "Film:" - toVertex: "Character:" + data: + edgeTable: + source: tableServer + collection: filmSpecies + toField: "$.from" + fromField: "$.to" + + - gid: filmCharacters + from: "Film:" + to: "Character:" label: characters - edgeTable: - source: tableServer - collection: filmCharacters - fromField: "$.from" - toField: "$.to" - - characterFilms: - fromVertex: "Character:" - toVertex: "Film:" + data: + edgeTable: + source: tableServer + collection: filmCharacters + fromField: "$.from" + toField: "$.to" + + - gid: characterFilms + from: "Character:" + to: "Film:" label: films - edgeTable: - source: tableServer - collection: filmCharacters - toField: "$.from" - fromField: "$.to" - - characterStarships: - fromVertex: "Character:" - toVertex: "Starship:" + data: + edgeTable: + source: tableServer + collection: filmCharacters + toField: "$.from" + fromField: "$.to" + + - gid: characterStarships + from: "Character:" + to: "Starship:" label: "starships" - edgeTable: - source: tableServer - collection: characterStarships - fromField: "$.from" - toField: "$.to" - - starshipCharacters: - toVertex: "Character:" - fromVertex: "Starship:" + data: + edgeTable: + source: tableServer + collection: characterStarships + fromField: "$.from" + toField: "$.to" + + - gid: starshipCharacters + to: "Character:" + from: "Starship:" label: "pilots" - edgeTable: - source: tableServer - collection: characterStarships - toField: "$.from" - fromField: "$.to" + data: + edgeTable: + source: tableServer + collection: characterStarships + toField: "$.from" + fromField: "$.to" diff --git a/gripql/graph.go b/gripql/graph.go index 83c3c495..03432849 100644 --- a/gripql/graph.go +++ b/gripql/graph.go @@ -145,3 +145,16 @@ func GraphToJSONString(graph *Graph) (string, error) { txt := m.Format(graph) return txt, nil } + +func GraphMapToProto(data map[string]interface{}) (*Graph, error) { + part, err := json.Marshal(data) + if err != nil { + return nil, err + } + g := &Graph{} + err = protojson.Unmarshal(part, g) + if err != nil { + return nil, err + } + return g, nil +} diff --git a/server/api.go b/server/api.go index 23e566e6..1b519d50 100644 --- a/server/api.go +++ b/server/api.go @@ -473,11 +473,7 @@ func (server *GripServer) AddMapping(ctx context.Context, req *gripql.Graph) (*g if err != nil { return nil, fmt.Errorf("failed to store new mapping: %v", err) } - c, err := gripper.GraphToConfig(req) - if err != nil { - return nil, err - } - server.mappings[req.Graph] = c + server.setupMapping(req.Graph, req) return &gripql.EditResult{}, nil } diff --git a/server/metagraphs.go b/server/metagraphs.go index 700b41d0..d3a6dfac 100644 --- a/server/metagraphs.go +++ b/server/metagraphs.go @@ -6,9 +6,10 @@ import ( "strings" "time" - "github.com/bmeg/grip/log" - + "github.com/bmeg/grip/config" + "github.com/bmeg/grip/gripper" "github.com/bmeg/grip/gripql" + "github.com/bmeg/grip/log" "github.com/bmeg/grip/util/rpc" ) @@ -23,6 +24,15 @@ func isMapping(graphName string) bool { return strings.HasSuffix(graphName, mappingSuffix) } +func (server *GripServer) setupMapping(name string, graph *gripql.Graph) { + server.mappings[name] = graph + mGraph, _ := gripper.GraphToConfig(graph) + dbs, err := StartDriver(server.conf, config.DriverConfig{Gripper: &gripper.Config{Mapping: mGraph}}) + if err == nil { + server.dbs[name] = dbs + } +} + func (server *GripServer) getGraph(graph string) (*gripql.Graph, error) { conn, err := gripql.Connect(rpc.ConfigWithDefaults(server.conf.Server.RPCAddress()), true) diff --git a/server/server.go b/server/server.go index bc42ea4a..1fdb3372 100644 --- a/server/server.go +++ b/server/server.go @@ -42,11 +42,11 @@ type GripServer struct { gripql.UnimplementedQueryServer gripql.UnimplementedEditServer gripql.UnimplementedJobServer - dbs map[string]gdbi.GraphDB //graph database drivers - graphMap map[string]string //mapping from graph name to graph database driver - conf *config.Config //global configuration - schemas map[string]*gripql.Graph //cached schemas - mappings map[string]*gripper.GraphConfig //cached gripper graph mappings + dbs map[string]gdbi.GraphDB //graph database drivers + graphMap map[string]string //mapping from graph name to graph database driver + conf *config.Config //global configuration + schemas map[string]*gripql.Graph //cached schemas + mappings map[string]*gripql.Graph //cached gripper graph mappings baseDir string jStorage jobstorage.JobStorage } @@ -70,7 +70,7 @@ func NewGripServer(conf *config.Config, baseDir string, drivers map[string]gdbi. } for name, dConfig := range conf.Drivers { if _, ok := gdbs[name]; !ok { - g, err := StartDriver(conf, dConfig, baseDir) + g, err := StartDriver(conf, dConfig) if err == nil { gdbs[name] = g } @@ -78,7 +78,6 @@ func NewGripServer(conf *config.Config, baseDir string, drivers map[string]gdbi. } server := &GripServer{dbs: gdbs, conf: conf, schemas: schemas} - /* for graph, schema := range schemas { if !server.graphExists(graph) { @@ -106,7 +105,7 @@ func NewGripServer(conf *config.Config, baseDir string, drivers map[string]gdbi. } // StartDriver: based on string entry in config file, figure out which driver to initialize -func StartDriver(conf *config.Config, d config.DriverConfig, baseDir string) (gdbi.GraphDB, error) { +func StartDriver(conf *config.Config, d config.DriverConfig) (gdbi.GraphDB, error) { if d.Bolt != nil { return kvgraph.NewKVGraphDB("bolt", *d.Bolt) } else if d.Badger != nil { @@ -124,7 +123,7 @@ func StartDriver(conf *config.Config, d config.DriverConfig, baseDir string) (gd } else if d.ExistingSQL != nil { return esql.NewGraphDB(*d.ExistingSQL) } else if d.Gripper != nil { - return gripper.NewGDB(*d.Gripper, baseDir, conf.Sources) + return gripper.NewGDBFromConfig(d.Gripper.Graph, d.Gripper.Mapping, conf.Sources) } return nil, fmt.Errorf("unknown driver: %#v", d) } @@ -139,11 +138,14 @@ func (server *GripServer) updateGraphMap() { o[g] = n if strings.HasSuffix(g, "__mapping__") { log.Infof("Starting up a gripper driver here") - } - graph, err := server.getGraph(g) - gConf, err := gripper.GraphToConfig(graph) - if err == nil { - fmt.Printf("Mapping: %s\n", gConf) + graph, err := server.getGraph(g) + if err == nil { + mapping, _ := gripper.GraphToConfig(graph) + gdb, err := StartDriver(server.conf, config.DriverConfig{Gripper: &gripper.Config{Mapping: mapping}}) + if err != nil { + server.dbs[strings.TrimSuffix(g, mappingSuffix)] = gdb + } + } } } } @@ -358,10 +360,7 @@ func (server *GripServer) Serve(pctx context.Context) error { log.WithFields(log.Fields{"graph": graph}).Debug("Loading existing mapping into cache") mapping, err := server.getGraph(graph) if err == nil { - config, err := gripper.GraphToConfig(mapping) - if err == nil { - server.mappings[strings.TrimSuffix(graph, mappingSuffix)] = config - } + server.mappings[strings.TrimSuffix(graph, mappingSuffix)] = mapping } } }