Skip to content

Commit

Permalink
Ec2MultiRegionAddressTranslator. (#91)
Browse files Browse the repository at this point in the history
*  Issue #90 Enabled the possibility to configure Ec2MultiregionAddressTranslator for jmx connections

*  Renamed setter

*  Entered dependency hell, increase guava version

* Fix the cucumber version

*  Fix dependencies
  • Loading branch information
MALPI authored and michaelsembwever committed Jun 27, 2017
1 parent 1b58bb1 commit 64dd4e5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
34 changes: 20 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dropwizard.version>1.1.0</dropwizard.version>
<dropwizard.cassandra.version>4.1.0</dropwizard.cassandra.version>
<cassandra.version>2.2.7</cassandra.version>
<cucumber.version>1.1.5</cucumber.version>
<cucumber.version>1.2.5</cucumber.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -63,6 +63,12 @@
<groupId>systems.composable</groupId>
<artifactId>dropwizard-cassandra</artifactId>
<version>${dropwizard.cassandra.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
Expand Down Expand Up @@ -120,11 +126,11 @@
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-all</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down Expand Up @@ -190,7 +196,7 @@
</excludes>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand All @@ -212,9 +218,9 @@
</configuration>
</execution>
</executions>
</plugin>
</plugin>
<plugin>
<!-- To know which version of your application you have deployed on
<!-- To know which version of your application you have deployed on
a machine -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -228,7 +234,7 @@
</configuration>
</plugin>
<plugin>
<!-- Creating a fat jar by including all classes required for running
<!-- Creating a fat jar by including all classes required for running
the app -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -323,7 +329,7 @@
</excludes>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -397,13 +403,13 @@
</goals>
<configuration>
<outputDirectory>src/main/resources/assets</outputDirectory>
<resources>
<resources>
<resource>
<directory>reaper_ui/build</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -418,7 +424,7 @@
</configuration>
</plugin>
<plugin>
<!-- To know which version of your application you have deployed on
<!-- To know which version of your application you have deployed on
a machine -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -432,7 +438,7 @@
</configuration>
</plugin>
<plugin>
<!-- Creating a fat jar by including all classes required for running
<!-- Creating a fat jar by including all classes required for running
the app -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -474,5 +480,5 @@
</build>
</profile>
</profiles>

</project>
10 changes: 7 additions & 3 deletions src/main/java/com/spotify/reaper/ReaperApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.datastax.driver.core.policies.EC2MultiRegionAddressTranslator;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.spotify.reaper.AppContext;
import com.spotify.reaper.ReaperApplicationConfiguration;

import com.spotify.reaper.ReaperApplicationConfiguration.JmxCredentials;
import com.spotify.reaper.ReaperException;
import com.spotify.reaper.cassandra.JmxConnectionFactory;
import com.spotify.reaper.resources.ClusterResource;
import com.spotify.reaper.resources.PingResource;
Expand Down Expand Up @@ -143,6 +143,10 @@ public void run(ReaperApplicationConfiguration config,
context.jmxConnectionFactory.setJmxPorts(jmxPorts);
}

if(config.useAddressTranslator()) {
context.jmxConnectionFactory.setAddressTranslator(new EC2MultiRegionAddressTranslator());
}

// Enable cross-origin requests for using external GUI applications.
if (config.isEnableCrossOrigin() || System.getProperty("enableCrossOrigin") != null) {
final FilterRegistration.Dynamic cors = environment.servlets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class ReaperApplicationConfiguration extends Configuration {
@DefaultValue("7")
private Integer scheduleDaysBetween;

@JsonProperty
@DefaultValue("false")
private boolean useAddressTranslator;

@JsonProperty
@NotNull
Expand Down Expand Up @@ -212,6 +215,14 @@ public Boolean getEnableDynamicSeedList() {
return this.enableDynamicSeedList==null?Boolean.TRUE:this.enableDynamicSeedList;
}

public void setUseAddressTranslator(Boolean useAddressTranslator) {
this.useAddressTranslator = useAddressTranslator;
}

public boolean useAddressTranslator() {
return this.useAddressTranslator;
}

public static class JmxCredentials {

@JsonProperty
Expand Down Expand Up @@ -241,7 +252,6 @@ public CassandraFactory getCassandraFactory() {
public void setCassandraFactory(CassandraFactory cassandra) {
this.cassandra = cassandra;
}


public Boolean getAllowUnreachableNodes() {
return allowUnreachableNodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package com.spotify.reaper.cassandra;

import com.google.common.base.Optional;

import com.datastax.driver.core.policies.EC2MultiRegionAddressTranslator;
import com.spotify.reaper.ReaperApplicationConfiguration.JmxCredentials;
import com.spotify.reaper.ReaperException;
import com.spotify.reaper.core.Cluster;
Expand All @@ -34,6 +36,7 @@ public class JmxConnectionFactory {
private static final Logger LOG = LoggerFactory.getLogger(JmxConnectionFactory.class);
private Map<String, Integer> jmxPorts;
private JmxCredentials jmxAuth;
private EC2MultiRegionAddressTranslator addressTranslator;

public JmxProxy connect(Optional<RepairStatusHandler> handler, String host)
throws ReaperException {
Expand All @@ -47,7 +50,7 @@ public JmxProxy connect(Optional<RepairStatusHandler> handler, String host)
username = jmxAuth.getUsername();
password = jmxAuth.getPassword();
}
return JmxProxy.connect(handler, host, username, password);
return JmxProxy.connect(handler, host, username, password, addressTranslator);
}

public final JmxProxy connect(String host) throws ReaperException {
Expand Down Expand Up @@ -91,4 +94,8 @@ public void setJmxPorts(Map<String, Integer> jmxPorts) {
public void setJmxAuth(JmxCredentials jmxAuth) {
this.jmxAuth = jmxAuth;
}

public void setAddressTranslator(EC2MultiRegionAddressTranslator addressTranslator) {
this.addressTranslator = addressTranslator;
}
}
24 changes: 16 additions & 8 deletions src/main/java/com/spotify/reaper/cassandra/JmxProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.util.AbstractMap;
import java.util.Collection;
Expand Down Expand Up @@ -55,7 +56,8 @@
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import com.datastax.driver.core.policies.EC2MultiRegionAddressTranslator;
import com.spotify.reaper.ReaperException;
import com.spotify.reaper.core.Cluster;
import com.spotify.reaper.service.RingRange;
Expand Down Expand Up @@ -90,8 +92,8 @@ public class JmxProxy implements NotificationListener, AutoCloseable {
private final String clusterName;

private JmxProxy(Optional<RepairStatusHandler> handler, String host, JMXServiceURL jmxUrl,
JMXConnector jmxConnector, Object ssProxy, ObjectName ssMbeanName,
MBeanServerConnection mbeanServer, CompactionManagerMBean cmProxy) {
JMXConnector jmxConnector, Object ssProxy, ObjectName ssMbeanName,
MBeanServerConnection mbeanServer, CompactionManagerMBean cmProxy) {
this.host = host;
this.jmxUrl = jmxUrl;
this.jmxConnector = jmxConnector;
Expand All @@ -105,20 +107,20 @@ private JmxProxy(Optional<RepairStatusHandler> handler, String host, JMXServiceU


/**
* @see JmxProxy#connect(Optional, String, int, String, String)
* @see JmxProxy#connect(Optional, String, int, String, String, EC2MultiRegionAddressTranslator)
*/
static JmxProxy connect(Optional<RepairStatusHandler> handler, String host, String username,
String password)
String password, final EC2MultiRegionAddressTranslator addressTranslator)
throws ReaperException {
if(host == null) {
throw new ReaperException("Null host given to JmxProxy.connect()");
}

String[] parts = host.split(":");
if (parts.length == 2) {
return connect(handler, parts[0], Integer.valueOf(parts[1]), username, password);
return connect(handler, parts[0], Integer.valueOf(parts[1]), username, password, addressTranslator);
} else {
return connect(handler, host, JMX_PORT, username, password);
return connect(handler, host, JMX_PORT, username, password, addressTranslator);
}
}

Expand All @@ -133,13 +135,19 @@ static JmxProxy connect(Optional<RepairStatusHandler> handler, String host, Stri
* @param port port number to use for JMX connection
* @param username username to use for JMX authentication
* @param password password to use for JMX authentication
* @param addressTranslator if EC2MultiRegionAddressTranslator isn't null it will be used to translate addresses
*/
static JmxProxy connect(Optional<RepairStatusHandler> handler, String host, int port,
String username, String password)
String username, String password, final EC2MultiRegionAddressTranslator addressTranslator)
throws ReaperException {
ObjectName ssMbeanName;
ObjectName cmMbeanName;
JMXServiceURL jmxUrl;

if(addressTranslator != null) {
host = addressTranslator.translate(new InetSocketAddress(host, port)).getHostString();
}

try {
jmxUrl = new JMXServiceURL(String.format(JMX_URL, host, port));
ssMbeanName = new ObjectName(SS_OBJECT_NAME);
Expand Down

0 comments on commit 64dd4e5

Please sign in to comment.