From 0c572b5ae2feb8f9c344158fd373d1c4ff339e2b Mon Sep 17 00:00:00 2001 From: Alan Sheinberg Date: Mon, 7 Dec 2020 20:15:10 -0800 Subject: [PATCH] Lint --- .../io/confluent/ksql/engine/KsqlEngine.java | 4 +-- .../ksql/rest/server/KsqlRestApplication.java | 2 +- .../ksql/rest/server/LocalCommand.java | 15 +++++++++ .../ksql/rest/server/LocalCommands.java | 32 ++++++++++++------- .../ksql/rest/server/LocalCommandsFile.java | 21 ++++++++++-- 5 files changed, 57 insertions(+), 17 deletions(-) diff --git a/ksqldb-engine/src/main/java/io/confluent/ksql/engine/KsqlEngine.java b/ksqldb-engine/src/main/java/io/confluent/ksql/engine/KsqlEngine.java index c629149fd423..b77defb0394a 100644 --- a/ksqldb-engine/src/main/java/io/confluent/ksql/engine/KsqlEngine.java +++ b/ksqldb-engine/src/main/java/io/confluent/ksql/engine/KsqlEngine.java @@ -318,8 +318,8 @@ public void cleanupOrphanedInternalTopics( final ServiceContext serviceContext, final Set queryApplicationIds ) { - orphanedTransientQueryCleaner.cleanupOrphanedInternalTopics(serviceContext, - queryApplicationIds); + orphanedTransientQueryCleaner + .cleanupOrphanedInternalTopics(serviceContext, queryApplicationIds); } /** diff --git a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlRestApplication.java b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlRestApplication.java index 50b585fd4115..88a0f40a829b 100644 --- a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlRestApplication.java +++ b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlRestApplication.java @@ -1069,7 +1069,7 @@ private static Optional createLocalCommands( final KsqlEngine ksqlEngine ) { if (!restConfig.getString(KsqlRestConfig.KSQL_LOCAL_COMMANDS_LOCATION_CONFIG).isEmpty()) { - File file + final File file = new File(restConfig.getString(KsqlRestConfig.KSQL_LOCAL_COMMANDS_LOCATION_CONFIG)); return Optional.of(LocalCommands.open(ksqlEngine, file)); } diff --git a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommand.java b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommand.java index e5b2a9490607..d07f1a710036 100644 --- a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommand.java +++ b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommand.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 Confluent Inc. + * + * Licensed under the Confluent Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.confluent.io/confluent-community-license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package io.confluent.ksql.rest.server; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommands.java b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommands.java index 183219d32500..625dae255391 100644 --- a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommands.java +++ b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommands.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 Confluent Inc. + * + * Licensed under the Confluent Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.confluent.io/confluent-community-license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package io.confluent.ksql.rest.server; import io.confluent.ksql.engine.KsqlEngine; @@ -56,19 +71,16 @@ public void processLocalCommandFiles( final ServiceContext serviceContext ) { final FilenameFilter filter = (dir, fileName) -> fileName.endsWith(LOCAL_COMMANDS_FILE_SUFFIX); - File[] files = directory.listFiles(filter); + final File[] files = directory.listFiles(filter); if (files == null) { throw new KsqlServerException("Bad directory " + directory.getAbsolutePath()); } - if (files.length == 1) { - System.out.println("Too small"); - } - for (File file : files) { + for (final File file : files) { if (file.equals(currentLocalCommands.getFile())) { continue; } try (LocalCommandsFile localCommandsFile = LocalCommandsFile.createReadonly(file)) { - List localCommands = localCommandsFile.readRecords(); + final List localCommands = localCommandsFile.readRecords(); cleanUpTransientQueryState(localCommands, serviceContext); markFileAsProcessed(file); @@ -143,8 +155,8 @@ public static LocalCommands open( return new LocalCommands(directory, ksqlEngine, LocalCommandsFile.createWriteable(file)); } - private void markFileAsProcessed(File file) { - File updatedName = new File(file.getParentFile(), + private void markFileAsProcessed(final File file) { + final File updatedName = new File(file.getParentFile(), file.getName() + LOCAL_COMMANDS_PROCESSED_SUFFIX); if (!file.renameTo(updatedName)) { throw new KsqlException("Couldn't rename file " + file.getAbsolutePath()); @@ -154,14 +166,12 @@ private void markFileAsProcessed(File file) { private void cleanUpTransientQueryState( final List localCommands, final ServiceContext serviceContext) { - Set queryApplicationIds = localCommands.stream() + final Set queryApplicationIds = localCommands.stream() .filter(c -> c.getType() == Type.TRANSIENT_QUERY) .map(LocalCommand::getQueryApplicationId) .collect(Collectors.toSet()); if (queryApplicationIds.size() > 0) { ksqlEngine.cleanupOrphanedInternalTopics(serviceContext, queryApplicationIds); - } else { - System.out.println("queryApplicationIds is " + queryApplicationIds); } } diff --git a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommandsFile.java b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommandsFile.java index 8edd9f73e601..307983b30aed 100644 --- a/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommandsFile.java +++ b/ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/LocalCommandsFile.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 Confluent Inc. + * + * Licensed under the Confluent Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.confluent.io/confluent-community-license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package io.confluent.ksql.rest.server; import com.fasterxml.jackson.databind.ObjectMapper; @@ -17,7 +32,7 @@ /** * Represents a single file of commands issued to this node. */ -public class LocalCommandsFile implements Closeable { +public final class LocalCommandsFile implements Closeable { private static final ObjectMapper MAPPER = new ObjectMapper(); private static final byte[] NEW_LINE_SEPARATOR_BYTES = @@ -50,7 +65,7 @@ public void write(final LocalCommand localCommand) throws IOException { throw new IOException("Write permission denied."); } - byte[] bytes = MAPPER.writeValueAsBytes(localCommand); + final byte[] bytes = MAPPER.writeValueAsBytes(localCommand); writer.write(bytes); writer.write(NEW_LINE_SEPARATOR_BYTES); writer.flush(); @@ -59,7 +74,7 @@ public void write(final LocalCommand localCommand) throws IOException { public List readRecords() throws IOException { final List localCommands = new ArrayList<>(); for (final String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) { - LocalCommand localCommand = MAPPER.readValue(line, LocalCommand.class); + final LocalCommand localCommand = MAPPER.readValue(line, LocalCommand.class); localCommands.add(localCommand); } return localCommands;