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

feat(discovery): port discovery types from cryostat #152

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.cryostat</groupId>
<artifactId>cryostat-core</artifactId>
<version>2.13.0-SNAPSHOT</version>
<version>2.13.0</version>
<packaging>jar</packaging>
<name>cryostat-core</name>
<url>http://maven.apache.org</url>
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/io/cryostat/core/discovery/AbstractNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat.core.discovery;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

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;

protected final String nodeType;

protected final Map<String, String> labels;

protected AbstractNode(AbstractNode other) {
this(other.name, other.nodeType, other.labels);
}

protected AbstractNode(String name, String nodeType, Map<String, String> labels) {
this.name = name;
this.nodeType = nodeType;
this.labels = new HashMap<>(labels);
}

public String getName() {
return name;
}

public String getNodeType() {
return nodeType;
}

public Map<String, String> getLabels() {
return Collections.unmodifiableMap(labels);
}

@Override
public int compareTo(AbstractNode other) {
return name.compareTo(other.name);
}

@Override
public int hashCode() {
return new HashCodeBuilder().append(name).append(nodeType).append(labels).build();
}

@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (!(o instanceof AbstractNode)) {
return false;
}
AbstractNode other = (AbstractNode) o;
return new EqualsBuilder()
.append(name, other.name)
.append(nodeType, other.nodeType)
.append(labels, other.labels)
.isEquals();
}
}
65 changes: 65 additions & 0 deletions src/main/java/io/cryostat/core/discovery/BaseNodeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat.core.discovery;

public enum BaseNodeType {
// represents the entire deployment scenario Cryostat finds itself in
UNIVERSE("Universe"),
// represents a division of the deployment scenario - the universe may consist of a
// Kubernetes Realm and a JDP Realm, for example
REALM("Realm"),
// represents a leaf node JVM, potentially represented by a connectable TargetNode with a JMX
// Service URL
JVM("JVM"),
;

private final String kind;

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

public String getKind() {
return kind;
}

@Override
public String toString() {
return getKind();
}
}
104 changes: 104 additions & 0 deletions src/main/java/io/cryostat/core/discovery/EnvironmentNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat.core.discovery;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.ConcurrentSkipListSet;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class EnvironmentNode extends AbstractNode {

private final SortedSet<AbstractNode> children;

public EnvironmentNode(EnvironmentNode other) {
this(other.name, other.nodeType, other.labels, other.children);
}

public EnvironmentNode(String name, String nodeType) {
this(name, nodeType, Collections.emptyMap());
}

public EnvironmentNode(String name, String nodeType, Map<String, String> labels) {
this(name, nodeType, labels, Collections.emptySortedSet());
}

public EnvironmentNode(
String name,
String nodeType,
Map<String, String> labels,
Collection<? extends AbstractNode> children) {
super(name, nodeType, labels);
this.children = new ConcurrentSkipListSet<>(children);
}

public SortedSet<AbstractNode> getChildren() {
return Collections.unmodifiableSortedSet(children);
}

public void addChildNode(AbstractNode child) {
this.children.add(child);
}

@Override
public int hashCode() {
return new HashCodeBuilder().appendSuper(super.hashCode()).append(children).build();
}

@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (!(o instanceof EnvironmentNode)) {
return false;
}
EnvironmentNode other = (EnvironmentNode) o;
return new EqualsBuilder()
.appendSuper(super.equals(o))
.append(children, other.children)
.isEquals();
}
}
Loading