Update Proto Actor cluster provider

This commit is contained in:
Sipke Schoorstra 2023-01-10 21:16:12 +01:00
parent 091161dd9a
commit d1cbfe07f6
3 changed files with 15 additions and 27 deletions

View file

@ -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",

View file

@ -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)

View file

@ -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<IPAddress> 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;
}