Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdgeHub awaits for Twin in non-MQTT broker scenario (#4084) #4129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,9 @@ void RegisterRoutingModule(
bool checkEntireQueueOnCleanup = this.configuration.GetValue("CheckEntireQueueOnCleanup", false);
int messageCleanupIntervalSecs = this.configuration.GetValue("MessageCleanupIntervalSecs", 1800);
bool closeCloudConnectionOnDeviceDisconnect = this.configuration.GetValue("CloseCloudConnectionOnDeviceDisconnect", true);

bool isLegacyUpstream = !experimentalFeatures.Enabled
|| !experimentalFeatures.EnableMqttBroker
|| !experimentalFeatures.EnableNestedEdge
|| !this.GetConfigurationValueIfExists<string>(Constants.ConfigKey.GatewayHostname).HasValue;
bool isLegacyUpstream = ExperimentalFeatures.IsViaBrokerUpstream(
experimentalFeatures,
this.GetConfigurationValueIfExists<string>(Constants.ConfigKey.GatewayHostname).HasValue);

builder.RegisterModule(
new RoutingModule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public static ExperimentalFeatures Create(IConfiguration experimentalFeaturesCon
return experimentalFeatures;
}

public static bool IsViaBrokerUpstream(ExperimentalFeatures experimentalFeatures, bool hasGatewayHostname)
{
bool isLegacyUpstream = !experimentalFeatures.Enabled
|| !experimentalFeatures.EnableMqttBroker
|| !experimentalFeatures.EnableNestedEdge
|| !hasGatewayHostname;

return isLegacyUpstream;
}

public bool Enabled { get; }

public bool DisableCloudSubscriptions { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,20 @@ static async Task<int> MainAsync(IConfigurationRoot configuration)
logger.LogInformation("Initializing configuration");
IConfigSource configSource = await container.Resolve<Task<IConfigSource>>();
ConfigUpdater configUpdater = await container.Resolve<Task<ConfigUpdater>>();
ExperimentalFeatures experimentalFeatures = CreateExperimentalFeatures(configuration);
var configUpdaterStartupFailed = new TaskCompletionSource<bool>();
_ = configUpdater.Init(configSource).ContinueWith(
_ => configUpdaterStartupFailed.SetResult(false),
TaskContinuationOptions.OnlyOnFaulted);
var configDownloadTask = configUpdater.Init(configSource);

_ = configDownloadTask.ContinueWith(
_ => configUpdaterStartupFailed.SetResult(false),
TaskContinuationOptions.OnlyOnFaulted);

if (!ExperimentalFeatures.IsViaBrokerUpstream(
experimentalFeatures,
string.IsNullOrEmpty(configuration.GetValue<string>(Constants.ConfigKey.GatewayHostname))))
{
await configDownloadTask;
}

if (!Enum.TryParse(configuration.GetValue("AuthenticationMode", string.Empty), true, out AuthenticationMode authenticationMode)
|| authenticationMode != AuthenticationMode.Cloud)
Expand All @@ -112,7 +122,7 @@ static async Task<int> MainAsync(IConfigurationRoot configuration)
TimeSpan shutdownWaitPeriod = TimeSpan.FromSeconds(configuration.GetValue("ShutdownWaitPeriod", DefaultShutdownWaitPeriod));
(CancellationTokenSource cts, ManualResetEventSlim completed, Option<object> handler) = ShutdownHandler.Init(shutdownWaitPeriod, logger);

using (IProtocolHead protocolHead = await GetEdgeHubProtocolHeadAsync(logger, configuration, container, hosting))
using (IProtocolHead protocolHead = await GetEdgeHubProtocolHeadAsync(logger, configuration, experimentalFeatures, container, hosting))
using (var renewal = new CertificateRenewal(certificates, logger))
{
try
Expand All @@ -138,6 +148,13 @@ static async Task<int> MainAsync(IConfigurationRoot configuration)
return 0;
}

static ExperimentalFeatures CreateExperimentalFeatures(IConfigurationRoot configuration)
{
IConfiguration experimentalFeaturesConfig = configuration.GetSection(Constants.ConfigKey.ExperimentalFeatures);
ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(experimentalFeaturesConfig, Logger.Factory.CreateLogger("EdgeHub"));
return experimentalFeatures;
}

static void LogVersionInfo(ILogger logger)
{
VersionInfo versionInfo = VersionInfo.Get(Constants.VersionInfoFileName);
Expand All @@ -147,11 +164,8 @@ static void LogVersionInfo(ILogger logger)
}
}

static async Task<EdgeHubProtocolHead> GetEdgeHubProtocolHeadAsync(ILogger logger, IConfigurationRoot configuration, IContainer container, Hosting hosting)
static async Task<EdgeHubProtocolHead> GetEdgeHubProtocolHeadAsync(ILogger logger, IConfigurationRoot configuration, ExperimentalFeatures experimentalFeatures, IContainer container, Hosting hosting)
{
IConfiguration experimentalFeaturesConfig = configuration.GetSection(Constants.ConfigKey.ExperimentalFeatures);
ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(experimentalFeaturesConfig, Logger.Factory.CreateLogger("EdgeHub"));

var protocolHeads = new List<IProtocolHead>();

// MQTT broker overrides the legacy MQTT protocol head
Expand Down