fix: lazy-compile API method scripts and prefix composed alarm trigger attributes
- InboundScriptExecutor lazy-compiles scripts on first request, solving the multi-node problem where methods created via CLI/UI were only compiled on the ManagementActor's node, not the node handling the HTTP request. - ManagementActor hot-registers API method scripts on create/update/delete for the local node. - FlatteningService prefixes the "attribute" field in composed alarm trigger configs with the composition instance name so alarms evaluate against the correct path-qualified attribute (e.g. CoolingTank.Level not Level).
This commit is contained in:
@@ -320,6 +320,7 @@ public class FlatteningService
|
||||
alarms[canonicalName] = alarm with
|
||||
{
|
||||
CanonicalName = canonicalName,
|
||||
TriggerConfiguration = PrefixTriggerAttribute(alarm.TriggerConfiguration, prefix),
|
||||
Source = "Composed"
|
||||
};
|
||||
}
|
||||
@@ -396,6 +397,51 @@ public class FlatteningService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefixes the "attribute" (or "attributeName") field in alarm trigger configuration JSON
|
||||
/// with the composition instance name, so composed alarms monitor the path-qualified attribute.
|
||||
/// </summary>
|
||||
private static string? PrefixTriggerAttribute(string? triggerConfigJson, string prefix)
|
||||
{
|
||||
if (string.IsNullOrEmpty(triggerConfigJson)) return triggerConfigJson;
|
||||
|
||||
try
|
||||
{
|
||||
using var doc = System.Text.Json.JsonDocument.Parse(triggerConfigJson);
|
||||
var root = doc.RootElement;
|
||||
|
||||
// Find the attribute key name used
|
||||
string? attrKey = null;
|
||||
if (root.TryGetProperty("attribute", out _)) attrKey = "attribute";
|
||||
else if (root.TryGetProperty("attributeName", out _)) attrKey = "attributeName";
|
||||
|
||||
if (attrKey == null) return triggerConfigJson;
|
||||
|
||||
var attrValue = root.GetProperty(attrKey).GetString();
|
||||
if (string.IsNullOrEmpty(attrValue)) return triggerConfigJson;
|
||||
|
||||
// Rebuild JSON with prefixed attribute name
|
||||
using var ms = new System.IO.MemoryStream();
|
||||
using (var writer = new System.Text.Json.Utf8JsonWriter(ms))
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
foreach (var prop in root.EnumerateObject())
|
||||
{
|
||||
if (prop.Name == attrKey)
|
||||
writer.WriteString(attrKey, $"{prefix}.{attrValue}");
|
||||
else
|
||||
prop.WriteTo(writer);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(ms.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return triggerConfigJson;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves alarm on-trigger script references from script IDs to canonical names.
|
||||
/// This is done by finding the script in the template chain whose ID matches the alarm's OnTriggerScriptId,
|
||||
|
||||
Reference in New Issue
Block a user