|
57 | 57 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_CODE;
|
58 | 58 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_PAGE_NO;
|
59 | 59 | 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; |
60 | 61 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_SCHEDULE_TIME_FORMAT;
|
61 | 62 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_DESC;
|
62 | 63 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_GEN_NUM;
|
63 | 64 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_DEFAULT_TASK_NAME;
|
64 | 65 | 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; |
65 | 67 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_ID;
|
66 | 68 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_ONLINE_URL;
|
67 | 69 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_PAGE_NO;
|
|
78 | 80 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_RESPONSE_TOTAL_LIST;
|
79 | 81 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SCHEDULE_DEF;
|
80 | 82 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SEARCH_VAL;
|
| 83 | +import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_SUCCESS; |
81 | 84 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_DEFINITION;
|
82 | 85 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_GEN_NUM;
|
83 | 86 | import static org.apache.inlong.manager.schedule.dolphinscheduler.DolphinScheduleConstants.DS_TASK_RELATION;
|
|
89 | 92 | import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.JSON_PARSE_ERROR;
|
90 | 93 | import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.NETWORK_ERROR;
|
91 | 94 | 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; |
92 | 96 | import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_QUERY_FAILED;
|
93 | 97 | import static org.apache.inlong.manager.schedule.exception.DolphinScheduleException.PROCESS_DEFINITION_RELEASE_FAILED;
|
94 | 98 | 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) {
|
489 | 493 | Map<String, String> header = buildHeader(token);
|
490 | 494 |
|
491 | 495 | String requestUrl = url + "/" + code;
|
| 496 | + for (int attempt = 1; attempt <= DS_DEFAULT_RETRY_TIMES; attempt++) { |
| 497 | + JsonObject response = executeHttpRequest(requestUrl, DELETE, new HashMap<>(), header); |
492 | 498 |
|
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 | + } |
495 | 510 |
|
| 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); |
496 | 517 | } catch (JsonParseException e) {
|
497 | 518 | LOGGER.error("JsonParseException during deleting process or project", e);
|
498 | 519 | throw new DolphinScheduleException(
|
499 | 520 | JSON_PARSE_ERROR,
|
500 | 521 | String.format("Error deleting process or project with code: %d at URL: %s", code, url), e);
|
501 | 522 |
|
502 | 523 | } catch (DolphinScheduleException e) {
|
| 524 | + LOGGER.error("Error deleting process or project: ", e); |
503 | 525 | throw new DolphinScheduleException(
|
504 | 526 | DELETION_FAILED,
|
505 | 527 | String.format("Error deleting process or project with code: %d at URL: %s", code, url), e);
|
|
0 commit comments