Skip to content

Commit c972174

Browse files
committed
Merge pull request #62 from DarinJ/checkstyle
Added a reasonable maven checkstyle that should enforce nice code. I…
2 parents b7a8278 + 1b0df6b commit c972174

File tree

7 files changed

+253
-34
lines changed

7 files changed

+253
-34
lines changed

checkstyle.xml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
5+
<!--
6+
7+
Checkstyle configuration that checks a modified sun coding conventions from:
8+
9+
- the Java Language Specification at
10+
http://java.sun.com/docs/books/jls/second_edition/html/index.html
11+
12+
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
13+
14+
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
15+
16+
- some best practices
17+
18+
Checkstyle is very configurable. Be sure to read the documentation at
19+
http://checkstyle.sf.net (or in your downloaded distribution).
20+
21+
Most Checks are configurable, be sure to consult the documentation.
22+
23+
To completely disable a check, just comment it out or delete it from the file.
24+
25+
Finally, it is worth reading the documentation.
26+
27+
-->
28+
29+
<module name="Checker">
30+
<!--
31+
If you set the basedir property below, then all reported file
32+
names will be relative to the specified directory. See
33+
http://checkstyle.sourceforge.net/5.x/config.html#Checker
34+
35+
<property name="basedir" value="${basedir}"/>
36+
-->
37+
<!--Todo(DarinJ): Uncomment to have warnings instead of errors (Build Success, even if failed checkstyles) -->
38+
<!--<property name="severity" value="warning"/>-->
39+
40+
<!-- Checks whether files end with a new line. -->
41+
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
42+
<module name="NewlineAtEndOfFile"/>
43+
44+
<!-- Checks that property files contain the same keys. -->
45+
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
46+
<module name="Translation"/>
47+
48+
<module name="FileLength"/>
49+
50+
<!-- Following interprets the header file as regular expressions. -->
51+
<!-- <module name="RegexpHeader"/> -->
52+
53+
<module name="FileTabCharacter">
54+
<property name="eachLine" value="true"/>
55+
</module>
56+
57+
<module name="RegexpSingleline">
58+
<!-- \s matches whitespace character, $ matches end of line. -->
59+
<property name="format" value="\s+$"/>
60+
<property name="message" value="Line has trailing spaces."/>
61+
</module>
62+
63+
<module name="TreeWalker">
64+
65+
<property name="cacheFile" value="${checkstyle.cache.file}"/>
66+
67+
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
68+
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
69+
<module name="SuppressWarningsHolder"/>
70+
71+
<!-- Checks for Javadoc comments. -->
72+
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
73+
<!-- <module name="JavadocMethod"/>
74+
<module name="JavadocType"/>
75+
<module name="JavadocVariable"/>
76+
<module name="JavadocStyle"/> -->
77+
78+
79+
<!-- Checks for Naming Conventions. -->
80+
<!-- See http://checkstyle.sf.net/config_naming.html -->
81+
<module name="ConstantName"/>
82+
<module name="LocalFinalVariableName"/>
83+
<module name="LocalVariableName"/>
84+
<module name="MemberName"/>
85+
<module name="MethodName"/>
86+
<module name="PackageName"/>
87+
<module name="ParameterName"/>
88+
<module name="StaticVariableName"/>
89+
<module name="TypeName"/>
90+
91+
92+
<!-- Checks for Headers -->
93+
<!-- See http://checkstyle.sf.net/config_header.html -->
94+
<!-- <module name="Header"> -->
95+
<!-- The follow property value demonstrates the ability -->
96+
<!-- to have access to ANT properties. In this case it uses -->
97+
<!-- the ${basedir} property to allow Checkstyle to be run -->
98+
<!-- from any directory within a project. See property -->
99+
<!-- expansion, -->
100+
<!-- http://checkstyle.sf.net/config.html#properties -->
101+
<!-- <property -->
102+
<!-- name="headerFile" -->
103+
<!-- value="${basedir}/java.header"/> -->
104+
<!-- </module> -->
105+
106+
107+
<!-- Checks for imports -->
108+
<!-- See http://checkstyle.sf.net/config_import.html -->
109+
<!-- Todo(DarinJ): add back AvoidStarImport -->
110+
<!-- <module name="AvoidStarImport"/> -->
111+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
112+
<module name="RedundantImport"/>
113+
<module name="UnusedImports"/>
114+
115+
116+
<!-- Checks for Size Violations. -->
117+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
118+
<!-- Todo(DarinJ): add back LineLength -->
119+
<!-- <module name="LineLength"/> -->
120+
<!-- Todo(DarinJ): add back MethodLength -->
121+
<!-- <module name="MethodLength"/> -->
122+
<module name="ParameterNumber"/>
123+
124+
125+
<!-- Checks for whitespace -->
126+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
127+
<module name="EmptyForIteratorPad"/>
128+
<module name="MethodParamPad"/>
129+
<module name="NoWhitespaceAfter"/>
130+
<module name="NoWhitespaceBefore"/>
131+
<!-- <module name="OperatorWrap"/> -->
132+
<module name="ParenPad"/>
133+
<module name="TypecastParenPad"/>
134+
<module name="WhitespaceAfter"/>
135+
<module name="WhitespaceAround"/>
136+
137+
<!--Indentation based off google styleguide -->
138+
<module name="Indentation">
139+
<property name="basicOffset" value="2"/>
140+
<property name="braceAdjustment" value="0"/>
141+
<property name="caseIndent" value="2"/>
142+
<property name="throwsIndent" value="4"/>
143+
<property name="lineWrappingIndentation" value="4"/>
144+
<property name="arrayInitIndent" value="2"/>
145+
</module>
146+
147+
<!-- Modifier Checks -->
148+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
149+
<module name="ModifierOrder"/>
150+
<module name="RedundantModifier"/>
151+
152+
<!-- Checks for blocks. You know, those {}'s -->
153+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
154+
<module name="AvoidNestedBlocks"/>
155+
<module name="EmptyBlock"/>
156+
<module name="LeftCurly"/>
157+
<module name="NeedBraces"/>
158+
<module name="RightCurly"/>
159+
160+
<!-- Checks for common coding problems -->
161+
<!-- See http://checkstyle.sf.net/config_coding.html -->
162+
<!-- Todo(DarinJ): add back AvoidInlineConditional??? used well maybe leave? -->
163+
<!-- <module name="AvoidInlineConditionals"/> -->
164+
<module name="EmptyStatement"/>
165+
<module name="EqualsHashCode"/>
166+
<!-- <module name="HiddenField"/> -->
167+
<module name="IllegalInstantiation"/>
168+
<module name="InnerAssignment"/>
169+
<!-- Todo(DarinJ): add back MagicNumbe -->
170+
<!-- <module name="MagicNumber"/> -->
171+
<module name="MissingSwitchDefault"/>
172+
<module name="SimplifyBooleanExpression"/>
173+
<module name="SimplifyBooleanReturn"/>
174+
175+
<!-- Checks for class design -->
176+
<!-- See http://checkstyle.sf.net/config_design.html -->
177+
<!--<module name="DesignForExtension"/> -->
178+
<module name="FinalClass"/>
179+
<module name="HideUtilityClassConstructor"/>
180+
<module name="InterfaceIsType"/>
181+
<!-- <module name="VisibilityModifier"/> -->
182+
183+
<!-- Miscellaneous other checks. -->
184+
<!-- See http://checkstyle.sf.net/config_misc.html -->
185+
<module name="ArrayTypeStyle"/>
186+
<!--<module name="FinalParameters"/>-->
187+
<module name="TodoComment"/>
188+
<module name="UpperEll"/>
189+
190+
</module>
191+
192+
<!-- Support @SuppressWarnings (added in Checkstyle 5.7) -->
193+
<!-- see http://checkstyle.sourceforge.net/config.html#SuppressWarningsFilter -->
194+
<module name="SuppressWarningsFilter"/>
195+
196+
<!-- Checks properties file for a duplicated properties. -->
197+
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->
198+
<module name="UniqueProperties"/>
199+
200+
</module>

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@
161161
<configuration>
162162
</configuration>
163163
</plugin>
164+
<plugin>
165+
<groupId>org.apache.maven.plugins</groupId>
166+
<artifactId>maven-checkstyle-plugin</artifactId>
167+
<version>2.15</version>
168+
<executions>
169+
<execution>
170+
<id>validate</id>
171+
<phase>validate</phase>
172+
<configuration>
173+
<configLocation>checkstyle.xml</configLocation>
174+
<encoding>UTF-8</encoding>
175+
<consoleOutput>true</consoleOutput>
176+
<failsOnError>true</failsOnError>
177+
</configuration>
178+
<goals>
179+
<goal>check</goal>
180+
</goals>
181+
</execution>
182+
</executions>
183+
</plugin>
164184
</plugins>
165185
</build>
166186

src/main/java/org/apache/hadoop/mapred/MesosExecutor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.io.*;
1313

1414
import java.lang.reflect.Field;
15-
import java.lang.ReflectiveOperationException;
1615

1716
import java.util.concurrent.BlockingQueue;
1817
import java.util.concurrent.Executors;
@@ -192,7 +191,7 @@ private JobConf configure(final TaskInfo task) {
192191

193192
/**
194193
* This is a hack to overcome lack of accessibility of the launcher. Will solicit feedback from Hadoop list.
195-
*
194+
*
196195
* @param tracker tracker with launcher we want to kill
197196
* @param name name of the field containing the launcher
198197
* @throws NoSuchFieldException

src/main/java/org/apache/hadoop/mapred/MesosTracker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public void run() {
6969
// fail to mark some TaskTrackers as active even though they are.
7070
// Here we do a final check with the JobTracker to make sure this
7171
// TaskTracker is really not there before we kill it.
72-
final Collection<TaskTrackerStatus> taskTrackers =
73-
MesosTracker.this.scheduler.jobTracker.taskTrackers();
72+
final Collection<TaskTrackerStatus> taskTrackers = MesosTracker.this.scheduler.jobTracker.taskTrackers();
7473

7574
for (TaskTrackerStatus status : taskTrackers) {
7675
HttpHost host = new HttpHost(status.getHost(), status.getHttpPort());

src/main/java/org/apache/hadoop/mapred/ResourcePolicy.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> offers)
130130
continue;
131131
}
132132
while (begin <= end && ports.size() < 2) {
133-
int port = begin + (int)(Math.random() * ((end - begin) + 1));
133+
int port = begin + (int) (Math.random() * ((end - begin) + 1));
134134
ports.add(port);
135135
begin += 1;
136136
}
@@ -220,7 +220,7 @@ public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> offers)
220220

221221
String jvmOpts = scheduler.conf.get("mapred.mesos.executor.jvm.opts");
222222
if (jvmOpts == null) {
223-
jvmOpts = StringUtils.join(" ", defaultJvmOpts);
223+
jvmOpts = StringUtils.join(" ", defaultJvmOpts);
224224
}
225225

226226
// Set up the environment for running the TaskTracker.
@@ -232,8 +232,8 @@ public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> offers)
232232
.setValue(
233233
jvmOpts +
234234
" -Xmx" + tasktrackerJVMHeap + "m" +
235-
" -XX:NewSize=" + tasktrackerJVMHeap / 3 + "m -XX:MaxNewSize=" + (int)Math.floor
236-
(tasktrackerJVMHeap * 0.6) + "m"
235+
" -XX:NewSize=" + tasktrackerJVMHeap / 3 + "m -XX:MaxNewSize=" +
236+
(int) Math.floor(tasktrackerJVMHeap * 0.6) + "m"
237237
));
238238

239239
// Set java specific environment, appropriately.
@@ -277,7 +277,7 @@ public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> offers)
277277

278278
directory = new File(uri).getName().split("\\.")[0] + "*";
279279
} else if (!isUriSet) {
280-
LOG.info("mapred.mesos.executor.uri is not set, relying on configured 'mapred.mesos.executor.directory' for working Hadoop distribution");
280+
LOG.info("mapred.mesos.executor.uri is not set, relying on configured 'mapred.mesos.executor.directory' for working Hadoop distribution");
281281
}
282282

283283
String command = scheduler.conf.get("mapred.mesos.executor.command");
@@ -290,7 +290,7 @@ public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> offers)
290290
.setEnvironment(envBuilder)
291291
.setValue(String.format("cd %s && %s", directory, command));
292292
if (uri != null) {
293-
commandInfo.addUris(CommandInfo.URI.newBuilder().setValue(uri));
293+
commandInfo.addUris(CommandInfo.URI.newBuilder().setValue(uri));
294294
}
295295

296296
// Populate ContainerInfo if needed
@@ -518,8 +518,8 @@ public void computeNeededSlots(List<JobInProgress> jobsInProgress,
518518
" Needed Reduce Slots: " + neededReduceSlots,
519519
" Unhealthy Trackers: " + unhealthyTrackers)));
520520

521-
File stateFile = scheduler.stateFile;
522-
if (stateFile != null) {
521+
File stateFile = scheduler.stateFile;
522+
if (stateFile != null) {
523523
// Update state file
524524
synchronized (this) {
525525
Set<String> hosts = new HashSet<>();
@@ -546,7 +546,7 @@ public void computeNeededSlots(List<JobInProgress> jobsInProgress,
546546
"")));
547547
fstream.close();
548548
if (!tmp.renameTo(stateFile)) {
549-
LOG.error("Can't overwrite state " + stateFile.getAbsolutePath());
549+
LOG.error("Can't overwrite state " + stateFile.getAbsolutePath());
550550
}
551551
} catch (Exception e) {
552552
LOG.error("Can't write state file: " + e.getMessage());

src/main/java/org/apache/mesos/hadoop/Metrics.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626
public class Metrics {
2727
public MetricRegistry registry;
2828
public Meter killMeter, flakyTrackerKilledMeter, launchTimeout, periodicGC;
29-
public Map<Integer, Meter> jobStateMeter =
30-
new ConcurrentHashMap<Integer, Meter>();
31-
public Map<TaskState, Meter> taskStateMeter =
32-
new ConcurrentHashMap<TaskState, Meter>();
29+
public Map<Integer, Meter> jobStateMeter = new ConcurrentHashMap<Integer, Meter>();
30+
public Map<TaskState, Meter> taskStateMeter = new ConcurrentHashMap<TaskState, Meter>();
3331
public com.codahale.metrics.Timer jobTimer, trackerTimer;
34-
public Map<JobID, com.codahale.metrics.Timer.Context> jobTimerContexts =
35-
new ConcurrentHashMap<JobID, com.codahale.metrics.Timer.Context>();
32+
public Map<JobID, com.codahale.metrics.Timer.Context> jobTimerContexts = new ConcurrentHashMap<JobID, com.codahale.metrics.Timer.Context>();
3633

3734
public Metrics(Configuration conf) {
3835
registry = new MetricRegistry();
@@ -62,10 +59,10 @@ public Metrics(Configuration conf) {
6259
final int interval = conf.getInt("mapred.mesos.metrics.csv.interval", 60);
6360

6461
CsvReporter csvReporter = CsvReporter.forRegistry(registry)
65-
.convertRatesTo(TimeUnit.SECONDS)
66-
.convertDurationsTo(TimeUnit.MILLISECONDS)
67-
.filter(MetricFilter.ALL)
68-
.build(new File(path));
62+
.convertRatesTo(TimeUnit.SECONDS)
63+
.convertDurationsTo(TimeUnit.MILLISECONDS)
64+
.filter(MetricFilter.ALL)
65+
.build(new File(path));
6966
csvReporter.start(interval, TimeUnit.SECONDS);
7067
}
7168

@@ -78,11 +75,11 @@ public Metrics(Configuration conf) {
7875

7976
Graphite graphite = new Graphite(new InetSocketAddress(host, port));
8077
GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(registry)
81-
.prefixedWith(prefix)
82-
.convertRatesTo(TimeUnit.SECONDS)
83-
.convertDurationsTo(TimeUnit.MILLISECONDS)
84-
.filter(MetricFilter.ALL)
85-
.build(graphite);
78+
.prefixedWith(prefix)
79+
.convertRatesTo(TimeUnit.SECONDS)
80+
.convertDurationsTo(TimeUnit.MILLISECONDS)
81+
.filter(MetricFilter.ALL)
82+
.build(graphite);
8683
graphiteReporter.start(interval, TimeUnit.SECONDS);
8784
}
8885

@@ -106,11 +103,11 @@ public Metrics(Configuration conf) {
106103
consistency);
107104

108105
CassandraReporter cassandraReporter = CassandraReporter.forRegistry(registry)
109-
.prefixedWith(prefix)
110-
.convertRatesTo(TimeUnit.SECONDS)
111-
.convertDurationsTo(TimeUnit.MILLISECONDS)
112-
.filter(MetricFilter.ALL)
113-
.build(cassandra);
106+
.prefixedWith(prefix)
107+
.convertRatesTo(TimeUnit.SECONDS)
108+
.convertDurationsTo(TimeUnit.MILLISECONDS)
109+
.filter(MetricFilter.ALL)
110+
.build(cassandra);
114111
cassandraReporter.start(interval, TimeUnit.SECONDS);
115112
}
116113
}

0 commit comments

Comments
 (0)