Skip to content

Commit 921aa1c

Browse files
committed
fix: add retry mechanism while deleting project or process
1 parent 104d8f3 commit 921aa1c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

inlong-manager/manager-schedule/src/main/java/org/apache/inlong/manager/schedule/dolphinscheduler/DolphinScheduleConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ public class DolphinScheduleConstants {
2222
// DS public constants
2323
public static final String DS_ID = "id";
2424
public static final String DS_CODE = "code";
25+
public static final String DS_SUCCESS = "success";
2526
public static final String DS_TOKEN = "token";
2627
public static final String DS_PAGE_SIZE = "pageSize";
2728
public static final String DS_PAGE_NO = "pageNo";
2829
public static final String DS_SEARCH_VAL = "searchVal";
2930
public static final String DS_RESPONSE_DATA = "data";
3031
public static final String DS_RESPONSE_NAME = "name";
3132
public static final String DS_RESPONSE_TOTAL_LIST = "totalList";
33+
public static final int DS_DEFAULT_RETRY_TIMES = 3;
34+
public static final int DS_DEFAULT_WAIT_MILLS = 1000;
3235
public static final String DS_DEFAULT_PAGE_SIZE = "10";
3336
public static final String DS_DEFAULT_PAGE_NO = "1";
3437
public static final String DS_DEFAULT_TIMEZONE_ID = "Asia/Shanghai";

inlong-manager/manager-schedule/src/main/java/org/apache/inlong/manager/schedule/dolphinscheduler/DolphinScheduleUtils.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_CODE;
5858
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_PAGE_NO;
5959
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_PAGE_SIZE;
60+
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_RETRY_TIMES;
6061
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_SCHEDULE_TIME_FORMAT;
6162
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_DESC;
6263
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_GEN_NUM;
6364
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_NAME;
6465
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TIMEZONE_ID;
66+
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_WAIT_MILLS;
6567
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_ID;
6668
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_ONLINE_URL;
6769
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_PAGE_NO;
@@ -78,6 +80,7 @@
7880
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_RESPONSE_TOTAL_LIST;
7981
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SCHEDULE_DEF;
8082
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SEARCH_VAL;
83+
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SUCCESS;
8184
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_DEFINITION;
8285
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_GEN_NUM;
8386
import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_RELATION;
@@ -89,6 +92,7 @@
8992
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.JSON_PARSE_ERROR;
9093
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.NETWORK_ERROR;
9194
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_CREATION_FAILED;
95+
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_IN_USED_ERROR;
9296
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_QUERY_FAILED;
9397
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_RELEASE_FAILED;
9498
import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROJECT_CREATION_FAILED;
@@ -489,17 +493,35 @@ public static void delete(String url, String token, long code) {
489493
Map<String, String> header = buildHeader(token);
490494

491495
String requestUrl = url + "/" + code;
496+
for (int attempt = 1; attempt <= DS_DEFAULT_RETRY_TIMES; attempt++) {
497+
JsonObject response = executeHttpRequest(requestUrl, DELETE, new HashMap<>(), header);
492498

493-
JsonObject response = executeHttpRequest(requestUrl, DELETE, new HashMap<>(), header);
494-
LOGGER.info("delete process or project success, response data: {}", response);
499+
if (response.get(DS_SUCCESS).getAsBoolean()) {
500+
LOGGER.info("Delete process or project success, response data: {}", response);
501+
return;
502+
}
503+
504+
if (response.get(DS_CODE).getAsInt() == PROCESS_DEFINITION_IN_USED_ERROR) {
505+
LOGGER.warn("Attempt {} of {}, retrying after {} ms...", attempt, DS_DEFAULT_RETRY_TIMES,
506+
DS_DEFAULT_WAIT_MILLS);
507+
Thread.sleep(DS_DEFAULT_WAIT_MILLS);
508+
}
509+
}
495510

511+
} catch (InterruptedException e) {
512+
Thread.currentThread().interrupt();
513+
LOGGER.error("Thread interrupted while retrying delete process or project: ", e);
514+
throw new DolphinScheduleException(
515+
DELETION_FAILED,
516+
String.format("Thread interrupted while retrying delete for code: %d at URL: %s", code, url), e);
496517
} catch (JsonParseException e) {
497518
LOGGER.error("JsonParseException during deleting process or project", e);
498519
throw new DolphinScheduleException(
499520
JSON_PARSE_ERROR,
500521
String.format("Error deleting process or project with code: %d at URL: %s", code, url), e);
501522

502523
} catch (DolphinScheduleException e) {
524+
LOGGER.error("Error deleting process or project: ", e);
503525
throw new DolphinScheduleException(
504526
DELETION_FAILED,
505527
String.format("Error deleting process or project with code: %d at URL: %s", code, url), e);

inlong-manager/manager-schedule/src/main/java/org/apache/inlong/manager/schedule/exception/DolphinScheduleException.java

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class DolphinScheduleException extends RuntimeException {
4242
public static final String GEN_TASK_CODE_FAILED = "GEN_TASK_CODE_FAILED";
4343

4444
// Process-related error codes
45+
public static final int PROCESS_DEFINITION_IN_USED_ERROR = 10168;
4546
public static final String PROCESS_DEFINITION_QUERY_FAILED = "PROCESS_DEFINITION_QUERY_FAILED";
4647
public static final String PROCESS_DEFINITION_CREATION_FAILED = "PROCESS_DEFINITION_CREATION_FAILED";
4748
public static final String PROCESS_DEFINITION_RELEASE_FAILED = "PROCESS_DEFINITION_RELEASE_FAILED";

0 commit comments

Comments
 (0)