1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Frank Celler 2013-02-13 14:34:00 +01:00
commit e37c0c1d21
10 changed files with 363 additions and 13 deletions

View File

@ -0,0 +1,20 @@
> curl --data @- -X PATCH --dump - http://localhost:8529/_api/graph/graph1/edge/edge1
{"optional3" : "val3"}
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"edge": {
"_id": "e/edge1",
"_rev": "57595398",
"_key": "edge1",
"_from": "v/vert2",
"_to": "v/vert1",
"$label": null,
"optional2": "val2",
"optional3": "val3"
},
"error": false,
"code": 200
}

View File

@ -0,0 +1,34 @@
> curl --data @- -X PATCH --dump - http://localhost:8529/_api/graph/graph1/vertex/v1
{"optional2" : "vertexPatch2"}
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"vertex": {
"_id": "v/v1",
"_rev": "24332193",
"_key": "v1",
"optional1": "val2",
"optional2": "vertexPatch2"
},
"error": false,
"code": 200
}
> curl --data @- -X PATCH --dump - http://localhost:8529/_api/graph/graph1/vertex/v1?keepNull=false
{"optional2" : null}
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"vertex": {
"_id": "v/v1",
"_rev": "24332199",
"_key": "v1",
"optional1": "val2"
},
"error": false,
"code": 200
}

View File

@ -27,6 +27,10 @@ HTTP Interface for Graphs {#HttpGraph}
@anchor A_JSF_PUT_graph_vertex
@copydetails JSF_put_graph_vertex
@CLEARPAGE
@anchor A_JSF_PATCH_graph_vertex
@copydetails JSF_patch_graph_vertex
@CLEARPAGE
@anchor A_JSF_DELETE_graph_vertex
@copydetails JSF_delete_graph_vertex
@ -43,6 +47,10 @@ HTTP Interface for Graphs {#HttpGraph}
@anchor A_JSF_PUT_graph_edge
@copydetails JSF_put_graph_edge
@CLEARPAGE
@anchor A_JSF_PATCH_graph_edge
@copydetails JSF_patch_graph_edge
@CLEARPAGE
@anchor A_JSF_DELETE_graph_edge
@copydetails JSF_delete_graph_edge

View File

@ -8,10 +8,12 @@ TOC {#HttpGraphTOC}
- @ref A_JSF_POST_graph_vertex "POST /_api/graph/graph-name/vertex"
- @ref A_JSF_GET_graph_vertex "GET /_api/graph/graph-name/vertex"
- @ref A_JSF_PUT_graph_vertex "PUT /_api/graph/graph-name/vertex"
- @ref A_JSF_PATCH_graph_vertex "PATCH /_api/graph/graph-name/vertex"
- @ref A_JSF_DELETE_graph_vertex "DELETE /_api/graph/graph-name/vertex"
- @ref A_JSF_POST_graph_vertices "POST /_api/graph/graph-name/vertices"
- @ref A_JSF_POST_graph_edge "POST /_api/graph/graph-name/edge"
- @ref A_JSF_GET_graph_edge "GET /_api/graph/graph-name/edge"
- @ref A_JSF_PUT_graph_edge "PUT /_api/graph/graph-name/edge"
- @ref A_JSF_PATCH_graph_edge "PATCH /_api/graph/graph-name/edge"
- @ref A_JSF_DELETE_graph_edge "DELETE /_api/graph/graph-name/edge"
- @ref A_JSF_POST_graph_edges "POST /_api/graph/graph-name/edges"

View File

@ -69,6 +69,8 @@ case "$1" in
;;
upgrade)
echo $"Upgrading ArangoDB database files"
start --upgrade
;;

View File

@ -22,8 +22,6 @@ CONF=/etc/arangodb/arangod.conf
test -x $DAEMON || exit 0
start () {
log_begin_msg "Starting $DESC" "$NAME"
pid=$( pidofproc -p $PIDFILE $DAEMON )
if [ -n "$pid" ] ; then
@ -41,6 +39,8 @@ start () {
case "$1" in
start)
log_begin_msg "Starting $DESC" "$NAME"
start
;;
@ -68,6 +68,8 @@ case "$1" in
;;
upgrade)
log_begin_msg "Upgrading $DESC" "$NAME"
start --upgrade
;;

View File

@ -44,8 +44,6 @@ ARANGO_PIDFILE=/var/run/arangodb/arangod.pid
rc_reset
start () {
echo -n "Starting ARANGODB daemon"
ARANGO_PIDDIR=`dirname $ARANGO_PIDFILE`
test -d $ARANGO_PIDDIR || (mkdir $ARANGO_PIDDIR && chown arangodb $ARANGO_PIDDIR)
@ -63,6 +61,8 @@ case "$1" in
################################################################################
start)
echo -n "Starting ArangoDB daemon"
start
;;
@ -72,7 +72,7 @@ case "$1" in
################################################################################
stop)
echo -n "Shutting down ARANGODB daemon"
echo -n "Shutting down ArangoDB daemon"
killproc -t $ARANGO_TIMEOUT -p $ARANGO_PIDFILE -TERM $ARANGO_BIN
@ -112,7 +112,7 @@ case "$1" in
################################################################################
force-reload|reload)
echo -n "Reload service ARANGODB"
echo -n "Reload service ArangoDB"
echo "reload is currently not supported"
@ -132,7 +132,7 @@ case "$1" in
################################################################################
status)
echo -n "Checking for service ARANGODB"
echo -n "Checking for service ArangoDB"
checkproc -p $ARANGO_PIDFILE $ARANGO_BIN
@ -145,6 +145,8 @@ case "$1" in
################################################################################
upgrade)
echo -n "Upgrading ArangoDB database files"
start --upgrade
;;

View File

@ -16,7 +16,7 @@
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/arangod
DESC="ArangoDB"
NAME="arangodb"
NAME="arangod"
PIDDIR=/var/run/arangodb
PIDFILE=${PIDDIR}/arangod.pid
CONF=/etc/arangodb/arangod.conf
@ -24,8 +24,6 @@ CONF=/etc/arangodb/arangod.conf
test -x $DAEMON || exit 0
start () {
log_daemon_msg "Starting $DESC" "$NAME"
test -d $PIDDIR || mkdir $PIDDIR
chown arangodb $PIDDIR
@ -35,6 +33,8 @@ start () {
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start
;;
@ -62,6 +62,8 @@ case "$1" in
;;
upgrade)
log_daemon_msg "Upgrading $DESC" "$NAME"
start --upgrade
;;

View File

@ -20,7 +20,7 @@ describe ArangoDB do
def create_graph (prefix, name, vertices, edges)
cmd = "/_api/graph"
body = "{\"_key\" : \"#{name}\", \"vertices\" : \"#{vertices}\", \"edges\" : \"#{edges}\"}"
body = "{\"_key\" : \"#{name}\", \"vertices\" : \"#{vertices}\", \"edges\" : \"#{edges}\"}"
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
return doc
end
@ -31,9 +31,20 @@ describe ArangoDB do
return doc
end
def patch_vertex (prefix, graphName, name, body, keepNull)
if keepNull == '' then
cmd = "/_api/graph/#{graphName}/vertex/#{name}"
else
cmd = "/_api/graph/#{graphName}/vertex/#{name}?keepNull=#{keepNull}"
end
doc = ArangoDB.log_patch("#{prefix}", cmd, :body => body)
return doc
end
def create_simple_vertex (prefix, graphName, name)
cmd = "/_api/graph/#{graphName}/vertex"
body = "{\"_key\" : \"#{name}\"}"
body = "{\"_key\" : \"#{name}\"}"
doc = ArangoDB.post(cmd, :body => body)
return doc
end
@ -56,6 +67,18 @@ describe ArangoDB do
return doc
end
def patch_edge (prefix, graphName, name, body, keepNull)
if keepNull == '' then
cmd = "/_api/graph/#{graphName}/edge/#{name}"
else
cmd = "/_api/graph/#{graphName}/edge/#{name}?keepNull=#{keepNull}"
end
doc = ArangoDB.log_patch("#{prefix}", cmd, :body => body)
return doc
end
################################################################################
## checking graph responses
################################################################################
@ -323,6 +346,55 @@ describe ArangoDB do
doc4.parsed_response['code'].should eq(400)
end
it "checks patch vertex" do
body = "{\"optional1\" : \"vertexPatch1\"}"
doc = create_vertex( prefix, graph_name, body )
doc.code.should eq(201)
doc.parsed_response['error'].should eq(false)
doc.parsed_response['vertex']['optional1'].should eq('vertexPatch1')
_key = doc.parsed_response['vertex']['_key'];
body = "{\"optional2\" : \"vertexPatch2\"}"
doc3 = patch_vertex(prefix, graph_name, _key, body, '')
doc3.code.should eq(200)
doc3.parsed_response['error'].should eq(false)
doc3.parsed_response['vertex']['optional1'].should eq('vertexPatch1')
doc3.parsed_response['vertex']['optional2'].should eq('vertexPatch2')
body = "{\"_key\":\"egal\", \"optional2\" : null}"
doc2 = patch_vertex(prefix, graph_name, _key, body, '')
doc2.code.should eq(200)
doc2.parsed_response['error'].should eq(false)
doc2.parsed_response['code'].should eq(200)
doc2.parsed_response['vertex']['optional1'].should eq('vertexPatch1')
doc2.parsed_response['vertex']['optional2'].should be_nil
doc2.parsed_response['vertex']['_key'].should eq(_key)
body = ""
doc4 = patch_vertex(prefix, graph_name, _key, body, '')
doc4.code.should eq(200)
doc4.parsed_response['error'].should eq(false)
doc4.parsed_response['code'].should eq(200)
doc4.parsed_response['vertex']['optional1'].should eq('vertexPatch1')
doc4.parsed_response['vertex']['optional2'].should be_nil
doc2.parsed_response['vertex']['_key'].should eq(_key)
body = "{\"_key\":\"egal\", \"optional2\" : null}"
doc5 = patch_vertex(prefix, graph_name, _key, body, 'false')
doc5.code.should eq(200)
doc5.parsed_response['error'].should eq(false)
doc5.parsed_response['code'].should eq(200)
doc5.parsed_response['vertex']['optional1'].should eq('vertexPatch1')
doc2.parsed_response['vertex']['_key'].should eq(_key)
doc5.parsed_response['vertex'].should_not have_key('optional2')
body = "error in body"
doc6 = patch_vertex(prefix, graph_name, _key, body, 'false')
doc6.code.should eq(400)
end
end
################################################################################
@ -513,6 +585,52 @@ describe ArangoDB do
end
it "checks patch edge" do
body = "{\"_key\" : \"patchEdge\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"$label\" : \"label1\", \"optional1\" : \"val1\"}"
doc = create_edge( prefix, graph_name, body )
doc.code.should eq(201)
doc.parsed_response['error'].should eq(false)
doc.parsed_response['code'].should eq(201)
doc.parsed_response['edge']['optional1'].should eq("val1")
doc.parsed_response['edge'].should_not have_key('optional2')
doc.parsed_response['edge']['$label'].should eq("label1")
doc.parsed_response['edge']['_key'].should eq("patchEdge")
_key = doc.parsed_response['edge']['_key'];
body = "{\"$label\" : \"egal\", \"optional2\" : \"val2\"}"
doc1 = patch_edge("#{prefix}", graph_name, _key, body, '');
doc1.code.should eq(200)
doc1.parsed_response['edge']['optional1'].should eq("val1")
doc1.parsed_response['edge']['optional2'].should eq("val2")
doc1.parsed_response['edge']['$label'].should eq("label1")
doc1.parsed_response['edge']['_key'].should eq("patchEdge")
body = "{\"optional2\" : null}"
doc2 = patch_edge("#{prefix}", graph_name, _key, body, '');
doc2.code.should eq(200)
doc2.parsed_response['edge']['optional1'].should eq("val1")
doc2.parsed_response['edge']['optional2'].should be_nil
doc2.parsed_response['edge']['$label'].should eq("label1")
doc2.parsed_response['edge']['_key'].should eq("patchEdge")
body = "{\"optional1\" : null}"
doc3 = patch_edge("#{prefix}", graph_name, _key, body, 'false');
doc3.code.should eq(200)
doc3.parsed_response['edge'].should_not have_key('optional1')
doc3.parsed_response['edge']['optional2'].should be_nil
doc3.parsed_response['edge']['$label'].should eq("label1")
doc3.parsed_response['edge']['_key'].should eq("patchEdge")
body = ""
doc4 = patch_edge("#{prefix}", graph_name, _key, body, '');
doc4.code.should eq(200)
doc3.parsed_response['edge'].should_not have_key('optional1')
doc3.parsed_response['edge']['optional2'].should be_nil
doc3.parsed_response['edge']['$label'].should eq("label1")
doc3.parsed_response['edge']['_key'].should eq("patchEdge")
end
end
################################################################################

View File

@ -390,6 +390,7 @@ function put_graph_vertex (req, res, g) {
var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX);
if (json === undefined) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "error in request body");
return;
}
@ -405,6 +406,64 @@ function put_graph_vertex (req, res, g) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief updates a vertex
///
/// @RESTHEADER{PATCH /_api/graph/@FA{graph-name}/vertex,update vertex}
///
/// @REST{PATCH /_api/graph/@FA{graph-name}/vertex/@FA{vertex-name}}
///
////////////////////////////////////////////////////////////////////////////////
///
/// Partially updates the vertex properties.
///
/// The call expects a JSON hash array as body with the properties to patch.
///
/// Setting an attribute value to @LIT{null} in the patch document will cause a value
/// of @LIT{null} be saved for the attribute by default. If the intention is to
/// delete existing attributes with the patch command, the URL parameter
/// @LIT{keepNull} can be used with a value of @LIT{false}.
/// This will modify the behavior of the patch command to remove any attributes
/// from the existing document that are contained in the patch document
/// with an attribute value of @LIT{null}.
//
/// Returns an object with an attribute @LIT{vertex} containing a
/// list of all vertex properties.
///
/// @EXAMPLES
///
/// @verbinclude api-graph-changep-vertex
////////////////////////////////////////////////////////////////////////////////
function patch_graph_vertex (req, res, g) {
try {
var v = vertex_by_request(req, g);
var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX);
if (json === undefined) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "error in request body");
return;
}
var keepNull = req.parameters['keepNull'];
if (keepNull != undefined || keepNull == "false") {
keepNull = false;
}
else {
keepNull = true;
}
var id2 = g._vertices.update(v._properties, json, true, keepNull);
var result = g._vertices.document(id2);
actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : result } );
}
catch (err) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, err);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the compare operator (throws exception)
////////////////////////////////////////////////////////////////////////////////
@ -717,6 +776,7 @@ function post_graph_edge (req, res, g) {
var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE);
if (json === undefined) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE, "error in request body");
return;
}
@ -817,6 +877,7 @@ function put_graph_edge (req, res, g) {
var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE);
if (json === undefined) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "error in request body");
return;
}
@ -833,6 +894,67 @@ function put_graph_edge (req, res, g) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief updates an edge
///
/// @RESTHEADER{PATCH /_api/graph/@FA{graph-name}/edge,update edge}
///
/// @REST{PATCH /_api/graph/@FA{graph-name}/edge/@FA{vertex-name}}
///
////////////////////////////////////////////////////////////////////////////////
///
/// Partially updates the edge properties.
///
/// The call expects a JSON hash array as body with the properties to patch.
///
/// Setting an attribute value to @LIT{null} in the patch document will cause a value
/// of @LIT{null} be saved for the attribute by default. If the intention is to
/// delete existing attributes with the patch command, the URL parameter
/// @LIT{keepNull} can be used with a value of @LIT{false}.
/// This will modify the behavior of the patch command to remove any attributes
/// from the existing document that are contained in the patch document
/// with an attribute value of @LIT{null}.
//
/// Returns an object with an attribute @LIT{edge} containing a
/// list of all edge properties.
///
/// @EXAMPLES
///
/// @verbinclude api-graph-changep-edge
////////////////////////////////////////////////////////////////////////////////
function patch_graph_edge (req, res, g) {
try {
var e = edge_by_request(req, g);
var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE);
if (json === undefined) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "error in request body");
return;
}
var keepNull = req.parameters['keepNull'];
if (keepNull != undefined || keepNull == "false") {
keepNull = false;
}
else {
keepNull = true;
}
var shallow = json.shallowCopy;
shallow.$label = e._properties.$label;
var id2 = g._edges.update(e._properties, shallow, true, keepNull);
var result = g._edges.document(id2);
actions.resultOk(req, res, actions.HTTP_OK, { "edge" : result} );
}
catch (err) {
actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, err);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get edges of a graph
///
@ -1182,7 +1304,41 @@ function put_graph (req, res) {
}
}
}
//
////////////////////////////////////////////////////////////////////////////////
/// @brief handle patch requests
////////////////////////////////////////////////////////////////////////////////
function patch_graph (req, res) {
if (req.suffix.length < 2) {
// PATCH /_api/graph
actions.resultUnsupported(req, res);
}
else {
// PATCh /_api/graph/<key>/...
try {
var g = graph_by_request(req);
switch (req.suffix[1]) {
case ("vertex") :
patch_graph_vertex(req, res, g);
break;
case ("edge") :
patch_graph_edge(req, res, g);
break;
default:
actions.resultUnsupported(req, res);
}
}
catch (err) {
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief handle delete requests
////////////////////////////////////////////////////////////////////////////////
@ -1248,6 +1404,10 @@ actions.defineHttp({
put_graph(req, res);
break;
case (actions.PATCH) :
patch_graph(req, res);
break;
default:
actions.resultUnsupported(req, res);
}