Skip to content

Commit

Permalink
Merge pull request #18 from Kritner/FEATURE/newCoreOrleansUpdate
Browse files Browse the repository at this point in the history
Update to latest orleans version
  • Loading branch information
Kritner authored Oct 12, 2020
2 parents 061f14d + 2e2b11d commit 5772c61
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ public static class IClientBuilderExtensions
/// the Orleans environment.
/// </summary>
/// <param name="builder">The client builder.</param>
/// <param name="orleansConfigOptions">The Orleans configuration options.</param>
/// <param name="orleansConfig">The Orleans configuration.</param>
/// <param name="environmentName">The environment.</param>
public static IClientBuilder ConfigureClustering(
this IClientBuilder builder,
IOptions<OrleansConfig> orleansConfigOptions,
OrleansConfig orleansConfig,
string environmentName
)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (orleansConfigOptions.Value == default(OrleansConfig))
{
throw new ArgumentException(nameof(orleansConfigOptions));
}

builder.UseLocalhostClustering();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="Microsoft.Orleans.Client" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.Client" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -18,6 +18,7 @@

<ItemGroup>
<Content Include="..\_appsettings\appsettings.json" Link="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<Content Include="..\_appsettings\appsettings.local.json" Link="appsettings.local.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<Content Include="..\_appsettings\appsettings.dev.json" Link="appsettings.dev.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

Expand Down
26 changes: 12 additions & 14 deletions src/Kritner.OrleansGettingStarted.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,29 @@
using System.Threading.Tasks;
using Kritner.OrleansGettingStarted.Common;
using Kritner.OrleansGettingStarted.Client.ExtensionMethods;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Kritner.OrleansGettingStarted.Client
{
public class Program
{
private static Startup Startup;
private static IServiceProvider ServiceProvider;
const int initializeAttemptsBeforeFailing = 5;
private static int attempt = 0;

static int Main(string[] args)
static async Task<int> Main(string[] args)
{
Startup = ConsoleAppConfigurator.BootstrapApp();
var serviceCollection = new ServiceCollection();
Startup.ConfigureServices(serviceCollection);
ServiceProvider = serviceCollection.BuildServiceProvider();

return RunMainAsync().Result;
var (env, configurationRoot, orleansConfig) =
ConsoleAppConfigurator.BootstrapConfigurationRoot();

return await CreateHostBuilder(args, env, configurationRoot, orleansConfig);
}

private static async Task<int> RunMainAsync()
private static async Task<int> CreateHostBuilder(string[] args, string env, IConfigurationRoot configurationRoot, OrleansConfig orleansConfig)
{
try
{
using (var client = await StartClientWithRetries())
await using (var client = await StartClientWithRetries(env, orleansConfig))
{
await new OrleansExamples(new OrleansFunctionProvider())
.ChooseFunction(client);
Expand All @@ -51,14 +49,14 @@ private static async Task<int> RunMainAsync()
}
}

private static async Task<IClusterClient> StartClientWithRetries()
private static async Task<IClusterClient> StartClientWithRetries(string env, OrleansConfig orleansConfig)
{
attempt = 0;
IClusterClient client;
client = new ClientBuilder()
.ConfigureClustering(
ServiceProvider.GetService<IOptions<OrleansConfig>>(),
Startup.HostingEnvironment.EnvironmentName
orleansConfig,
env
)
.Configure<ClusterOptions>(options =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,40 @@
using Microsoft.Extensions.Hosting.Internal;
using System;
using System.IO;
using Kritner.OrleansGettingStarted.Common.Config;
using Microsoft.Extensions.Options;

namespace Kritner.OrleansGettingStarted.Common.Helpers
{
public static class ConsoleAppConfigurator
{
public static Startup BootstrapApp()
public static (string env, IConfigurationRoot configurationRoot, OrleansConfig orleansConfig) BootstrapConfigurationRoot()
{
var environment = GetEnvironment();
var hostingEnvironment = GetHostingEnvironment(environment);
var configurationBuilder = CreateConfigurationBuilder(environment);
var env = GetEnvironmentName();
var tempConfigBuilder = new ConfigurationBuilder();

return new Startup(hostingEnvironment, configurationBuilder);
}
tempConfigBuilder
.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: false)
.AddJsonFile($"appsettings.{env}.json", optional: false, reloadOnChange: false);

private static string GetEnvironment()
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (string.IsNullOrEmpty(environmentName))
{
return "dev";
}
var configurationRoot = tempConfigBuilder.Build();

return environmentName;
var serviceCollection = new ServiceCollection();
serviceCollection.Configure<OrleansConfig>(configurationRoot.GetSection(nameof(OrleansConfig)));
var serviceProvider = serviceCollection.BuildServiceProvider();
var orleansConfig = serviceProvider.GetService<IOptions<OrleansConfig>>().Value;
return (env, configurationRoot, orleansConfig);
}

private static IHostingEnvironment GetHostingEnvironment(string environmentName)
public static string GetEnvironmentName()
{
return new HostingEnvironment
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (string.IsNullOrWhiteSpace(env))
{
EnvironmentName = environmentName,
ApplicationName = AppDomain.CurrentDomain.FriendlyName,
ContentRootPath = AppDomain.CurrentDomain.BaseDirectory,
ContentRootFileProvider = new PhysicalFileProvider(AppDomain.CurrentDomain.BaseDirectory)
};
}

private static IConfigurationBuilder CreateConfigurationBuilder(string environmentName)
{
var config = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
throw new Exception("ASPNETCORE_ENVIRONMENT env variable not set.");
}

return config;
return env;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
Expand Down
28 changes: 0 additions & 28 deletions src/Kritner.OrleansGettingStarted.Common/Startup.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@

namespace Kritner.OrleansGettingStarted.SiloHost.ExtensionMethods
{
public static class ISiloHostBuilderExtensions
public static class ISiloBuilderExtensions
{
/// <summary>
/// Configures clustering for the Orleans Silo Host based on
/// the Orleans environment.
/// </summary>
/// <param name="builder">The silo host builder.</param>
/// <param name="orleansConfigOptions">The Orleans configuration options.</param>
/// <param name="builder">The silo builder.</param>
/// <param name="orleansConfig">The Orleans configuration.</param>
/// <param name="environmentName">The environment.</param>
public static ISiloHostBuilder ConfigureClustering(
this ISiloHostBuilder builder,
IOptions<OrleansConfig> orleansConfigOptions,
public static ISiloBuilder ConfigureClustering(
this ISiloBuilder builder,
OrleansConfig orleansConfig,
string environmentName
)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (orleansConfigOptions.Value == default(OrleansConfig))
{
throw new ArgumentException(nameof(orleansConfigOptions));
}

builder.UseLocalhostClustering();
builder.Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="Microsoft.Orleans.OrleansTelemetryConsumers.Counters" Version="3.0.2" />
<PackageReference Include="Microsoft.Orleans.Server" Version="3.0.2" />
<PackageReference Include="OrleansDashboard" Version="3.0.7" />
<PackageReference Include="Microsoft.Orleans.OrleansTelemetryConsumers.Counters" Version="3.3.0" />
<PackageReference Include="Microsoft.Orleans.Server" Version="3.3.0" />
<PackageReference Include="OrleansDashboard" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,6 +20,7 @@

<ItemGroup>
<Content Include="..\_appsettings\appsettings.json" Link="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<Content Include="..\_appsettings\appsettings.local.json" Link="appsettings.local.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<Content Include="..\_appsettings\appsettings.dev.json" Link="appsettings.dev.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 5772c61

Please sign in to comment.