This is an automated email from the ASF dual-hosted git repository.
wangchao316 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new a41439e2ab6 Fix Some Code Smells of Node Commons Module (#11604)
a41439e2ab6 is described below
commit a41439e2ab6491158a721e0741ac5c48ddb88919
Author: Bo Cui <[email protected]>
AuthorDate: Fri Nov 24 09:44:47 2023 +0800
Fix Some Code Smells of Node Commons Module (#11604)
Fix Some Code Smells of Node Commons Module (#11604)
---
.../iotdb/commons/auth/authorizer/BasicAuthorizer.java | 6 +++---
.../org/apache/iotdb/commons/client/ClientManager.java | 7 +++----
.../java/org/apache/iotdb/commons/utils/FileUtils.java | 16 ++++++++--------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/authorizer/BasicAuthorizer.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/authorizer/BasicAuthorizer.java
index 9650b4fd0a7..cfb58e808e3 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/authorizer/BasicAuthorizer.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/authorizer/BasicAuthorizer.java
@@ -338,7 +338,7 @@ public abstract class BasicAuthorizer implements
IAuthorizer, IService {
try {
userWaterMarkStatus.put(user, isUserUseWaterMark(user));
} catch (AuthException e) {
- LOGGER.error(String.format(NO_SUCH_USER_EXCEPTION, user));
+ LOGGER.error("No such user: {}", user);
}
}
return userWaterMarkStatus;
@@ -352,7 +352,7 @@ public abstract class BasicAuthorizer implements
IAuthorizer, IService {
try {
allUsers.put(userName, getUser(userName));
} catch (AuthException e) {
- LOGGER.error(String.format("get all users failed, No such user : %s",
userName));
+ LOGGER.error("get all users failed, No such user: {}", userName);
}
}
return allUsers;
@@ -366,7 +366,7 @@ public abstract class BasicAuthorizer implements
IAuthorizer, IService {
try {
allRoles.put(roleName, getRole(roleName));
} catch (AuthException e) {
- LOGGER.error(String.format("get all roles failed, No such role : %s",
roleName));
+ LOGGER.error("get all roles failed, No such role: {}", roleName);
}
}
return allRoles;
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManager.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManager.java
index 3ee338d4ec7..c41f6dbe5e9 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManager.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManager.java
@@ -31,7 +31,7 @@ import java.util.Optional;
public class ClientManager<K, V> implements IClientManager<K, V> {
- private static final Logger logger =
LoggerFactory.getLogger(ClientManager.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ClientManager.class);
private final KeyedObjectPool<K, V> pool;
@@ -69,8 +69,7 @@ public class ClientManager<K, V> implements IClientManager<K,
V> {
try {
pool.returnObject(node, client);
} catch (Exception e) {
- logger.warn(
- String.format("Return client %s for node %s to pool
failed.", client, node), e);
+ LOGGER.warn("Return client {} for node {} to pool failed.",
client, node, e);
}
});
}
@@ -83,7 +82,7 @@ public class ClientManager<K, V> implements IClientManager<K,
V> {
try {
pool.clear(node);
} catch (Exception e) {
- logger.warn(String.format("Clear all client in pool for node
%s failed.", node), e);
+ LOGGER.warn("Clear all client in pool for node {} failed.",
node, e);
}
});
}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
index 2058e523f09..584fba2ab5f 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
@@ -36,7 +36,7 @@ import java.util.Arrays;
import java.util.Objects;
public class FileUtils {
- private static final Logger logger =
LoggerFactory.getLogger(FileUtils.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(FileUtils.class);
private static final int BUFFER_SIZE = 1024;
@@ -47,7 +47,7 @@ public class FileUtils {
Files.deleteIfExists(file.toPath());
return true;
} catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
return false;
}
}
@@ -61,9 +61,9 @@ public class FileUtils {
try {
Files.delete(folder.toPath());
} catch (NoSuchFileException | DirectoryNotEmptyException e) {
- logger.warn("{}: {}", e.getMessage(), Arrays.toString(folder.list()), e);
+ LOGGER.warn("{}: {}", e.getMessage(), Arrays.toString(folder.list()), e);
} catch (Exception e) {
- logger.warn("{}: {}", e.getMessage(), folder.getName(), e);
+ LOGGER.warn("{}: {}", e.getMessage(), folder.getName(), e);
}
}
@@ -73,27 +73,27 @@ public class FileUtils {
if (parentFolder.isDirectory()
&& Objects.requireNonNull(parentFolder.listFiles()).length == 0) {
if (!parentFolder.delete()) {
- logger.warn("Delete folder failed: {}",
parentFolder.getAbsolutePath());
+ LOGGER.warn("Delete folder failed: {}",
parentFolder.getAbsolutePath());
}
}
}
public static boolean copyDir(File sourceDir, File targetDir) throws
IOException {
if (!sourceDir.exists() || !sourceDir.isDirectory()) {
- logger.error(
+ LOGGER.error(
"Failed to copy folder, because source folder [{}] doesn't exist.",
sourceDir.getAbsolutePath());
return false;
}
if (!targetDir.exists()) {
if (!targetDir.mkdirs()) {
- logger.error(
+ LOGGER.error(
"Failed to copy folder, because failed to create target
folder[{}].",
targetDir.getAbsolutePath());
return false;
}
} else if (!targetDir.isDirectory()) {
- logger.error(
+ LOGGER.error(
"Failed to copy folder, because target folder [{}] already exist.",
targetDir.getAbsolutePath());
return false;