Skip to content

Commit b636565

Browse files
committed
Merge remote-tracking branch 'origin/hotfix_1.8_3.9_24098' into 1.8_release_3.10.x
# Conflicts: # rdb/rdb-sink/src/main/java/com/dtstack/flink/sql/sink/rdb/format/RetractJDBCOutputFormat.java
2 parents a0e7d5b + c4ce935 commit b636565

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.enums;
20+
21+
import org.apache.commons.lang.StringUtils;
22+
import org.apache.commons.lang.exception.ExceptionUtils;
23+
24+
import java.util.Arrays;
25+
26+
/**
27+
* Date: 2020/4/2
28+
* Company: www.dtstack.com
29+
* @author maqi
30+
*/
31+
public enum EConnectionErrorCode {
32+
ERROR_NOT_MATCH(0, "错误信息未匹配", new String[]{}),
33+
CONN_DB_INVALID(1, "数据库连接失效,请重新打开", new String[]{"the last packet successfully received from the server was", "Zookeeper session has been expired"}),
34+
CONN_DB_FAILED(2, "数据库连接失败,请检查用户名或密码是否正确", new String[]{"Access denied for user"}),
35+
DB_TABLE_NOT_EXIST(3, "操作的表名不存在", new String[]{"doesn't exist"});
36+
37+
private int code;
38+
private String description;
39+
private String[] baseErrorInfo;
40+
41+
EConnectionErrorCode(int code, String description, String[] baseErrorInfo) {
42+
this.code = code;
43+
this.description = description;
44+
this.baseErrorInfo = baseErrorInfo;
45+
}
46+
47+
48+
public static EConnectionErrorCode resolveErrorCodeFromException(Throwable e) {
49+
final String stackErrorMsg = ExceptionUtils.getFullStackTrace(e);
50+
return Arrays.stream(values())
51+
.filter(errorCode -> matchKnowError(errorCode, stackErrorMsg))
52+
.findAny()
53+
.orElse(ERROR_NOT_MATCH);
54+
}
55+
56+
public static boolean matchKnowError(EConnectionErrorCode errorCode, String errorMsg) {
57+
return Arrays.stream(errorCode.baseErrorInfo)
58+
.filter(baseInfo -> StringUtils.containsIgnoreCase(errorMsg, baseInfo))
59+
.findAny()
60+
.isPresent();
61+
}
62+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.side;
20+
21+
import com.dtstack.flink.sql.enums.EConnectionErrorCode;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
/**
26+
* Date: 2020/4/2
27+
* Company: www.dtstack.com
28+
* @author maqi
29+
*/
30+
public class EConnectionErrorCodeTest {
31+
32+
@Test
33+
public void testResolveErrorCodeFromException(){
34+
EConnectionErrorCode errorCode =
35+
EConnectionErrorCode.resolveErrorCodeFromException(new Exception("The last packet successfully received from the server was 179 milliseconds"));
36+
37+
EConnectionErrorCode ckSessionExpired =
38+
EConnectionErrorCode.resolveErrorCodeFromException(new Exception("Excepetion: Zookeeper session has been expired"));
39+
40+
Assert.assertEquals(errorCode, EConnectionErrorCode.CONN_DB_INVALID);
41+
Assert.assertEquals(ckSessionExpired, EConnectionErrorCode.CONN_DB_INVALID);
42+
}
43+
}

0 commit comments

Comments
 (0)