diff --git a/src/main/java/io/cryostat/discovery/Discovery.java b/src/main/java/io/cryostat/discovery/Discovery.java index 89e7402f8..62f5b5269 100644 --- a/src/main/java/io/cryostat/discovery/Discovery.java +++ b/src/main/java/io/cryostat/discovery/Discovery.java @@ -229,8 +229,7 @@ public Response register(@Context RoutingContext ctx, JsonObject body) // check if a plugin record with the same callback already exists. If it does, // ping it: // if it's still there reject this request as a duplicate, otherwise delete the - // previous - // record and accept this new one as a replacement + // previous record and accept this new one as a replacement DiscoveryPlugin.find("callback", unauthCallback) .singleResultOptional() .ifPresent( diff --git a/src/main/java/io/cryostat/targets/Target.java b/src/main/java/io/cryostat/targets/Target.java index 6b6d4c14d..8d89c073b 100644 --- a/src/main/java/io/cryostat/targets/Target.java +++ b/src/main/java/io/cryostat/targets/Target.java @@ -55,6 +55,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.JoinColumn; +import jakarta.persistence.NamedQueries; +import jakarta.persistence.NamedQuery; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.PostPersist; @@ -73,6 +75,7 @@ @Entity @EntityListeners(Target.Listener.class) +@NamedQueries({@NamedQuery(name = "Target.unconnected", query = "from Target where jvmId is null")}) public class Target extends PanacheEntity { public static final String TARGET_JVM_DISCOVERY = "TargetJvmDiscovery"; @@ -319,9 +322,9 @@ void onMessage(TargetDiscovery event) { @ConsumeEvent(value = Credential.CREDENTIALS_STORED, blocking = true) @Transactional + @Blocking void updateCredential(Credential credential) { - Target.find("jvmId", (String) null) - .list() + Target.stream("#Target.unconnected") .forEach( t -> { try { @@ -360,15 +363,19 @@ void prePersist(Target target) { @Blocking private void updateTargetJvmId(Target t, Credential credential) { - t.jvmId = - connectionManager - .executeDirect( - t, - Optional.ofNullable(credential), - JFRConnection::getJvmIdentifier) - .map(JvmIdentifier::getHash) - .await() - .atMost(timeout); + try { + t.jvmId = + connectionManager + .executeDirect( + t, + Optional.ofNullable(credential), + JFRConnection::getJvmIdentifier) + .map(JvmIdentifier::getHash) + .await() + .atMost(timeout); + } catch (Exception e) { + logger.error(e); + } } @PostPersist