Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Enforce ConfusingTernary and PrematureDeclaration rules
  • Loading branch information
williamhyun committed Aug 8, 2024
commit dab0e64e2fc9d39e9976e29503eb138b2231888f
2 changes: 0 additions & 2 deletions config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor" />
<exclude name="CommentDefaultAccessModifier" />
<exclude name="ConfusingTernary" />
<exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
<exclude name="FieldNamingConventions" />
<exclude name="GenericsNaming" />
Expand All @@ -37,7 +36,6 @@
<exclude name="LongVariable" />
<exclude name="MethodArgumentCouldBeFinal" />
<exclude name="OnlyOneReturn" />
<exclude name="PrematureDeclaration" />
<exclude name="ShortVariable" />
<exclude name="TooManyStaticImports" />
<exclude name="UseUnderscoresInNumericLiterals" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,23 @@ private long toSeconds(long startTimeInMilliseconds) {
private Histogram getHistogram(Class<?> kclass, String... names) {
String name = MetricRegistry.name(kclass.getSimpleName(), names).toLowerCase();
Histogram histogram;
if (!histograms.containsKey(name)) {
if (histograms.containsKey(name)) {
histogram = histograms.get(name);
} else {
histogram = metricRegistry.histogram(name);
histograms.put(name, histogram);
} else {
histogram = histograms.get(name);
}
return histogram;
}

private Counter getCounter(Class<?> klass, String... names) {
String name = MetricRegistry.name(klass.getSimpleName(), names).toLowerCase();
Counter counter;
if (!counters.containsKey(name)) {
if (counters.containsKey(name)) {
counter = counters.get(name);
} else {
counter = metricRegistry.counter(name);
counters.put(name, counter);
} else {
counter = counters.get(name);
}
return counter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ public class ProbeService {

public ProbeService(
List<Operator> operators, List<SentinelManager<?>> sentinelManagers, Executor executor) {
HealthProbe healthProbe = new HealthProbe(operators, sentinelManagers);
try {
this.server = HttpServer.create(new InetSocketAddress(OPERATOR_PROBE_PORT.getValue()), 0);
} catch (IOException e) {
throw new RuntimeException("Failed to create Probe Service Server", e);
}
server.createContext(READYZ, new ReadinessProbe(operators));
server.createContext(HEALTHZ, healthProbe);
server.createContext(HEALTHZ, new HealthProbe(operators, sentinelManagers));
server.setExecutor(executor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ protected List<AppReconcileStep> getReconcileSteps(final SparkApplication app) {
public DeleteControl cleanup(
SparkApplication sparkApplication, Context<SparkApplication> context) {
LoggingUtils.TrackedMDC trackedMDC = new LoggingUtils.TrackedMDC();
DeleteControl deleteControl = DeleteControl.defaultDelete();
try {
trackedMDC.set(sparkApplication);
log.info("Cleaning up resources for SparkApp.");
Expand All @@ -229,6 +228,6 @@ public DeleteControl cleanup(
trackedMDC.reset();
}
sparkAppStatusRecorder.removeCachedStatus(sparkApplication);
return deleteControl;
return DeleteControl.defaultDelete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public class AppDriverTimeoutObserver extends BaseAppDriverObserver {
@Override
public Optional<ApplicationState> observe(
Pod driver, ApplicationSpec spec, ApplicationStatus currentStatus) {
Instant lastTransitionTime =
Instant.parse(currentStatus.getCurrentState().getLastTransitionTime());
long timeoutThreshold;
Supplier<ApplicationState> supplier;
ApplicationTimeoutConfig timeoutConfig =
Expand All @@ -82,6 +80,8 @@ public Optional<ApplicationState> observe(
// No timeout check needed for other states
return Optional.empty();
}
Instant lastTransitionTime =
Instant.parse(currentStatus.getCurrentState().getLastTransitionTime());
if (timeoutThreshold > 0L
&& lastTransitionTime.plusMillis(timeoutThreshold).isBefore(Instant.now())) {
ApplicationState state = supplier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public ReconcileProgress reconcile(
}
}
}
if (!proposedStateSummary.equals(prevStateSummary)) {
if (proposedStateSummary.equals(prevStateSummary)) {
return observeDriver(
context, statusRecorder, Collections.singletonList(new AppDriverRunningObserver()));
} else {
statusRecorder.persistStatus(
context,
context
.getResource()
.getStatus()
.appendNewState(new ApplicationState(proposedStateSummary, stateMessage)));
return completeAndDefaultRequeue();
} else {
return observeDriver(
context, statusRecorder, Collections.singletonList(new AppDriverRunningObserver()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public static <T extends HasMetadata> Optional<T> getOrCreateSecondaryResource(
maxAttempts);
}
// retry only on 409 Conflict
if (e.getCode() != 409) {
throw e;
} else {
if (e.getCode() == 409) {
if (isConflictForExistingResource(e)) {
current = getResource(client, resource);
if (current.isPresent()) {
Expand All @@ -100,6 +98,8 @@ public static <T extends HasMetadata> Optional<T> getOrCreateSecondaryResource(
log.error("Max Retries exceeded while trying to create resource");
throw e;
}
} else {
throw e;
}
}
}
Expand Down Expand Up @@ -147,10 +147,10 @@ public static <T extends HasMetadata> void deleteResourceIfExists(
.delete();
}
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
if (e.getCode() == 404) {
log.info("Pod to delete does not exist, proceeding...");
} else {
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ private void patchAndStatusWithVersionLocked(CR resource, KubernetesClient clien
return;
}

STATUS prevStatus = objectMapper.convertValue(previousStatusNode, statusClass);

Exception err = null;
long maxRetry = API_STATUS_PATCH_MAX_ATTEMPTS.getValue();
for (long i = 0; i < maxRetry; i++) {
Expand All @@ -110,6 +108,7 @@ private void patchAndStatusWithVersionLocked(CR resource, KubernetesClient clien
}

statusCache.put(resourceId, newStatusNode);
STATUS prevStatus = objectMapper.convertValue(previousStatusNode, statusClass);
statusListeners.forEach(
listener -> {
listener.listenStatus(resource, prevStatus, resource.getStatus());
Expand Down