Skip to content

Commit 386892c

Browse files
authored
Use dropwizard 1.0 (#66)
* Upgrade to Dropwizard 1.0 Escape from dependency hell * Remove health check registered as a resource in jersey * Upgrade to Dropwizard 1.1 * Use version number 0.5.1
1 parent e1eea2d commit 386892c

File tree

12 files changed

+184
-167
lines changed

12 files changed

+184
-167
lines changed

pom.xml

+54-24
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<dropwizard.version>0.7.1</dropwizard.version>
14+
<dropwizard.version>1.1.0</dropwizard.version>
1515
<dropwizard.cassandra.version>4.0.0</dropwizard.cassandra.version>
1616
<cassandra.version>2.2.7</cassandra.version>
1717
<cucumber.version>1.1.5</cucumber.version>
@@ -22,7 +22,27 @@
2222
<dependency>
2323
<groupId>com.google.guava</groupId>
2424
<artifactId>guava</artifactId>
25-
<version>16.0.1</version>
25+
<version>19.0</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>ch.qos.logback</groupId>
29+
<artifactId>logback-core</artifactId>
30+
<version>1.2.2</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>ch.qos.logback</groupId>
34+
<artifactId>logback-access</artifactId>
35+
<version>1.2.2</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>ch.qos.logback</groupId>
39+
<artifactId>logback-classic</artifactId>
40+
<version>1.2.2</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>javax.mail</groupId>
44+
<artifactId>javax.mail-api</artifactId>
45+
<version>1.5.6</version>
2646
</dependency>
2747
<dependency>
2848
<groupId>io.dropwizard</groupId>
@@ -37,7 +57,12 @@
3757
<dependency>
3858
<groupId>io.dropwizard</groupId>
3959
<artifactId>dropwizard-assets</artifactId>
40-
<version>${dropwizard.version}</version>
60+
<version>1.0.0</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>systems.composable</groupId>
64+
<artifactId>dropwizard-cassandra</artifactId>
65+
<version>${dropwizard.cassandra.version}</version>
4166
</dependency>
4267
<dependency>
4368
<groupId>org.apache.cassandra</groupId>
@@ -52,46 +77,35 @@
5277
<groupId>org.codehaus.jackson</groupId>
5378
<artifactId>*</artifactId>
5479
</exclusion>
80+
<exclusion>
81+
<groupId>com.google.guava</groupId>
82+
<artifactId>guava</artifactId>
83+
</exclusion>
5584
</exclusions>
5685
</dependency>
5786
<dependency>
5887
<groupId>org.postgresql</groupId>
5988
<artifactId>postgresql</artifactId>
6089
<version>9.3-1100-jdbc41</version>
6190
</dependency>
62-
<dependency>
63-
<groupId>systems.composable</groupId>
64-
<artifactId>dropwizard-cassandra</artifactId>
65-
<version>${dropwizard.cassandra.version}</version>
66-
</dependency>
6791
<dependency>
6892
<groupId>com.h2database</groupId>
6993
<artifactId>h2</artifactId>
7094
<version>1.4.186</version>
7195
</dependency>
7296
<dependency>
73-
<groupId>org.cognitor.cassandra</groupId>
74-
<artifactId>cassandra-migration</artifactId>
75-
<version>2.0.0</version>
97+
<groupId>org.cognitor.cassandra</groupId>
98+
<artifactId>cassandra-migration</artifactId>
99+
<version>2.0.0</version>
76100
</dependency>
77101
<dependency>
78102
<groupId>org.flywaydb</groupId>
79103
<artifactId>flyway-core</artifactId>
80104
<version>4.0.3</version>
81105
</dependency>
82-
<dependency>
83-
<groupId>com.fasterxml.jackson.datatype</groupId>
84-
<artifactId>jackson-datatype-jsr310</artifactId>
85-
<version>2.6.1</version>
86-
</dependency>
87-
<dependency>
88-
<groupId>com.fasterxml.jackson.core</groupId>
89-
<artifactId>jackson-annotations</artifactId>
90-
<version>2.6.1</version>
91-
</dependency>
92106

93107
<!--test scope -->
94-
108+
95109
<dependency>
96110
<groupId>junit</groupId>
97111
<artifactId>junit</artifactId>
@@ -103,11 +117,21 @@
103117
<artifactId>dropwizard-testing</artifactId>
104118
<version>${dropwizard.version}</version>
105119
<scope>test</scope>
120+
<exclusions>
121+
<exclusion>
122+
<groupId>org.mockito</groupId>
123+
<artifactId>mockito-core</artifactId>
124+
</exclusion>
125+
<exclusion>
126+
<groupId>org.mockito</groupId>
127+
<artifactId>mockito-all</artifactId>
128+
</exclusion>
129+
</exclusions>
106130
</dependency>
107131
<dependency>
108132
<groupId>org.mockito</groupId>
109133
<artifactId>mockito-all</artifactId>
110-
<version>1.9.5</version>
134+
<version>1.10.19</version>
111135
<scope>test</scope>
112136
</dependency>
113137
<dependency>
@@ -127,7 +151,13 @@
127151
<artifactId>awaitility</artifactId>
128152
<version>2.0.0</version>
129153
<scope>test</scope>
130-
</dependency>
154+
</dependency>
155+
<dependency>
156+
<groupId>org.easytesting</groupId>
157+
<artifactId>fest-assert-core</artifactId>
158+
<version>2.0M10</version>
159+
<scope>test</scope>
160+
</dependency>
131161
</dependencies>
132162

133163
<profiles>

src/main/java/com/spotify/reaper/ReaperApplication.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ public void run(ReaperApplicationConfiguration config,
156156
// Notice that health checks are registered under the admin application on /healthcheck
157157
final ReaperHealthCheck healthCheck = new ReaperHealthCheck(context);
158158
environment.healthChecks().register("reaper", healthCheck);
159-
environment.jersey().register(healthCheck);
160159

161160
LOG.info("creating resources and registering endpoints");
162161
final PingResource pingResource = new PingResource();
@@ -193,13 +192,8 @@ private IStorage initializeStorage(ReaperApplicationConfiguration config,
193192
} else if ("database".equalsIgnoreCase(config.getStorageType())) {
194193
// create DBI instance
195194
DBI jdbi;
196-
try {
197-
final DBIFactory factory = new DBIFactory();
198-
jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");
199-
} catch (ClassNotFoundException ex) {
200-
LOG.error("failed creating database connection: {}", ex);
201-
throw new ReaperException(ex);
202-
}
195+
final DBIFactory factory = new DBIFactory();
196+
jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");
203197

204198
// instanciate store
205199
storage = new PostgresStorage(jdbi);

src/main/java/com/spotify/reaper/resources/view/RepairRunStatus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.spotify.reaper.resources.CommonTools;
2121

2222
import org.apache.cassandra.repair.RepairParallelism;
23-
import org.apache.commons.lang.time.DurationFormatUtils;
23+
import org.apache.commons.lang3.time.DurationFormatUtils;
2424
import org.joda.time.DateTime;
2525
import org.joda.time.Duration;
2626
import org.joda.time.format.ISODateTimeFormat;

src/main/java/com/spotify/reaper/service/SegmentRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected Set<String> initialize() {
184184
synchronized (condition) {
185185
commandId = coordinator.triggerRepair(segment.getStartToken(), segment.getEndToken(),
186186
keyspace, validationParallelism, repairUnit.getColumnFamilies(), fullRepair);
187-
187+
188188
if (commandId == 0) {
189189
// From cassandra source in "forceRepairAsync":
190190
//if (ranges.isEmpty() || Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor() < 2)

src/test/java/com/spotify/reaper/SimpleReaperClient.java

+35-18
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import com.spotify.reaper.resources.view.ClusterStatus;
88
import com.spotify.reaper.resources.view.RepairRunStatus;
99
import com.spotify.reaper.resources.view.RepairScheduleStatus;
10-
import com.sun.jersey.api.client.Client;
11-
import com.sun.jersey.api.client.ClientResponse;
12-
import com.sun.jersey.api.client.WebResource;
1310

11+
import org.glassfish.jersey.client.ClientResponse;
12+
import org.glassfish.jersey.client.JerseyClient;
13+
import org.glassfish.jersey.client.JerseyClientBuilder;
14+
import org.glassfish.jersey.client.JerseyWebTarget;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617

@@ -19,6 +20,14 @@
1920
import java.util.List;
2021
import java.util.Map;
2122

23+
import javax.ws.rs.client.Client;
24+
import javax.ws.rs.client.ClientBuilder;
25+
import javax.ws.rs.client.Entity;
26+
import javax.ws.rs.client.Invocation;
27+
import javax.ws.rs.client.WebTarget;
28+
import javax.ws.rs.core.MediaType;
29+
import javax.ws.rs.core.Response;
30+
2231
import static org.junit.Assert.assertEquals;
2332

2433
/**
@@ -31,7 +40,7 @@ public class SimpleReaperClient {
3140

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

34-
public static ClientResponse doHttpCall(String httpMethod, String host, int port, String urlPath,
43+
public static Response doHttpCall(String httpMethod, String host, int port, String urlPath,
3544
Optional<Map<String, String>> params) {
3645
String reaperBase = "http://" + host.toLowerCase() + ":" + port + "/";
3746
URI uri;
@@ -40,29 +49,37 @@ public static ClientResponse doHttpCall(String httpMethod, String host, int port
4049
} catch (Exception ex) {
4150
throw new RuntimeException(ex);
4251
}
43-
Client client = new Client();
44-
WebResource resource = client.resource(uri);
45-
LOG.info("calling (" + httpMethod + ") Reaper in resource: " + resource.getURI());
52+
53+
Client client = ClientBuilder.newClient();
54+
WebTarget webTarget = client.target(uri);
55+
56+
57+
LOG.info("calling (" + httpMethod + ") Reaper in resource: " + webTarget.getUri());
4658
if (params.isPresent()) {
4759
for (Map.Entry<String, String> entry : params.get().entrySet()) {
48-
resource = resource.queryParam(entry.getKey(), entry.getValue());
60+
webTarget = webTarget.queryParam(entry.getKey(), entry.getValue());
4961
}
5062
}
51-
ClientResponse response;
63+
64+
Invocation.Builder invocationBuilder =
65+
webTarget.request(MediaType.APPLICATION_JSON);
66+
67+
Response response;
5268
if ("GET".equalsIgnoreCase(httpMethod)) {
53-
response = resource.get(ClientResponse.class);
69+
response = invocationBuilder.get();
5470
} else if ("POST".equalsIgnoreCase(httpMethod)) {
55-
response = resource.post(ClientResponse.class);
71+
response = invocationBuilder.post(null);
5672
} else if ("PUT".equalsIgnoreCase(httpMethod)) {
57-
response = resource.put(ClientResponse.class);
73+
response = invocationBuilder.put(Entity.entity("",MediaType.APPLICATION_JSON));
5874
} else if ("DELETE".equalsIgnoreCase(httpMethod)) {
59-
response = resource.delete(ClientResponse.class);
75+
response = invocationBuilder.delete();
6076
} else if ("OPTIONS".equalsIgnoreCase(httpMethod)) {
61-
response = resource.options(ClientResponse.class);
77+
response = invocationBuilder.options();
6278
} else {
6379
throw new RuntimeException("Invalid HTTP method: " + httpMethod);
6480
}
65-
return response;
81+
82+
return response;
6683
}
6784

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

118135
public List<RepairScheduleStatus> getRepairSchedulesForCluster(String clusterName) {
119-
ClientResponse response = doHttpCall("GET", reaperHost, reaperPort,
136+
Response response = doHttpCall("GET", reaperHost, reaperPort,
120137
"/repair_schedule/cluster/" + clusterName, EMPTY_PARAMS);
121138
assertEquals(200, response.getStatus());
122-
String responseData = response.getEntity(String.class);
123-
return parseRepairScheduleStatusListJSON(responseData);
139+
String responseData = response.readEntity(String.class);
140+
return parseRepairScheduleStatusListJSON(responseData);
124141
}
125142

126143
}

0 commit comments

Comments
 (0)