Skip to content

Commit

Permalink
fix(jvmId): correct query for Targets with null jvmId (backport #496) (
Browse files Browse the repository at this point in the history
…#502)

fix(jvmId): correct query for Targets with null jvmId (#496)

(cherry picked from commit 2d1a768)

Co-authored-by: Andrew Azores <[email protected]>
  • Loading branch information
mergify[bot] and andrewazores authored Jun 6, 2024
1 parent 5b320f5 commit 819c451
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/main/java/io/cryostat/discovery/Discovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.<DiscoveryPlugin>find("callback", unauthCallback)
.singleResultOptional()
.ifPresent(
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/io/cryostat/targets/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -319,9 +322,9 @@ void onMessage(TargetDiscovery event) {

@ConsumeEvent(value = Credential.CREDENTIALS_STORED, blocking = true)
@Transactional
@Blocking
void updateCredential(Credential credential) {
Target.<Target>find("jvmId", (String) null)
.list()
Target.<Target>stream("#Target.unconnected")
.forEach(
t -> {
try {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 819c451

Please sign in to comment.