Commit 9a201acb authored by godkaikai's avatar godkaikai

error完整打印

parent d0406156
package com.dlink.utils;
import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
/**
* LogUtil
*
* @author wenmo
* @since 2022/2/11 15:46
**/
public class LogUtil {
private static final Logger logger = LoggerFactory.getLogger(LogUtil.class);
public static String getError(Exception e){
// e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String error = sw.toString();
logger.error(sw.toString());
return error;
}
public static String getError(String msg,Exception e){
// e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
LocalDateTime now = LocalDateTime.now();
String error = now.toString() + ": " + msg + " \nError message:\n " + sw.toString();
logger.error(error);
return error;
}
}
......@@ -27,6 +27,7 @@ import com.dlink.session.SessionConfig;
import com.dlink.session.SessionInfo;
import com.dlink.session.SessionPool;
import com.dlink.trans.Operations;
import com.dlink.utils.LogUtil;
import com.dlink.utils.SqlUtil;
import com.dlink.utils.UDFUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -44,6 +45,8 @@ import org.apache.flink.yarn.configuration.YarnConfigOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
......@@ -366,16 +369,9 @@ public class JobManager {
job.setStatus(Job.JobStatus.SUCCESS);
success();
} catch (Exception e) {
e.printStackTrace();
StackTraceElement[] trace = e.getStackTrace();
StringBuffer resMsg = new StringBuffer("");
for (StackTraceElement s : trace) {
resMsg.append(" \n " + s + " ");
}
LocalDateTime now = LocalDateTime.now();
job.setEndTime(now);
String error = LogUtil.getError("Exception in executing FlinkSQL:\n" + currentSql,e);
job.setEndTime(LocalDateTime.now());
job.setStatus(Job.JobStatus.FAILED);
String error = now.toString() + ":" + "Exception in executing FlinkSQL:\n" + currentSql + " \nError message: " + e.getMessage() + " \n >>> PrintStackTrace <<<" + resMsg.toString();
job.setError(error);
failed();
close();
......@@ -490,16 +486,9 @@ public class JobManager {
job.setStatus(Job.JobStatus.SUCCESS);
success();
} catch (Exception e) {
e.printStackTrace();
StackTraceElement[] trace = e.getStackTrace();
StringBuffer resMsg = new StringBuffer("");
for (StackTraceElement s : trace) {
resMsg.append(" \n " + s + " ");
}
LocalDateTime now = LocalDateTime.now();
job.setEndTime(now);
String error = LogUtil.getError("Exception in executing Jar:\n" + config.getGatewayConfig().getAppConfig().getUserJarPath(),e);
job.setEndTime(LocalDateTime.now());
job.setStatus(Job.JobStatus.FAILED);
String error = now.toString() + ":" + "Exception in executing Jar:\n" + config.getGatewayConfig().getAppConfig().getUserJarPath() + " \nError message: " + e.getMessage() + " \n >>> PrintStackTrace <<<" + resMsg.toString();
job.setError(error);
failed();
close();
......
......@@ -6,6 +6,7 @@ import com.dlink.gateway.config.AppConfig;
import com.dlink.gateway.exception.GatewayException;
import com.dlink.gateway.result.GatewayResult;
import com.dlink.gateway.result.KubernetesResult;
import com.dlink.utils.LogUtil;
import org.apache.flink.client.deployment.ClusterSpecification;
import org.apache.flink.client.deployment.application.ApplicationConfiguration;
import org.apache.flink.client.program.ClusterClient;
......@@ -52,9 +53,7 @@ public class KubernetesApplicationGateway extends KubernetesGateway {
result.setWebURL(clusterClient.getWebInterfaceURL());
result.success();
}catch (Exception e){
e.printStackTrace();
logger.error("任务提交时发生异常",e);
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}finally {
kubernetesClusterDescriptor.close();
}
......
......@@ -8,6 +8,7 @@ import com.dlink.gateway.exception.GatewayException;
import com.dlink.gateway.model.JobInfo;
import com.dlink.gateway.result.SavePointResult;
import com.dlink.gateway.result.TestResult;
import com.dlink.utils.LogUtil;
import org.apache.flink.api.common.JobID;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.configuration.Configuration;
......@@ -102,9 +103,7 @@ public abstract class KubernetesGateway extends AbstractGateway {
runSavePointJob(jobInfos,clusterClient,savePoint);
result.setJobInfos(jobInfos);
}catch (Exception e){
e.printStackTrace();
logger.error(e.getMessage());
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}
return null;
}
......@@ -139,9 +138,7 @@ public abstract class KubernetesGateway extends AbstractGateway {
runSavePointJob(jobInfos,clusterClient,savePoint);
result.setJobInfos(jobInfos);
}catch (Exception e){
e.printStackTrace();
logger.error(e.getMessage());
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}
return result;
}
......
......@@ -7,6 +7,7 @@ import com.dlink.gateway.config.GatewayConfig;
import com.dlink.gateway.exception.GatewayException;
import com.dlink.gateway.result.GatewayResult;
import com.dlink.gateway.result.YarnResult;
import com.dlink.utils.LogUtil;
import org.apache.flink.client.deployment.ClusterSpecification;
import org.apache.flink.client.deployment.application.ApplicationConfiguration;
import org.apache.flink.client.program.ClusterClient;
......@@ -66,9 +67,7 @@ public class YarnApplicationGateway extends YarnGateway {
result.setWebURL(clusterClient.getWebInterfaceURL());
result.success();
}catch (Exception e){
e.printStackTrace();
logger.error("任务提交时发生异常",e);
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}finally {
yarnClusterDescriptor.close();
}
......
......@@ -8,6 +8,7 @@ import com.dlink.gateway.exception.GatewayException;
import com.dlink.gateway.model.JobInfo;
import com.dlink.gateway.result.SavePointResult;
import com.dlink.gateway.result.TestResult;
import com.dlink.utils.LogUtil;
import org.apache.flink.api.common.JobID;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.configuration.DeploymentOptions;
......@@ -29,6 +30,8 @@ import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.client.api.YarnClient;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.util.*;
import java.util.concurrent.CompletableFuture;
......@@ -141,6 +144,9 @@ public abstract class YarnGateway extends AbstractGateway {
result.setJobInfos(jobInfos);
}catch (Exception e){
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
logger.error(e.getMessage());
result.fail(e.getMessage());
}
......@@ -184,9 +190,7 @@ public abstract class YarnGateway extends AbstractGateway {
runSavePointJob(jobInfos,clusterClient,savePoint);
result.setJobInfos(jobInfos);
}catch (Exception e){
e.printStackTrace();
logger.error(e.getMessage());
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}
return result;
}
......
......@@ -6,6 +6,7 @@ import com.dlink.gateway.GatewayType;
import com.dlink.gateway.exception.GatewayException;
import com.dlink.gateway.result.GatewayResult;
import com.dlink.gateway.result.YarnResult;
import com.dlink.utils.LogUtil;
import org.apache.flink.client.deployment.ClusterSpecification;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.client.program.ClusterClientProvider;
......@@ -51,9 +52,7 @@ public class YarnPerJobGateway extends YarnGateway {
result.setWebURL(clusterClient.getWebInterfaceURL());
result.success();
}catch (Exception e){
e.printStackTrace();
logger.error("任务提交时发生异常",e);
result.fail(e.getMessage());
result.fail(LogUtil.getError(e));
}finally {
yarnClusterDescriptor.close();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment