Skip to content

Commit 0772fde

Browse files
cmccaberajinisivaram
authored andcommitted
KAFKA-5776; Add the Trogdor fault injection daemon
Author: Colin P. Mccabe <cmccabe@confluent.io> Reviewers: Ismael Juma <ismael@juma.me.uk>, Rajini Sivaram <rajinisivaram@googlemail.com> Closes apache#3699 from cmccabe/trogdor-review
1 parent 607c3c2 commit 0772fde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4648
-7
lines changed

bin/trogdor.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
usage() {
18+
cat <<EOF
19+
The Trogdor fault injector.
20+
21+
Usage:
22+
$0 [action] [options]
23+
24+
Actions:
25+
agent: Run the trogdor agent.
26+
coordinator: Run the trogdor coordinator.
27+
client: Run the client which communicates with the trogdor coordinator.
28+
agent-client: Run the client which communicates with the trogdor agent.
29+
help: This help message.
30+
EOF
31+
}
32+
33+
if [[ $# -lt 1 ]]; then
34+
usage
35+
exit 0
36+
fi
37+
action="${1}"
38+
shift
39+
CLASS=""
40+
case ${action} in
41+
agent) CLASS="org.apache.kafka.trogdor.agent.Agent";;
42+
coordinator) CLASS="org.apache.kafka.trogdor.coordinator.Coordinator";;
43+
client) CLASS="org.apache.kafka.trogdor.coordinator.CoordinatorClient";;
44+
agent-client) CLASS="org.apache.kafka.trogdor.agent.AgentClient";;
45+
help) usage; exit 0;;
46+
*) echo "Unknown action '${action}'. Type '$0 help' for help."; exit 1;;
47+
esac
48+
49+
export INCLUDE_TEST_JARS=1
50+
exec $(dirname $0)/kafka-run-class.sh "${CLASS}" "$@"

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,15 @@ project(':tools') {
837837
compile libs.jacksonDatabind
838838
compile libs.slf4jlog4j
839839

840+
compile libs.jacksonJaxrsJsonProvider
841+
compile libs.jerseyContainerServlet
842+
compile libs.jettyServer
843+
compile libs.jettyServlet
844+
compile libs.jettyServlets
845+
840846
testCompile project(':clients')
841847
testCompile libs.junit
848+
testCompile project(':clients').sourceSets.test.output
842849
}
843850

844851
javadoc {

checkstyle/import-control.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@
177177
<allow pkg="org.apache.log4j" />
178178
</subpackage>
179179

180+
<subpackage name="trogdor">
181+
<allow pkg="com.fasterxml.jackson" />
182+
<allow pkg="javax.servlet" />
183+
<allow pkg="javax.ws.rs" />
184+
<allow pkg="net.sourceforge.argparse4j" />
185+
<allow pkg="org.apache.kafka.test"/>
186+
<allow pkg="org.apache.kafka.trogdor" />
187+
<allow pkg="org.apache.log4j" />
188+
<allow pkg="org.eclipse.jetty" />
189+
<allow pkg="org.glassfish.jersey" />
190+
</subpackage>
191+
180192
<subpackage name="streams">
181193
<allow pkg="org.apache.kafka.common"/>
182194
<allow pkg="org.apache.kafka.test"/>

checkstyle/suppressions.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
files="AbstractRequest.java"/>
5757

5858
<suppress checks="NPathComplexity"
59-
files="(BufferPool|MetricName|Node|ConfigDef|SslTransportLayer|MetadataResponse|KerberosLogin|SslTransportLayer|Sender|Serdes).java"/>
59+
files="(BufferPool|MetricName|Node|ConfigDef|SslTransportLayer|MetadataResponse|KerberosLogin|SslTransportLayer|Sender|Serdes|Agent).java"/>
6060

6161
<!-- clients tests -->
6262
<suppress checks="ClassDataAbstractionCoupling"
@@ -186,14 +186,14 @@
186186
files="VerifiableConsumer.java"/>
187187

188188
<suppress checks="CyclomaticComplexity"
189-
files="StreamsResetter.java"/>
190-
<suppress checks="CyclomaticComplexity"
191-
files="ProducerPerformance.java"/>
189+
files="(StreamsResetter|ProducerPerformance|Agent).java"/>
192190

193191
<suppress checks="NPathComplexity"
194-
files="StreamsResetter.java"/>
195-
<suppress checks="NPathComplexity"
196-
files="ProducerPerformance.java"/>
192+
files="(ProducerPerformance|StreamsResetter|Agent).java"/>
193+
<suppress checks="ImportControl"
194+
files="SignalLogger.java"/>
195+
<suppress checks="IllegalImport"
196+
files="SignalLogger.java"/>
197197

198198
<!-- Log4J-Appender -->
199199
<suppress checks="CyclomaticComplexity"

clients/src/main/java/org/apache/kafka/common/utils/Utils.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.io.InputStream;
3232
import java.io.PrintWriter;
3333
import java.io.StringWriter;
34+
import java.lang.reflect.Constructor;
35+
import java.lang.reflect.InvocationTargetException;
3436
import java.nio.ByteBuffer;
3537
import java.nio.MappedByteBuffer;
3638
import java.nio.channels.FileChannel;
@@ -306,6 +308,42 @@ public static <T> T newInstance(String klass, Class<T> base) throws ClassNotFoun
306308
return Utils.newInstance(Class.forName(klass, true, Utils.getContextOrKafkaClassLoader()).asSubclass(base));
307309
}
308310

311+
/**
312+
* Construct a new object using a class name and parameters.
313+
*
314+
* @param className The full name of the class to construct.
315+
* @param params A sequence of (type, object) elements.
316+
* @param <T> The type of object to construct.
317+
* @return The new object.
318+
* @throws ClassNotFoundException If there was a problem constructing the object.
319+
*/
320+
public static <T> T newParameterizedInstance(String className, Object... params)
321+
throws ClassNotFoundException {
322+
Class<?>[] argTypes = new Class<?>[params.length / 2];
323+
Object[] args = new Object[params.length / 2];
324+
try {
325+
Class c = Class.forName(className, true, Utils.getContextOrKafkaClassLoader());
326+
for (int i = 0; i < params.length / 2; i++) {
327+
argTypes[i] = (Class<?>) params[2 * i];
328+
args[i] = params[(2 * i) + 1];
329+
}
330+
Constructor<T> constructor = c.getConstructor(argTypes);
331+
return constructor.newInstance(args);
332+
} catch (NoSuchMethodException e) {
333+
throw new ClassNotFoundException(String.format("Failed to find " +
334+
"constructor with %s for %s", Utils.join(argTypes, ", "), className), e);
335+
} catch (InstantiationException e) {
336+
throw new ClassNotFoundException(String.format("Failed to instantiate " +
337+
"%s", className), e);
338+
} catch (IllegalAccessException e) {
339+
throw new ClassNotFoundException(String.format("Unable to access " +
340+
"constructor of %s", className), e);
341+
} catch (InvocationTargetException e) {
342+
throw new ClassNotFoundException(String.format("Unable to invoke " +
343+
"constructor of %s", className), e);
344+
}
345+
}
346+
309347
/**
310348
* Generates 32 bit murmur2 hash from byte array
311349
* @param data byte array to hash

0 commit comments

Comments
 (0)