Skip to content

Commit

Permalink
Merge pull request #429 from Laixer/develop
Browse files Browse the repository at this point in the history
v2.9.4
  • Loading branch information
yorickdewid authored Jan 18, 2021
2 parents a37a0a8 + e7bda31 commit e189e7c
Show file tree
Hide file tree
Showing 36 changed files with 435 additions and 227 deletions.
7 changes: 7 additions & 0 deletions FunderMaps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Portal", "src\Fu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunderMaps.BatchNode", "src\FunderMaps.BatchNode\FunderMaps.BatchNode.csproj", "{532227C4-BAD4-46AB-B45D-65F15317AFFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunderMaps.Cli", "src\FunderMaps.Cli\FunderMaps.Cli.csproj", "{ACDD237D-7C7E-425B-88CD-EF90A0037505}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -89,6 +91,10 @@ Global
{532227C4-BAD4-46AB-B45D-65F15317AFFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{532227C4-BAD4-46AB-B45D-65F15317AFFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{532227C4-BAD4-46AB-B45D-65F15317AFFA}.Release|Any CPU.Build.0 = Release|Any CPU
{ACDD237D-7C7E-425B-88CD-EF90A0037505}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACDD237D-7C7E-425B-88CD-EF90A0037505}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACDD237D-7C7E-425B-88CD-EF90A0037505}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACDD237D-7C7E-425B-88CD-EF90A0037505}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -106,6 +112,7 @@ Global
{2A345D40-2842-4AAA-A552-630FAD97B9D5} = {0219D434-DD4F-4187-ADED-8CD4A62E90F1}
{CF0E7A1A-20A8-4A15-8B57-D7218B9F33D1} = {2E7D6F8C-F448-46D2-88BA-2CA8DD7836E9}
{532227C4-BAD4-46AB-B45D-65F15317AFFA} = {2E7D6F8C-F448-46D2-88BA-2CA8DD7836E9}
{ACDD237D-7C7E-425B-88CD-EF90A0037505} = {2E7D6F8C-F448-46D2-88BA-2CA8DD7836E9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CDA50611-E011-4C1E-8823-7A6943652DCE}
Expand Down
1 change: 0 additions & 1 deletion contrib/FunderMapsCli/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions contrib/FunderMapsCli/Makefile

This file was deleted.

137 changes: 0 additions & 137 deletions contrib/FunderMapsCli/batch_client.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/FunderMaps.AspNetCore/FunderMaps.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/FunderMaps.BatchNode/Command/CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FunderMaps.BatchNode.Command
/// <summary>
/// Command descriptor.
/// </summary>
public class CommandInfo
public class CommandInfo // TODO: Move to core
{
/// <summary>
/// Command filename.
Expand Down
2 changes: 1 addition & 1 deletion src/FunderMaps.BatchNode/Jobs/BundleBuilder/BundleBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace FunderMaps.BatchNode.Jobs.BundleBuilder
/// <summary>
/// Bundle batch job entry.
/// </summary>
internal class BundleBatch : CommandTask
internal class BundleBatch : CommandTask // TODO: Rename to BundleAllJob
{
private const string TaskName = "BUNDLE_BATCH";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FunderMaps.BatchNode.Jobs.BundleBuilder
/// <summary>
/// Context for executing a bundle build task.
/// </summary>
public class BundleBuildingContext
public class BundleBuildingContext // TODO: Remove, this is moved to core
{
/// <summary>
/// The id of the bundle to process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public BundleLayerSource(Bundle bundle, Layer layer, string workspace)
layerOutputName = layer.Slug;

// Select layer field as follows:
// * If no column is specified then select everything from the layer
// * If wildcard is found, then only use wildcard.
// * If no geometry column was found, then add one.
// - If no column is specified then select everything from the layer
// - If wildcard is found, then only use wildcard.
// - If no geometry column was found, then add one.
List<string> columns = new(configuration.ColumnNames);
if (columns.Count == 0)
{
Expand Down Expand Up @@ -65,4 +65,4 @@ public override void Imbue(CommandInfo commandInfo)
commandInfo.ArgumentList.Add(layerOutputName);
}
}
}
}
8 changes: 8 additions & 0 deletions src/FunderMaps.BatchNode/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;

Expand Down Expand Up @@ -29,6 +30,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options =>
{
options.ConfigureEndpointDefaults(config =>
{
config.Protocols = HttpProtocols.Http2;
});
});
webBuilder.UseStartup<Startup>();
});
}
Expand Down
7 changes: 1 addition & 6 deletions src/FunderMaps.BatchNode/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@
"SecretKey": "",
"ServiceUri": "",
"BlobStorageName": ""
},
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
}
}
}
18 changes: 18 additions & 0 deletions src/FunderMaps.Cli/CommandDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

namespace FunderMaps.Cli.Drivers
{
internal abstract class CommandDriver
{
protected static Task ResolveSelfScope<TDriver>(IServiceProvider services, Func<TDriver, Task> shadowFunc)
{
var scopeFactory = services.GetRequiredService<IServiceScopeFactory>();
using var serviceScope = scopeFactory.CreateScope();
var serviceProvider = serviceScope.ServiceProvider;
TDriver driver = serviceProvider.GetService<TDriver>();
return shadowFunc(driver);
}
}
}
38 changes: 38 additions & 0 deletions src/FunderMaps.Cli/DriverHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;

namespace FunderMaps.Cli
{
/// <summary>
/// Driver command handler.
/// </summary>
public static class DriverHandler
{
/// <summary>
/// Create delegate with default parametes.
/// </summary>
/// <param name="action">Handler action.</param>
/// <returns>See <see cref="ICommandHandler"/>.</returns>
public static ICommandHandler InstantiateDriver(Func<FileInfo, IHost, Task> action)
=> CommandHandler.Create<FileInfo, IHost>(action);

/// <summary>
/// Create delegate with default parametes.
/// </summary>
/// <param name="action">Handler action.</param>
/// <returns>See <see cref="ICommandHandler"/>.</returns>
public static ICommandHandler InstantiateDriver<T0>(Func<FileInfo, IHost, T0, Task> action)
=> CommandHandler.Create<FileInfo, IHost, T0>(action);

/// <summary>
/// Create delegate with default parametes.
/// </summary>
/// <param name="action">Handler action.</param>
/// <returns>See <see cref="ICommandHandler"/>.</returns>
public static ICommandHandler InstantiateDriver<T0, T1>(Func<FileInfo, IHost, T0, T1, Task> action)
=> CommandHandler.Create<FileInfo, IHost, T0, T1>(action);
}
}
68 changes: 68 additions & 0 deletions src/FunderMaps.Cli/Drivers/BatchDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FunderMaps.Core.Interfaces;
using FunderMaps.Core.MapBundle;
using FunderMaps.Core.Threading;
using FunderMaps.Core.Types;
using Microsoft.Extensions.Hosting;

namespace FunderMaps.Cli.Drivers
{
/// <summary>
/// gRPC channel factory.
/// </summary>
internal class BatchDriver : CommandDriver
{
private readonly IBatchService _batchService;
private readonly IBundleService _bundleService;

/// <summary>
/// Create new instance.
/// </summary>
public BatchDriver(IBatchService batchService, IBundleService bundleService)
=> (_batchService, _bundleService) = (batchService, bundleService);

private async Task StatusAsync(CancellationToken token = default)
{
DispatchManagerStatus status = await _batchService.StatusAsync(token);
Console.WriteLine($"Jobs failed: {status.JobsFailed}");
Console.WriteLine($"Jobs succeeded: {status.JobsSucceeded}");
}

private async Task BuildBundleAsync(IEnumerable<Guid> bundleIdList, CancellationToken token = default)
{
foreach (var bundleId in bundleIdList)
{
await _bundleService.BuildAsync(new BundleBuildingContext
{
BundleId = bundleId,
Formats = new List<GeometryFormat> { GeometryFormat.GeoPackage },
});
}
}

private async Task BuildAllAsync(CancellationToken token = default)
{
await _bundleService.BuildAllAsync(new BundleBuildingContext
{
Formats = new List<GeometryFormat> { GeometryFormat.GeoPackage },
});
}

#region Factory Methods

public static Task StatusAsync(FileInfo config, IHost host)
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.StatusAsync());

public static Task BuildBundleAsync(FileInfo config, IHost host, IEnumerable<Guid> bundleId)
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.BuildBundleAsync(bundleId));

public static Task BuildAllAsync(FileInfo config, IHost host)
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.BuildAllAsync());

#endregion Factory Methods
}
}
Loading

0 comments on commit e189e7c

Please sign in to comment.