This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Dapr "standalone" applications (#1194)
* Try inverting default placement service behavior. * Eliminate placement service management. * Remove references to placement service options. * Try to determine Dapr status. * Update formatting. * Sketch service-based override of Dapr configuration. * Move types to separate files. * Fix formatting.
- Loading branch information
1 parent
565b7d3
commit bbf5475
Showing
5 changed files
with
147 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Tye.Extensions/Dapr/DaprExtensionConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Tye.Extensions.Dapr | ||
{ | ||
internal abstract class DaprExtensionCommonConfiguration | ||
{ | ||
public int? PlacementPort { get; set; } | ||
} | ||
|
||
internal sealed class DaprExtensionServiceConfiguration : DaprExtensionCommonConfiguration | ||
{ | ||
public bool? Enabled { get; set; } | ||
} | ||
|
||
internal sealed class DaprExtensionConfiguration : DaprExtensionCommonConfiguration | ||
{ | ||
public IReadOnlyDictionary<string, DaprExtensionServiceConfiguration> Services { get; set; } | ||
= new Dictionary<string, DaprExtensionServiceConfiguration>(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Microsoft.Tye.Extensions/Dapr/DaprExtensionConfigurationReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Tye.Extensions.Dapr | ||
{ | ||
internal static class DaprExtensionConfigurationReader | ||
{ | ||
public static DaprExtensionConfiguration ReadConfiguration(IDictionary<string, object> rawConfiguration) | ||
{ | ||
var configuration = new DaprExtensionConfiguration(); | ||
|
||
ReadCommonConfiguration(rawConfiguration, configuration); | ||
|
||
if (rawConfiguration.TryGetValue("services", out var servicesObject) && servicesObject is Dictionary<string, object> rawServicesConfiguration) | ||
{ | ||
var services = new Dictionary<string, DaprExtensionServiceConfiguration>(); | ||
|
||
foreach (var kvp in rawServicesConfiguration) | ||
{ | ||
if (kvp.Value is Dictionary<string, object> rawServiceConfiguration) | ||
{ | ||
var serviceConfiguration = new DaprExtensionServiceConfiguration(); | ||
|
||
ReadServiceConfiguration(rawServiceConfiguration, serviceConfiguration); | ||
|
||
services.Add(kvp.Key, serviceConfiguration); | ||
} | ||
} | ||
|
||
configuration.Services = services; | ||
} | ||
|
||
return configuration; | ||
} | ||
|
||
private static void ReadServiceConfiguration(IDictionary<string, object> rawConfiguration, DaprExtensionServiceConfiguration serviceConfiguration) | ||
{ | ||
ReadCommonConfiguration(rawConfiguration, serviceConfiguration); | ||
|
||
if (rawConfiguration.TryGetValue("enabled", out var obj) && obj is string && Boolean.TryParse(obj.ToString(), out var enabled)) | ||
{ | ||
serviceConfiguration.Enabled = enabled; | ||
} | ||
} | ||
|
||
private static void ReadCommonConfiguration(IDictionary<string, object> rawConfiguration, DaprExtensionCommonConfiguration commonConfiguration) | ||
{ | ||
if (rawConfiguration.TryGetValue("placement-port", out var obj) && obj?.ToString() is string && int.TryParse(obj.ToString(), out var customPlacementPort)) | ||
{ | ||
commonConfiguration.PlacementPort = customPlacementPort; | ||
} | ||
} | ||
} | ||
} |