ASC.Data.Storage.Migration: transferring from the old solution to the new one

This commit is contained in:
maksim 2020-08-18 16:46:50 +03:00
parent 6897cd21ba
commit 7481b25ad4
8 changed files with 286 additions and 1 deletions

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\common\ASC.Common\ASC.Common.csproj" />
<ProjectReference Include="..\common\ASC.Core.Common\ASC.Core.Common.csproj" />
<ProjectReference Include="..\common\ASC.Data.Storage\ASC.Data.Storage.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,88 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using ASC.Common.Logging;
using ASC.Common.Threading.Progress;
using ASC.Core;
using ASC.Data.Storage.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Data.Storage.Migration
{
public class MigrationService : IService
{
public StorageUploader StorageUploader { get; }
public StaticUploader StaticUploader { get; }
public StorageFactoryConfig StorageFactoryConfig { get; }
public IServiceProvider ServiceProvider { get; }
public ILog Log { get; }
public MigrationService(
StorageUploader storageUploader,
StaticUploader staticUploader,
StorageFactoryConfig storageFactoryConfig,
IServiceProvider serviceProvider,
IOptionsMonitor<ILog> options)
{
StorageUploader = storageUploader;
StaticUploader = staticUploader;
StorageFactoryConfig = storageFactoryConfig;
ServiceProvider = serviceProvider;
Log = options.Get("ASC.Data.Storage.Migration");
}
public void Migrate(int tenantId, StorageSettings newStorageSettings)
{
StorageUploader.Start(tenantId, newStorageSettings, StorageFactoryConfig);
}
public void UploadCdn(int tenantId, string relativePath, string mappedPath, CdnStorageSettings cdnStorageSettings = null)
{
using var scope = ServiceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
tenantManager.SetCurrentTenant(tenantId);
StaticUploader.UploadDir(relativePath, mappedPath);
Log.DebugFormat("UploadDir {0}", mappedPath);
}
public double GetProgress(int tenantId)
{
var progress = (ProgressBase)StorageUploader.GetProgress(tenantId) ?? StaticUploader.GetProgress(tenantId);
return progress != null ? progress.Percentage : -1;
}
public void StopMigrate()
{
StorageUploader.Stop();
}
}
}

View File

@ -0,0 +1,72 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Threading;
using System.Threading.Tasks;
using ASC.Core;
using ASC.Data.Storage.Configuration;
using Microsoft.Extensions.Hosting;
namespace ASC.Data.Storage.Migration
{
public class MigrationServiceLauncher : IHostedService
{
public MigrationService MigrationService { get; }
public TenantManager TenantManager { get; }
public StorageSettings StorageSettings { get; }
public MigrationServiceLauncher(
MigrationService migrationService,
TenantManager tenantManager,
StorageSettings storageSettings)
{
MigrationService = migrationService;
TenantManager = tenantManager;
StorageSettings = storageSettings;
}
public Task StartAsync(CancellationToken cancellationToken)
{
var tenantId = TenantManager.GetCurrentTenant().TenantId;
MigrationService.Migrate(tenantId, StorageSettings);
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
if (MigrationService != null)
{
MigrationService.StopMigrate();
}
return Task.CompletedTask;
}
}
}

View File

@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using ASC.Common;
using ASC.Common.DependencyInjection;
using ASC.Common.Logging;
using ASC.Core.Common;
using ASC.Core.Notify.Senders;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace ASC.Data.Storage.Migration
{
public class Program
{
public static async Task Main(string[] args)
{
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
config
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path }
}
)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env}.json", true)
.AddJsonFile($"appsettings.services.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
.AddEnvironmentVariables()
.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
var diHelper = new DIHelper(services);
diHelper.AddNLogManager("ASC.Data.Storage.Migration");
diHelper.TryAddSingleton<CommonLinkUtilitySettings>();
diHelper
.AddJabberSenderService()
.AddSmtpSenderService()
.AddAWSSenderService();
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
})
.UseConsoleLifetime()
.Build()
.Run();
}
}
}

View File

@ -0,0 +1,36 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55754/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"$STORAGE_ROOT": "../../../Data",
"log__name": "storage.migration",
"log__dir": "../../../Logs",
"core__products__folder": "../../../products"
}
},
"ASC.Data.Storage.Migration": {
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"$STORAGE_ROOT": "../../../Data",
"log__name": "storage.migration",
"log__dir": "../../../Logs",
"core__products__folder": "../../../products"
},
"applicationUrl": "http://localhost:55754/"
}
}
}

View File

@ -0,0 +1,3 @@
{
"pathToConf": "..\\..\\..\\config"
}

View File

@ -62,6 +62,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Data.Backup", "common\s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Files.Core", "products\ASC.Files\Core\ASC.Files.Core.csproj", "{F0A39728-940D-4DBE-A37A-05D4EB57F342}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASC.Data.Storage.Migration", "ASC.Data.Storage.Migration\ASC.Data.Storage.Migration.csproj", "{4182F17A-82DE-4BE5-A5E1-F4886D0C92E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -180,6 +182,10 @@ Global
{F0A39728-940D-4DBE-A37A-05D4EB57F342}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0A39728-940D-4DBE-A37A-05D4EB57F342}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0A39728-940D-4DBE-A37A-05D4EB57F342}.Release|Any CPU.Build.0 = Release|Any CPU
{4182F17A-82DE-4BE5-A5E1-F4886D0C92E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4182F17A-82DE-4BE5-A5E1-F4886D0C92E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4182F17A-82DE-4BE5-A5E1-F4886D0C92E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4182F17A-82DE-4BE5-A5E1-F4886D0C92E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,5 +1,5 @@
{
"kafka": {
"BootstrapServers": ""
"BootstrapServers": "localhost:9092"
}
}