Skip to content

Commit

Permalink
feat: sonar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
taoran1250 committed Oct 29, 2024
1 parent 0975197 commit a0660d8
Show file tree
Hide file tree
Showing 35 changed files with 350 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public static void checkStatus() {
LOG.info("CurrentUser: " + curUsr);
if (curUsr == null) {
LOG.info("CurrentUser is null");
throw new Exception("CurrentUser is null");
} else {
LOG.info("CurrentUser is not null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public class UJESClientFactory {

private static UJESClient client;

public static synchronized UJESClient getReusable(VarAccess stdVarAccess) {
if (client == null) {
client = getNew(stdVarAccess);
public static UJESClient getReusable(VarAccess stdVarAccess) {
if (client == null) { // NOSONAR
synchronized (UJESClientFactory.class) {
if (client == null) {
client = getNew(stdVarAccess);
}
}
}
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,24 @@ public static ExecutorService newFixedThreadPool(
return Executors.newFixedThreadPool(threadNum, threadFactory(threadName, isDaemon));
}

public static synchronized ThreadPoolExecutor getCachedThreadPoolExecutor() {
if (cachedThreadPool == null) {
cachedThreadPool = newCachedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
public static ThreadPoolExecutor getCachedThreadPoolExecutor() {
if (cachedThreadPool == null) { // NOSONAR
synchronized (SchedulerManager.class) {
if (cachedThreadPool == null) {
cachedThreadPool = newCachedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
}
}
return cachedThreadPool;
}

public static synchronized ExecutorService getFixedThreadPool() {
if (fixedThreadPool == null) {
fixedThreadPool = newFixedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
public static ExecutorService getFixedThreadPool() {
if (fixedThreadPool == null) { // NOSONAR
synchronized (SchedulerManager.class) {
if (fixedThreadPool == null) {
fixedThreadPool = newFixedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
}
}
return fixedThreadPool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Message taskinfo(
int runningNumber = 0;
int queuedNumber = 0;

if (undoneTasks.length > 0) {
if (null != undoneTasks) {
for (EntranceJob task : undoneTasks) {
if (task.isRunning()) {
runningNumber++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public void uploadToECHome(MultipartFile mfile) {
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.close();
in.close();
} catch (Exception e) {
log.info("file {} upload fail", mfile.getOriginalFilename());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@ public static void register(Class<? extends LabelBuilderFactory> clazz) {
LabelBuilderFactoryContext.clazz = clazz;
}

public static synchronized LabelBuilderFactory getLabelBuilderFactory() {
public static LabelBuilderFactory getLabelBuilderFactory() {
if (labelBuilderFactory == null) {
String className = LabelCommonConfig.LABEL_FACTORY_CLASS.acquireNew();
if (clazz == StdLabelBuilderFactory.class && StringUtils.isNotBlank(className)) {
try {
clazz = (Class<? extends LabelBuilderFactory>) ClassUtils.getClass(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("find class + " + className + " failed!", e);
synchronized (LabelBuilderFactoryContext.class) { // NOSONAR
if (labelBuilderFactory == null) {
String className = LabelCommonConfig.LABEL_FACTORY_CLASS.acquireNew();
if (clazz == StdLabelBuilderFactory.class && StringUtils.isNotBlank(className)) {
try {
clazz = (Class<? extends LabelBuilderFactory>) ClassUtils.getClass(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("find class + " + className + " failed!", e);
}
}
try {
labelBuilderFactory = clazz.newInstance();
labelBuilderInitRegister(labelBuilderFactory);
} catch (Throwable e) {
throw new RuntimeException("initial class + " + className + " failed!", e);
}
}
}
try {
labelBuilderFactory = clazz.newInstance();
labelBuilderInitRegister(labelBuilderFactory);
} catch (Throwable e) {
throw new RuntimeException("initial class + " + className + " failed!", e);
}
}
return labelBuilderFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,60 @@ public class EngineTypeLabelCreator {
init();
}

private static synchronized void init() {
if (null == defaultVersion) {
defaultVersion = new HashMap<>(16);
defaultVersion.put(
EngineType.SPARK().toString(), LabelCommonConfig.SPARK_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.HIVE().toString(), LabelCommonConfig.HIVE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PYTHON().toString(), LabelCommonConfig.PYTHON_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.REPL().toString(), LabelCommonConfig.REPL_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.IO_ENGINE_FILE().toString(), LabelCommonConfig.FILE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.IO_ENGINE_HDFS().toString(), LabelCommonConfig.HDFS_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.JDBC().toString(), LabelCommonConfig.JDBC_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PIPELINE().toString(), LabelCommonConfig.PIPELINE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SHELL().toString(), LabelCommonConfig.SHELL_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.APPCONN().toString(), LabelCommonConfig.APPCONN_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.FLINK().toString(), LabelCommonConfig.FLINK_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PRESTO().toString(), LabelCommonConfig.PRESTO_ENGINE_VERSION.getValue());
private static void init() {
if (null == defaultVersion) { // NOSONAR
synchronized (EngineTypeLabelCreator.class) {
if (null == defaultVersion) {
defaultVersion = new HashMap<>(16);
defaultVersion.put(
EngineType.SPARK().toString(), LabelCommonConfig.SPARK_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.HIVE().toString(), LabelCommonConfig.HIVE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PYTHON().toString(), LabelCommonConfig.PYTHON_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.REPL().toString(), LabelCommonConfig.REPL_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.IO_ENGINE_FILE().toString(), LabelCommonConfig.FILE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.IO_ENGINE_HDFS().toString(), LabelCommonConfig.HDFS_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.JDBC().toString(), LabelCommonConfig.JDBC_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PIPELINE().toString(), LabelCommonConfig.PIPELINE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SHELL().toString(), LabelCommonConfig.SHELL_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.APPCONN().toString(), LabelCommonConfig.APPCONN_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.FLINK().toString(), LabelCommonConfig.FLINK_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.PRESTO().toString(), LabelCommonConfig.PRESTO_ENGINE_VERSION.getValue());

defaultVersion.put(
EngineType.HBASE().toString(), LabelCommonConfig.HBASE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.NEBULA().toString(), LabelCommonConfig.NEBULA_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.DORIS().toString(), LabelCommonConfig.DORIS_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SQOOP().toString(), LabelCommonConfig.SQOOP_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.DATAX().toString(), LabelCommonConfig.DATAX_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.OPENLOOKENG().toString(),
LabelCommonConfig.OPENLOOKENG_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.TRINO().toString(), LabelCommonConfig.TRINO_ENGINE_CONN_VERSION.getValue());
defaultVersion.put(
EngineType.ELASTICSEARCH().toString(),
LabelCommonConfig.ELASTICSEARCH_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SEATUNNEL().toString(),
LabelCommonConfig.SEATUNNEL_ENGINE_CONN_VERSION.getValue());
defaultVersion.put("*", "*");
defaultVersion.put(
EngineType.HBASE().toString(), LabelCommonConfig.HBASE_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.NEBULA().toString(), LabelCommonConfig.NEBULA_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.DORIS().toString(), LabelCommonConfig.DORIS_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SQOOP().toString(), LabelCommonConfig.SQOOP_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.DATAX().toString(), LabelCommonConfig.DATAX_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.OPENLOOKENG().toString(),
LabelCommonConfig.OPENLOOKENG_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.TRINO().toString(), LabelCommonConfig.TRINO_ENGINE_CONN_VERSION.getValue());
defaultVersion.put(
EngineType.ELASTICSEARCH().toString(),
LabelCommonConfig.ELASTICSEARCH_ENGINE_VERSION.getValue());
defaultVersion.put(
EngineType.SEATUNNEL().toString(),
LabelCommonConfig.SEATUNNEL_ENGINE_CONN_VERSION.getValue());
defaultVersion.put("*", "*");
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ public Operation createOperation(SqlCommandCall call, FlinkEngineConnContext con

private static OperationFactory operationFactory;

public static synchronized OperationFactory getInstance() {
if (operationFactory == null) {
operationFactory = ClassUtil.getInstance(OperationFactory.class, new OperationFactoryImpl());
public static OperationFactory getInstance() {
if (operationFactory == null) { // NOSONAR
synchronized (OperationFactory.class) {
if (operationFactory == null) {
operationFactory =
ClassUtil.getInstance(OperationFactory.class, new OperationFactoryImpl());
}
}
}
return operationFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.linkis.engineconnplugin.flink.client.sql.parser;

import org.apache.linkis.engineconnplugin.flink.client.sql.operation.OperationFactory;
import org.apache.linkis.engineconnplugin.flink.exception.SqlParseException;
import org.apache.linkis.engineconnplugin.flink.util.ClassUtil;

Expand Down Expand Up @@ -226,9 +227,14 @@ private SqlParser.Config createSqlParserConfig(boolean isBlinkPlanner) {

private static SqlCommandParser sqlCommandParser;

public static synchronized SqlCommandParser getInstance() {
if (sqlCommandParser == null) {
sqlCommandParser = ClassUtil.getInstance(SqlCommandParser.class, new SqlCommandParserImpl());
public static SqlCommandParser getInstance() {
if (sqlCommandParser == null) { // NOSONAR
synchronized (OperationFactory.class) {
if (sqlCommandParser == null) {
sqlCommandParser =
ClassUtil.getInstance(SqlCommandParser.class, new SqlCommandParserImpl());
}
}
}
return sqlCommandParser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ public class HBaseConnectionManager {
private static final AtomicBoolean kerberosEnvInit = new AtomicBoolean(false);
private static final int KERBEROS_RE_LOGIN_MAX_RETRY = 5;
private static final long KERBEROS_RE_LOGIN_INTERVAL = 30 * 60 * 1000L;
private static HBaseConnectionManager instance = null;
private static volatile HBaseConnectionManager instance = null;

private HBaseConnectionManager() {
connectionMap = new ConcurrentHashMap<>();
}

public static synchronized HBaseConnectionManager getInstance() {
if (instance == null) {
instance = new HBaseConnectionManager();
public static HBaseConnectionManager getInstance() {
if (instance == null) { // NOSONAR
synchronized (HBaseConnectionManager.class) {
if (instance == null) {
instance = new HBaseConnectionManager();
}
}
}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,58 @@
public class HBaseShellCommands {
private static final Logger LOG = LoggerFactory.getLogger(HBaseShellCommands.class);
private static final String COMMANDS_PATH = "hbase-ruby/shell/commands/";
private static Set<String> commandsSet;
private static volatile Set<String> commandsSet;

private HBaseShellCommands() {}

public static synchronized Set<String> getAllCommands() throws IOException {
public static Set<String> getAllCommands() throws IOException {
if (commandsSet == null) {
Set<String> sortedSet = new TreeSet<>();
URL commandFilesUrl = HBaseShellCommands.class.getClassLoader().getResource(COMMANDS_PATH);
if (commandFilesUrl == null) {
throw new IOException("The command files path is null!");
}
String commandFilePath = commandFilesUrl.getPath();
File commandFile = new File(commandFilePath);
if (!commandFile.exists()) {
LOG.warn("The command files path is not exists, starting read file from jar.");
String jarPath =
commandFilesUrl.toString().substring(0, commandFilesUrl.toString().indexOf("!/") + 2);
LOG.info("The path in jar is " + jarPath);
URL jarUrl = new URL(jarPath);
JarURLConnection jarCon = (JarURLConnection) jarUrl.openConnection();
JarFile jarFile = jarCon.getJarFile();
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry entry = jarEntries.nextElement();
String name = entry.getName();
if (!entry.isDirectory() && name.startsWith(COMMANDS_PATH)) {
String commandName =
name.substring(name.lastIndexOf(File.separator) + 1, name.lastIndexOf(".rb"));
sortedSet.add(commandName);
synchronized (HBaseShellCommands.class) {
if (commandsSet == null) {
Set<String> sortedSet = new TreeSet<>();
URL commandFilesUrl =
HBaseShellCommands.class.getClassLoader().getResource(COMMANDS_PATH);
if (commandFilesUrl == null) {
throw new IOException("The command files path is null!");
}
}
String commandFilePath = commandFilesUrl.getPath();
File commandFile = new File(commandFilePath);
if (!commandFile.exists()) {
LOG.warn("The command files path is not exists, starting read file from jar.");
String jarPath =
commandFilesUrl
.toString()
.substring(0, commandFilesUrl.toString().indexOf("!/") + 2);
LOG.info("The path in jar is " + jarPath);
URL jarUrl = new URL(jarPath);
JarURLConnection jarCon = (JarURLConnection) jarUrl.openConnection();
JarFile jarFile = jarCon.getJarFile();
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry entry = jarEntries.nextElement();
String name = entry.getName();
if (!entry.isDirectory() && name.startsWith(COMMANDS_PATH)) {
String commandName =
name.substring(name.lastIndexOf(File.separator) + 1, name.lastIndexOf(".rb"));
sortedSet.add(commandName);
}
}

} else {
String[] files = commandFile.list();
if (files == null) {
throw new IOException("The command files is null!");
}
for (String file : files) {
if (file.endsWith(".rb")) {
sortedSet.add(file.substring(0, file.lastIndexOf(".rb")));
} else {
String[] files = commandFile.list();
if (files == null) {
throw new IOException("The command files is null!");
}
for (String file : files) {
if (file.endsWith(".rb")) {
sortedSet.add(file.substring(0, file.lastIndexOf(".rb")));
}
}
}

commandsSet = sortedSet;
}
}

commandsSet = sortedSet;
}
return commandsSet;
}
Expand Down
Loading

0 comments on commit a0660d8

Please sign in to comment.