This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Branch - 2.31] Configurable retry delay policy (#2371)
* Custom strategy for configurable retry delay * Addressing code review comments * Removing redundant space * Addressed code review comments * Address code review feedback and added new retry policy at workflow task level * Fix test code formatting * Fix test code formatting * Addressed code review comments * Removed the proto Co-authored-by: pgolash <[email protected]>
- Loading branch information
1 parent
b751d16
commit 1e7f467
Showing
16 changed files
with
474 additions
and
42 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
common/src/main/java/com/netflix/conductor/common/constraints/RetryLogicConstraint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed 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 com.netflix.conductor.common.constraints; | ||
|
||
import com.netflix.conductor.common.metadata.tasks.TaskDef; | ||
import com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
|
||
@Documented | ||
@Constraint(validatedBy = RetryLogicConstraint.RetryLogicValidator.class) | ||
@Target({TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface RetryLogicConstraint { | ||
String message() default ""; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
class RetryLogicValidator implements ConstraintValidator<RetryLogicConstraint, TaskDef> { | ||
|
||
@Override | ||
public void initialize(RetryLogicConstraint constraintAnnotation) { | ||
} | ||
|
||
@Override | ||
public boolean isValid(TaskDef taskDef, ConstraintValidatorContext context) { | ||
context.disableDefaultConstraintViolation(); | ||
|
||
boolean valid = true; | ||
if (taskDef.getRetryLogic() == RetryLogic.UNSPECIFIED && taskDef.isRetryDelaySet()) { | ||
valid = false; | ||
String message = String.format("TaskDef: %s retryPolicy can't be UNSPECIFIED as retryDelay is set", | ||
taskDef.getName()); | ||
context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); | ||
} | ||
return valid; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.junit.Test; | ||
|
||
import com.netflix.conductor.common.metadata.tasks.TaskDef; | ||
import com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic; | ||
|
||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Validation; | ||
|
@@ -44,27 +45,29 @@ public void setup(){ | |
this.validator = factory.getValidator(); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
String name = "test1"; | ||
String description = "desc"; | ||
int retryCount = 10; | ||
int timeout = 100; | ||
TaskDef def = new TaskDef(name, description, retryCount, timeout); | ||
assertEquals(36_00, def.getResponseTimeoutSeconds()); | ||
assertEquals(name, def.getName()); | ||
assertEquals(description, def.getDescription()); | ||
assertEquals(retryCount, def.getRetryCount()); | ||
assertEquals(timeout, def.getTimeoutSeconds()); | ||
} | ||
|
||
@Test | ||
public void testTaskDef() { | ||
TaskDef taskDef = new TaskDef(); | ||
taskDef.setName("task1"); | ||
taskDef.setRetryCount(-1); | ||
taskDef.setTimeoutSeconds(1000); | ||
taskDef.setResponseTimeoutSeconds(1001); | ||
@Test | ||
public void test() { | ||
String name = "test1"; | ||
String description = "desc"; | ||
int retryCount = 10; | ||
int timeout = 100; | ||
TaskDef def = new TaskDef(name, description, retryCount, timeout); | ||
assertEquals(36_00, def.getResponseTimeoutSeconds()); | ||
assertEquals(name, def.getName()); | ||
assertEquals(description, def.getDescription()); | ||
assertEquals(retryCount, def.getRetryCount()); | ||
assertEquals(timeout, def.getTimeoutSeconds()); | ||
} | ||
|
||
@Test | ||
public void testTaskDef() { | ||
TaskDef taskDef = new TaskDef(); | ||
taskDef.setName("task1"); | ||
taskDef.setRetryCount(-1); | ||
taskDef.setTimeoutSeconds(1000); | ||
taskDef.setResponseTimeoutSeconds(1001); | ||
taskDef.setRetryLogic(RetryLogic.FIXED); | ||
taskDef.setRetryDelaySeconds(10); | ||
|
||
Set<ConstraintViolation<Object>> result = validator.validate(taskDef); | ||
assertEquals(3, result.size()); | ||
|
@@ -77,6 +80,26 @@ public void testTaskDef() { | |
assertTrue(validationErrors.contains("ownerEmail cannot be empty")); | ||
} | ||
|
||
@Test | ||
public void testTaskDefRetryLogic() { | ||
TaskDef taskDef = new TaskDef(); | ||
taskDef.setName("task1"); | ||
taskDef.setRetryCount(1); | ||
taskDef.setTimeoutSeconds(1000); | ||
taskDef.setResponseTimeoutSeconds(10); | ||
taskDef.setOwnerEmail("[email protected]"); | ||
taskDef.setRetryLogic(RetryLogic.UNSPECIFIED); | ||
taskDef.setRetryDelaySeconds(100); | ||
|
||
Set<ConstraintViolation<Object>> result = validator.validate(taskDef); | ||
assertEquals(1, result.size()); | ||
|
||
List<String> validationErrors = new ArrayList<>(); | ||
result.forEach(e -> validationErrors.add(e.getMessage())); | ||
|
||
assertTrue(validationErrors.contains("TaskDef: task1 retryPolicy can't be UNSPECIFIED as retryDelay is set")); | ||
} | ||
|
||
@Test | ||
public void testTaskDefNameAndOwnerNotSet() { | ||
TaskDef taskDef = new TaskDef(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.