Skip to content

Commit

Permalink
added jmxPorts to configuration, added jmx port lookup in con.factory
Browse files Browse the repository at this point in the history
  • Loading branch information
spodkowinski authored and varjoranta committed Feb 17, 2015
1 parent 9cfc676 commit 438e329
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/spotify/reaper/ReaperApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.spotify.reaper;

import com.google.common.annotations.VisibleForTesting;

import com.spotify.reaper.cassandra.JmxConnectionFactory;
import com.spotify.reaper.resources.ClusterResource;
import com.spotify.reaper.resources.PingResource;
Expand All @@ -36,6 +35,7 @@
import sun.misc.SignalHandler;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.dropwizard.Application;
Expand Down Expand Up @@ -109,6 +109,13 @@ public void run(ReaperApplicationConfiguration config,
LOG.info("no JMX connection factory given in context, creating default");
context.jmxConnectionFactory = new JmxConnectionFactory();
}

// read jmx host/port mapping from config and provide to jmx con.factory
Map<String, Integer> jmxPorts = config.getJmxPorts();
if(jmxPorts != null) {
LOG.debug("Using JMX ports mapping: " + jmxPorts);
context.jmxConnectionFactory.setJmxPorts(jmxPorts);
}

LOG.info("creating and registering health checks");
// Notice that health checks are registered under the admin application on /healthcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package com.spotify.reaper;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.hibernate.validator.constraints.NotEmpty;
Expand Down Expand Up @@ -53,6 +55,10 @@ public class ReaperApplicationConfiguration extends Configuration {
@JsonProperty
private DataSourceFactory database = new DataSourceFactory();

@JsonProperty
private Map<String, Integer> jmxPorts;


public int getSegmentCount() {
return segmentCount;
}
Expand Down Expand Up @@ -105,4 +111,13 @@ public int getHangingRepairTimeoutMins() {
public void setHangingRepairTimeoutMins(int hangingRepairTimeoutMins) {
this.hangingRepairTimeoutMins = hangingRepairTimeoutMins;
}

public Map<String, Integer> getJmxPorts() {
return jmxPorts;
}

public void setJmxPorts(Map<String, Integer> jmxPorts) {
this.jmxPorts = jmxPorts;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
package com.spotify.reaper.cassandra;

import com.google.common.base.Optional;

import com.spotify.reaper.ReaperException;
import com.spotify.reaper.core.Cluster;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class JmxConnectionFactory {

private Map<String, Integer> jmxPorts;

public JmxProxy connect(Optional<RepairStatusHandler> handler, String host)
throws ReaperException {
// use configured jmx port for host if provided
if(jmxPorts != null && jmxPorts.containsKey(host) && !host.contains(":"))
host = host + ":" + jmxPorts.get(host);
return JmxProxy.connect(handler, host);
}

Expand All @@ -48,4 +53,8 @@ public final JmxProxy connectAny(Cluster cluster)
}
return connectAny(Optional.<RepairStatusHandler>absent(), hosts);
}

public void setJmxPorts(Map<String, Integer> jmxPorts) {
this.jmxPorts = jmxPorts;
}
}

0 comments on commit 438e329

Please sign in to comment.