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

Mongodb implementation #4127

Merged
merged 31 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f29eff6
Implemented MongoDb
gurkanguran May 30, 2023
5e10320
Refactor
gurkanguran May 30, 2023
6c811b3
Refactor
gurkanguran May 30, 2023
252a2bb
Use main entity models in mongodb
gurkanguran Jun 1, 2023
2b69729
Fixed object serialization issue
gurkanguran Jun 9, 2023
839acc8
Refactor
gurkanguran Jun 9, 2023
6f15926
Fixed issues caused by duplicate collection names
gurkanguran Jun 9, 2023
0bd2002
Optimized count query
gurkanguran Jun 12, 2023
c2e0dec
Merge branch 'v3' into mongodb
gurkanguran Jun 12, 2023
5568af6
Fixed the issues after merge
gurkanguran Jun 12, 2023
0c69308
Merge branch 'v3' into mongodb
gurkanguran Jun 12, 2023
d1cffa2
Revert "Fixed the issues after merge"
gurkanguran Jun 12, 2023
1b30f42
Use expression helper to solve mongodb query issue
gurkanguran Jun 12, 2023
28b02b5
Merge branch 'v3' into mongodb
gurkanguran Jun 12, 2023
0018e71
Handle null values during deserialization
gurkanguran Jun 12, 2023
9fe1b9f
Moved MongoDb project to persistence folder
gurkanguran Jun 12, 2023
703be36
Merge branch 'v3' into mongodb
gurkanguran Jun 14, 2023
8b88d70
Refactor
gurkanguran Jun 14, 2023
461e887
Did some refactor and added type serializer for variable fix
gurkanguran Jun 15, 2023
0d57717
Modularize mongodb indices creation
gurkanguran Jun 17, 2023
1c67677
Refactor
gurkanguran Jun 17, 2023
14c56d3
Merge branch 'v3' into mongodb
gurkanguran Jun 17, 2023
ceda7e2
Fixed the build
gurkanguran Jun 17, 2023
0b8d919
Refactor
gurkanguran Jun 18, 2023
0949fda
Merge branch 'v3' into mongodb
gurkanguran Jun 18, 2023
6f25915
Merge branch 'v3' into mongodb
gurkanguran Jun 18, 2023
4258026
Merge branch 'v3' into mongodb
sfmskywalker Jun 28, 2023
7f22b71
Remove unused imports
sfmskywalker Jun 28, 2023
2a1b960
Import necessary usings
sfmskywalker Jun 28, 2023
501b8a3
Implement variable serializer
sfmskywalker Jun 28, 2023
94eabd5
Update SQLite migrations
sfmskywalker Jun 28, 2023
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
Prev Previous commit
Next Next commit
Refactor
  • Loading branch information
gurkanguran committed Jun 14, 2023
commit 8b88d70ec68403cc43e946e593acedb7a8e8634c
14 changes: 7 additions & 7 deletions Elsa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.EntityFrameworkCore.My
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.AspNet.DslWorkflowProvider", "src\samples\aspnet\Elsa.Samples.AspNet.DslWorkflowProvider\Elsa.Samples.AspNet.DslWorkflowProvider.csproj", "{4BC5D3D2-9425-41D7-9804-D145B92520EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.MongoDB", "src\modules\Elsa.MongoDB\Elsa.MongoDB.csproj", "{F84DD219-8693-4F1E-8C65-59B673E70DD5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "persistence", "persistence", "{9B4F139F-7D26-435C-A561-89E65A67A8E5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripting", "scripting", "{6EF07978-A6D2-40EB-891D-7D70C5F37E76}"
Expand All @@ -226,6 +224,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.WorkflowProviders.Blob
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ConsoleApp.ActivityOutput", "src\samples\console\Elsa.Samples.ConsoleApp.ActivityOutput\Elsa.Samples.ConsoleApp.ActivityOutput.csproj", "{9C9FEB8E-A253-4705-A344-49BFEFC9A516}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.MongoDb", "src\modules\Elsa.MongoDb\Elsa.MongoDb.csproj", "{3A377A6A-F735-4010-9E00-72E8BEB8F1F2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -540,10 +540,6 @@ Global
{4BC5D3D2-9425-41D7-9804-D145B92520EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BC5D3D2-9425-41D7-9804-D145B92520EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BC5D3D2-9425-41D7-9804-D145B92520EE}.Release|Any CPU.Build.0 = Release|Any CPU
{F84DD219-8693-4F1E-8C65-59B673E70DD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F84DD219-8693-4F1E-8C65-59B673E70DD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F84DD219-8693-4F1E-8C65-59B673E70DD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F84DD219-8693-4F1E-8C65-59B673E70DD5}.Release|Any CPU.Build.0 = Release|Any CPU
{4D8F3BB2-709D-481A-8FD3-0DA9762B366D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D8F3BB2-709D-481A-8FD3-0DA9762B366D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D8F3BB2-709D-481A-8FD3-0DA9762B366D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -564,6 +560,10 @@ Global
{9C9FEB8E-A253-4705-A344-49BFEFC9A516}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C9FEB8E-A253-4705-A344-49BFEFC9A516}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C9FEB8E-A253-4705-A344-49BFEFC9A516}.Release|Any CPU.Build.0 = Release|Any CPU
{3A377A6A-F735-4010-9E00-72E8BEB8F1F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A377A6A-F735-4010-9E00-72E8BEB8F1F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A377A6A-F735-4010-9E00-72E8BEB8F1F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A377A6A-F735-4010-9E00-72E8BEB8F1F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{155227F0-A33B-40AA-A4B4-06F813EB921B} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F}
Expand Down Expand Up @@ -665,6 +665,6 @@ Global
{A86DF0F0-24E9-470E-984B-9E7332544972} = {9B4F139F-7D26-435C-A561-89E65A67A8E5}
{A702DD84-B55C-4807-9C28-D8F5AC3CCA78} = {B08B4E00-C2AB-48F3-8389-449F42AEF179}
{9C9FEB8E-A253-4705-A344-49BFEFC9A516} = {873BFC3E-63C2-4495-A503-5EC05DCD84E4}
{F84DD219-8693-4F1E-8C65-59B673E70DD5} = {9B4F139F-7D26-435C-A561-89E65A67A8E5}
{3A377A6A-F735-4010-9E00-72E8BEB8F1F2} = {9B4F139F-7D26-435C-A561-89E65A67A8E5}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ProjectReference Include="..\..\modules\Elsa.EntityFrameworkCore\Elsa.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Environments\Elsa.Environments.csproj" />
<ProjectReference Include="..\..\modules\Elsa.MassTransit\Elsa.MassTransit.csproj" />
<ProjectReference Include="..\..\modules\Elsa.MongoDB\Elsa.MongoDB.csproj" />
<ProjectReference Include="..\..\modules\Elsa.MongoDb\Elsa.MongoDb.csproj" />
<ProjectReference Include="..\..\modules\Elsa.ProtoActor\Elsa.ProtoActor.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Identity\Elsa.Identity.csproj" />
<ProjectReference Include="..\..\modules\Elsa.ProtoActor.Cluster.AzureContainerApps\Elsa.ProtoActor.Cluster.AzureContainerApps.csproj" />
Expand Down
13 changes: 7 additions & 6 deletions src/bundles/Elsa.WorkflowServer.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Http.Handlers;
using Elsa.JavaScript.Options;
using Elsa.MongoDB.Extensions;
using Elsa.MongoDB.Modules.Identity;
using Elsa.MongoDB.Modules.Labels;
using Elsa.MongoDB.Modules.Management;
using Elsa.MongoDB.Modules.Runtime;
using Elsa.MongoDb.Extensions;
using Elsa.MongoDb.Modules.Identity;
using Elsa.MongoDb.Modules.Labels;
using Elsa.MongoDb.Modules.Management;
using Elsa.MongoDb.Modules.Runtime;
using Elsa.WorkflowServer.Web;
using Jint;

EndpointSecurityOptions.DisableSecurity();

Expand Down Expand Up @@ -59,7 +60,7 @@
.UseLabels(options => options.UseMongoDb())
.UseHttp(http => http.HttpEndpointAuthorizationHandler = sp => sp.GetRequiredService<AllowAnonymousHttpEndpointAuthorizationHandler>())
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options))
.UseMongoDb(options => configuration.GetSection("MongoDb").Bind(options))
.UseMongoDb(configuration.GetConnectionString("MongoDb")!)
);

services.Configure<JintOptions>(options => options.AllowClrAccess = true);
Expand Down
7 changes: 2 additions & 5 deletions src/bundles/Elsa.WorkflowServer.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;"
},
"MongoDb": {
"ConnectionString": "mongodb:https://localhost:27017",
"DatabaseName": "elsa-workflows"
"Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;",
"MongoDb": "mongodb:https://localhost:27017/elsa-workflows"
},
"Smtp": {
"Host": "localhost",
Expand Down
62 changes: 0 additions & 62 deletions src/modules/Elsa.MongoDB/Modules/Labels/LabelStore.cs

This file was deleted.

20 changes: 0 additions & 20 deletions src/modules/Elsa.MongoDB/Options/MongoDbOptions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using System.Linq.Expressions;
using Elsa.MongoDB.Extensions;
using Elsa.MongoDb.Extensions;
using JetBrains.Annotations;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace Elsa.MongoDB.Common;
namespace Elsa.MongoDb.Common;

/// <summary>
/// A generic repository class around MongoDb for accessing documents.
/// </summary>
/// <typeparam name="TDocument">The type of the document.</typeparam>
[PublicAPI]
public class MongoStore<TDocument> where TDocument : class
public class MongoDbStore<TDocument> where TDocument : class
{
private readonly IMongoCollection<TDocument> _collection;

/// <param name="collection"></param>
public MongoStore(IMongoCollection<TDocument> collection)
public MongoDbStore(IMongoCollection<TDocument> collection)
{
_collection = collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Elsa.Features.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Elsa.MongoDB.Common;
namespace Elsa.MongoDb.Common;

/// <summary>
/// Base class for features that configure MongoDb persistence.
Expand All @@ -15,14 +15,14 @@ protected PersistenceFeatureBase(IModule module) : base(module)
}

/// <summary>
/// Registers an <see cref="MongoStore{TDocument}"/>.
/// Registers a <see cref="MongoDbStore{TDocument}"/>.
/// </summary>
/// <typeparam name="TStore">The type of the store.</typeparam>
/// <typeparam name="TDocument">The document type of the store.</typeparam>
protected void AddStore<TDocument, TStore>() where TDocument : class where TStore : class
{
Services
.AddSingleton<MongoStore<TDocument>>()
.AddSingleton<MongoDbStore<TDocument>>()
.AddSingleton<TStore>()
;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\common.props" />
<Import Project="..\..\..\common.props" />
<Import Project="..\..\..\configureawait.props" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using MongoDB.Driver;

namespace Elsa.MongoDB.Extensions;
namespace Elsa.MongoDb.Extensions;

public static class DocumentExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Elsa.Features.Services;
using Elsa.MongoDB.Features;
using Elsa.MongoDB.Options;
using Elsa.MongoDb.Features;
using JetBrains.Annotations;

namespace Elsa.MongoDB.Extensions;
namespace Elsa.MongoDb.Extensions;

/// <summary>
/// Extends <see cref="IModule"/> to configure the <see cref="MongoDbFeature"/> feature.
Expand All @@ -16,10 +15,10 @@ public static class ModuleExtensions
/// </summary>
public static IModule UseMongoDb(
this IModule module,
Action<MongoDbOptions> options,
string connectionString,
Action<MongoDbFeature>? configure = default)
{
configure += f => f.Options += options;
configure += f => f.ConnectionString = connectionString;
module.Configure(configure);
return module;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace Elsa.MongoDB.Extensions;
namespace Elsa.MongoDb.Extensions;

public static class QueryableExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
using System.Security.Authentication;
using Elsa.Features.Abstractions;
using Elsa.Features.Services;
using Elsa.Http.Models;
using Elsa.Identity.Contracts;
using Elsa.Identity.Entities;
using Elsa.Labels.Contracts;
using Elsa.Labels.Entities;
using Elsa.MongoDB.HostedServices;
using Elsa.MongoDB.Modules.Identity;
using Elsa.MongoDB.Modules.Labels;
using Elsa.MongoDB.Modules.Management;
using Elsa.MongoDB.Modules.Runtime;
using Elsa.MongoDB.Options;
using Elsa.MongoDB.Serializers;
using Elsa.Workflows.Core.Services;
using Elsa.MongoDb.HostedServices;
using Elsa.MongoDb.Modules.Identity;
using Elsa.MongoDb.Modules.Labels;
using Elsa.MongoDb.Modules.Management;
using Elsa.MongoDb.Modules.Runtime;
using Elsa.MongoDb.Serializers;
using Elsa.Workflows.Core.State;
using Elsa.Workflows.Management.Contracts;
using Elsa.Workflows.Management.Entities;
using Elsa.Workflows.Runtime.Contracts;
using Elsa.Workflows.Runtime.Entities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
using MongoDB.Driver.Core.Extensions.DiagnosticSources;
using StoredBookmark = Elsa.Workflows.Runtime.Entities.StoredBookmark;
using WorkflowExecutionLogRecord = Elsa.Workflows.Runtime.Entities.WorkflowExecutionLogRecord;

namespace Elsa.MongoDB.Features;
namespace Elsa.MongoDb.Features;

/// <summary>
/// Configures MongoDb.
Expand All @@ -41,16 +36,14 @@ public MongoDbFeature(IModule module) : base(module)
}

/// <summary>
/// A delegate that configures MongoDb.
/// The MongoDB connection string.
/// </summary>
public Action<MongoDbOptions> Options { get; set; } = _ => { };
public string ConnectionString { get; set; }

/// <inheritdoc />
public override void Apply()
{
Services.Configure(Options);

Services.AddSingleton(CreateDatabase);
Services.AddSingleton(_ => CreateDatabase(ConnectionString));

RegisterSerializers();

Expand Down Expand Up @@ -87,11 +80,11 @@ private void RegisterSerializers()
BsonSerializer.RegisterSerializer(typeof(object), new PolymorphicSerializer());
}

private static IMongoDatabase CreateDatabase(IServiceProvider sp)
private static IMongoDatabase CreateDatabase(string connectionString)
{
var options = sp.GetRequiredService<IOptions<MongoDbOptions>>().Value;
var settings = MongoClientSettings.FromConnectionString(options.ConnectionString);

var mongoUrl = new MongoUrl(connectionString);
var settings = MongoClientSettings.FromUrl(mongoUrl);
settings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber());
settings.ApplicationName = "elsa_workflows";
settings.WriteConcern = WriteConcern.WMajority;
Expand All @@ -105,7 +98,7 @@ private static IMongoDatabase CreateDatabase(IServiceProvider sp)
};

var mongoClient = new MongoClient(settings);
return mongoClient.GetDatabase(options.DatabaseName);
return mongoClient.GetDatabase(mongoUrl.DatabaseName);
}

private static void AddMongoCollection<T>(IServiceCollection services, string collectionName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Elsa.Workflows.Management.Entities;
using Elsa.Workflows.Management.Models;

namespace Elsa.MongoDB.Helpers;
namespace Elsa.MongoDb.Helpers;

public class ExpressionHelpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using StoredBookmark = Elsa.Workflows.Runtime.Entities.StoredBookmark;
using WorkflowExecutionLogRecord = Elsa.Workflows.Runtime.Entities.WorkflowExecutionLogRecord;

namespace Elsa.MongoDB.HostedServices;
namespace Elsa.MongoDb.HostedServices;

internal class CreateIndices : IHostedService
{
Expand Down
Loading