Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): override nodetype tostrings for display #856

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@
import java.util.Collections;
import java.util.Map;

import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public abstract class AbstractNode implements Comparable<AbstractNode> {

protected final String name;

@SerializedName("kind")
protected final NodeType nodeType;

protected final Map<String, String> labels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public enum BaseNodeType implements NodeType {
public String getKind() {
return kind;
}

@Override
public String toString() {
return getKind();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,10 @@ public enum CustomTargetNodeType implements NodeType {
public String getKind() {
return "CustomTarget";
}

@Override
public String toString() {
return getKind();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,10 @@ public enum JDPNodeType implements NodeType {
public String getKind() {
return "JVM";
}

@Override
public String toString() {
return getKind();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public enum KubernetesNodeType implements NodeType {
this.getFn = getFn;
}

@Override
public String getKind() {
return kubernetesKind;
}
Expand All @@ -425,5 +426,10 @@ public static KubernetesNodeType fromKubernetesKind(String kubernetesKind) {
}
return null;
}

@Override
public String toString() {
return getKind();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

class KubeEnvPlatformClient extends AbstractPlatformClient {

public static final KubernetesNodeType NODE_TYPE = new KubernetesNodeType();
private static final Pattern SERVICE_ENV_PATTERN =
Pattern.compile("([\\S]+)_PORT_([\\d]+)_TCP_ADDR");
private final Lazy<JFRConnectionToolkit> connectionToolkit;
Expand Down Expand Up @@ -89,7 +88,7 @@ public EnvironmentNode getDiscoveryTree() {
EnvironmentNode root = new EnvironmentNode("KubernetesEnv", BaseNodeType.REALM);
List<ServiceRef> targets = listDiscoverableServices();
for (ServiceRef target : targets) {
TargetNode targetNode = new TargetNode(NODE_TYPE, target);
TargetNode targetNode = new TargetNode(KubernetesNodeType.SERVICE, target);
root.addChildNode(targetNode);
}
return root;
Expand All @@ -113,18 +112,24 @@ private ServiceRef envToServiceRef(Map.Entry<String, String> entry) {
}
}

public static class KubernetesNodeType implements NodeType {
public enum KubernetesNodeType implements NodeType {
SERVICE("Service"),
;

public static final String KIND = "KubernetesEnv";
private final String kind;

KubernetesNodeType(String kind) {
this.kind = kind;
}

@Override
public String getKind() {
return KIND;
return kind;
}

@Override
public int ordinal() {
return 0;
public String toString() {
return getKind();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,18 @@ public JMXServiceURL answer(InvocationOnMock args)
Matchers.hasProperty(
"name", Matchers.equalTo(serv1.getServiceUri().toString())),
Matchers.hasProperty(
"nodeType", Matchers.equalTo(KubeEnvPlatformClient.NODE_TYPE)),
"nodeType",
Matchers.equalTo(
KubeEnvPlatformClient.KubernetesNodeType.SERVICE)),
Matchers.hasProperty("target", Matchers.equalTo(serv1)));
Matcher<AbstractNode> sr2Matcher =
Matchers.allOf(
Matchers.hasProperty(
"name", Matchers.equalTo(serv2.getServiceUri().toString())),
Matchers.hasProperty(
"nodeType", Matchers.equalTo(KubeEnvPlatformClient.NODE_TYPE)),
"nodeType",
Matchers.equalTo(
KubeEnvPlatformClient.KubernetesNodeType.SERVICE)),
Matchers.hasProperty("target", Matchers.equalTo(serv2)));
MatcherAssert.assertThat(
realmNode.getChildren(), Matchers.hasItems(sr1Matcher, sr2Matcher));
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/itest/DiscoveryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void testDiscovery() throws Exception {
List<Node> realms = rootNode.children;
MatcherAssert.assertThat(
realms,
Matchers.everyItem(Matchers.hasProperty("kind", Matchers.equalTo("Realm"))));
Matchers.everyItem(Matchers.hasProperty("nodeType", Matchers.equalTo("Realm"))));
MatcherAssert.assertThat(
realms,
Matchers.allOf(
Expand All @@ -151,7 +151,7 @@ void testDiscovery() throws Exception {
MatcherAssert.assertThat(jdp.target, Matchers.nullValue());
MatcherAssert.assertThat(
jdp.children,
Matchers.everyItem(Matchers.hasProperty("kind", Matchers.equalTo("JVM"))));
Matchers.everyItem(Matchers.hasProperty("nodeType", Matchers.equalTo("JVM"))));

// There should be 2 JDP JVMs and both should be targets without further children
List<Node> jvms = jdp.children;
Expand Down Expand Up @@ -242,7 +242,7 @@ public Node getNode() {

public static class Node {
String name;
String kind;
String nodeType;
List<Node> children;
Map<String, String> labels;
Target target;
Expand All @@ -251,8 +251,8 @@ public String getName() {
return name;
}

public String getKind() {
return kind;
public String getNodeType() {
return nodeType;
}

public List<Node> getChildren() {
Expand Down