From d1cbfe07f6d77c5b9d0dc4cd1e72420d9d4e9125 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 10 Jan 2023 21:16:12 +0100 Subject: [PATCH] Update Proto Actor cluster provider --- .../elsa-workflows-designer/package.json | 2 +- .../AzureContainerAppsProvider.cs | 25 +++++++------------ .../ConfigUtils.cs | 15 ++++------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/designer/elsa-workflows-designer/package.json b/src/designer/elsa-workflows-designer/package.json index c4a6c582e..292bb7b3f 100644 --- a/src/designer/elsa-workflows-designer/package.json +++ b/src/designer/elsa-workflows-designer/package.json @@ -1,6 +1,6 @@ { "name": "@elsa-workflows/elsa-workflows-designer", - "version": "3.0.2-preview.12", + "version": "3.0.2-preview.26", "description": "A workflow designer for Elsa 3", "main": "./dist/index.cjs.js", "module": "./dist/index.js", diff --git a/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/AzureContainerAppsProvider.cs b/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/AzureContainerAppsProvider.cs index d66326c7b..46206bd44 100644 --- a/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/AzureContainerAppsProvider.cs +++ b/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/AzureContainerAppsProvider.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Azure.ResourceManager; +using Azure.ResourceManager; using Azure.ResourceManager.AppContainers; using JetBrains.Annotations; using Microsoft.Extensions.Logging; @@ -44,20 +40,17 @@ public class AzureContainerAppsProvider : IClusterProvider public AzureContainerAppsProvider( ArmClient client, string resourceGroup, - [CanBeNull] string containerAppName = default, - [CanBeNull] string revision = default, - [CanBeNull] string replicaName = default, - [CanBeNull] string advertisedHost = default) + string? containerAppName = default, + string? revision = default, + string? replicaName = default, + string? advertisedHost = default) { _client = client; _resourceGroup = resourceGroup; - _containerAppName = containerAppName ?? Environment.GetEnvironmentVariable("CONTAINER_APP_NAME"); - _revisionName = revision ?? Environment.GetEnvironmentVariable("CONTAINER_APP_REVISION"); - _replicaName = replicaName ?? Environment.GetEnvironmentVariable("HOSTNAME"); - _advertisedHost = advertisedHost; - - if (string.IsNullOrEmpty(_advertisedHost)) - _advertisedHost = ConfigUtils.FindIpAddress().ToString(); + _containerAppName = containerAppName ?? Environment.GetEnvironmentVariable("CONTAINER_APP_NAME") ?? throw new Exception("No app name provided"); + _revisionName = revision ?? Environment.GetEnvironmentVariable("CONTAINER_APP_REVISION") ?? throw new Exception("No app revision provided"); + _replicaName = replicaName ?? Environment.GetEnvironmentVariable("HOSTNAME") ?? throw new Exception("No replica name provided"); + _advertisedHost = !string.IsNullOrEmpty(advertisedHost) ? advertisedHost : ConfigUtils.FindSmallestIpAddress().ToString(); } public async Task StartMemberAsync(global::Proto.Cluster.Cluster cluster) diff --git a/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/ConfigUtils.cs b/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/ConfigUtils.cs index 19ef925f3..51c7086c7 100644 --- a/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/ConfigUtils.cs +++ b/src/modules/Elsa.ProtoActor.Cluster.AzureContainerApps/ConfigUtils.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; +using JetBrains.Annotations; namespace Elsa.ProtoActor.Cluster.AzureContainerApps; public static class ConfigUtils { - internal static IPAddress FindIpAddress(AddressFamily family = AddressFamily.InterNetwork) + [PublicAPI] + public static IPAddress FindSmallestIpAddress(AddressFamily family = AddressFamily.InterNetwork) { var addressCandidates = NetworkInterface.GetAllNetworkInterfaces() .Where(nif => nif.OperationalStatus == OperationalStatus.Up) @@ -22,15 +22,14 @@ public static class ConfigUtils private static IPAddress PickSmallestIpAddress(IEnumerable candidates) { IPAddress result = null!; + foreach (var addr in candidates) - { if (CompareIpAddresses(addr, result)) result = addr; - } return result; - static bool CompareIpAddresses(IPAddress lhs, IPAddress rhs) + static bool CompareIpAddresses(IPAddress lhs, IPAddress? rhs) { if (rhs == null) return true; @@ -41,12 +40,8 @@ public static class ConfigUtils if (lbytes.Length != rbytes.Length) return lbytes.Length < rbytes.Length; for (var i = 0; i < lbytes.Length; i++) - { if (lbytes[i] != rbytes[i]) - { return lbytes[i] < rbytes[i]; - } - } return false; }