diff --git a/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java b/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java index 58d8efd33..70a6102ad 100644 --- a/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java +++ b/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java @@ -102,12 +102,7 @@ void onMessage(TargetDiscovery event) { } } - // used only for validating script syntax without an actual Target to evaluate against Script createScript(String matchExpression) throws ScriptCreateException { - return createScript(null, matchExpression); - } - - Script createScript(Target target, String matchExpression) throws ScriptCreateException { ScriptCreation evt = new ScriptCreation(); try { evt.begin(); @@ -118,7 +113,7 @@ Script createScript(Target target, String matchExpression) throws ScriptCreateEx Decls.newVar( "target", Decls.newObjectType(SimplifiedTarget.class.getName()))) - .withLibraries(List.of(new EventTypesLibrary(connectionManager, target))) + .withLibraries(List.of(new EventTypesLibrary(connectionManager))) .build(); } finally { evt.end(); @@ -130,7 +125,7 @@ Script createScript(Target target, String matchExpression) throws ScriptCreateEx @CacheResult(cacheName = CACHE_NAME) boolean load(Target target, String matchExpression) throws ScriptException { - Script script = createScript(target, matchExpression); + Script script = createScript(matchExpression); return script.execute(Boolean.class, Map.of("target", SimplifiedTarget.from(target))); } @@ -236,6 +231,7 @@ public static class ScriptCreation extends Event {} * expression-relevant fields exposed, connection URI exposed as a String, etc. */ private static record SimplifiedTarget( + long id, boolean agent, String connectUrl, String alias, @@ -255,6 +251,7 @@ private static record SimplifiedTarget( static SimplifiedTarget from(Target target) { return new SimplifiedTarget( + target.id, target.isAgent(), target.connectUrl.toString(), target.alias, @@ -267,11 +264,9 @@ static SimplifiedTarget from(Target target) { static class EventTypesLibrary implements Library { private final TargetConnectionManager connectionManager; - private final Target target; - EventTypesLibrary(TargetConnectionManager connectionManager, Target target) { + EventTypesLibrary(TargetConnectionManager connectionManager) { this.connectionManager = connectionManager; - this.target = target; } @Override @@ -282,7 +277,9 @@ public List getCompileOptions() { "eventTypeIds", Decls.newOverload( "eventTypeIds_void", - Collections.emptyList(), + List.of( + Decls.newObjectType( + SimplifiedTarget.class.getName())), Decls.newListType(Decls.String))))); } @@ -290,15 +287,17 @@ public List getCompileOptions() { public List getProgramOptions() { return List.of( ProgramOption.functions( - Overload.function( + Overload.unary( "eventTypeIds", - (args) -> ListT.newStringArrayList(getEventTypeIds())))); + (arg) -> + ListT.newStringArrayList( + getEventTypeIds( + (SimplifiedTarget) arg.value()))))); } - private String[] getEventTypeIds() { - if (target == null) { - return new String[0]; - } + private String[] getEventTypeIds(SimplifiedTarget st) { + Log.infov("Target: {0}", st); + Target target = Target.find("id", st.id()).singleResult(); try { return connectionManager.executeConnectedTask( target,