diff --git a/src/main/java/io/cryostat/platform/discovery/AbstractNode.java b/src/main/java/io/cryostat/platform/discovery/AbstractNode.java index 36b6d8ca02..6778785c8c 100644 --- a/src/main/java/io/cryostat/platform/discovery/AbstractNode.java +++ b/src/main/java/io/cryostat/platform/discovery/AbstractNode.java @@ -40,7 +40,6 @@ 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; @@ -48,7 +47,6 @@ public abstract class AbstractNode implements Comparable { protected final String name; - @SerializedName("kind") protected final NodeType nodeType; protected final Map labels; diff --git a/src/main/java/io/cryostat/platform/discovery/BaseNodeType.java b/src/main/java/io/cryostat/platform/discovery/BaseNodeType.java index 4f993f5757..cf150b55f1 100644 --- a/src/main/java/io/cryostat/platform/discovery/BaseNodeType.java +++ b/src/main/java/io/cryostat/platform/discovery/BaseNodeType.java @@ -55,4 +55,9 @@ public enum BaseNodeType implements NodeType { public String getKind() { return kind; } + + @Override + public String toString() { + return getKind(); + } } diff --git a/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java b/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java index 759e21f99c..829c5afd8a 100644 --- a/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java @@ -148,5 +148,10 @@ public enum CustomTargetNodeType implements NodeType { public String getKind() { return "CustomTarget"; } + + @Override + public String toString() { + return getKind(); + } } } diff --git a/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java b/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java index 7ee8605c43..07eb9034d7 100644 --- a/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java @@ -136,5 +136,10 @@ public enum JDPNodeType implements NodeType { public String getKind() { return "JVM"; } + + @Override + public String toString() { + return getKind(); + } } } diff --git a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java index 14389395e2..8534f98f09 100644 --- a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java @@ -405,6 +405,7 @@ public enum KubernetesNodeType implements NodeType { this.getFn = getFn; } + @Override public String getKind() { return kubernetesKind; } @@ -425,5 +426,10 @@ public static KubernetesNodeType fromKubernetesKind(String kubernetesKind) { } return null; } + + @Override + public String toString() { + return getKind(); + } } } diff --git a/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java b/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java index bb132f88c4..b13a55437b 100644 --- a/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java @@ -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 connectionToolkit; @@ -89,7 +88,7 @@ public EnvironmentNode getDiscoveryTree() { EnvironmentNode root = new EnvironmentNode("KubernetesEnv", BaseNodeType.REALM); List 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; @@ -113,18 +112,24 @@ private ServiceRef envToServiceRef(Map.Entry 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(); } } } diff --git a/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java index a1d6b97c1c..bf91876ea2 100644 --- a/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java @@ -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 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)); diff --git a/src/test/java/itest/DiscoveryIT.java b/src/test/java/itest/DiscoveryIT.java index 8e71b4e607..6316ec5322 100644 --- a/src/test/java/itest/DiscoveryIT.java +++ b/src/test/java/itest/DiscoveryIT.java @@ -125,7 +125,7 @@ void testDiscovery() throws Exception { List 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( @@ -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 jvms = jdp.children; @@ -242,7 +242,7 @@ public Node getNode() { public static class Node { String name; - String kind; + String nodeType; List children; Map labels; Target target; @@ -251,8 +251,8 @@ public String getName() { return name; } - public String getKind() { - return kind; + public String getNodeType() { + return nodeType; } public List getChildren() {