From d30f34803be905af3ee6099f6fb7800df437eb51 Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 4 Mar 2022 17:39:31 +0300 Subject: [PATCH 01/12] Implemented DistributedLock.Redis Added into Administration Identity Ordering Payment --- .../AdministrationServiceHttpApiHostModule.cs | 9 ++++++ ...ionServiceDatabaseMigrationEventHandler.cs | 28 +++++++++++++---- ...ityServiceDatabaseMigrationEventHandler.cs | 29 +++++++++++++----- .../IdentityServiceHttpApiHostModule.cs | 18 +++++++---- ...ingServiceDatabaseMigrationEventHandler.cs | 30 ++++++++++++++----- ...pOnAbp.OrderingService.HttpApi.Host.csproj | 3 ++ .../OrderingServiceHttpApiHostModule.cs | 14 +++++++-- ...entServiceDatabaseMigrationEventHandler.cs | 20 +++++++++++-- .../PaymentServiceHttpApiHostModule.cs | 9 ++++++ .../DatabaseEfCoreMigrationEventHandler.cs | 9 +++++- ...pOnAbp.Shared.Hosting.Microservices.csproj | 1 + 11 files changed, 137 insertions(+), 33 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs index beafc3f7..44f96600 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs @@ -6,11 +6,14 @@ using EShopOnAbp.AdministrationService.DbMigrations; using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; +using Medallion.Threading.Redis; +using Medallion.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.Http.Client.IdentityModel.Web; @@ -66,6 +69,12 @@ public class AdministrationServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); + + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs index 4640dfcf..4df15ec5 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs @@ -1,8 +1,10 @@ using EShopOnAbp.AdministrationService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; +using Medallion.Threading; +using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading.Tasks; -using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; using Volo.Abp.EventBus.Distributed; @@ -26,13 +28,16 @@ namespace EShopOnAbp.AdministrationService.DbMigrations ITenantStore tenantStore, IPermissionDefinitionManager permissionDefinitionManager, IPermissionDataSeeder permissionDataSeeder, - IDistributedEventBus distributedEventBus + IDistributedEventBus distributedEventBus, + IDistributedLockProvider distributedLockProvider ) : base( currentTenant, unitOfWorkManager, tenantStore, distributedEventBus, - AdministrationServiceDbProperties.ConnectionStringName) + AdministrationServiceDbProperties.ConnectionStringName, + distributedLockProvider + ) { _permissionDefinitionManager = permissionDefinitionManager; _permissionDataSeeder = permissionDataSeeder; @@ -40,6 +45,8 @@ namespace EShopOnAbp.AdministrationService.DbMigrations public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) { + Logger.LogInformation("AdministrationService - HandleEventAsync started ..."); + if (eventData.DatabaseName != DatabaseName) { return; @@ -47,7 +54,7 @@ namespace EShopOnAbp.AdministrationService.DbMigrations try { - var schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId); + await MigrateDatabaseSchemaAsync(eventData.TenantId); await SeedDataAsync(eventData.TenantId); } catch (Exception ex) @@ -60,8 +67,17 @@ namespace EShopOnAbp.AdministrationService.DbMigrations { try { - await MigrateDatabaseSchemaAsync(eventData.Id); - await SeedDataAsync(eventData.Id); + Logger.LogInformation("AdministrationService - Before Acquire"); + + await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + { + if(handle != null) + { + await MigrateDatabaseSchemaAsync(eventData.Id); + Logger.LogInformation("Starting AdministrationService DataSeeder..."); + await SeedDataAsync(eventData.Id); + } + } } catch (Exception ex) { diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs index 17d8dd98..00cdaade 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -10,6 +10,8 @@ using Volo.Abp.EventBus.Local; using Volo.Abp.Identity; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; +using Medallion.Threading; +using Microsoft.Extensions.Logging; namespace EShopOnAbp.IdentityService.DbMigrations { @@ -29,13 +31,15 @@ namespace EShopOnAbp.IdentityService.DbMigrations IIdentityDataSeeder identityDataSeeder, IdentityServerDataSeeder identityServerDataSeeder, IDistributedEventBus distributedEventBus, - ILocalEventBus localEventBus + ILocalEventBus localEventBus, + IDistributedLockProvider distributedLockProvider ) : base( currentTenant, unitOfWorkManager, tenantStore, distributedEventBus, - IdentityServiceDbProperties.ConnectionStringName) + IdentityServiceDbProperties.ConnectionStringName, + distributedLockProvider) { _identityDataSeeder = identityDataSeeder; _identityServerDataSeeder = identityServerDataSeeder; @@ -51,12 +55,21 @@ namespace EShopOnAbp.IdentityService.DbMigrations try { - var schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId); - await SeedDataAsync( - tenantId: eventData.TenantId, - adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress, - adminPassword: IdentityServiceDbProperties.DefaultAdminPassword - ); + Logger.LogInformation("IdentityService - Before Acquire "); + + await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + { + if (handle != null) + { + await MigrateDatabaseSchemaAsync(eventData.TenantId); + Logger.LogInformation("Starting IdentityService DataSeeder..."); + await SeedDataAsync( + tenantId: eventData.TenantId, + adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress, + adminPassword: IdentityServiceDbProperties.DefaultAdminPassword + ); + } + } await _localEventBus.PublishAsync(new ApplyDatabaseSeedsEto()); } diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs index 5fbed800..e6a22d55 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs @@ -1,20 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using EShopOnAbp.IdentityService.DbMigrations; using EShopOnAbp.IdentityService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Gateways; using EShopOnAbp.Shared.Hosting.Microservices; +using Medallion.Threading; +using Medallion.Threading.Redis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Modularity; -using Volo.Abp.Threading; namespace EShopOnAbp.IdentityService; @@ -63,6 +65,12 @@ public class IdentityServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); + + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs index 98f77546..1e32c00f 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs @@ -1,8 +1,9 @@ using EShopOnAbp.OrderingService.EntityFrameworkCore; -using System; -using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; +using Medallion.Threading; using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; @@ -15,24 +16,29 @@ namespace EShopOnAbp.OrderingService.DbMigrations IDistributedEventHandler { private readonly IDataSeeder _dataSeeder; + public OrderingServiceDatabaseMigrationEventHandler( ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, - IDistributedEventBus distributedEventBus, - IDataSeeder dataSeeder) + IDistributedEventBus distributedEventBus, + IDataSeeder dataSeeder, + IDistributedLockProvider distributedLockProvider) : base( currentTenant, unitOfWorkManager, tenantStore, distributedEventBus, - OrderingServiceDbProperties.ConnectionStringName) + OrderingServiceDbProperties.ConnectionStringName, + distributedLockProvider) { _dataSeeder = dataSeeder; } public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) { + Logger.LogInformation("OrderingService - HandleEventAsync started ..."); + if (eventData.DatabaseName != DatabaseName) { return; @@ -45,9 +51,17 @@ namespace EShopOnAbp.OrderingService.DbMigrations try { - await MigrateDatabaseSchemaAsync(null); - Logger.LogInformation("Starting OrderingService DataSeeder..."); - await _dataSeeder.SeedAsync(); + Logger.LogInformation("OrderingService - Before Acquire "); + + await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + { + if (handle != null) + { + await MigrateDatabaseSchemaAsync(null); + Logger.LogInformation("Starting OrderingService DataSeeder..."); + await _dataSeeder.SeedAsync(); + } + } } catch (Exception ex) { diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj index 116c3153..5c007a33 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj @@ -10,6 +10,9 @@ + + + diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs index d5a9a9eb..23484319 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs @@ -2,19 +2,22 @@ using EShopOnAbp.OrderingService.DbMigrations; using EShopOnAbp.OrderingService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; +using Medallion.Threading; +using Medallion.Threading.Redis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.DistributedLocking; using Volo.Abp.Modularity; -using Volo.Abp.Threading; namespace EShopOnAbp.OrderingService; @@ -22,6 +25,7 @@ namespace EShopOnAbp.OrderingService; typeof(OrderingServiceHttpApiModule), typeof(OrderingServiceApplicationModule), typeof(OrderingServiceEntityFrameworkCoreModule), + //typeof(MedallionAbpDistributedLock), typeof(EShopOnAbpSharedHostingMicroservicesModule) )] public class OrderingServiceHttpApiHostModule : AbpModule @@ -63,6 +67,12 @@ public class OrderingServiceHttpApiHostModule : AbpModule }); }); + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); + // TODO: Crate controller instead of auto-controller configuration Configure(options => { diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs index 7fd87b4f..19f29057 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs @@ -6,6 +6,8 @@ using Volo.Abp.Data; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; +using Medallion.Threading; +using Microsoft.Extensions.Logging; namespace EShopOnAbp.PaymentService.DbMigrations { @@ -17,13 +19,15 @@ namespace EShopOnAbp.PaymentService.DbMigrations ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, - IDistributedEventBus distributedEventBus) + IDistributedEventBus distributedEventBus, + IDistributedLockProvider distributedLockProvider) : base( currentTenant, unitOfWorkManager, tenantStore, distributedEventBus, - PaymentServiceDbProperties.ConnectionStringName) + PaymentServiceDbProperties.ConnectionStringName, + distributedLockProvider) { } @@ -41,7 +45,17 @@ namespace EShopOnAbp.PaymentService.DbMigrations try { - await MigrateDatabaseSchemaAsync(null); + Logger.LogInformation("PaymentService - Before Acquire "); + + await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + { + if (handle != null) + { + await MigrateDatabaseSchemaAsync(null); + Logger.LogInformation("PaymentService No Seed..."); + + } + } } catch (Exception ex) { diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs index e267e8d3..c0576256 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs @@ -14,6 +14,9 @@ using Microsoft.Extensions.Configuration; using Volo.Abp; using Volo.Abp.Modularity; using Volo.Abp.Threading; +using Medallion.Threading.Redis; +using Medallion.Threading; +using StackExchange.Redis; namespace EShopOnAbp.PaymentService; @@ -63,6 +66,12 @@ public class PaymentServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); + + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs index 298102b5..1fd0d377 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Medallion.Threading; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -29,19 +30,23 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database protected IDistributedEventBus DistributedEventBus { get; } protected ILogger> Logger { get; set; } protected string DatabaseName { get; } + protected IDistributedLockProvider DistributedLockProvider { get; } protected DatabaseEfCoreMigrationEventHandler( ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, IDistributedEventBus distributedEventBus, - string databaseName) + string databaseName, + IDistributedLockProvider distributedLockProvider + ) { CurrentTenant = currentTenant; UnitOfWorkManager = unitOfWorkManager; TenantStore = tenantStore; DatabaseName = databaseName; DistributedEventBus = distributedEventBus; + DistributedLockProvider = distributedLockProvider; Logger = NullLogger>.Instance; } @@ -76,6 +81,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database if (tenantId == null) { //Migrating the host database + Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is null"); result = await MigrateDatabaseSchemaWithDbContextAsync(); } else @@ -85,6 +91,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database !tenantConfiguration.ConnectionStrings.GetOrDefault(DatabaseName).IsNullOrWhiteSpace()) { //Migrating the tenant database (only if tenant has a separate database) + Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is not null"); result = await MigrateDatabaseSchemaWithDbContextAsync(); } } diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbp.Shared.Hosting.Microservices.csproj b/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbp.Shared.Hosting.Microservices.csproj index b4bd451f..948da22e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbp.Shared.Hosting.Microservices.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbp.Shared.Hosting.Microservices.csproj @@ -9,6 +9,7 @@ + From d1b7dde496f9bc787da344d4fec0c5a1ba908ad7 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 7 Mar 2022 09:53:37 +0300 Subject: [PATCH 02/12] removed unnecessary reference --- .../EShopOnAbp.OrderingService.HttpApi.Host.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj index 5c007a33..77ac43d4 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj @@ -10,9 +10,7 @@ - - From b1924b2f552ffeedc37f954b9a55dead0d951524 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 7 Mar 2022 11:01:10 +0300 Subject: [PATCH 03/12] Implemented Distributed Lock for Catalog Service Implemented Distributed Lock for MongoDB on shared and has been used in CatalogService --- .../CatalogServiceHttpApiHostModule.cs | 9 +++++++++ ...logServiceDatabaseMigrationEventHandler.cs | 19 ++++++++++++++++--- .../DatabaseMongoDbMigrationEventHandler.cs | 17 +++++++++++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs index b8a4881d..029aa848 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs @@ -20,6 +20,9 @@ using Volo.Abp.AspNetCore.Mvc.AntiForgery; using Volo.Abp.Modularity; using Volo.Abp.Threading; using Volo.Abp.Uow; +using Medallion.Threading.Redis; +using Medallion.Threading; +using StackExchange.Redis; namespace EShopOnAbp.CatalogService; @@ -67,6 +70,12 @@ public class CatalogServiceHttpApiHostModule : AbpModule }); }); + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); + Configure(options => { options.ConventionalControllers.Create(typeof(CatalogServiceApplicationModule).Assembly, opts => diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs index 9fb54311..1b513492 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using EShopOnAbp.CatalogService.MongoDB; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; +using Medallion.Threading; +using Microsoft.Extensions.Logging; using Volo.Abp.Data; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; @@ -18,13 +20,16 @@ namespace EShopOnAbp.CatalogService.DbMigrations IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, IDistributedEventBus distributedEventBus, - IServiceProvider serviceProvider + IServiceProvider serviceProvider, + IDistributedLockProvider distributedLockProvider ) : base( currentTenant, unitOfWorkManager, tenantStore, distributedEventBus, - CatalogServiceDbProperties.ConnectionStringName,serviceProvider) + CatalogServiceDbProperties.ConnectionStringName, + serviceProvider, + distributedLockProvider) { } @@ -42,7 +47,15 @@ namespace EShopOnAbp.CatalogService.DbMigrations try { - await MigrateDatabaseSchemaAsync(null); + Logger.LogInformation("CatalogService - Before Acquire "); + + await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + { + if (handle != null) + { + await MigrateDatabaseSchemaAsync(null); + } + } } catch (Exception ex) { diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs index 452cd7de..251e6a92 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using Medallion.Threading; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Data; using Volo.Abp.Domain.Entities.Events.Distributed; @@ -27,16 +27,20 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas protected ITenantStore TenantStore { get; } protected IDistributedEventBus DistributedEventBus { get; } protected ILogger> Logger { get; set; } - protected IServiceProvider ServiceProvider { get; } protected string DatabaseName { get; } + protected IDistributedLockProvider DistributedLockProvider { get; } + protected DatabaseMongoDbMigrationEventHandler( ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, IDistributedEventBus distributedEventBus, - string databaseName, IServiceProvider serviceProvider) + string databaseName, + IServiceProvider serviceProvider, + IDistributedLockProvider distributedLockProvider + ) { CurrentTenant = currentTenant; UnitOfWorkManager = unitOfWorkManager; @@ -44,6 +48,7 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas DatabaseName = databaseName; ServiceProvider = serviceProvider; DistributedEventBus = distributedEventBus; + DistributedLockProvider = distributedLockProvider; Logger = NullLogger>.Instance; } From ea4333a13bb28a1bc0be5b60f408d895d3ee44d4 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 8 Mar 2022 10:40:59 +0300 Subject: [PATCH 04/12] Used IAbpDistributedLock instead of IDistributedLockProvider --- ...strationServiceDatabaseMigrationEventHandler.cs | 10 +++++----- .../CatalogServiceDatabaseMigrationEventHandler.cs | 14 +++++++------- ...IdentityServiceDatabaseMigrationEventHandler.cs | 5 +++-- ...OrderingServiceDatabaseMigrationEventHandler.cs | 6 +++--- .../PaymentServiceDatabaseMigrationEventHandler.cs | 12 ++++++------ .../EfCore/DatabaseEfCoreMigrationEventHandler.cs | 5 +++-- .../DatabaseMongoDbMigrationEventHandler.cs | 8 ++++---- 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs index 4df15ec5..a25acdb1 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs @@ -1,12 +1,12 @@ using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Medallion.Threading; using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; @@ -29,7 +29,7 @@ namespace EShopOnAbp.AdministrationService.DbMigrations IPermissionDefinitionManager permissionDefinitionManager, IPermissionDataSeeder permissionDataSeeder, IDistributedEventBus distributedEventBus, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -67,11 +67,11 @@ namespace EShopOnAbp.AdministrationService.DbMigrations { try { - Logger.LogInformation("AdministrationService - Before Acquire"); + Logger.LogInformation("AdministrationService - Before Acquire and Migration and Seed Data"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { - if(handle != null) + if (handle != null) { await MigrateDatabaseSchemaAsync(eventData.Id); Logger.LogInformation("Starting AdministrationService DataSeeder..."); diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs index 1b513492..7c126a57 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs @@ -1,10 +1,10 @@ -using System; -using System.Threading.Tasks; -using EShopOnAbp.CatalogService.MongoDB; +using EShopOnAbp.CatalogService.MongoDB; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; -using Medallion.Threading; using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -21,7 +21,7 @@ namespace EShopOnAbp.CatalogService.DbMigrations ITenantStore tenantStore, IDistributedEventBus distributedEventBus, IServiceProvider serviceProvider, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -47,9 +47,9 @@ namespace EShopOnAbp.CatalogService.DbMigrations try { - Logger.LogInformation("CatalogService - Before Acquire "); + Logger.LogInformation("CatalogService - Before Acquire and MigrateDatabaseSchemaAsync"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs index 00cdaade..726c51a1 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -12,6 +12,7 @@ using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; using Medallion.Threading; using Microsoft.Extensions.Logging; +using Volo.Abp.DistributedLocking; namespace EShopOnAbp.IdentityService.DbMigrations { @@ -32,7 +33,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations IdentityServerDataSeeder identityServerDataSeeder, IDistributedEventBus distributedEventBus, ILocalEventBus localEventBus, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -57,7 +58,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations { Logger.LogInformation("IdentityService - Before Acquire "); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs index 1e32c00f..7804ec2c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs @@ -1,10 +1,10 @@ using EShopOnAbp.OrderingService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Medallion.Threading; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -23,7 +23,7 @@ namespace EShopOnAbp.OrderingService.DbMigrations ITenantStore tenantStore, IDistributedEventBus distributedEventBus, IDataSeeder dataSeeder, - IDistributedLockProvider distributedLockProvider) + IAbpDistributedLock distributedLockProvider) : base( currentTenant, unitOfWorkManager, @@ -53,7 +53,7 @@ namespace EShopOnAbp.OrderingService.DbMigrations { Logger.LogInformation("OrderingService - Before Acquire "); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs index 19f29057..a94fe4ff 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs @@ -1,13 +1,13 @@ using EShopOnAbp.PaymentService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; +using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; -using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; -using Medallion.Threading; -using Microsoft.Extensions.Logging; namespace EShopOnAbp.PaymentService.DbMigrations { @@ -20,7 +20,7 @@ namespace EShopOnAbp.PaymentService.DbMigrations IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, IDistributedEventBus distributedEventBus, - IDistributedLockProvider distributedLockProvider) + IAbpDistributedLock distributedLockProvider) : base( currentTenant, unitOfWorkManager, @@ -45,9 +45,9 @@ namespace EShopOnAbp.PaymentService.DbMigrations try { - Logger.LogInformation("PaymentService - Before Acquire "); + Logger.LogInformation("PaymentService - Before Acquire and MigrateDatabaseSchemaAsync"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs index 1fd0d377..1180fa7c 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Serilog; using Volo.Abp; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EventBus.Distributed; @@ -30,7 +31,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database protected IDistributedEventBus DistributedEventBus { get; } protected ILogger> Logger { get; set; } protected string DatabaseName { get; } - protected IDistributedLockProvider DistributedLockProvider { get; } + protected IAbpDistributedLock DistributedLockProvider { get; } protected DatabaseEfCoreMigrationEventHandler( ICurrentTenant currentTenant, @@ -38,7 +39,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database ITenantStore tenantStore, IDistributedEventBus distributedEventBus, string databaseName, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) { CurrentTenant = currentTenant; diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs index 251e6a92..18235262 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs @@ -1,5 +1,4 @@ -using Medallion.Threading; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using MongoDB.Driver; @@ -8,6 +7,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MongoDB; @@ -29,7 +29,7 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas protected ILogger> Logger { get; set; } protected IServiceProvider ServiceProvider { get; } protected string DatabaseName { get; } - protected IDistributedLockProvider DistributedLockProvider { get; } + protected IAbpDistributedLock DistributedLockProvider { get; } protected DatabaseMongoDbMigrationEventHandler( @@ -39,7 +39,7 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas IDistributedEventBus distributedEventBus, string databaseName, IServiceProvider serviceProvider, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) { CurrentTenant = currentTenant; From 6942e2b04e74989f1753aa405a7f599e48537df3 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 8 Mar 2022 10:57:27 +0300 Subject: [PATCH 05/12] Moved IDistributedLockProvider into the shared project --- .../AdministrationServiceHttpApiHostModule.cs | 17 +++++------------ .../CatalogServiceHttpApiHostModule.cs | 18 +++--------------- .../IdentityServiceHttpApiHostModule.cs | 9 --------- ...opOnAbp.OrderingService.HttpApi.Host.csproj | 1 - .../OrderingServiceHttpApiHostModule.cs | 10 ---------- .../PaymentServiceHttpApiHostModule.cs | 12 +----------- ...hopOnAbpSharedHostingMicroservicesModule.cs | 10 +++++++++- 7 files changed, 18 insertions(+), 59 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs index 44f96600..b2017ef9 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs @@ -1,25 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using EShopOnAbp.AdministrationService.DbMigrations; using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; -using Medallion.Threading.Redis; using Medallion.Threading; +using Medallion.Threading.Redis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.Http.Client.IdentityModel.Web; using Volo.Abp.Identity; using Volo.Abp.Modularity; -using Volo.Abp.Threading; namespace EShopOnAbp.AdministrationService; @@ -69,12 +68,6 @@ public class AdministrationServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); - - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs index 029aa848..72c8cf92 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs @@ -1,28 +1,22 @@ using EShopOnAbp.CatalogService.DbMigrations; +using EShopOnAbp.CatalogService.Grpc; +using EShopOnAbp.CatalogService.MongoDB; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; -using EShopOnAbp.CatalogService.Grpc; -using EShopOnAbp.CatalogService.MongoDB; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.AntiForgery; using Volo.Abp.Modularity; -using Volo.Abp.Threading; using Volo.Abp.Uow; -using Medallion.Threading.Redis; -using Medallion.Threading; -using StackExchange.Redis; namespace EShopOnAbp.CatalogService; @@ -70,12 +64,6 @@ public class CatalogServiceHttpApiHostModule : AbpModule }); }); - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - Configure(options => { options.ConventionalControllers.Create(typeof(CatalogServiceApplicationModule).Assembly, opts => diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs index e6a22d55..ddffb7a5 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs @@ -3,14 +3,11 @@ using EShopOnAbp.IdentityService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Gateways; using EShopOnAbp.Shared.Hosting.Microservices; -using Medallion.Threading; -using Medallion.Threading.Redis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; @@ -65,12 +62,6 @@ public class IdentityServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); - - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj index 77ac43d4..116c3153 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/EShopOnAbp.OrderingService.HttpApi.Host.csproj @@ -10,7 +10,6 @@ - diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs index 23484319..ed376a3e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs @@ -2,21 +2,17 @@ using EShopOnAbp.OrderingService.DbMigrations; using EShopOnAbp.OrderingService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; -using Medallion.Threading; -using Medallion.Threading.Redis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.DistributedLocking; using Volo.Abp.Modularity; namespace EShopOnAbp.OrderingService; @@ -67,12 +63,6 @@ public class OrderingServiceHttpApiHostModule : AbpModule }); }); - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - // TODO: Crate controller instead of auto-controller configuration Configure(options => { diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs index c0576256..d51fbba3 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs @@ -4,19 +4,15 @@ using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; using Volo.Abp; using Volo.Abp.Modularity; -using Volo.Abp.Threading; -using Medallion.Threading.Redis; -using Medallion.Threading; -using StackExchange.Redis; namespace EShopOnAbp.PaymentService; @@ -66,12 +62,6 @@ public class PaymentServiceHttpApiHostModule : AbpModule .AllowCredentials(); }); }); - - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbpSharedHostingMicroservicesModule.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbpSharedHostingMicroservicesModule.cs index 1e9fcfe6..c3cb453e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbpSharedHostingMicroservicesModule.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/EShopOnAbpSharedHostingMicroservicesModule.cs @@ -1,5 +1,7 @@ using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.AspNetCore; +using Medallion.Threading; +using Medallion.Threading.Redis; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; @@ -26,7 +28,6 @@ namespace EShopOnAbp.Shared.Hosting.Microservices public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var hostingEnvironment = context.Services.GetHostingEnvironment(); Configure(options => { @@ -42,6 +43,13 @@ namespace EShopOnAbp.Shared.Hosting.Microservices context.Services .AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "EShopOnAbp-Protection-Keys"); + + + context.Services.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); } } } \ No newline at end of file From e6c0dae2bc32224805e40cb8518f110be24f100a Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 10 Mar 2022 10:35:14 +0300 Subject: [PATCH 06/12] Update readme I've added some notes regarding the shell access issue. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27d403ae..1a9cd24a 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,11 @@ You can either run in Visual Studio, or using [Microsoft Tye](https://github.com - Rename `.env.example` file to `.env` file and provide PayPal ClientID and Secret. - Execute `run-tye.ps1` - +- **Note**: If you meet with some shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [for more detail](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) +```bash +Get-ExecutionPolicy list +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine + ``` - Wait until all applications are up! - You can check running application from tye dashboard ([localhost:8000](http://127.0.0.1:8000/)) From f61cf5ffb6c9bd57674e4096bcd9b3c6b4ab8983 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 10 Mar 2022 10:54:32 +0300 Subject: [PATCH 07/12] Update README.md Co-authored-by: Enis Necipoglu --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1a9cd24a..454ed0eb 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ You can either run in Visual Studio, or using [Microsoft Tye](https://github.com - Rename `.env.example` file to `.env` file and provide PayPal ClientID and Secret. - Execute `run-tye.ps1` -- **Note**: If you meet with some shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [for more detail](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) -```bash -Get-ExecutionPolicy list -Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine - ``` + - **Note**: If you meet with some shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [for more detail](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) + ```bash + Get-ExecutionPolicy list + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine + ``` - Wait until all applications are up! - You can check running application from tye dashboard ([localhost:8000](http://127.0.0.1:8000/)) From 381abe6d875988861135270603db2211999e80b1 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 10 Mar 2022 14:05:35 +0300 Subject: [PATCH 08/12] Corrected spelling mistake Used Products instead of Questions --- .../MongoDB/CatalogServiceMongoDbContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.MongoDB/MongoDB/CatalogServiceMongoDbContext.cs b/services/catalog/src/EShopOnAbp.CatalogService.MongoDB/MongoDB/CatalogServiceMongoDbContext.cs index 3e7570b4..c82af0c6 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.MongoDB/MongoDB/CatalogServiceMongoDbContext.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.MongoDB/MongoDB/CatalogServiceMongoDbContext.cs @@ -8,7 +8,7 @@ namespace EShopOnAbp.CatalogService.MongoDB [ConnectionStringName(CatalogServiceDbProperties.ConnectionStringName)] public class CatalogServiceMongoDbContext : AbpMongoDbContext, ICatalogServiceMongoDbContext { - public IMongoCollection Questions => Collection(); + public IMongoCollection Products => Collection(); protected override void CreateModel(IMongoModelBuilder modelBuilder) { From 542447f665bee9dd94fbb697062f8e0af21f4a79 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 10 Mar 2022 14:53:12 +0300 Subject: [PATCH 09/12] Made correction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 454ed0eb..2d80f01b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ You can either run in Visual Studio, or using [Microsoft Tye](https://github.com - Rename `.env.example` file to `.env` file and provide PayPal ClientID and Secret. - Execute `run-tye.ps1` - - **Note**: If you meet with some shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [for more detail](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) + - **Note**: If you come across shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [See Microsoft Powershell documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) ```bash Get-ExecutionPolicy list Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine From d2feca1ad721ad50b9a24cf36d5e6d8f9781b3e2 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Thu, 10 Mar 2022 15:01:07 +0300 Subject: [PATCH 10/12] Update README.md Moved powershell script notification under tye dashboard --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d80f01b..672fdcd1 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,16 @@ You can either run in Visual Studio, or using [Microsoft Tye](https://github.com - Rename `.env.example` file to `.env` file and provide PayPal ClientID and Secret. - Execute `run-tye.ps1` - - **Note**: If you come across shell issues regarding authorization. You may check with the following codes your access and then set your machine configuration. [See Microsoft Powershell documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) + +- Wait until all applications are up! + + - You can check running application from tye dashboard ([localhost:8000](http://127.0.0.1:8000/)) + - **Note**: If you see all of your applications keep restarting on tye dashboard or tye console, you may be facing ssl certificate issues. To diagnose the problems better, check any application logs. If it is related with SSL, developer certificate creation may have failed because of powershell issues regarding authorization. Check the powershell script running configuration and set policy for your local machine as: ```bash Get-ExecutionPolicy list Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine - ``` -- Wait until all applications are up! - - - You can check running application from tye dashboard ([localhost:8000](http://127.0.0.1:8000/)) + ``` + See [Microsoft Powershell documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-executionpolicy?view=powershell-7.2) for more information. - After all your backend services are up, start the angular application: From fb46286b921eba9de8102b5872cbfaa258f6fccf Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Thu, 10 Mar 2022 19:24:06 +0300 Subject: [PATCH 11/12] Updated logging --- ...ionServiceDatabaseMigrationEventHandler.cs | 38 +++++++++---------- ...logServiceDatabaseMigrationEventHandler.cs | 4 +- ...ityServiceDatabaseMigrationEventHandler.cs | 8 ++-- ...ingServiceDatabaseMigrationEventHandler.cs | 10 ++--- ...entServiceDatabaseMigrationEventHandler.cs | 6 +-- .../DatabaseEfCoreMigrationEventHandler.cs | 6 +-- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs index a25acdb1..2fb26184 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading.Tasks; +using Serilog; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; using Volo.Abp.DistributedLocking; @@ -15,7 +16,7 @@ using Volo.Abp.Uow; namespace EShopOnAbp.AdministrationService.DbMigrations { public class AdministrationServiceDatabaseMigrationEventHandler - : DatabaseEfCoreMigrationEventHandler, + : DatabaseEfCoreMigrationEventHandler, IDistributedEventHandler, IDistributedEventHandler { @@ -37,7 +38,7 @@ namespace EShopOnAbp.AdministrationService.DbMigrations distributedEventBus, AdministrationServiceDbProperties.ConnectionStringName, distributedLockProvider - ) + ) { _permissionDefinitionManager = permissionDefinitionManager; _permissionDataSeeder = permissionDataSeeder; @@ -45,8 +46,6 @@ namespace EShopOnAbp.AdministrationService.DbMigrations public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) { - Logger.LogInformation("AdministrationService - HandleEventAsync started ..."); - if (eventData.DatabaseName != DatabaseName) { return; @@ -54,8 +53,16 @@ namespace EShopOnAbp.AdministrationService.DbMigrations try { - await MigrateDatabaseSchemaAsync(eventData.TenantId); - await SeedDataAsync(eventData.TenantId); + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) + { + Log.Information("AdministrationService acquired lock for db migration and seeding..."); + + if (handle != null) + { + await MigrateDatabaseSchemaAsync(eventData.TenantId); + await SeedDataAsync(eventData.TenantId); + } + } } catch (Exception ex) { @@ -67,17 +74,9 @@ namespace EShopOnAbp.AdministrationService.DbMigrations { try { - Logger.LogInformation("AdministrationService - Before Acquire and Migration and Seed Data"); - - await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) - { - if (handle != null) - { - await MigrateDatabaseSchemaAsync(eventData.Id); - Logger.LogInformation("Starting AdministrationService DataSeeder..."); - await SeedDataAsync(eventData.Id); - } - } + await MigrateDatabaseSchemaAsync(eventData.Id); + Logger.LogInformation("Starting AdministrationService DataSeeder..."); + await SeedDataAsync(eventData.Id); } catch (Exception ex) { @@ -98,7 +97,8 @@ namespace EShopOnAbp.AdministrationService.DbMigrations var permissionNames = _permissionDefinitionManager .GetPermissions() .Where(p => p.MultiTenancySide.HasFlag(multiTenancySide)) - .Where(p => !p.Providers.Any() || p.Providers.Contains(RolePermissionValueProvider.ProviderName)) + .Where(p => !p.Providers.Any() || + p.Providers.Contains(RolePermissionValueProvider.ProviderName)) .Select(p => p.Name) .ToArray(); @@ -114,4 +114,4 @@ namespace EShopOnAbp.AdministrationService.DbMigrations } } } -} +} \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs index 7c126a57..4e1e5310 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs @@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; +using Serilog; using Volo.Abp.Data; using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; @@ -47,12 +48,13 @@ namespace EShopOnAbp.CatalogService.DbMigrations try { - Logger.LogInformation("CatalogService - Before Acquire and MigrateDatabaseSchemaAsync"); + Log.Information("CatalogService has acquired lock for db migration..."); await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { + Log.Information("CatalogService is migrating database..."); await MigrateDatabaseSchemaAsync(null); } } diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs index 726c51a1..ef9235b2 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -56,14 +56,15 @@ namespace EShopOnAbp.IdentityService.DbMigrations try { - Logger.LogInformation("IdentityService - Before Acquire "); - await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { + Log.Information("IdentityService has acquired lock for db migration..."); + if (handle != null) { + Log.Information("IdentityService is migrating database..."); await MigrateDatabaseSchemaAsync(eventData.TenantId); - Logger.LogInformation("Starting IdentityService DataSeeder..."); + Log.Information("IdentityService is seeding data..."); await SeedDataAsync( tenantId: eventData.TenantId, adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress, @@ -78,7 +79,6 @@ namespace EShopOnAbp.IdentityService.DbMigrations { await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); } - } public async Task HandleEventAsync(TenantCreatedEto eventData) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs index 7804ec2c..f5183f69 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs @@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; +using Serilog; using Volo.Abp.Data; using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; @@ -37,8 +38,6 @@ namespace EShopOnAbp.OrderingService.DbMigrations public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) { - Logger.LogInformation("OrderingService - HandleEventAsync started ..."); - if (eventData.DatabaseName != DatabaseName) { return; @@ -51,14 +50,15 @@ namespace EShopOnAbp.OrderingService.DbMigrations try { - Logger.LogInformation("OrderingService - Before Acquire "); - await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { + Log.Information("OrderingService has acquired lock for db migration..."); + if (handle != null) { + Log.Information("OrderingService is migrating database..."); await MigrateDatabaseSchemaAsync(null); - Logger.LogInformation("Starting OrderingService DataSeeder..."); + Log.Information("OrderingService is seeding data..."); await _dataSeeder.SeedAsync(); } } diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs index a94fe4ff..b330bc7f 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs @@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; +using Serilog; using Volo.Abp.Data; using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; @@ -45,15 +46,14 @@ namespace EShopOnAbp.PaymentService.DbMigrations try { - Logger.LogInformation("PaymentService - Before Acquire and MigrateDatabaseSchemaAsync"); + Log.Information("PaymentService has acquired lock for db migration..."); await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { + Log.Information("PaymentService is migrating database..."); await MigrateDatabaseSchemaAsync(null); - Logger.LogInformation("PaymentService No Seed..."); - } } } diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs index 1180fa7c..d35f2b91 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs @@ -82,7 +82,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database if (tenantId == null) { //Migrating the host database - Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is null"); + Log.Information($"There is no tenant. Migrating {DatabaseName}..."); result = await MigrateDatabaseSchemaWithDbContextAsync(); } else @@ -92,7 +92,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database !tenantConfiguration.ConnectionStrings.GetOrDefault(DatabaseName).IsNullOrWhiteSpace()) { //Migrating the tenant database (only if tenant has a separate database) - Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is not null"); + Log.Information($"Migrating tenant database:{DatabaseName} with tenantId:{tenantId}..."); result = await MigrateDatabaseSchemaWithDbContextAsync(); } } @@ -134,7 +134,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database var tryCount = IncrementEventTryCount(eventData); if (tryCount <= MaxEventTryCount) { - Logger.LogWarning( + Log.Warning( $"Could not perform tenant created event. Re-queueing the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}."); Logger.LogException(exception, LogLevel.Warning); From e775624558f7e5d130dd96116419f92e905ebd28 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Thu, 10 Mar 2022 19:33:13 +0300 Subject: [PATCH 12/12] Removed unnecessary usings --- .../DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs | 1 - .../IdentityServiceDatabaseMigrationEventHandler.cs | 2 -- .../OrderingServiceDatabaseMigrationEventHandler.cs | 1 - .../DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs | 1 - 4 files changed, 5 deletions(-) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs index 4e1e5310..0ad78438 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs @@ -1,6 +1,5 @@ using EShopOnAbp.CatalogService.MongoDB; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; -using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Serilog; diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs index ef9235b2..71c99268 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -10,8 +10,6 @@ using Volo.Abp.EventBus.Local; using Volo.Abp.Identity; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; -using Medallion.Threading; -using Microsoft.Extensions.Logging; using Volo.Abp.DistributedLocking; namespace EShopOnAbp.IdentityService.DbMigrations diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs index f5183f69..b2402578 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs @@ -1,6 +1,5 @@ using EShopOnAbp.OrderingService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Serilog; diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs index b330bc7f..2f447e7b 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs @@ -1,6 +1,5 @@ using EShopOnAbp.PaymentService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Serilog;