Skip to content

Commit

Permalink
Added Pregel API support with 3.10 features
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoubert authored and DiscoPYF committed Sep 28, 2022
1 parent ec7b030 commit 06bec11
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 0 deletions.
7 changes: 7 additions & 0 deletions arangodb-net-standard/ArangoDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ArangoDBNetStandard.DocumentApi;
using ArangoDBNetStandard.GraphApi;
using ArangoDBNetStandard.IndexApi;
using ArangoDBNetStandard.PregelApi;
using ArangoDBNetStandard.Serialization;
using ArangoDBNetStandard.TransactionApi;
using ArangoDBNetStandard.Transport;
Expand Down Expand Up @@ -99,6 +100,11 @@ public class ArangoDBClient : IArangoDBClient
/// </summary>
public AdminApiClient Admin { get; private set; }

/// <summary>
/// Pregel management API
/// </summary>
public PregelApiClient Pregel { get; private set; }

/// <summary>
/// Create an instance of <see cref="ArangoDBClient"/> from an existing
/// <see cref="HttpClient"/> instance, using the default JSON serialization.
Expand Down Expand Up @@ -166,6 +172,7 @@ private void InitializeApis(
View = new ViewApiClient(transport, serialization);
Analyzer = new AnalyzerApiClient(transport, serialization);
Admin = new AdminApiClient(transport, serialization);
Pregel = new PregelApiClient(transport, serialization);
}
}
}
6 changes: 6 additions & 0 deletions arangodb-net-standard/IArangoDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ArangoDBNetStandard.DocumentApi;
using ArangoDBNetStandard.GraphApi;
using ArangoDBNetStandard.IndexApi;
using ArangoDBNetStandard.PregelApi;
using ArangoDBNetStandard.TransactionApi;
using ArangoDBNetStandard.UserApi;
using ArangoDBNetStandard.ViewApi;
Expand Down Expand Up @@ -87,5 +88,10 @@ public interface IArangoDBClient : IDisposable
/// Admin API
/// </summary>
AdminApiClient Admin { get; }

/// <summary>
/// Pregel API
/// </summary>
PregelApiClient Pregel { get; }
}
}
76 changes: 76 additions & 0 deletions arangodb-net-standard/PregelApi/IPregelApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using ArangoDBNetStandard.PregelApi.Models;
using ArangoDBNetStandard.ViewApi.Models;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using static System.Net.WebRequestMethods;

namespace ArangoDBNetStandard.PregelApi
{
/// <summary>
/// Defines a client to access the ArangoDB API for Pregel
/// (Distributed Iterative Graph Processing).
/// </summary>
public interface IPregelApiClient
{
/// <summary>
/// Start the execution of a Pregel algorithm.
/// POST /_api/control_pregel
/// </summary>
/// <remarks>
/// To start an execution you need to specify the
/// algorithm name and a named graph (SmartGraph in cluster).
/// Alternatively you can specify the vertex and edge collections.
/// Additionally you can specify custom parameters which
/// vary for each algorithm
/// </remarks>
/// <param name="body">The body of the request containing required properties.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns>The ID of the newly started job.</returns>
Task<string> PostStartJobAsync(
PostStartJobBody body,
CancellationToken token = default);

/// <summary>
/// Get the status of a Pregel job execution.
/// GET /_api/control_pregel/{id}
/// </summary>
/// <param name="jobId">The ID of the job.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
Task<PregelJobStatus> GetJobStatusAsync(
string jobId,
CancellationToken token = default);

/// <summary>
/// Get the overview of currently running Pregel jobs.
/// GET /_api/control_pregel
/// </summary>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns>
/// Returns a list of currently running and recently
/// finished Pregel jobs without retrieving their results.
/// </returns>
Task<List<PregelJobStatus>> GetAllRunningJobsAsync(
CancellationToken token = default);

/// <summary>
/// Cancel an ongoing Pregel execution.
/// DELETE /_api/control_pregel/{id}
/// </summary>
/// <remarks>
/// Cancel an execution which is still running, and
/// discard any intermediate results. This will immediately
/// free all memory taken up by the execution, and will
/// make you lose all intermediary data.
/// For more information <see cref="https://www.arangodb.com/docs/stable/http/pregel.html#cancel-pregel-job-execution"/>
/// </remarks>
/// <param name="jobId">The ID of the job.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
Task<string> DeleteJobAsync(
string jobId,
CancellationToken token = default);
}
}
57 changes: 57 additions & 0 deletions arangodb-net-standard/PregelApi/Models/PostStartJobBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using static System.Net.WebRequestMethods;

namespace ArangoDBNetStandard.PregelApi.Models
{
/// <summary>
/// Body parameter for
/// <see cref="IPregelApiClient.PostStartJobAsync(PostStartJobBody, System.Threading.CancellationToken)"/>
/// </summary>
public class PostStartJobBody
{
/// <summary>
/// Required. Name of the algorithm.
/// See <see cref="PregelAlgorithms"/> for possible values.
/// </summary>
public string Algorithm { get; set; }

/// <summary>
/// Optional. Name of a graph. Either this or the parameters
/// <see cref="VertexCollections"/> and <see cref="EdgeCollections"/>
/// are required.
/// </summary>
/// <remarks>
/// Please note that there are special sharding requirements
/// for graphs in order to be used with Pregel.
/// </remarks>
public string GraphName { get; set; }

/// <summary>
/// List of vertex collection names.
/// </summary>
/// <remarks>
/// Please note that there are special sharding requirements
/// for collections in order to be used with Pregel.
/// </remarks>
public IEnumerable<string> VertexCollections { get; set; }

/// <summary>
/// List of edge collection names.
/// </summary>
/// <remarks>
/// Please note that there are special sharding requirements
/// for collections in order to be used with Pregel.
/// </remarks>
public IEnumerable<string> EdgeCollections { get; set; }

/// <summary>
/// General as well as algorithm-specific options.
/// </summary>
/// <remarks>
/// <see cref="https://www.arangodb.com/docs/stable/http/pregel.html#start-pregel-job-execution"/>
/// </remarks>
public Dictionary<string,object> Params { get; set; }
}
}
58 changes: 58 additions & 0 deletions arangodb-net-standard/PregelApi/Models/PregelAlgorithms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace ArangoDBNetStandard.PregelApi.Models
{
/// <summary>
/// List of pregel algorithm names
/// </summary>
public struct PregelAlgorithms
{
/// <summary>
/// Page Rank
/// </summary>
public const string PageRank = "pagerank";

/// <summary>
/// Single-Source Shortest Path
/// </summary>
public const string SSSP = "sssp";

/// <summary>
/// Connected Components
/// </summary>
public const string ConnectedComponents = "connectedcomponents";

/// <summary>
/// Weakly Connected Components
/// </summary>
public const string WCC = "wcc";

/// <summary>
/// Strongly Connected Components
/// </summary>
public const string SCC = "scc";

/// <summary>
/// Hyperlink-Induced Topic Search
/// </summary>
public const string HITS = "hits";

/// <summary>
/// Effective Closeness
/// </summary>
public const string EffectiveCloseness = "effectivecloseness";

/// <summary>
/// LineRank
/// </summary>
public const string LineRank = "linerank";

/// <summary>
/// Label Propagation
/// </summary>
public const string LabelPropagation = "labelpropagation";

/// <summary>
/// Speaker-Listener Label Propagation
/// </summary>
public const string SLPA = "slpa";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ArangoDBNetStandard.PregelApi.Models
{
public class PregelJobAggregatedStatus
{
public string TimeStamp { get; set; }
public PregelJobGraphStoreStatus GraphStoreStatus { get; set; }
public PregelJobGssStatus AllGssStatus { get; set; }
public object WorkerStatus { get; set; }
}
}
7 changes: 7 additions & 0 deletions arangodb-net-standard/PregelApi/Models/PregelJobDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ArangoDBNetStandard.PregelApi.Models
{
public class PregelJobDetail
{
public PregelJobAggregatedStatus AggregatedStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ArangoDBNetStandard.PregelApi.Models
{
public class PregelJobGraphStoreStatus
{
public int? VerticesLoaded { get; set; }
public int? EdgesLoaded { get; set; }
public long? MemoryBytesUsed { get; set; }
public int? VerticesStored { get; set; }
}
}
9 changes: 9 additions & 0 deletions arangodb-net-standard/PregelApi/Models/PregelJobGssStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace ArangoDBNetStandard.PregelApi.Models
{
public class PregelJobGssStatus
{
public List<PregelJobGssStatusItem> Items { get; set; }
}
}
10 changes: 10 additions & 0 deletions arangodb-net-standard/PregelApi/Models/PregelJobGssStatusItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ArangoDBNetStandard.PregelApi.Models
{
public class PregelJobGssStatusItem
{
public int? VerticesProcessed { get; set; }
public int? MessagesSent { get; set; }
public int? MessagesReceived { get; set; }
public long? MemoryBytesUsedForMessages { get; set; }
}
}
Loading

0 comments on commit 06bec11

Please sign in to comment.