Skip to content

Commit 7f3ff17

Browse files
committed
Allow to configure a custom JMX port per cluster
Adding a cluster to Reaper now takes a jmx port parameter which will be stored in the backend for that cluster. All JMX connection now require a full Cluster object to build the Node instance that is passed to the JmxConnectionFactory so we can get the custom port for that cluster. The integration tests have been modified so that node 127.0.0.1 jmx port is now removed from the yaml file and the cluster is registered with port 7100. The other nodes JMX ports are still in the yaml file and will prevail over the cluster's custom JMX port. Make the partitioner optional in the Cluster object
1 parent 7e2441a commit 7f3ff17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+640
-164
lines changed

src/packaging/bin/spreaper

+3-2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def _arguments_for_status_schedule(parser):
171171
def _arguments_for_add_cluster(parser):
172172
"""Arguments relevant for registering a cluster"""
173173
parser.add_argument("seed_host", help="the seed host of the Cassandra cluster to be registered")
174+
parser.add_argument("jmx_port", help="the JMX port of the Cassandra cluster to be registered", default="7199")
174175

175176

176177
def _argument_owner(parser):
@@ -596,8 +597,8 @@ class ReaperCLI(object):
596597
"Register a cluster.",
597598
extra_arguments=_arguments_for_add_cluster
598599
)
599-
printq("# Registering Cassandra cluster with seed host: {0}".format(args.seed_host))
600-
cluster_data = reaper.post("cluster", seedHost=args.seed_host)
600+
printq("# Registering Cassandra cluster with seed host: {0} and jmx port : {1}".format(args.seed_host, args.jmx_port))
601+
cluster_data = reaper.post("cluster", seedHost=args.seed_host, jmxPort=args.jmx_port)
601602
printq("# Registration succeeded:")
602603
print json.dumps(json.loads(cluster_data), indent=2, sort_keys=True)
603604

src/server/src/main/java/io/cassandrareaper/ReaperApplication.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private void schedulePurge(ScheduledExecutorService scheduler) {
307307
try {
308308
int purgedRuns = purgeManager.purgeDatabase();
309309
LOG.info("Purged {} repair runs from history", purgedRuns);
310-
} catch (RuntimeException e) {
310+
} catch (RuntimeException | ReaperException e) {
311311
LOG.error("Failed purging repair runs from history", e);
312312
}
313313
},
@@ -405,7 +405,7 @@ private void initializeJmxSeedsForAllClusters() {
405405
.forEach(cluster -> jmxConnectionsIntializer.on(cluster));
406406

407407
LOG.info("Initialized JMX seed list for all clusters.");
408-
} catch (RuntimeException e) {
408+
} catch (RuntimeException | ReaperException e) {
409409
LOG.error("Failed initializing JMX seed list", e);
410410
}
411411
}

src/server/src/main/java/io/cassandrareaper/core/Cluster.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,33 @@
1717

1818
package io.cassandrareaper.core;
1919

20+
import java.util.Optional;
2021
import java.util.Set;
2122

2223
import com.google.common.base.Preconditions;
2324

2425
public final class Cluster {
2526

27+
public static final int DEFAULT_JMX_PORT = 7199;
2628
private final String name;
27-
private final String partitioner; // Full name of the partitioner class
29+
private final Optional<String> partitioner; // Full name of the partitioner class
2830
private final Set<String> seedHosts;
31+
private final ClusterProperties properties;
2932

30-
public Cluster(String name, String partitioner, Set<String> seedHosts) {
33+
public Cluster(String name, Optional<String> partitioner, Set<String> seedHosts) {
34+
this(
35+
name,
36+
partitioner,
37+
seedHosts,
38+
ClusterProperties.builder().withJmxPort(DEFAULT_JMX_PORT).build());
39+
}
40+
41+
public Cluster(
42+
String name, Optional<String> partitioner, Set<String> seedHosts, ClusterProperties properties) {
3143
this.name = toSymbolicName(name);
3244
this.partitioner = partitioner;
3345
this.seedHosts = seedHosts;
46+
this.properties = properties;
3447
}
3548

3649
public static String toSymbolicName(String name) {
@@ -42,11 +55,15 @@ public String getName() {
4255
return name;
4356
}
4457

45-
public String getPartitioner() {
58+
public Optional<String> getPartitioner() {
4659
return partitioner;
4760
}
4861

4962
public Set<String> getSeedHosts() {
5063
return seedHosts;
5164
}
65+
66+
public ClusterProperties getProperties() {
67+
return properties;
68+
}
5269
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2014-2017 Spotify AB
3+
* Copyright 2016-2018 The Last Pickle Ltd
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.cassandrareaper.core;
19+
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
22+
23+
@JsonDeserialize(builder = ClusterProperties.Builder.class)
24+
public final class ClusterProperties {
25+
private final int jmxPort;
26+
27+
private ClusterProperties(Builder builder) {
28+
this.jmxPort = builder.jmxPort;
29+
}
30+
31+
public int getJmxPort() {
32+
return jmxPort;
33+
}
34+
35+
public static Builder builder() {
36+
return new Builder();
37+
}
38+
39+
@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with")
40+
public static final class Builder {
41+
private int jmxPort;
42+
43+
private Builder() {}
44+
45+
public Builder withJmxPort(int jmxPort) {
46+
this.jmxPort = jmxPort;
47+
return this;
48+
}
49+
50+
public ClusterProperties build() {
51+
return new ClusterProperties(this);
52+
}
53+
}
54+
}

src/server/src/main/java/io/cassandrareaper/core/Node.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package io.cassandrareaper.core;
1919

2020
import java.util.Collections;
21+
import java.util.Optional;
2122

2223
public final class Node {
2324

@@ -57,7 +58,7 @@ public Builder withCluster(Cluster cluster) {
5758
}
5859

5960
public Builder withClusterName(String clusterName) {
60-
this.cluster = new Cluster(clusterName, null, Collections.emptySet());
61+
this.cluster = new Cluster(clusterName, Optional.empty(), Collections.emptySet());
6162
return this;
6263
}
6364

src/server/src/main/java/io/cassandrareaper/jmx/JmxConnectionFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ protected JmxProxy connectImpl(Node node, int connectionTimeout) throws ReaperEx
8585
String host = node.getHostname();
8686
if (jmxPorts != null && jmxPorts.containsKey(host) && !host.contains(":")) {
8787
host = host + ":" + jmxPorts.get(host);
88+
LOG.debug("Connecting to {} with specific port", host);
89+
} else {
90+
host = host + ":" + node.getCluster().getProperties().getJmxPort();
91+
LOG.debug("Connecting to {} with custom port", host);
8892
}
8993

9094
String username = null;

src/server/src/main/java/io/cassandrareaper/jmx/JmxProxyImpl.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ final class JmxProxyImpl implements JmxProxy {
9292

9393
private static final Logger LOG = LoggerFactory.getLogger(JmxProxy.class);
9494

95-
private static final int JMX_PORT = 7199;
96-
9795
private static final String VALUE_ATTRIBUTE = "Value";
9896
private static final String FAILED_TO_CONNECT_TO_USING_JMX = "Failed to connect to {} using JMX";
9997
private static final String ERROR_GETTING_ATTR_JMX = "Error getting attribute from JMX";
@@ -160,13 +158,13 @@ static JmxProxy connect(
160158
final HostAndPort hostAndPort = HostAndPort.fromString(host);
161159

162160
return connect(
163-
hostAndPort.getHost(),
164-
hostAndPort.getPortOrDefault(JMX_PORT),
165-
username,
166-
password,
167-
addressTranslator,
168-
connectionTimeout,
169-
metricRegistry);
161+
hostAndPort.getHost(),
162+
hostAndPort.getPortOrDefault(Cluster.DEFAULT_JMX_PORT),
163+
username,
164+
password,
165+
addressTranslator,
166+
connectionTimeout,
167+
metricRegistry);
170168
}
171169

172170
/**

0 commit comments

Comments
 (0)