You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2014/05/29 07:16:15 UTC
git commit: Enable more PMD rules.
Repository: incubator-aurora
Updated Branches:
refs/heads/master 2d5f0087f -> eb1155d49
Enable more PMD rules.
Reviewed at https://reviews.apache.org/r/21951/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/eb1155d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/eb1155d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/eb1155d4
Branch: refs/heads/master
Commit: eb1155d49f2544792518b50db96e8239d565493e
Parents: 2d5f008
Author: Bill Farner <wf...@apache.org>
Authored: Wed May 28 22:05:10 2014 -0700
Committer: Bill Farner <wf...@apache.org>
Committed: Wed May 28 22:05:10 2014 -0700
----------------------------------------------------------------------
build.gradle | 5 -
config/pmd/imports.xml | 167 +++++
config/pmd/naming.xml | 621 +++++++++++++++++++
.../aurora/scheduler/MesosSchedulerImpl.java | 36 +-
.../aurora/scheduler/async/Preemptor.java | 2 +-
.../aurora/scheduler/base/Conversions.java | 4 +-
.../aurora/scheduler/cron/CrontabEntry.java | 3 +-
.../aurora/scheduler/cron/quartz/Quartz.java | 2 +-
.../scheduler/filter/SchedulingFilterImpl.java | 10 +-
.../aurora/scheduler/http/Utilization.java | 3 +-
.../aurora/scheduler/log/mesos/MesosLog.java | 16 +-
.../aurora/scheduler/quota/QuotaInfo.java | 4 +-
.../aurora/scheduler/quota/QuotaManager.java | 2 +-
.../scheduler/state/StateManagerImpl.java | 2 +-
.../aurora/scheduler/stats/SlotSizeCounter.java | 3 +-
.../scheduler/storage/ReadWriteLockManager.java | 12 +-
.../scheduler/storage/backup/StorageBackup.java | 3 +-
.../storage/log/WriteAheadStorage.java | 28 +-
.../scheduler/storage/mem/MemTaskStore.java | 40 +-
.../thrift/SchedulerThriftInterface.java | 9 +-
.../scheduler/quota/QuotaManagerImplTest.java | 9 +-
.../thrift/SchedulerThriftInterfaceTest.java | 4 +-
22 files changed, 885 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index f105e9e..1e36bbd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -280,13 +280,8 @@ pmd {
ruleSets = [
'java-basic',
'java-braces',
- // TODO(wfarner): Circle back to (at least partially) re-enable the rules below.
- //'java-design',
'java-empty',
- //'java-imports',
'java-junit',
- //'java-logging-java',
- //'java-naming',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode']
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/config/pmd/imports.xml
----------------------------------------------------------------------
diff --git a/config/pmd/imports.xml b/config/pmd/imports.xml
new file mode 100644
index 0000000..40dc226
--- /dev/null
+++ b/config/pmd/imports.xml
@@ -0,0 +1,167 @@
+<?xml version="1.0"?>
+<!--
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this work except in compliance with the License.
+You may obtain a copy of the License in the LICENSE file, or at:
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<!--
+This is a modified file from the PMD project. Copying and editing ruleset
+configurations is the approach used to modify a ruleset behavior, such as
+disabling individul rules.
+-->
+
+<ruleset name="Import Statements"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
+
+ <description>
+These rules deal with different problems that can occur with import statements.
+ </description>
+
+ <rule name="DuplicateImports"
+ since="0.5"
+ message="Avoid duplicate imports such as ''{0}''"
+ class="net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#DuplicateImports">
+ <description>
+Duplicate or overlapping import statements should be avoided.
+ </description>
+ <priority>4</priority>
+ <example>
+<![CDATA[
+import java.lang.String;
+import java.lang.*;
+public class Foo {}
+]]>
+ </example>
+ </rule>
+
+ <rule name="DontImportJavaLang"
+ since="0.5"
+ message="Avoid importing anything from the package 'java.lang'"
+ class="net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#DontImportJavaLang">
+ <description>
+Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
+ </description>
+ <priority>4</priority>
+ <example>
+<![CDATA[
+import java.lang.String; // this is unnecessary
+
+public class Foo {}
+
+// --- in another source code file...
+
+import java.lang.*; // this is bad
+
+public class Foo {}
+]]>
+ </example>
+ </rule>
+
+ <rule name="UnusedImports"
+ since="1.0"
+ message="Avoid unused imports such as ''{0}''"
+ class="net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#UnusedImports">
+ <description>
+Avoid the use of unused import statements to prevent unwanted dependencies.
+ </description>
+ <priority>4</priority>
+ <example>
+<![CDATA[
+// this is bad
+import java.io.File;
+public class Foo {}
+]]>
+ </example>
+ </rule>
+
+ <rule name="ImportFromSamePackage"
+ since="1.02"
+ message="No need to import a type that lives in the same package"
+ class="net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#ImportFromSamePackage">
+ <description>
+There is no need to import a type that lives in the same package.
+ </description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+ package foo;
+
+ import foo.Buz; // no need for this
+ import foo.*; // or this
+
+ public class Bar{}
+ ]]>
+ </example>
+ </rule>
+
+<!--
+We frequently use static imports for enum fields (making other code more concise),
+but those trip this rule.
+ <rule name="TooManyStaticImports"
+ language="java"
+ since="4.1"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ message="Too many static imports may lead to messy code"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#TooManyStaticImports">
+ <description><![CDATA[
+If you overuse the static import feature, it can make your program unreadable and
+unmaintainable, polluting its namespace with all the static members you import.
+Readers of your code (including you, a few months after you wrote it) will not know
+which class a static member comes from (Sun 1.5 Language Guide).
+ ]]></description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximumStaticImports" type="Integer"
+ description="All static imports can be disallowed by setting this to 0" min="0" max="100" value="4"/>
+ <property name="xpath">
+ <value><![CDATA[
+.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
+ ]]></value>
+ </property>
+ </properties>
+ <example><![CDATA[
+import static Lennon;
+import static Ringo;
+import static George;
+import static Paul;
+import static Yoko; // Too much !
+ ]]></example>
+ </rule>
+-->
+
+ <rule name="UnnecessaryFullyQualifiedName"
+ language="java"
+ since="5.0"
+ class="net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule"
+ message="Unnecessary use of fully qualified name ''{0}'' due to existing import ''{1}''"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/imports.html#UnnecessaryFullyQualifiedName">
+ <description><![CDATA[
+Import statements allow the use of non-fully qualified names. The use of a fully qualified name
+which is covered by an import statement is redundant. Consider using the non-fully qualified name.
+ ]]></description>
+ <priority>4</priority>
+ <example><![CDATA[
+import java.util.List;
+
+public class Foo {
+ private java.util.List list1; // Unnecessary FQN
+ private List list2; // More appropriate given import of 'java.util.List'
+}
+ ]]></example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/config/pmd/naming.xml
----------------------------------------------------------------------
diff --git a/config/pmd/naming.xml b/config/pmd/naming.xml
new file mode 100644
index 0000000..233352d
--- /dev/null
+++ b/config/pmd/naming.xml
@@ -0,0 +1,621 @@
+<?xml version="1.0"?>
+<!--
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this work except in compliance with the License.
+You may obtain a copy of the License in the LICENSE file, or at:
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<!--
+This is a modified file from the PMD project. Copying and editing ruleset
+configurations is the approach used to modify a ruleset behavior, such as
+disabling individul rules.
+-->
+
+<ruleset name="Naming"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
+ <description>
+The Naming Ruleset contains rules regarding preferred usage of names and identifiers.
+ </description>
+
+<!--
+Requiring longer variable names can be cumbersome when applied globally.
+ <rule name="ShortVariable"
+ language="java"
+ since="0.3"
+ message="Avoid variables with short names like {0}"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#ShortVariable">
+ <description>
+Fields, local variables, or parameter names that are very short are not helpful to the reader.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//VariableDeclaratorId[string-length(@Image) < 3]
+ [not(ancestor::ForInit)]
+ [not(../../VariableDeclarator and ../../../LocalVariableDeclaration and ../../../../ForStatement)]
+ [not((ancestor::FormalParameter) and (ancestor::TryStatement))]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+<![CDATA[
+public class Something {
+ private int q = 15; // field - too short
+ public static void main( String as[] ) { // formal arg - too short
+ int r = 20 + q; // local var - too short
+ for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
+ r += q;
+ }
+ for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
+ r += q;
+ }
+ }
+}
+]]>
+ </example>
+ </rule>
+-->
+
+<!--
+Requiring shorter variable names can be cumbersome when applied globally.
+ <rule name="LongVariable"
+ language="java"
+ since="0.3"
+ message="Avoid excessively long variable names like {0}"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#LongVariable">
+ <description>
+Fields, formal arguments, or local variable names that are too long can make the code difficult to follow.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="minimum" type="Integer" description="The variable length reporting threshold" min="1" max="100" value="17"/>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//VariableDeclaratorId[string-length(@Image) > $minimum]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+<![CDATA[
+public class Something {
+ int reallyLongIntName = -3; // VIOLATION - Field
+ public static void main( String argumentsList[] ) { // VIOLATION - Formal
+ int otherReallyLongName = -5; // VIOLATION - Local
+ for (int interestingIntIndex = 0; // VIOLATION - For
+ interestingIntIndex < 10;
+ interestingIntIndex ++ ) {
+ }
+}
+]]>
+ </example>
+ </rule>
+-->
+
+<!--
+Short method names are useful on occasion, such as with factory methods: Rate.of(...).
+ <rule name="ShortMethodName"
+ language="java"
+ since="0.3"
+ message="Avoid using short method names"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#ShortMethodName">
+ <description>
+Method names that are very short are not helpful to the reader.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//MethodDeclarator[string-length(@Image) < 3]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+<![CDATA[
+public class ShortMethod {
+ public void a( int i ) { // Violation
+ }
+}
+]]>
+ </example>
+ </rule>
+-->
+
+ <rule name="VariableNamingConventions"
+ since="1.2"
+ message="{0} variable {1} should begin with {2}"
+ class="net.sourceforge.pmd.lang.java.rule.naming.VariableNamingConventionsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#VariableNamingConventions">
+ <description>
+A variable naming conventions rule - customize this to your liking. Currently, it
+checks for final variables that should be fully capitalized and non-final variables
+that should not include underscores.
+ </description>
+ <priority>1</priority>
+ <example>
+<![CDATA[
+public class Foo {
+ public static final int MY_NUM = 0;
+ public String myTest = "";
+ DataModule dmTest = new DataModule();
+}
+]]>
+ </example>
+ </rule>
+
+ <rule name="MethodNamingConventions"
+ since="1.2"
+ message="Method name does not begin with a lower case character."
+ class="net.sourceforge.pmd.lang.java.rule.naming.MethodNamingConventionsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#MethodNamingConventions">
+ <description>
+Method names should always begin with a lower case character, and should not contain underscores.
+ </description>
+ <priority>1</priority>
+ <example>
+<![CDATA[
+public class Foo {
+ public void fooStuff() {
+ }
+}
+]]>
+ </example>
+ </rule>
+
+ <rule name="ClassNamingConventions"
+ since="1.2"
+ message="Class names should begin with an uppercase character"
+ class="net.sourceforge.pmd.lang.java.rule.naming.ClassNamingConventionsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#ClassNamingConventions">
+ <description>
+Class names should always begin with an upper case character.
+ </description>
+ <priority>1</priority>
+ <example>
+<![CDATA[
+public class Foo {}
+]]>
+ </example>
+ </rule>
+
+<!--
+TODO(wfarner): Enable this if/when we have automatic transaction management, rather than the classes
+in org.apache.aurora.scheduler.storage.Storage (e.g. Work).
+ <rule name="AbstractNaming"
+ language="java"
+ since="1.4"
+ message="Abstract classes should be named 'AbstractXXX'"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#AbstractNaming">
+ <description>
+Abstract classes should be named 'AbstractXXX'.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//ClassOrInterfaceDeclaration
+ [@Abstract='true' and @Interface='false']
+ [not (starts-with(@Image,'Abstract'))]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+<![CDATA[
+public abstract class Foo { // should be AbstractFoo
+}
+]]>
+ </example>
+ </rule>
+-->
+
+ <rule name="AvoidDollarSigns"
+ since="1.5"
+ message="Avoid using dollar signs in variable/method/class/interface names"
+ class="net.sourceforge.pmd.lang.java.rule.naming.AvoidDollarSignsRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#AvoidDollarSigns">
+ <description>
+Avoid using dollar signs in variable/method/class/interface names.
+ </description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+public class Fo$o { // not a recommended name
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="MethodWithSameNameAsEnclosingClass"
+ since="1.5"
+ message="Classes should not have non-constructor methods with the same name as the class"
+ class="net.sourceforge.pmd.lang.java.rule.naming.MethodWithSameNameAsEnclosingClassRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#MethodWithSameNameAsEnclosingClass">
+ <description>
+Non-constructor methods should not have the same name as the enclosing class.
+ </description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+public class MyClass {
+
+ public MyClass() {} // this is OK because it is a constructor
+
+ public void MyClass() {} // this is bad because it is a method
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="SuspiciousHashcodeMethodName"
+ since="1.5"
+ message="The method name and return type are suspiciously close to hashCode()"
+ class="net.sourceforge.pmd.lang.java.rule.naming.SuspiciousHashcodeMethodNameRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#SuspiciousHashcodeMethodName">
+ <description>
+The method name and return type are suspiciously close to hashCode(), which may denote an intention
+to override the hashCode() method.
+ </description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+public class Foo {
+ public int hashcode() { // oops, this probably was supposed to be 'hashCode'
+
+ }
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="SuspiciousConstantFieldName"
+ language="java"
+ since="2.0"
+ message="The field name indicates a constant but its modifiers do not"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#SuspiciousConstantFieldName">
+ <description>
+Field names using all uppercase characters - Sun's Java naming conventions indicating constants - should
+be declared as final.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+<![CDATA[
+//ClassOrInterfaceDeclaration[@Interface='false']
+ /ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
+ [@Final='false']
+ [VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+public class Foo {
+ // this is bad, since someone could accidentally
+ // do PI = 2.71828; which is actually e
+ // final double PI = 3.16; is ok
+ double PI = 3.16;
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="SuspiciousEqualsMethodName"
+ language="java"
+ since="2.0"
+ message="The method name and parameter number are suspiciously close to equals(Object)"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#SuspiciousEqualsMethodName">
+ <description>
+The method name and parameter number are suspiciously close to equals(Object), which can denote an
+intention to override the equals(Object) method.
+ </description>
+ <priority>2</priority>
+ <properties>
+ <property name="xpath">
+ <value><![CDATA[
+//MethodDeclarator[@Image = 'equals']
+[
+ (count(FormalParameters/*) = 1
+ and not (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
+ [@Image = 'Object' or @Image = 'java.lang.Object'])
+ or not (../ResultType/Type/PrimitiveType[@Image = 'boolean'])
+ ) or (
+ count(FormalParameters/*) = 2
+ and ../ResultType/Type/PrimitiveType[@Image = 'boolean']
+ and FormalParameters//ClassOrInterfaceType[@Image = 'Object' or @Image = 'java.lang.Object']
+ )
+]
+| //MethodDeclarator[@Image = 'equal']
+[
+ count(FormalParameters/*) = 1
+ and FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
+ [@Image = 'Object' or @Image = 'java.lang.Object']
+]
+]]>
+ </value>
+ </property>
+ </properties>
+ <example><![CDATA[
+public class Foo {
+ public int equals(Object o) {
+ // oops, this probably was supposed to be boolean equals
+ }
+ public boolean equals(String s) {
+ // oops, this probably was supposed to be equals(Object)
+ }
+ public boolean equals(Object o1, Object o2) {
+ // oops, this probably was supposed to be equals(Object)
+ }
+}
+ ]]></example>
+ </rule>
+
+ <rule name="AvoidFieldNameMatchingTypeName"
+ since="3.0"
+ message="It is somewhat confusing to have a field name matching the declaring class name"
+ class="net.sourceforge.pmd.lang.java.rule.naming.AvoidFieldNameMatchingTypeNameRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#AvoidFieldNameMatchingTypeName">
+ <description>
+It is somewhat confusing to have a field name matching the declaring class name.
+This probably means that type and/or field names should be chosen more carefully.
+ </description>
+ <priority>3</priority>
+ <example>
+<![CDATA[
+public class Foo extends Bar {
+ int foo; // There is probably a better name that can be used
+}
+]]>
+ </example>
+ </rule>
+
+ <rule name="AvoidFieldNameMatchingMethodName"
+ since="3.0"
+ message="Field {0} has the same name as a method"
+ class="net.sourceforge.pmd.lang.java.rule.naming.AvoidFieldNameMatchingMethodNameRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#AvoidFieldNameMatchingMethodName">
+ <description>
+It can be confusing to have a field name with the same name as a method. While this is permitted,
+having information (field) and actions (method) is not clear naming. Developers versed in
+Smalltalk often prefer this approach as the methods denote accessor methods.
+ </description>
+ <priority>3</priority>
+ <example>
+<![CDATA[
+public class Foo {
+ Object bar;
+ // bar is data or an action or both?
+ void bar() {
+ }
+}
+]]>
+ </example>
+ </rule>
+
+
+
+ <rule name="NoPackage"
+ language="java"
+ since="3.3"
+ message="All classes and interfaces must belong to a named package"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#NoPackage">
+ <description>
+Detects when a class or interface does not have a package definition.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//ClassOrInterfaceDeclaration[count(preceding::PackageDeclaration) = 0]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+<![CDATA[
+// no package declaration
+public class ClassInDefaultPackage {
+}
+]]>
+ </example>
+ </rule>
+
+ <rule name="PackageCase"
+ language="java"
+ since="3.3"
+ message="Package name contains upper case characters"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#PackageCase">
+ <description>
+Detects when a package definition contains uppercase characters.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//PackageDeclaration/Name[lower-case(@Image)!=@Image]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+package com.MyCompany; // should be lowercase name
+
+public class SomeClass {
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="MisleadingVariableName"
+ language="java"
+ since="3.4"
+ message="Avoid naming non-fields with the prefix 'm_'"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#MisleadingVariableName">
+ <description>
+Detects when a non-field has a name starting with 'm_'. This usually denotes a field and could be confusing.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//VariableDeclaratorId
+[starts-with(@Image, 'm_')]
+[not (../../../FieldDeclaration)]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+public class Foo {
+ private int m_foo; // OK
+ public void bar(String m_baz) { // Bad
+ int m_boz = 42; // Bad
+ }
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule name="BooleanGetMethodName"
+ language="java"
+ since="4.0"
+ message="A 'getX()' method which returns a boolean should be named 'isX()'"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#BooleanGetMethodName">
+ <description>
+Methods that return boolean results should be named as predicate statements to denote this.
+I.e, 'isReady()', 'hasValues()', 'canCommit()', 'willFail()', etc. Avoid the use of the 'get'
+prefix for these methods.
+ </description>
+ <priority>4</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//MethodDeclaration[
+MethodDeclarator[count(FormalParameters/FormalParameter) = 0 or $checkParameterizedMethods = 'true']
+ [starts-with(@Image, 'get')]
+and
+ResultType/Type/PrimitiveType[@Image = 'boolean']
+]
+]]>
+ </value>
+ </property>
+ <property name="checkParameterizedMethods" type="Boolean" description="Check parameterized methods" value="false"/>
+ </properties>
+ <example>
+ <![CDATA[
+public boolean getFoo(); // bad
+public boolean isFoo(); // ok
+public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
+ ]]></example>
+ </rule>
+
+<!--
+There are rare, but valid, cases where short class names are useful.
+ <rule name="ShortClassName"
+ language="java"
+ since="5.0"
+ message="A Classname should have a minimum of five characters"
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#ShortClassName">
+ <description>
+ <![CDATA[
+Classnames with fewer than five characters are not recommended.
+ ]]>
+ </description>
+ <priority>4</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//ClassOrInterfaceDeclaration[string-length(@Image) < 5]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+public class Foo {
+}
+ ]]>
+ </example>
+ </rule>
+-->
+
+ <rule name="GenericsNaming"
+ language="java"
+ since="4.2.6"
+ message="Generics names should be a one letter long and upper case."
+ class="net.sourceforge.pmd.lang.rule.XPathRule"
+ externalInfoUrl="http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html#GenericsNaming">
+ <description>
+Names for references to generic values should be limited to a single uppercase letter.
+ </description>
+ <priority>4</priority>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+//TypeDeclaration/ClassOrInterfaceDeclaration/TypeParameters/TypeParameter[
+ string-length(@Image) > 1
+ or
+ string:upper-case(@Image) != @Image
+]
+]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+public interface GenericDao<E extends BaseModel, K extends Serializable> extends BaseDao {
+ // This is ok...
+}
+
+public interface GenericDao<E extends BaseModel, K extends Serializable> {
+ // Also this
+}
+
+public interface GenericDao<e extends BaseModel, K extends Serializable> {
+ // 'e' should be an 'E'
+}
+
+public interface GenericDao<EF extends BaseModel, K extends Serializable> {
+ // 'EF' is not ok.
+}
+ ]]></example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/MesosSchedulerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/MesosSchedulerImpl.java b/src/main/java/org/apache/aurora/scheduler/MesosSchedulerImpl.java
index 2b97198..0dce5c4 100644
--- a/src/main/java/org/apache/aurora/scheduler/MesosSchedulerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/MesosSchedulerImpl.java
@@ -58,13 +58,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
class MesosSchedulerImpl implements Scheduler {
private static final Logger LOG = Logger.getLogger(MesosSchedulerImpl.class.getName());
- private final AtomicLong resourceOffers = Stats.exportLong("scheduler_resource_offers");
- private final AtomicLong failedStatusUpdates = Stats.exportLong("scheduler_status_updates");
- private final AtomicLong frameworkDisconnects =
+ private final AtomicLong totalResourceOffers = Stats.exportLong("scheduler_resource_offers");
+ private final AtomicLong totalFailedStatusUpdates = Stats.exportLong("scheduler_status_updates");
+ private final AtomicLong totalFrameworkDisconnects =
Stats.exportLong("scheduler_framework_disconnects");
- private final AtomicLong frameworkReregisters =
+ private final AtomicLong totalFrameworkReregisters =
Stats.exportLong("scheduler_framework_reregisters");
- private final AtomicLong lostExecutors = Stats.exportLong("scheduler_lost_executors");
+ private final AtomicLong totalLostExecutors = Stats.exportLong("scheduler_lost_executors");
private final List<TaskLauncher> taskLaunchers;
@@ -72,7 +72,7 @@ class MesosSchedulerImpl implements Scheduler {
private final StateManager stateManager;
private final Lifecycle lifecycle;
private final EventSink eventSink;
- private volatile boolean registered = false;
+ private volatile boolean isRegistered = false;
/**
* Creates a new scheduler.
@@ -119,27 +119,27 @@ class MesosSchedulerImpl implements Scheduler {
storeProvider.getSchedulerStore().saveFrameworkId(frameworkId.getValue());
}
});
- registered = true;
+ isRegistered = true;
eventSink.post(new DriverRegistered());
}
@Override
public void disconnected(SchedulerDriver schedulerDriver) {
LOG.warning("Framework disconnected.");
- frameworkDisconnects.incrementAndGet();
+ totalFrameworkDisconnects.incrementAndGet();
eventSink.post(new DriverDisconnected());
}
@Override
public void reregistered(SchedulerDriver schedulerDriver, MasterInfo masterInfo) {
LOG.info("Framework re-registered with master " + masterInfo);
- frameworkReregisters.incrementAndGet();
+ totalFrameworkReregisters.incrementAndGet();
}
@Timed("scheduler_resource_offers")
@Override
public void resourceOffers(SchedulerDriver driver, final List<Offer> offers) {
- Preconditions.checkState(registered, "Must be registered before receiving offers.");
+ Preconditions.checkState(isRegistered, "Must be registered before receiving offers.");
// Store all host attributes in a single write operation to prevent other threads from
// securing the storage lock between saves. We also save the host attributes before passing
@@ -158,8 +158,10 @@ class MesosSchedulerImpl implements Scheduler {
});
for (Offer offer : offers) {
- log(Level.FINE, "Received offer: %s", offer);
- resourceOffers.incrementAndGet();
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.log(Level.FINE, String.format("Received offer: %s", offer));
+ }
+ totalResourceOffers.incrementAndGet();
for (TaskLauncher launcher : taskLaunchers) {
if (launcher.willUse(offer)) {
break;
@@ -203,7 +205,7 @@ class MesosSchedulerImpl implements Scheduler {
}
LOG.warning("Unhandled status update " + status);
- failedStatusUpdates.incrementAndGet();
+ totalFailedStatusUpdates.incrementAndGet();
}
@Override
@@ -217,7 +219,7 @@ class MesosSchedulerImpl implements Scheduler {
int status) {
LOG.info("Lost executor " + executorID);
- lostExecutors.incrementAndGet();
+ totalLostExecutors.incrementAndGet();
}
@Timed("scheduler_framework_message")
@@ -252,10 +254,4 @@ class MesosSchedulerImpl implements Scheduler {
LOG.log(Level.SEVERE, "Failed to decode framework message.", e);
}
}
-
- private static void log(Level level, String message, Object... args) {
- if (LOG.isLoggable(level)) {
- LOG.log(level, String.format(message, args));
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/async/Preemptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/async/Preemptor.java b/src/main/java/org/apache/aurora/scheduler/async/Preemptor.java
index d717ae1..f29ad7f 100644
--- a/src/main/java/org/apache/aurora/scheduler/async/Preemptor.java
+++ b/src/main/java/org/apache/aurora/scheduler/async/Preemptor.java
@@ -344,7 +344,7 @@ public interface Preemptor {
stateManager.changeState(
toPreempt.getTaskId(),
Optional.<ScheduleStatus>absent(),
- ScheduleStatus.PREEMPTING,
+ PREEMPTING,
Optional.of("Preempting in favor of " + pendingTask.getTaskId()));
tasksPreempted.incrementAndGet();
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/base/Conversions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/base/Conversions.java b/src/main/java/org/apache/aurora/scheduler/base/Conversions.java
index 3340a2a..02e57ac 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/Conversions.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/Conversions.java
@@ -79,8 +79,8 @@ public final class Conversions {
/**
* Typedef to make anonymous implementation more concise.
*/
- private abstract static class AttributeConverter
- implements Function<Entry<String, Collection<Protos.Attribute>>, Attribute> {
+ private interface AttributeConverter
+ extends Function<Entry<String, Collection<Protos.Attribute>>, Attribute> {
}
private static final Function<Protos.Attribute, String> VALUE_CONVERTER =
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/cron/CrontabEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/cron/CrontabEntry.java b/src/main/java/org/apache/aurora/scheduler/cron/CrontabEntry.java
index 6bfe5ca..6f01a69 100644
--- a/src/main/java/org/apache/aurora/scheduler/cron/CrontabEntry.java
+++ b/src/main/java/org/apache/aurora/scheduler/cron/CrontabEntry.java
@@ -14,6 +14,7 @@
package org.apache.aurora.scheduler.cron;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -369,7 +370,7 @@ public final class CrontabEntry {
}
private String replaceNameAliases(String rawComponent, Map<String, Integer> names) {
- String component = rawComponent.toUpperCase();
+ String component = rawComponent.toUpperCase(Locale.ENGLISH);
for (Map.Entry<String, Integer> entry : names.entrySet()) {
if (component.contains(entry.getKey())) {
component = component.replaceAll(entry.getKey(), entry.getValue().toString());
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/cron/quartz/Quartz.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/cron/quartz/Quartz.java b/src/main/java/org/apache/aurora/scheduler/cron/quartz/Quartz.java
index c60868e..25c81b9 100644
--- a/src/main/java/org/apache/aurora/scheduler/cron/quartz/Quartz.java
+++ b/src/main/java/org/apache/aurora/scheduler/cron/quartz/Quartz.java
@@ -89,7 +89,7 @@ final class Quartz {
/**
* Convert a Quartz JobKey to an Aurora IJobKey.
*/
- static IJobKey auroraJobKey(org.quartz.JobKey jobKey) {
+ static IJobKey auroraJobKey(JobKey jobKey) {
return JobKeys.parse(jobKey.getName());
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/filter/SchedulingFilterImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/filter/SchedulingFilterImpl.java b/src/main/java/org/apache/aurora/scheduler/filter/SchedulingFilterImpl.java
index 3a28a25..589cab3 100644
--- a/src/main/java/org/apache/aurora/scheduler/filter/SchedulingFilterImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/filter/SchedulingFilterImpl.java
@@ -89,7 +89,7 @@ public class SchedulingFilterImpl implements SchedulingFilter {
/**
* Convenience class for a rule that will only ever have a single veto.
*/
- private abstract static class SingleVetoRule implements FilterRule {
+ private abstract static class AbstractSingleVetoRule implements FilterRule {
@Override
public final Iterable<Veto> apply(ITaskConfig task) {
return doApply(task).asSet();
@@ -141,7 +141,7 @@ public class SchedulingFilterImpl implements SchedulingFilter {
private Iterable<FilterRule> rulesFromOffer(final ResourceSlot available) {
return ImmutableList.<FilterRule>of(
- new SingleVetoRule() {
+ new AbstractSingleVetoRule() {
@Override
public Optional<Veto> doApply(ITaskConfig task) {
return CPU.maybeVeto(
@@ -149,7 +149,7 @@ public class SchedulingFilterImpl implements SchedulingFilter {
ResourceSlot.from(task).getNumCpus());
}
},
- new SingleVetoRule() {
+ new AbstractSingleVetoRule() {
@Override
public Optional<Veto> doApply(ITaskConfig task) {
return RAM.maybeVeto(
@@ -157,14 +157,14 @@ public class SchedulingFilterImpl implements SchedulingFilter {
ResourceSlot.from(task).getRam().as(Data.MB));
}
},
- new SingleVetoRule() {
+ new AbstractSingleVetoRule() {
@Override
public Optional<Veto> doApply(ITaskConfig task) {
return DISK.maybeVeto(available.getDisk().as(Data.MB),
ResourceSlot.from(task).getDisk().as(Data.MB));
}
},
- new SingleVetoRule() {
+ new AbstractSingleVetoRule() {
@Override
public Optional<Veto> doApply(ITaskConfig task) {
return PORTS.maybeVeto(available.getNumPorts(),
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/Utilization.java b/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
index aed9823..06dc846 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
@@ -14,6 +14,7 @@
package org.apache.aurora.scheduler.http;
import java.io.StringWriter;
+import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
@@ -160,7 +161,7 @@ public class Utilization {
}
private MetricType getTypeByName(String name) throws WebApplicationException {
- MetricType type = MetricType.valueOf(name.toUpperCase());
+ MetricType type = MetricType.valueOf(name.toUpperCase(Locale.ENGLISH));
if (type == null) {
throw new WebApplicationException(
Response.status(Status.BAD_REQUEST).entity("Invalid metric type.").build());
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLog.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLog.java b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLog.java
index 045a370..b8a94ff 100644
--- a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLog.java
+++ b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLog.java
@@ -172,9 +172,9 @@ public class MesosLog implements org.apache.aurora.scheduler.log.Log {
}
};
- private final OpStats read = new OpStats("read");
- private final OpStats append = new OpStats("append");
- private final OpStats truncate = new OpStats("truncate");
+ private final OpStats readStats = new OpStats("read");
+ private final OpStats appendStats = new OpStats("append");
+ private final OpStats truncateStats = new OpStats("truncate");
private final AtomicLong entriesSkipped =
Stats.exportLong("scheduler_log_native_native_entries_skipped");
@@ -284,13 +284,13 @@ public class MesosLog implements org.apache.aurora.scheduler.log.Log {
return true;
}
} catch (TimeoutException e) {
- read.timeouts.getAndIncrement();
+ readStats.timeouts.getAndIncrement();
throw new StreamAccessException("Timeout reading from log.", e);
} catch (Log.OperationFailedException e) {
- read.failures.getAndIncrement();
+ readStats.failures.getAndIncrement();
throw new StreamAccessException("Problem reading from log", e);
} finally {
- read.timing.accumulate(System.nanoTime() - start);
+ readStats.timing.accumulate(System.nanoTime() - start);
}
}
return false;
@@ -313,7 +313,7 @@ public class MesosLog implements org.apache.aurora.scheduler.log.Log {
public LogPosition append(final byte[] contents) throws StreamAccessException {
checkNotNull(contents);
- Log.Position position = mutate(append, new Mutation<Log.Position>() {
+ Log.Position position = mutate(appendStats, new Mutation<Log.Position>() {
@Override
public Log.Position apply(WriterInterface logWriter)
throws TimeoutException, Log.WriterFailedException {
@@ -331,7 +331,7 @@ public class MesosLog implements org.apache.aurora.scheduler.log.Log {
Preconditions.checkArgument(position instanceof LogPosition);
final Log.Position before = ((LogPosition) position).unwrap();
- mutate(truncate, new Mutation<Void>() {
+ mutate(truncateStats, new Mutation<Void>() {
@Override
public Void apply(WriterInterface logWriter)
throws TimeoutException, Log.WriterFailedException {
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/quota/QuotaInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/quota/QuotaInfo.java b/src/main/java/org/apache/aurora/scheduler/quota/QuotaInfo.java
index 515fb24..d349c5f 100644
--- a/src/main/java/org/apache/aurora/scheduler/quota/QuotaInfo.java
+++ b/src/main/java/org/apache/aurora/scheduler/quota/QuotaInfo.java
@@ -49,7 +49,7 @@ public class QuotaInfo {
*
* @return Production job consumption.
*/
- public IResourceAggregate prodConsumption() {
+ public IResourceAggregate getProdConsumption() {
return prodConsumption;
}
@@ -58,7 +58,7 @@ public class QuotaInfo {
*
* @return Non production job consumption.
*/
- public IResourceAggregate nonProdConsumption() {
+ public IResourceAggregate getNonProdConsumption() {
return nonProdConsumption;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java b/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
index c03c6d1..7aedea5 100644
--- a/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
@@ -138,7 +138,7 @@ public interface QuotaManager {
return QuotaCheckResult.greaterOrEqual(
quotaInfo.guota(),
- add(quotaInfo.prodConsumption(), additionalRequested));
+ add(quotaInfo.getProdConsumption(), additionalRequested));
}
private static IResourceAggregate fromTasks(Iterable<ITaskConfig> tasks) {
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java b/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
index eb84110..7f27a1f 100644
--- a/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
@@ -203,7 +203,7 @@ public class StateManagerImpl implements StateManager {
Set<String> portNames,
Set<Integer> allocatedPorts) {
- Preconditions.checkNotNull(portNames);
+ checkNotNull(portNames);
// Expand ports.
Map<String, Integer> ports = Maps.newHashMap();
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/stats/SlotSizeCounter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/stats/SlotSizeCounter.java b/src/main/java/org/apache/aurora/scheduler/stats/SlotSizeCounter.java
index 822721c..af99957 100644
--- a/src/main/java/org/apache/aurora/scheduler/stats/SlotSizeCounter.java
+++ b/src/main/java/org/apache/aurora/scheduler/stats/SlotSizeCounter.java
@@ -19,7 +19,6 @@ import javax.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
@@ -60,7 +59,7 @@ class SlotSizeCounter implements Runnable {
private final boolean dedicated;
public MachineResource(IResourceAggregate size, boolean dedicated) {
- this.size = Preconditions.checkNotNull(size);
+ this.size = checkNotNull(size);
this.dedicated = dedicated;
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/storage/ReadWriteLockManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/ReadWriteLockManager.java b/src/main/java/org/apache/aurora/scheduler/storage/ReadWriteLockManager.java
index fa49e22..3725590 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/ReadWriteLockManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/ReadWriteLockManager.java
@@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* a read-locked thread to a write-locked thread, which would otherwise deadlock.
*/
public class ReadWriteLockManager {
- private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private final ReentrantReadWriteLock managedLock = new ReentrantReadWriteLock();
private enum LockMode {
NONE,
@@ -91,12 +91,12 @@ public class ReadWriteLockManager {
checkNotNull(type);
if (LockType.READ == type) {
- lock.readLock().lock();
+ managedLock.readLock().lock();
} else {
Preconditions.checkState(lockState.get().initialLockMode != LockMode.READ,
"A read operation may not be upgraded to a write operation.");
- lock.writeLock().lock();
+ managedLock.writeLock().lock();
}
return lockState.get().lockAcquired(type.getMode());
@@ -111,9 +111,9 @@ public class ReadWriteLockManager {
checkNotNull(type);
if (LockType.READ == type) {
- lock.readLock().unlock();
+ managedLock.readLock().unlock();
} else {
- lock.writeLock().unlock();
+ managedLock.writeLock().unlock();
}
lockState.get().lockReleased(type.getMode());
@@ -126,6 +126,6 @@ public class ReadWriteLockManager {
* @return The estimated number of threads waiting for this lock.
*/
public int getQueueLength() {
- return lock.getQueueLength();
+ return managedLock.getQueueLength();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/storage/backup/StorageBackup.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/backup/StorageBackup.java b/src/main/java/org/apache/aurora/scheduler/storage/backup/StorageBackup.java
index 10b596b..8bc0b8c 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/backup/StorageBackup.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/backup/StorageBackup.java
@@ -22,6 +22,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -122,7 +123,7 @@ public interface StorageBackup {
this.delegate = checkNotNull(delegate);
this.clock = checkNotNull(clock);
this.config = checkNotNull(config);
- backupDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
+ backupDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm", Locale.ENGLISH);
backupIntervalMs = config.interval.as(Time.MILLISECONDS);
lastBackupMs = clock.nowMillis();
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorage.java
index 2a338e9..796dca3 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorage.java
@@ -116,7 +116,7 @@ class WriteAheadStorage extends ForwardingStore implements
this.attributeStore = checkNotNull(attributeStore);
}
- private void log(Op op) {
+ private void write(Op op) {
Preconditions.checkState(
transactionManager.hasActiveTransaction(),
"Mutating operations must be within a transaction.");
@@ -128,7 +128,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void saveFrameworkId(final String frameworkId) {
checkNotNull(frameworkId);
- log(Op.saveFrameworkId(new SaveFrameworkId(frameworkId)));
+ write(Op.saveFrameworkId(new SaveFrameworkId(frameworkId)));
schedulerStore.saveFrameworkId(frameworkId);
}
@@ -140,7 +140,7 @@ class WriteAheadStorage extends ForwardingStore implements
boolean mutated = taskStore.unsafeModifyInPlace(taskId, taskConfiguration);
if (mutated) {
- log(Op.rewriteTask(new RewriteTask(taskId, taskConfiguration.newBuilder())));
+ write(Op.rewriteTask(new RewriteTask(taskId, taskConfiguration.newBuilder())));
}
return mutated;
}
@@ -150,7 +150,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void deleteTasks(final Set<String> taskIds) {
checkNotNull(taskIds);
- log(Op.removeTasks(new RemoveTasks(taskIds)));
+ write(Op.removeTasks(new RemoveTasks(taskIds)));
taskStore.deleteTasks(taskIds);
}
@@ -159,7 +159,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void saveTasks(final Set<IScheduledTask> newTasks) {
checkNotNull(newTasks);
- log(Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(newTasks))));
+ write(Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(newTasks))));
taskStore.saveTasks(newTasks);
}
@@ -181,7 +181,7 @@ class WriteAheadStorage extends ForwardingStore implements
}
// TODO(William Farner): Avoid writing an op when mutated is empty.
- log(Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(mutated))));
+ write(Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(mutated))));
return mutated;
}
@@ -191,7 +191,7 @@ class WriteAheadStorage extends ForwardingStore implements
checkNotNull(role);
checkNotNull(quota);
- log(Op.saveQuota(new SaveQuota(role, quota.newBuilder())));
+ write(Op.saveQuota(new SaveQuota(role, quota.newBuilder())));
quotaStore.saveQuota(role, quota);
}
@@ -209,7 +209,7 @@ class WriteAheadStorage extends ForwardingStore implements
attributeStore.saveHostAttributes(attrs);
Optional<HostAttributes> updated = getHostAttributes(attrs.getHost());
if (!saved.equals(updated)) {
- log(Op.saveHostAttributes(new SaveHostAttributes(updated.get())));
+ write(Op.saveHostAttributes(new SaveHostAttributes(updated.get())));
}
}
@@ -218,7 +218,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void removeJob(final IJobKey jobKey) {
checkNotNull(jobKey);
- log(Op.removeJob(new RemoveJob().setJobKey(jobKey.newBuilder())));
+ write(Op.removeJob(new RemoveJob().setJobKey(jobKey.newBuilder())));
jobStore.removeJob(jobKey);
}
@@ -228,7 +228,7 @@ class WriteAheadStorage extends ForwardingStore implements
checkNotNull(managerId);
checkNotNull(jobConfig);
- log(Op.saveAcceptedJob(new SaveAcceptedJob(managerId, jobConfig.newBuilder())));
+ write(Op.saveAcceptedJob(new SaveAcceptedJob(managerId, jobConfig.newBuilder())));
jobStore.saveAcceptedJob(managerId, jobConfig);
}
@@ -237,7 +237,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void removeQuota(final String role) {
checkNotNull(role);
- log(Op.removeQuota(new RemoveQuota(role)));
+ write(Op.removeQuota(new RemoveQuota(role)));
quotaStore.removeQuota(role);
}
@@ -246,7 +246,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void saveLock(final ILock lock) {
checkNotNull(lock);
- log(Op.saveLock(new SaveLock(lock.newBuilder())));
+ write(Op.saveLock(new SaveLock(lock.newBuilder())));
lockStore.saveLock(lock);
}
@@ -255,7 +255,7 @@ class WriteAheadStorage extends ForwardingStore implements
public void removeLock(final ILockKey lockKey) {
checkNotNull(lockKey);
- log(Op.removeLock(new RemoveLock(lockKey.newBuilder())));
+ write(Op.removeLock(new RemoveLock(lockKey.newBuilder())));
lockStore.removeLock(lockKey);
}
@@ -297,7 +297,7 @@ class WriteAheadStorage extends ForwardingStore implements
Optional<HostAttributes> saved = getHostAttributes(host);
if (saved.isPresent()) {
HostAttributes attributes = saved.get().setMode(mode);
- log(Op.saveHostAttributes(new SaveHostAttributes(attributes)));
+ write(Op.saveHostAttributes(new SaveHostAttributes(attributes)));
attributeStore.saveHostAttributes(attributes);
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
index e2b70c3..3d3dcb1 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
@@ -171,9 +171,11 @@ class MemTaskStore implements TaskStore.Mutable {
Task removed = tasks.remove(id);
if (removed != null) {
for (SecondaryIndex<?> index : secondaryIndices) {
- index.remove(removed.task);
+ index.remove(removed.storedTask);
}
- configInterner.removeAssociation(removed.task.getAssignedTask().getTask().newBuilder(), id);
+ configInterner.removeAssociation(
+ removed.storedTask.getAssignedTask().getTask().newBuilder(),
+ id);
}
}
}
@@ -189,14 +191,14 @@ class MemTaskStore implements TaskStore.Mutable {
ImmutableSet.Builder<IScheduledTask> mutated = ImmutableSet.builder();
for (Task original : matches(query).toList()) {
- IScheduledTask maybeMutated = mutator.apply(original.task);
- if (!original.task.equals(maybeMutated)) {
+ IScheduledTask maybeMutated = mutator.apply(original.storedTask);
+ if (!original.storedTask.equals(maybeMutated)) {
Preconditions.checkState(
- Tasks.id(original.task).equals(Tasks.id(maybeMutated)),
+ Tasks.id(original.storedTask).equals(Tasks.id(maybeMutated)),
"A task's ID may not be mutated.");
tasks.put(Tasks.id(maybeMutated), toTask.apply(maybeMutated));
for (SecondaryIndex<?> index : secondaryIndices) {
- index.replace(original.task, maybeMutated);
+ index.replace(original.storedTask, maybeMutated);
}
mutated.add(maybeMutated);
@@ -216,7 +218,7 @@ class MemTaskStore implements TaskStore.Mutable {
if (stored == null) {
return false;
} else {
- ScheduledTask updated = stored.task.newBuilder();
+ ScheduledTask updated = stored.storedTask.newBuilder();
updated.getAssignedTask().setTask(taskConfiguration.newBuilder());
tasks.put(taskId, toTask.apply(IScheduledTask.build(updated)));
return true;
@@ -227,7 +229,7 @@ class MemTaskStore implements TaskStore.Mutable {
return new Predicate<Task>() {
@Override
public boolean apply(Task canonicalTask) {
- IScheduledTask task = canonicalTask.task;
+ IScheduledTask task = canonicalTask.storedTask;
ITaskConfig config = task.getAssignedTask().getTask();
if (query.getOwner() != null) {
if (!StringUtils.isBlank(query.getOwner().getRole())
@@ -311,7 +313,7 @@ class MemTaskStore implements TaskStore.Mutable {
new Function<Task, IScheduledTask>() {
@Override
public IScheduledTask apply(Task task) {
- return task.task;
+ return task.storedTask;
}
};
@@ -319,16 +321,18 @@ class MemTaskStore implements TaskStore.Mutable {
Functions.compose(Tasks.SCHEDULED_TO_ID, TO_SCHEDULED);
private static class Task {
- private final IScheduledTask task;
+ private final IScheduledTask storedTask;
- Task(IScheduledTask task, Interner<TaskConfig, String> interner) {
- interner.removeAssociation(task.getAssignedTask().getTask().newBuilder(), Tasks.id(task));
+ Task(IScheduledTask storedTask, Interner<TaskConfig, String> interner) {
+ interner.removeAssociation(
+ storedTask.getAssignedTask().getTask().newBuilder(),
+ Tasks.id(storedTask));
TaskConfig canonical = interner.addAssociation(
- task.getAssignedTask().getTask().newBuilder(),
- Tasks.id(task));
- ScheduledTask builder = task.newBuilder();
+ storedTask.getAssignedTask().getTask().newBuilder(),
+ Tasks.id(storedTask));
+ ScheduledTask builder = storedTask.newBuilder();
builder.getAssignedTask().setTask(canonical);
- this.task = IScheduledTask.build(builder);
+ this.storedTask = IScheduledTask.build(builder);
}
@Override
@@ -338,12 +342,12 @@ class MemTaskStore implements TaskStore.Mutable {
}
Task other = (Task) o;
- return task.equals(other.task);
+ return storedTask.equals(other.storedTask);
}
@Override
public int hashCode() {
- return task.hashCode();
+ return storedTask.hashCode();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
index 9b7f6c3..d9c3a1e 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -41,7 +41,6 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
-import com.twitter.common.base.MorePreconditions;
import org.apache.aurora.auth.CapabilityValidator;
import org.apache.aurora.auth.CapabilityValidator.AuditCheck;
@@ -621,7 +620,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
SessionKey session) {
IJobKey jobKey = JobKeys.assertValid(IJobKey.build(mutableJobKey));
- MorePreconditions.checkNotBlank(shardIds);
+ checkNotBlank(shardIds);
checkNotNull(session);
Response response = Util.emptyResponse();
@@ -653,8 +652,8 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
QuotaInfo quotaInfo = quotaManager.getQuotaInfo(ownerRole);
GetQuotaResult result = new GetQuotaResult(quotaInfo.guota().newBuilder())
- .setProdConsumption(quotaInfo.prodConsumption().newBuilder())
- .setNonProdConsumption(quotaInfo.nonProdConsumption().newBuilder());
+ .setProdConsumption(quotaInfo.getProdConsumption().newBuilder())
+ .setNonProdConsumption(quotaInfo.getNonProdConsumption().newBuilder());
return okResponse(Result.getQuotaResult(result));
}
@@ -943,7 +942,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
ConfigRewrite command,
MutableStoreProvider storeProvider) {
- Optional<String> error = Optional.absent();
+ Optional<String> error;
switch (command.getSetField()) {
case JOB_REWRITE:
error = rewriteJob(command.getJobRewrite(), storeProvider.getJobStore());
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java
index 67d911e..a0ef57e 100644
--- a/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java
@@ -73,9 +73,10 @@ public class QuotaManagerImplTest extends EasyMockTest {
QuotaInfo quotaInfo = quotaManager.getQuotaInfo(ROLE);
assertEquals(quota, quotaInfo.guota());
assertEquals(
- IResourceAggregate.build(new ResourceAggregate(3, 3, 3)), quotaInfo.prodConsumption());
+ IResourceAggregate.build(new ResourceAggregate(3, 3, 3)), quotaInfo.getProdConsumption());
assertEquals(
- IResourceAggregate.build(new ResourceAggregate(2, 2, 2)), quotaInfo.nonProdConsumption());
+ IResourceAggregate.build(new ResourceAggregate(2, 2, 2)),
+ quotaInfo.getNonProdConsumption());
}
@Test
@@ -90,8 +91,8 @@ public class QuotaManagerImplTest extends EasyMockTest {
QuotaInfo quotaInfo = quotaManager.getQuotaInfo(ROLE);
assertEquals(quota, quotaInfo.guota());
- assertEquals(ResourceAggregates.none(), quotaInfo.prodConsumption());
- assertEquals(ResourceAggregates.none(), quotaInfo.nonProdConsumption());
+ assertEquals(ResourceAggregates.none(), quotaInfo.getProdConsumption());
+ assertEquals(ResourceAggregates.none(), quotaInfo.getNonProdConsumption());
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/eb1155d4/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index 16ece20..2996796 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -1518,9 +1518,9 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
QuotaInfo infoMock = createMock(QuotaInfo.class);
expect(quotaManager.getQuotaInfo(ROLE)).andReturn(infoMock);
expect(infoMock.guota()).andReturn(QUOTA);
- expect(infoMock.prodConsumption()).andReturn(CONSUMED);
+ expect(infoMock.getProdConsumption()).andReturn(CONSUMED);
IResourceAggregate nonProdConsumed = IResourceAggregate.build(new ResourceAggregate(1, 0, 0));
- expect(infoMock.nonProdConsumption()).andReturn(nonProdConsumed);
+ expect(infoMock.getNonProdConsumption()).andReturn(nonProdConsumed);
control.replay();
Response response = assertOkResponse(thrift.getQuota(ROLE));