Skip to content

Commit

Permalink
Merge pull request #16 from beyondnetworks/master
Browse files Browse the repository at this point in the history
Updates to support Amazon Neptune
  • Loading branch information
damienstamates committed Apr 16, 2020
2 parents e76d18e + 16495be commit a0883ed
Show file tree
Hide file tree
Showing 55 changed files with 162 additions and 304 deletions.
2 changes: 1 addition & 1 deletion examples/add-vertex-by-struct/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {

// Print out the resulting vertex and its values.
logger.Info("Vertex", zap.String("label", vertex.Label()))
logger.Info("Vertex", zap.Int64("ID", vertex.ID()))
logger.Info("Vertex", zap.Any("ID", vertex.ID()))

for k, v := range vertex.PropertyMap() {
logger.Info("Property", zap.Any(k, v[0].GetValue()))
Expand Down
2 changes: 1 addition & 1 deletion examples/all-vertices/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func main() {
for _, vertex := range vertices {
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
)
}
}
2 changes: 1 addition & 1 deletion examples/drop-vertex-by-id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of dropping vertices using only their IDs using the `DropVertexByID`

## Description

**drop-vertex-by-id** demonstrates how to drop specific vertices on the graph using their IDs. Specifically this examples shows how to drop the vertices using the `DropVertexByID` function in the Grammes client which takes in an `int64` for the ID of the vertex.
**drop-vertex-by-id** demonstrates how to drop specific vertices on the graph using their IDs. Specifically this examples shows how to drop the vertices using the `DropVertexByID` function in the Grammes client which takes in an object for the ID of the vertex.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/id-by-label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDs` function.

## Description

**id-by-label** demonstrates how to get vertex IDs using a label. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and returns a `[]int64` and `error`. *(This function has multiple purposes and is also shown in `id-by-property`)*
**id-by-label** demonstrates how to get vertex IDs using a label. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and returns a `[]interface{}` and `error`. *(This function has multiple purposes and is also shown in `id-by-property`)*

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/id-by-label/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ func main() {
// Print out all the received vertex IDs.
// This should only print out one ID.
for _, id := range ids {
logger.Info("vertex id", zap.Int64("value", id))
logger.Info("vertex id", zap.Any("value", id))
}
}
2 changes: 1 addition & 1 deletion examples/id-by-property/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDs` function.

## Description

**id-by-property** demonstrates how to get vertex IDs using a label and vertex properties. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and `...interface{}` for properties. Then returns a `[]int64` and `error`. *(This function has multiple purposes and is also shown in `id-by-label`)*
**id-by-property** demonstrates how to get vertex IDs using a label and vertex properties. Specifically this examples shows how to by using the `VertexIDs` function which takes a `string` label and `...interface{}` for properties. Then returns a `[]interface{}` and `error`. *(This function has multiple purposes and is also shown in `id-by-label`)*

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/id-by-property/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ func main() {
// Print out all the received vertex IDs.
// This should only print out one ID.
for _, id := range ids {
logger.Info("vertex id", zap.Int64("value", id))
logger.Info("vertex id", zap.Any("value", id))
}
}
2 changes: 1 addition & 1 deletion examples/id-by-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDsByQuery` function.

## Description

**id-by-query** demonstrates how to get vertex IDs using a `Query` object. Specifically this examples shows how to by using the `VertexIDsByQuery` function which takes a `Query` object that's meant to identify one or more vertices then returns a `[]int64` and `error`.
**id-by-query** demonstrates how to get vertex IDs using a `Query` object. Specifically this examples shows how to by using the `VertexIDsByQuery` function which takes a `Query` object that's meant to identify one or more vertices then returns a `[]interface{}` and `error`.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/id-by-query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func main() {

// Print out all the received vertex IDs.
for _, id := range ids {
logger.Info("vertex id", zap.Int64("value", id))
logger.Info("vertex id", zap.Any("value", id))
}
}
2 changes: 1 addition & 1 deletion examples/id-by-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of getting vertex IDs using the `VertexIDsByString` function.

## Description

**id-by-query** demonstrates how to get vertex IDs using a `string` query. Specifically this examples shows how to by using the `VertexIDsByString` function which takes a `string` query that's meant to identify one or more vertices then returns a `[]int64` and `error`.
**id-by-query** demonstrates how to get vertex IDs using a `string` query. Specifically this examples shows how to by using the `VertexIDsByString` function which takes a `string` query that's meant to identify one or more vertices then returns a `[]interface{}` and `error`.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/id-by-string/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func main() {

// Print out all the received vertex IDs.
for _, id := range ids {
logger.Info("vertex id", zap.Int64("value", id))
logger.Info("vertex id", zap.Any("value", id))
}
}
2 changes: 1 addition & 1 deletion examples/vertex-by-id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The basics of getting vertices using the `VertexByID` function from a Grammes cl

## Description

**vertex-by-id** demonstrates how to receive a vertex on the graph using a Grammes client. Specifically this examples shows how to by using the `VertexByID` function which takes in an `int64` as the ID. Then returns a slice of `Vertex` and `error`.
**vertex-by-id** demonstrates how to receive a vertex on the graph using a Grammes client. Specifically this examples shows how to by using the `VertexByID` function which takes in an object as the ID. Then returns a slice of `Vertex` and `error`.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/vertex-by-id/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func main() {
// Print out the received vertex.
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
)
}
6 changes: 3 additions & 3 deletions examples/vertex-edge-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) {
// its ID, label, and its properties.

logger.Info("Edge",
zap.String("ID", edges[0].ID()),
zap.Any("ID", edges[0].ID()),
zap.String("Label", edges[0].Label()),
zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")),
zap.Any("driveDist", edges[0].PropertyValue("driveDist")),
)

logger.Info("OutVertex",
zap.Int64("ID", edges[0].OutVertexID()),
zap.Any("ID", edges[0].OutVertexID()),
zap.String("Label", edges[0].OutVertexLabel()),
zap.Any("Name", v1.PropertyValue("name", 0)),
)

logger.Info("InVertex",
zap.Int64("ID", edges[0].InVertexID()),
zap.Any("ID", edges[0].InVertexID()),
zap.String("Label", edges[0].InVertexLabel()),
zap.Any("Name", v2.PropertyValue("name", 0)),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/vertices-by-label/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
for _, vertex := range vertices {
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
)
}
}
2 changes: 1 addition & 1 deletion examples/vertices-by-property/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
for _, vertex := range vertices {
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
zap.Any("name", vertex.PropertyValue("name", 0)),
)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vertices-by-query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
for _, vertex := range vertices {
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
)
}
}
2 changes: 1 addition & 1 deletion examples/vertices-by-string/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func main() {
for _, vertex := range vertices {
logger.Info("gathered vertex",
zap.String("label", vertex.Label()),
zap.Int64("id", vertex.ID()),
zap.Any("id", vertex.ID()),
)
}
}
25 changes: 13 additions & 12 deletions gremconnect/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func MarshalResponse(msg []byte) (Response, error) {
code = status["code"].(float64)
resp = Response{Code: int(code)}
)
message, _ := status["message"].(string)

err = responseDetectError(resp.Code)
err = responseDetectError(resp.Code, message)
if err != nil {
resp.Data = err // Use the Data field as a vehicle for the error.
} else {
Expand All @@ -67,7 +68,7 @@ func MarshalResponse(msg []byte) (Response, error) {

// responseDetectError detects any possible errors in responses
// from Gremlin Server and generates an error for each code
func responseDetectError(code int) error {
func responseDetectError(code int, message string) error {
switch code {
case 200:
break
Expand All @@ -76,25 +77,25 @@ func responseDetectError(code int) error {
case 206:
break
case 401:
return gremerror.NewNetworkError(401, "UNAUTHORIZED")
return gremerror.NewNetworkError(401, "UNAUTHORIZED", message)
case 407:
return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED")
return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", message)
case 498:
return gremerror.NewNetworkError(498, "MALFORMED REQUEST")
return gremerror.NewNetworkError(498, "MALFORMED REQUEST", message)
case 499:
return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS")
return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", message)
case 500:
return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR")
return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", message)
case 503:
return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE")
return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE", message)
case 597:
return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR")
return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", message)
case 598:
return gremerror.NewNetworkError(598, "SERVER TIMEOUT")
return gremerror.NewNetworkError(598, "SERVER TIMEOUT", message)
case 599:
return gremerror.NewNetworkError(599, "SERIALIZATION ERROR")
return gremerror.NewNetworkError(599, "SERIALIZATION ERROR", message)
default:
return gremerror.NewNetworkError(code, "UNKNOWN ERROR")
return gremerror.NewNetworkError(code, "UNKNOWN ERROR", message)
}
return nil
}
19 changes: 10 additions & 9 deletions gremconnect/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var (
{
"requestId": "d2476e5b-b2bc-6a70-2647-3991f68ab415",
"status": {
"message": "Some error",
"code": 401,
"attributes": {}
},
Expand Down Expand Up @@ -233,67 +234,67 @@ func TestMarshalRespone(t *testing.T) {
})

Convey("And resp401.Data should be 'UNAUTHORIZED'", func() {
So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED"))
So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED", "Some error"))
})

Convey("Then the status code should be 407", func() {
So(resp407.Code, ShouldEqual, 407)
})

Convey("And resp407.Data should be 'AUTHENTICATE'", func() {
So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED"))
So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", ""))
})

Convey("Then the status code should be 498", func() {
So(resp498.Code, ShouldEqual, 498)
})

Convey("And resp498.Data should be 'MALFORMED REQUEST", func() {
So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST"))
So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST", ""))
})

Convey("Then the status code should be 499", func() {
So(resp499.Code, ShouldEqual, 499)
})

Convey("And resp499.Data should be 'INVALID REQUEST ARGUMENTS'", func() {
So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS"))
So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", ""))
})

Convey("Then the status code should be 500", func() {
So(resp500.Code, ShouldEqual, 500)
})

Convey("And resp500.Data should be 'SERVER ERROR'", func() {
So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR"))
So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", ""))
})

Convey("Then the status code should be 597", func() {
So(resp597.Code, ShouldEqual, 597)
})

Convey("And resp597.Data should be 'SCRIPT EVALUATION ERROR'", func() {
So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR"))
So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", ""))
})

Convey("Then the status code should be 598", func() {
So(resp598.Code, ShouldEqual, 598)
})

Convey("And resp598.Data should be 'SERVER TIMEOUT'", func() {
So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT"))
So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT", ""))
})

Convey("Then the status code should be 599", func() {
So(resp599.Code, ShouldEqual, 599)
})

Convey("And resp599.Data should be 'SERVER SERIALIZATION ERROR'", func() {
So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR"))
So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR", ""))
})

Convey("Then respDefault.Data should be 'UNKNOWN ERROR'", func() {
So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR"))
So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR", ""))
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion gremerror/networkerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import "strconv"
type NetworkError struct {
statusCode int
msg string
origMsg string
}

// NewNetworkError returns a status code related error.
func NewNetworkError(statusCode int, msg string) error {
func NewNetworkError(statusCode int, msg string, origMsg string) error {
return &NetworkError{
statusCode: statusCode,
msg: msg,
origMsg: origMsg,
}
}

Expand All @@ -41,5 +43,6 @@ func (g *NetworkError) Error() string {
fmtError("type", "NETWORK_ERROR"),
fmtError("status code", strconv.Itoa(g.statusCode)),
fmtError("error", g.msg),
fmtError("original error", g.origMsg),
)
}
19 changes: 7 additions & 12 deletions manager/addvertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ import (
var testVertex = model.Vertex{
Type: "testType",
Value: model.VertexValue{
ID: model.ID{
Type: "testID",
Value: 1234,
},
ID: 1234,
Label: "testLabel",
Properties: model.PropertyMap{"testDetail": []model.Property{
model.Property{
{
Type: "testType",
Value: model.PropertyValue{
ID: model.PropertyID{
Type: "testIDType",
Value: model.PropertyIDValue{
RelationID: "testRelID",
},
Type: "testIDType",
Value: "testRelID",
},
Value: model.ValueWrapper{
PropertyDetailedValue: model.PropertyDetailedValue{
Expand Down Expand Up @@ -76,7 +71,7 @@ func TestAddAPIVertex(t *testing.T) {
data.Properties = map[string]string{"testkey": "testval"}
v, _ := qm.AddAPIVertex(data)
Convey("Then the return vertex ID value should be 28720", func() {
So(v.Value.ID.Value, ShouldEqual, 28720)
So(v.Value.ID, ShouldEqual, 28720)
})
})
})
Expand All @@ -103,7 +98,7 @@ func TestAddVertexByStruct(t *testing.T) {
Convey("When AddVertexByStruct is called", func() {
res, _ := qm.AddVertexByStruct(testVertex)
Convey("Then the return vertex ID value should be 28720", func() {
So(res.Value.ID.Value, ShouldEqual, 28720)
So(res.Value.ID, ShouldEqual, 28720)
})
})
})
Expand Down Expand Up @@ -169,7 +164,7 @@ func TestAddVertexByQuery(t *testing.T) {
var q mockQuery
res, _ := qm.AddVertexByQuery(q)
Convey("Then the return vertex ID value should be 28720", func() {
So(res.Value.ID.Value, ShouldEqual, 28720)
So(res.Value.ID, ShouldEqual, 28720)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion manager/dropvertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (v *dropQueryManager) DropVertexLabel(label string) error {
return nil
}

func (v *dropQueryManager) DropVertexByID(ids ...int64) error {
func (v *dropQueryManager) DropVertexByID(ids ...interface{}) error {
var err error
for _, id := range ids {
query := traversal.NewTraversal().V().HasID(id).Drop()
Expand Down
Loading

0 comments on commit a0883ed

Please sign in to comment.