This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-kubernetes-operator.git
The following commit(s) were added to refs/heads/main by this push:
new cef5ca4 [SPARK-49156] Enforce ImmutableField and UselessParentheses
rules
cef5ca4 is described below
commit cef5ca4978dd9ac923377dceee32a44af11f54a7
Author: William Hyun <[email protected]>
AuthorDate: Wed Aug 7 23:46:01 2024 -0700
[SPARK-49156] Enforce ImmutableField and UselessParentheses rules
### What changes were proposed in this pull request?
This PR aims to enforce ImmutableField and UselessParentheses rules.
### Why are the changes needed?
To ensure future code quality.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #37 from williamhyun/immutable.
Authored-by: William Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
config/pmd/ruleset.xml | 2 --
.../apache/spark/k8s/operator/status/ApplicationStatus.java | 8 ++++----
.../k8s/operator/metrics/healthcheck/SentinelManager.java | 2 +-
.../operator/reconciler/reconcilesteps/AppRunningStep.java | 2 +-
.../org/apache/spark/k8s/operator/utils/StatusRecorder.java | 2 +-
.../org/apache/spark/k8s/operator/probe/HealthProbeTest.java | 4 ++--
.../k8s/operator/reconciler/SparkAppReconcilerTest.java | 12 ++++++------
7 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/config/pmd/ruleset.xml b/config/pmd/ruleset.xml
index d96f059..515783e 100644
--- a/config/pmd/ruleset.xml
+++ b/config/pmd/ruleset.xml
@@ -41,7 +41,6 @@
<exclude name="ShortVariable" />
<exclude name="TooManyStaticImports" />
<exclude name="UseUnderscoresInNumericLiterals" />
- <exclude name="UselessParentheses" />
</rule>
<rule ref="category/java/design.xml">
<exclude name="AbstractClassWithoutAnyMethod" />
@@ -51,7 +50,6 @@
<exclude name="CognitiveComplexity" />
<exclude name="CyclomaticComplexity" />
<exclude name="ExcessiveImports" />
- <exclude name="ImmutableField" />
<exclude name="LawOfDemeter" />
<exclude name="NPathComplexity" />
<exclude name="SignatureDeclareThrowsException" />
diff --git
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
index a3059a6..ae7ea89 100644
---
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
+++
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
@@ -95,8 +95,8 @@ public class ApplicationStatus
ApplicationState state =
new ApplicationState(ApplicationStateSummary.ResourceReleased,
stateMessageOverride);
if (ResourceRetainPolicy.Always.equals(resourceRetainPolicy)
- || (ResourceRetainPolicy.OnFailure.equals(resourceRetainPolicy)
- && currentState.currentStateSummary.isFailure())) {
+ || ResourceRetainPolicy.OnFailure.equals(resourceRetainPolicy)
+ && currentState.currentStateSummary.isFailure()) {
state = terminateAppWithoutReleaseResource(stateMessageOverride);
}
return new ApplicationStatus(
@@ -116,8 +116,8 @@ public class ApplicationStatus
ApplicationState state =
new ApplicationState(ApplicationStateSummary.ResourceReleased,
stateMessage);
if (ResourceRetainPolicy.Always.equals(resourceRetainPolicy)
- || (ResourceRetainPolicy.OnFailure.equals(resourceRetainPolicy)
- && currentState.currentStateSummary.isFailure())) {
+ || ResourceRetainPolicy.OnFailure.equals(resourceRetainPolicy)
+ && currentState.currentStateSummary.isFailure()) {
state = terminateAppWithoutReleaseResource(stateMessage);
}
// still use previous & current attempt summary - they are to be updated
only upon
diff --git
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/healthcheck/SentinelManager.java
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/healthcheck/SentinelManager.java
index 108af26..0525555 100644
---
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/healthcheck/SentinelManager.java
+++
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/healthcheck/SentinelManager.java
@@ -72,7 +72,7 @@ public class SentinelManager<CR extends BaseResource<?, ?, ?,
?, ?>> {
}
private static boolean shouldSentinelWatchGivenNamespace(String namespace) {
- if ((!Utils.getWatchedNamespaces().isEmpty())
+ if (!Utils.getWatchedNamespaces().isEmpty()
&& !Utils.getWatchedNamespaces().contains(namespace)) {
if (log.isErrorEnabled()) {
log.error("Skip watching sentinel resource in namespace {}",
namespace);
diff --git
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppRunningStep.java
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppRunningStep.java
index 02db781..0c529a9 100644
---
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppRunningStep.java
+++
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppRunningStep.java
@@ -49,7 +49,7 @@ public class AppRunningStep extends AppReconcileStep {
String stateMessage =
context.getResource().getStatus().getCurrentState().getMessage();
if (instanceConfig == null
|| instanceConfig.getInitExecutors() == 0L
- || (!prevStateSummary.isStarting() && instanceConfig.getMinExecutors()
== 0L)) {
+ || !prevStateSummary.isStarting() && instanceConfig.getMinExecutors()
== 0L) {
proposedStateSummary = ApplicationStateSummary.RunningHealthy;
stateMessage = Constants.RUNNING_HEALTHY_MESSAGE;
} else {
diff --git
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/StatusRecorder.java
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/StatusRecorder.java
index 997d709..42c07c1 100644
---
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/StatusRecorder.java
+++
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/StatusRecorder.java
@@ -99,7 +99,7 @@ public class StatusRecorder<
resource.getMetadata().setResourceVersion(updated.getMetadata().getResourceVersion());
err = null;
} catch (KubernetesClientException e) {
- log.error("Error while patching status, retrying {}/{}...", (i + 1),
maxRetry, e);
+ log.error("Error while patching status, retrying {}/{}...", i + 1,
maxRetry, e);
Thread.sleep(TimeUnit.SECONDS.toMillis(API_RETRY_ATTEMPT_AFTER_SECONDS.getValue()));
err = e;
}
diff --git
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/HealthProbeTest.java
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/HealthProbeTest.java
index 18f04ec..a8b4587 100644
---
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/HealthProbeTest.java
+++
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/HealthProbeTest.java
@@ -57,9 +57,9 @@ class HealthProbeTest {
private KubernetesClient kubernetesClient;
private AtomicBoolean isRunning;
private AtomicBoolean isRunning2;
- private Map<String, Map<String, InformerWrappingEventSourceHealthIndicator>>
+ private final Map<String, Map<String,
InformerWrappingEventSourceHealthIndicator>>
unhealthyEventSources = new HashMap<>();
- private Map<String, Map<String, InformerWrappingEventSourceHealthIndicator>>
+ private final Map<String, Map<String,
InformerWrappingEventSourceHealthIndicator>>
unhealthyEventSources2 = new HashMap<>();
@BeforeAll
diff --git
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/SparkAppReconcilerTest.java
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/SparkAppReconcilerTest.java
index 2b2ca1e..dedf067 100644
---
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/SparkAppReconcilerTest.java
+++
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/SparkAppReconcilerTest.java
@@ -53,12 +53,12 @@ import org.apache.spark.k8s.operator.utils.ReconcilerUtils;
import org.apache.spark.k8s.operator.utils.SparkAppStatusRecorder;
class SparkAppReconcilerTest {
- private SparkAppStatusRecorder mockRecorder =
mock(SparkAppStatusRecorder.class);
- private SentinelManager<SparkApplication> mockSentinelManager =
mock(SentinelManager.class);
- private KubernetesClient mockClient = mock(KubernetesClient.class);
- private Context<SparkApplication> mockContext = mock(Context.class);
- private Pod mockDriver = mock(Pod.class);
- private SparkAppSubmissionWorker mockWorker =
mock(SparkAppSubmissionWorker.class);
+ private final SparkAppStatusRecorder mockRecorder =
mock(SparkAppStatusRecorder.class);
+ private final SentinelManager<SparkApplication> mockSentinelManager =
mock(SentinelManager.class);
+ private final KubernetesClient mockClient = mock(KubernetesClient.class);
+ private final Context<SparkApplication> mockContext = mock(Context.class);
+ private final Pod mockDriver = mock(Pod.class);
+ private final SparkAppSubmissionWorker mockWorker =
mock(SparkAppSubmissionWorker.class);
SparkApplication app = new SparkApplication();
SparkAppReconciler reconciler =
new SparkAppReconciler(mockWorker, mockRecorder, mockSentinelManager);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]