Skip to content

Commit

Permalink
handle conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mayinrain committed Dec 19, 2024
2 parents 7557192 + ec342a0 commit 817c450
Show file tree
Hide file tree
Showing 437 changed files with 16,027 additions and 8,380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.linkis.common.exception;

public class LinkisRetryException extends LinkisException {
public class LinkisRetryException extends LinkisRuntimeException {
LinkisRetryException(int errCode, String desc, String ip, int port, String serviceKind) {
super(errCode, desc, ip, port, serviceKind);
}
Expand All @@ -27,7 +27,7 @@ public LinkisRetryException(int errCode, String desc) {
}

@Override
ExceptionLevel getLevel() {
public ExceptionLevel getLevel() {
return ExceptionLevel.RETRY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.common.utils;

import org.apache.linkis.common.exception.ErrorException;
import org.apache.linkis.common.exception.FatalException;
import org.apache.linkis.common.exception.WarnException;

import java.util.concurrent.Callable;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LinkisUtils {
private static final Logger logger = LoggerFactory.getLogger(LinkisUtils.class);

public static <T> T tryCatch(Callable<T> tryOp, Function<Throwable, T> catchOp) {
T result = null;
try {
result = tryOp.call();
} catch (Throwable t) {
if (t instanceof FatalException) {
logger.error("Fatal error, system exit...", t);
System.exit(((FatalException) t).getErrCode());
} else if (t instanceof VirtualMachineError) {
logger.error("Fatal error, system exit...", t);
System.exit(-1);
} else if (null != t.getCause()
&& (t.getCause() instanceof FatalException
|| t.getCause() instanceof VirtualMachineError)) {
logger.error("Caused by fatal error, system exit...", t);
System.exit(-1);
} else if (t instanceof Error) {
logger.error("Throw error", t);
throw (Error) t;
} else {
result = catchOp.apply(t);
}
}
return result;
}

public static void tryFinally(Runnable tryOp, Runnable finallyOp) {
try {
tryOp.run();
} finally {
finallyOp.run();
}
}

public static <T> T tryAndWarn(Callable<T> tryOp, Logger log) {
return tryCatch(
tryOp,
t -> {
if (t instanceof ErrorException) {
ErrorException error = (ErrorException) t;
log.error(
"Warning code(警告码): {}, Warning message(警告信息): {}.",
error.getErrCode(),
error.getDesc(),
error);

} else if (t instanceof WarnException) {
WarnException warn = (WarnException) t;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.",
warn.getErrCode(),
warn.getDesc(),
warn);

} else {
log.warn("", t);
}
return null;
});
}

public static void tryAndErrorMsg(Runnable tryOp, String message, Logger log) {
try {
tryOp.run();
} catch (WarnException t) {
WarnException warn = (WarnException) t;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.", warn.getErrCode(), warn.getDesc());
log.warn(message, warn);
} catch (Exception t) {
log.warn(message, t);
}
}

public static <T> void tryAndWarn(Runnable tryOp, Logger log) {
try {
tryOp.run();
} catch (Throwable error) {
if (error instanceof WarnException) {
WarnException warn = (WarnException) error;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.",
warn.getErrCode(),
warn.getDesc(),
error);
} else {
log.warn("", error);
}
}
}

public static void tryAndWarnMsg(Runnable tryOp, String message, Logger log) {
try {
tryOp.run();
} catch (WarnException t) {
WarnException warn = (WarnException) t;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.", warn.getErrCode(), warn.getDesc());
log.warn(message, warn);
} catch (Exception t) {
log.warn(message, t);
}
}

public static <T> T tryAndWarnMsg(Callable<T> tryOp, String message, Logger log) {
return tryCatch(
tryOp,
t -> {
if (t instanceof ErrorException) {
ErrorException error = (ErrorException) t;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.",
error.getErrCode(),
error.getDesc());
log.warn(message, error);
} else if (t instanceof WarnException) {
WarnException warn = (WarnException) t;
log.warn(
"Warning code(警告码): {}, Warning message(警告信息): {}.",
warn.getErrCode(),
warn.getDesc());
log.warn(message, warn);
} else {
log.warn(message, t);
}
return null;
});
}

public static String getJvmUser() {
return System.getProperty("user.name");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.common.utils;

import org.apache.linkis.common.conf.CommonVars;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHAUtils {

public static String DOCTOR_NONCE = "12345";
public static final CommonVars<String> DOCTOR_TOKEN =
CommonVars.apply("linkis.doctor.signature.token", "");

/**
* 对字符串加密,默认使用SHA-256
*
* @param strSrc 要加密的字符串
* @param encName 加密类型
* @return
* @throws UnsupportedEncodingException
*/
public static String Encrypt(String strSrc, String encName) throws UnsupportedEncodingException {
MessageDigest md = null;
String strDes = null;
byte[] bt = strSrc.getBytes("utf-8");
try {
if (encName == null || encName.equals("")) {
encName = "SHA-256";
}
md = MessageDigest.getInstance(encName);
md.update(bt);
strDes = bytes2Hex(md.digest()); // to HexString
} catch (NoSuchAlgorithmException e) {
return null;
}
return strDes;
}

public static String bytes2Hex(byte[] bts) {
String des = "";
String tmp = null;
for (int i = 0; i < bts.length; i++) {
tmp = (Integer.toHexString(bts[i] & 0xFF));
if (tmp.length() == 1) {
des += "0";
}
des += tmp;
}
return des;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,40 @@ private static boolean isNotSecurity(String key, String value, String param) {
return key.toLowerCase().contains(param.toLowerCase())
|| value.toLowerCase().contains(param.toLowerCase());
}

/**
* allowLoadLocalInfile=false&autoDeserialize=false&allowLocalInfile=false&allowUrlInLocalInfile=false
*
* @return
*/
public static Properties getMysqlSecurityParams() {
Properties properties = new Properties();
properties.setProperty("allowLoadLocalInfile", "false");
properties.setProperty("autoDeserialize", "false");
properties.setProperty("allowLocalInfile", "false");
properties.setProperty("allowUrlInLocalInfile", "false");
return properties;
}

/**
* Check if the path has a relative path
*
* @param path
* @return
*/
public static boolean containsRelativePath(String path) {
if (path.startsWith("./")
|| path.contains("/./")
|| path.startsWith("../")
|| path.contains("/../")) {
return true;
}
if (path.startsWith(".\\")
|| path.contains("\\.\\")
|| path.startsWith("..\\")
|| path.contains("\\..\\")) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ object Configuration extends Logging {

val IS_TEST_MODE = CommonVars("wds.linkis.test.mode", false)

val LINKIS_SYS_NAME = CommonVars("linkis.system.name", "")

val IS_PROMETHEUS_ENABLE = CommonVars("wds.linkis.prometheus.enable", false)

val IS_MULTIPLE_YARN_CLUSTER = CommonVars("linkis.multiple.yarn.cluster", false).getValue

val PROMETHEUS_ENDPOINT = CommonVars("wds.linkis.prometheus.endpoint", "/actuator/prometheus")

val LINKIS_HOME = CommonVars("wds.linkis.home", CommonVars("LINKIS_HOME", "/tmp").getValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ object HadoopConf {

val KERBEROS_ENABLE = CommonVars("wds.linkis.keytab.enable", false).getValue

val KERBEROS_ENABLE_MAP =
CommonVars("linkis.keytab.enable.map", "cluster1=false,cluster2=true")

val KEYTAB_FILE = CommonVars("wds.linkis.keytab.file", "/appcom/keytab/")

val EXTERNAL_KEYTAB_FILE_PREFIX =
CommonVars("linkis.external.keytab.file.prefix", "/appcom/config/external-conf/keytab")

val KEYTAB_HOST = CommonVars("wds.linkis.keytab.host", "127.0.0.1")

val KEYTAB_HOST_MAP =
CommonVars("linkis.keytab.host.map", "cluster1=127.0.0.2,cluster2=127.0.0.3")

val KEYTAB_HOST_ENABLED = CommonVars("wds.linkis.keytab.host.enabled", false)

val KEYTAB_PROXYUSER_ENABLED = CommonVars("wds.linkis.keytab.proxyuser.enable", false)

val KEYTAB_PROXYUSER_SUPERUSER = CommonVars("wds.linkis.keytab.proxyuser.superuser", "hadoop")

val KEYTAB_PROXYUSER_SUPERUSER_MAP =
CommonVars("linkis.keytab.proxyuser.superuser.map", "cluster1=hadoop1,cluster2=hadoop2")

val hadoopConfDir =
CommonVars("hadoop.config.dir", CommonVars("HADOOP_CONF_DIR", "").getValue).getValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.linkis.hadoop.common.conf.HadoopConf

import org.apache.hadoop.fs.FileSystem

class HDFSFileSystemContainer(fs: FileSystem, user: String) {
class HDFSFileSystemContainer(fs: FileSystem, user: String, label: String) {

private var lastAccessTime: Long = System.currentTimeMillis()

Expand All @@ -31,6 +31,8 @@ class HDFSFileSystemContainer(fs: FileSystem, user: String) {

def getUser: String = this.user

def getLabel: String = this.label

def getLastAccessTime: Long = this.lastAccessTime

def updateLastAccessTime: Unit = {
Expand Down
Loading

0 comments on commit 817c450

Please sign in to comment.