Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What do you think Dad ? #17

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34e645f
Using configuration key to locate .env
clun Jul 17, 2018
96ab998
moving to dse
clun Jul 17, 2018
4b545f4
updating Docker configuration to latest, adding Mac scripts
jeffreyscarpenter Jul 20, 2018
ca66498
adding subtree pull script for Mac
jeffreyscarpenter Jul 20, 2018
cecea77
Squashed 'lib/killrvideo-docker-common/' changes from 94e497e..c3a7f58
jeffreyscarpenter Jul 20, 2018
aceb92b
Merge commit 'cecea7740f58325f456a60c6d1e00313f30e85b4'
jeffreyscarpenter Jul 20, 2018
c968875
removing debug step from setup-docker.sh
jeffreyscarpenter Jul 20, 2018
e346920
alternate configuration file approach
jeffreyscarpenter Jul 20, 2018
19e11cf
Integrating Gremlin DSL
clun Aug 1, 2018
4975f96
Shift to DSE in all service + enable Authenticatio + enable Graph + S…
clun Aug 6, 2018
a6d2119
Adding Graph Vertex
clun Aug 7, 2018
82bfe8b
Adding Graph Vertex
clun Aug 7, 2018
3aca3fd
Fixing user, video and rating creation
clun Aug 8, 2018
c8aa45e
Fixing Tags in Graph
clun Aug 9, 2018
5525288
New Module in Common for DSL
clun Aug 21, 2018
f0a26fc
Missing Added date and remove unsed method
clun Aug 21, 2018
64661b1
Merge pull request #1 from KillrVideo/dse-graph
clun Aug 30, 2018
6cad089
Update README.md
jeffreyscarpenter Sep 6, 2019
7522888
Adding ignore for Jetbrains tooling.
Adron Sep 10, 2019
505c2a7
Major path, project, and solution file refactor.
Adron Sep 10, 2019
ec49bf0
The migrated code and removed old code.
Adron Sep 20, 2019
82e0367
Merge pull request #10 from Adron/solution-refactor
Adron Sep 20, 2019
c4739b4
added base KillrVideo project code from previous version
jeffreyscarpenter Sep 20, 2019
a4dcb67
Fixed build for root KillrVideo Project and some minor name/rename re…
Adron Sep 24, 2019
9269d71
Merge pull request #11 from Adron/upstream/remove_etcd
Adron Sep 24, 2019
2cb1018
Fixing the DryIoc reference by deleting the Rating dependency (probab…
Adron Sep 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ src/spark/*.ipynb

# User environment file
.env

# Mac-specific files
.DS_Store
.idea
12 changes: 12 additions & 0 deletions KillrVideo.Cassandra/KillrVideo.Cassandra.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dse" Version="2.8.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="4.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace KillrVideo.Cassandra
{
Expand Down Expand Up @@ -42,4 +42,4 @@ public static long ToMicrosecondsSinceEpoch(this DateTimeOffset dateTimeOffset)
return FromDateTimeOffset(dateTimeOffset);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
using System;
using System;
using System.Collections.Concurrent;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Cassandra;
using Dse;

namespace KillrVideo.Cassandra
{
/// <summary>
/// A cache for PreparedStatements based on the CQL string.
/// </summary>
[Export]
public class PreparedStatementCache
{
private readonly ISession _session;
public class PreparedStatementCache {

/// <summary>
/// Inject Dse Session
/// </summary>
private readonly IDseSession _session;

/// <summary>
/// Working Cache
/// </summary>
private readonly ConcurrentDictionary<string, Lazy<Task<PreparedStatement>>> _cachedItems;

/// <summary>
/// Create a new TaskCache using the provided factoryFunc to generate items from keys.
/// </summary>
public PreparedStatementCache(ISession session)
public PreparedStatementCache(IDseSession session)
{
if (session == null) throw new ArgumentNullException(nameof(session));
_session = session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading.Tasks;
using Cassandra;
//using Cassandra;
using Dse;
using Google.Protobuf.Reflection;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Serilog;
using KillrVideo.Cassandra;
using KillrVideo.Comments.Events;
using KillrVideo.MessageBus;
Expand All @@ -20,13 +22,30 @@ namespace KillrVideo.Comments
[Export(typeof(IGrpcServerService))]
public class CommentsServiceImpl : CommentsService.CommentsServiceBase, IGrpcServerService
{
private readonly ISession _session;
private readonly IBus _bus;
/// <summary>
/// Logger for the class to write into both files and console
/// </summary>
private static readonly ILogger Logger = Log.ForContext(typeof(CommentsServiceImpl));

/// <summary>
/// Inject Dse Session.
/// </summary>
private readonly IDseSession _session;

/// <summary>
/// Cache of results
/// </summary>
private readonly PreparedStatementCache _statementCache;

/// <summary>
/// Exchange messages between services.
/// </summary>
private readonly IBus _bus;


public ServiceDescriptor Descriptor => CommentsService.Descriptor;

public CommentsServiceImpl(ISession session, PreparedStatementCache statementCache, IBus bus)
public CommentsServiceImpl(IDseSession session, PreparedStatementCache statementCache, IBus bus)
{
if (session == null) throw new ArgumentNullException(nameof(session));
if (statementCache == null) throw new ArgumentNullException(nameof(statementCache));
Expand Down
22 changes: 22 additions & 0 deletions KillrVideo.Comments/KillrVideo.Comments.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dse" Version="2.8.0" />
<PackageReference Include="Google.Protobuf" Version="3.10.0-rc1" />
<PackageReference Include="Grpc.Core" Version="2.24.0-pre1" />
<PackageReference Include="Serilog" Version="2.8.0" />
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KillrVideo.Cassandra\KillrVideo.Cassandra.csproj" />
<ProjectReference Include="..\KillrVideo.MessageBus\KillrVideo.MessageBus.csproj" />
<ProjectReference Include="..\KillrVideo.Protobuf\KillrVideo.Protobuf.csproj" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions KillrVideo.GraphDsl/Dsl/Enrichment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Collections.Generic;
using System.Linq;
using Gremlin.Net.Process.Traversal;
using static KillrVideo.GraphDsl.__KillrVideo;

namespace KillrVideo.GraphDsl.Dsl
{
/// <summary>
/// Provides for pre-built data enrichment options for the <code>enrich(Enrichment...)</code> step. These options will
/// include extra information about the <code>Vertex</code>> when output from that step. Note that the enrichment
/// examples presented here are examples to demonstrate this concept. The primary lesson here is to show how one might
/// merge map results as part of a DSL. These enrichment options may not be suitable for traversals in production systems
/// as counting all edges might add an unreasonable amount of time to an otherwise fast traversal.
/// </summary>
public class Enrichment
{
private List<string> projectedKeys;

private List<GraphTraversal<object, object>> traversals;

private Enrichment(string projectedKeys, GraphTraversal<object, object> traversal) :
this(new List<string>() { projectedKeys }, new List<GraphTraversal<object, object>>() { traversal })
{
}

private Enrichment(List<string> projectedKeys, List<GraphTraversal<object, object>> traversals)
{
this.projectedKeys = projectedKeys;
this.traversals = traversals;
}

public List<GraphTraversal<object, object>> GetTraversals()
{
return traversals;
}

public List<string> GetProjectedKeys()
{
return projectedKeys;
}

/// <summary>
/// Include the <code>Vertex</code> itself as a value in the enriched output which might be helpful if additional
/// traversing on that element is required.
/// </summary>
public static Enrichment Vertex()
{
return new Enrichment(KeyVertex, __.Identity());
}

/// <summary>
/// The number of incoming edges on the <code>Vertex</code>.
/// </summary>
public static Enrichment InDegree()
{
return new Enrichment(KeyInDegree, __.Map<object>(__.InE().Count()));
}


/// <summary>
/// The number of outgoing edges on the <code>Vertex</code>.
/// </summary>
public static Enrichment OutDegree()
{
return new Enrichment(KeyOutDegree, __.Map<object>(__.OutE().Count()));
}

/// <summary>
/// The total number of in and out edges on the <code>Vertex</code>.
/// </summary>
public static Enrichment Degree()
{
return new Enrichment(KeyDegree, __.Map<object>(__.BothE().Count()));
}

/// <summary>
/// Calculates the edge label distribution for the <code>Vertex</code>>.
/// </summary>
public static Enrichment Distribution()
{
return new Enrichment(KeyDistribution, __.Map<object>(__.BothE().GroupCount<string>().By(T.Label)));
}

/// <summary>
/// Chooses the keys to include in the output.
/// </summary>
public static Enrichment Keys(params string[] keys)
{
var valueTraversals = keys.Select(k => __.Values<object>(k)).ToList();
return new Enrichment(keys.ToList(), valueTraversals);
}
}
}

101 changes: 101 additions & 0 deletions KillrVideo.GraphDsl/Dsl/KillrVideoGraphTraversalExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Linq;
using Gremlin.Net.Process.Traversal;
using Gremlin.Net.Structure;
using static Gremlin.Net.Process.Traversal.P;

using static KillrVideo.GraphDsl.__KillrVideo;

namespace KillrVideo.GraphDsl.Dsl {

/// <summary>
/// The KillrVideo Traversal class which exposes the available steps of the DSL.
/// </summary>
public static class KillrVideoGraphTraversalExtensions {

/// <summary>
/// Traverses from a "user" to an "videos" over the "rated" edge.
/// </summary>
public static GraphTraversal<Vertex, Vertex> RatedVideos(this GraphTraversal<Vertex, Vertex> t, int minRate)
{
return t.OutE(EdgeRated).Has(PropertyRating, Gt(minRate)).InV();
}

/// <summary>
/// what other users rated those videos highly
/// </summary>
public static GraphTraversal<Vertex, Vertex> OtherUserRatedVideos(this GraphTraversal<Vertex, Vertex> t, int minRate, int sample)
{
return
// what other users rated those videos highly? (this is like saying "what users share my taste")
t.InE(EdgeRated).Has(PropertyRating, Gt(minRate))

// but don't grab too many, or this won't work OLTP, and "by('rating')" favors the higher ratings
.Sample(sample).By(PropertyRating).OutV();
}

/// <summary>
/// what other users rated those videos highly
/// </summary>
public static GraphTraversal<Vertex, Vertex> VideosRatedByOthers(this GraphTraversal<Vertex, Vertex> t,
int minRate, long minLocalRate) {
return
// Now we're working with "similar users". For those users who share my taste, grab N highly rated
// videos. Save the rating so we can sum the scores later, and use sack() because it does not require
// path information. (as()/select() was slow)
t.Local<List<Vertex>>(
__.OutE(EdgeRated)
.Has(PropertyRating, Gt(minRate))
.Limit(minLocalRate))
.Sack(Operator.Assign)
.By(PropertyRating).InV();
}

/// <summary>
/// what other users rated those videos highly
/// </summary>
public static GraphTraversal<Vertex, Vertex> AllRatedVideos(this GraphTraversal<Vertex, Vertex> t)
{
return t.Map<Vertex>(__.Out(EdgeRated).Dedup().Fold());
}

/// <summary>
/// Expects an incoming <code>Vertex</code> and projects it to a <code>Map</code> with the specified <code>Enrichment</code>>
/// values passed to it.
/// </summary>
public static GraphTraversal<Vertex, IDictionary<string, object>> Enrich(this GraphTraversal<Vertex, Vertex> t, bool includeIdLabel, params Enrichment[] enrichments)
{
var projectTraversals = enrichments.Select(e => e.GetTraversals()).SelectMany(i => i).ToList();
if (includeIdLabel)
{
projectTraversals.Add(__.Id());
projectTraversals.Add(__.Map<object>(__.Label()));
}

var keys = enrichments.Select(e => e.GetProjectedKeys()).SelectMany(i => i).ToList();
if (includeIdLabel)
{
keys.Add("id");
keys.Add("label");
}

var projectedKeys = keys.GetRange(1, keys.Count() - 1).ToArray();
var te = t.Project<object>(keys.First(), projectedKeys);
foreach (GraphTraversal<object, object> projectTraversal in projectTraversals)
{
te = te.By(projectTraversal);
}

return te;
}

/// <summary>
/// This step is an alias for the <code>SideEffect()</code> step. As an alias, it makes certain aspects of the DSL more
/// readable.
/// </summary>
public static GraphTraversal<S, E> Ensure<S, S1, E>(
this GraphTraversal<S, E> t, GraphTraversal<S1, E> mutationTraversal) {
return t.SideEffect(mutationTraversal);
}
}
}
34 changes: 34 additions & 0 deletions KillrVideo.GraphDsl/Dsl/Recommender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using Gremlin.Net.Process.Traversal;
using Gremlin.Net.Structure;


namespace KillrVideo.GraphDsl.Dsl
{

/// <summary>
/// Provides for pre-built "sampling" settings to the <code>recommend(int, int, Recommender, Traversal)<code>
/// step. The sampling options help determine the nature of the initial set of movies to recommend, by limiting the
/// number of actors used from highly rated movies of the user who is target for the recommendation.
/// </summary>
public enum Recommender
{
SmallSample,
LargeSample,
Fifty50Sample,
TimedSample,
All
}

public static class RecommenderLookup
{
public static readonly Dictionary<Recommender, GraphTraversal<object, IList<Vertex>>> Traversals = new Dictionary<Recommender, GraphTraversal<object, IList<Vertex>>>
{
{Recommender.SmallSample, __.OutE(KvGraph.EdgeActor).Sample(3).InV().Fold()},
{Recommender.LargeSample, __.OutE(KvGraph.EdgeActor).Sample(10).InV().Fold()},
{Recommender.Fifty50Sample, __.OutE(KvGraph.EdgeActor).Coin(0.5).InV().Fold()},
{Recommender.TimedSample, __.OutE(KvGraph.EdgeActor).TimeLimit(250).InV().Fold()},
{Recommender.All, __.OutE(KvGraph.EdgeActor).InV().Fold()}
};
}
}
Loading