Skip to content

Commit

Permalink
fix(discovery): ensure all nodes have parent ref
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Apr 22, 2024
1 parent 3d6f4fc commit a05895c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/cryostat/discovery/ContainerDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void onStart(@Observes StartupEvent evt) {
plugin.realm = node;
plugin.builtin = true;
universe.children.add(node);
node.parent = universe;
plugin.persist();
universe.persist();
}
Expand Down Expand Up @@ -364,7 +365,9 @@ public void handleContainerEvent(ContainerSpec desc, EventKind evtKind) {
DiscoveryNode.environment(podName, ContainerDiscoveryNodeType.POD);
if (!realm.children.contains(pod)) {
pod.children.add(node);
node.parent = pod;
realm.children.add(pod);
pod.parent = realm;
} else {
pod =
DiscoveryNode.getChild(
Expand All @@ -376,10 +379,12 @@ public void handleContainerEvent(ContainerSpec desc, EventKind evtKind) {
.equals(n.nodeType))
.orElseThrow();
pod.children.add(node);
node.parent = pod;
}
pod.persist();
} else {
realm.children.add(node);
node.parent = realm;
}
target.persist();
node.persist();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/cryostat/discovery/CustomDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void onStart(@Observes StartupEvent evt) {
plugin.realm = node;
plugin.builtin = true;
universe.children.add(node);
node.parent = universe;
plugin.persist();
universe.persist();
}
Expand Down Expand Up @@ -167,6 +168,7 @@ Response doV2Create(
DiscoveryNode realm = DiscoveryNode.getRealm(REALM).orElseThrow();

realm.children.add(node);
node.parent = realm;
target.persist();
node.persist();
realm.persist();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/cryostat/discovery/DiscoveryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public class DiscoveryNode extends PanacheEntity {
@Nullable
public List<DiscoveryNode> children = new ArrayList<>();

@ManyToOne(cascade = {CascadeType.ALL})
@JsonIgnore
@Nullable
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentNode")
@JsonIgnore
public DiscoveryNode parent;

@OneToOne(
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/cryostat/discovery/JDPDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void onStart(@Observes StartupEvent evt) {
plugin.realm = node;
plugin.builtin = true;
universe.children.add(node);
node.parent = universe;
plugin.persist();
universe.persist();
}
Expand Down Expand Up @@ -143,6 +144,7 @@ public synchronized void handleJdpEvent(JvmDiscoveryEvent evt) {

target.discoveryNode = node;
realm.children.add(node);
node.parent = realm;
target.persist();
node.persist();
realm.persist();
Expand Down

0 comments on commit a05895c

Please sign in to comment.