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

Ec2MultiRegionAddressTranslator. #91

Merged
merged 5 commits into from
May 4, 2017
Merged
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
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 @@ -304,7 +310,7 @@
</excludes>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -378,13 +384,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 @@ -399,7 +405,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 @@ -413,7 +419,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 @@ -455,5 +461,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 @@ -27,14 +27,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 @@ -136,6 +136,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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Introduce a new variable instead of reusing the parameter "host". rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done by intention?

}

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