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

Use dropwizard 1.0 #66

Merged
merged 4 commits into from
Mar 31, 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
78 changes: 54 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dropwizard.version>0.7.1</dropwizard.version>
<dropwizard.version>1.1.0</dropwizard.version>
<dropwizard.cassandra.version>4.0.0</dropwizard.cassandra.version>
<cassandra.version>2.2.7</cassandra.version>
<cucumber.version>1.1.5</cucumber.version>
Expand All @@ -22,7 +22,27 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
<version>19.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
Expand All @@ -37,7 +57,12 @@
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
<version>${dropwizard.version}</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>systems.composable</groupId>
<artifactId>dropwizard-cassandra</artifactId>
<version>${dropwizard.cassandra.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
Expand All @@ -52,46 +77,35 @@
<groupId>org.codehaus.jackson</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
<dependency>
<groupId>systems.composable</groupId>
<artifactId>dropwizard-cassandra</artifactId>
<version>${dropwizard.cassandra.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.186</version>
</dependency>
<dependency>
<groupId>org.cognitor.cassandra</groupId>
<artifactId>cassandra-migration</artifactId>
<version>2.0.0</version>
<groupId>org.cognitor.cassandra</groupId>
<artifactId>cassandra-migration</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.1</version>
</dependency>

<!--test scope -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -103,11 +117,21 @@
<artifactId>dropwizard-testing</artifactId>
<version>${dropwizard.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -127,7 +151,13 @@
<artifactId>awaitility</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M10</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/spotify/reaper/ReaperApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void run(ReaperApplicationConfiguration config,
// Notice that health checks are registered under the admin application on /healthcheck
final ReaperHealthCheck healthCheck = new ReaperHealthCheck(context);
environment.healthChecks().register("reaper", healthCheck);
environment.jersey().register(healthCheck);

LOG.info("creating resources and registering endpoints");
final PingResource pingResource = new PingResource();
Expand Down Expand Up @@ -193,13 +192,8 @@ private IStorage initializeStorage(ReaperApplicationConfiguration config,
} else if ("database".equalsIgnoreCase(config.getStorageType())) {
// create DBI instance
DBI jdbi;
try {
final DBIFactory factory = new DBIFactory();
jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");
} catch (ClassNotFoundException ex) {
LOG.error("failed creating database connection: {}", ex);
throw new ReaperException(ex);
}
final DBIFactory factory = new DBIFactory();
jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");

// instanciate store
storage = new PostgresStorage(jdbi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.spotify.reaper.resources.CommonTools;

import org.apache.cassandra.repair.RepairParallelism;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.format.ISODateTimeFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected Set<String> initialize() {
synchronized (condition) {
commandId = coordinator.triggerRepair(segment.getStartToken(), segment.getEndToken(),
keyspace, validationParallelism, repairUnit.getColumnFamilies(), fullRepair);

if (commandId == 0) {
// From cassandra source in "forceRepairAsync":
//if (ranges.isEmpty() || Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor() < 2)
Expand Down
53 changes: 35 additions & 18 deletions src/test/java/com/spotify/reaper/SimpleReaperClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import com.spotify.reaper.resources.view.ClusterStatus;
import com.spotify.reaper.resources.view.RepairRunStatus;
import com.spotify.reaper.resources.view.RepairScheduleStatus;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

import org.glassfish.jersey.client.ClientResponse;
import org.glassfish.jersey.client.JerseyClient;
import org.glassfish.jersey.client.JerseyClientBuilder;
import org.glassfish.jersey.client.JerseyWebTarget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -19,6 +20,14 @@
import java.util.List;
import java.util.Map;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;

/**
Expand All @@ -31,7 +40,7 @@ public class SimpleReaperClient {

private static Optional<Map<String, String>> EMPTY_PARAMS = Optional.absent();

public static ClientResponse doHttpCall(String httpMethod, String host, int port, String urlPath,
public static Response doHttpCall(String httpMethod, String host, int port, String urlPath,
Optional<Map<String, String>> params) {
String reaperBase = "http://" + host.toLowerCase() + ":" + port + "/";
URI uri;
Expand All @@ -40,29 +49,37 @@ public static ClientResponse doHttpCall(String httpMethod, String host, int port
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Client client = new Client();
WebResource resource = client.resource(uri);
LOG.info("calling (" + httpMethod + ") Reaper in resource: " + resource.getURI());

Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(uri);


LOG.info("calling (" + httpMethod + ") Reaper in resource: " + webTarget.getUri());
if (params.isPresent()) {
for (Map.Entry<String, String> entry : params.get().entrySet()) {
resource = resource.queryParam(entry.getKey(), entry.getValue());
webTarget = webTarget.queryParam(entry.getKey(), entry.getValue());
}
}
ClientResponse response;

Invocation.Builder invocationBuilder =
webTarget.request(MediaType.APPLICATION_JSON);

Response response;
if ("GET".equalsIgnoreCase(httpMethod)) {
response = resource.get(ClientResponse.class);
response = invocationBuilder.get();
} else if ("POST".equalsIgnoreCase(httpMethod)) {
response = resource.post(ClientResponse.class);
response = invocationBuilder.post(null);
} else if ("PUT".equalsIgnoreCase(httpMethod)) {
response = resource.put(ClientResponse.class);
response = invocationBuilder.put(Entity.entity("",MediaType.APPLICATION_JSON));
} else if ("DELETE".equalsIgnoreCase(httpMethod)) {
response = resource.delete(ClientResponse.class);
response = invocationBuilder.delete();
} else if ("OPTIONS".equalsIgnoreCase(httpMethod)) {
response = resource.options(ClientResponse.class);
response = invocationBuilder.options();
} else {
throw new RuntimeException("Invalid HTTP method: " + httpMethod);
}
return response;

return response;
}

private static <T> T parseJSON(String json, TypeReference<T> ref) {
Expand Down Expand Up @@ -116,11 +133,11 @@ public SimpleReaperClient(String reaperHost, int reaperPort) {
}

public List<RepairScheduleStatus> getRepairSchedulesForCluster(String clusterName) {
ClientResponse response = doHttpCall("GET", reaperHost, reaperPort,
Response response = doHttpCall("GET", reaperHost, reaperPort,
"/repair_schedule/cluster/" + clusterName, EMPTY_PARAMS);
assertEquals(200, response.getStatus());
String responseData = response.getEntity(String.class);
return parseRepairScheduleStatusListJSON(responseData);
String responseData = response.readEntity(String.class);
return parseRepairScheduleStatusListJSON(responseData);
}

}
Loading