-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/MRADUL9936/kestra into d…
…evelop
- Loading branch information
Showing
94 changed files
with
2,109 additions
and
718 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
core/src/main/java/io/kestra/core/models/executions/ExecutionError.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,45 @@ | ||
package io.kestra.core.models.executions; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
public class ExecutionError { | ||
private static final int MAX_NB_FRAMES = 10; | ||
|
||
private String message; | ||
private String stacktrace; | ||
|
||
public static ExecutionError from(Throwable throwable) { | ||
if (throwable == null) { | ||
return ExecutionError.builder().message("Unknown error").build(); | ||
} | ||
|
||
String firstLine = throwable.getClass().getName() + ": " + throwable.getMessage() + "\n"; | ||
StackTraceElement[] stackTraces = throwable.getStackTrace(); | ||
String stackTraceStr; | ||
if (stackTraces.length > 10) { | ||
// keep only the top 10 frames | ||
stackTraceStr = stackTraceToString(firstLine, Arrays.copyOf(stackTraces, 10)) + "\n\t[...]"; | ||
} else { | ||
stackTraceStr = stackTraceToString(firstLine, stackTraces); | ||
} | ||
return ExecutionError.builder() | ||
.message(throwable.getMessage()) | ||
.stacktrace(stackTraceStr) | ||
.build(); | ||
} | ||
|
||
private static String stackTraceToString(String firstLine, StackTraceElement[] stackTraces) { | ||
return Stream.of(stackTraces) | ||
.map(stackTraceElement -> stackTraceElement.toString()) | ||
.collect(Collectors.joining("\n\t", firstLine, "")); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
core/src/main/java/io/kestra/core/models/flows/input/EmailInput.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,25 @@ | ||
package io.kestra.core.models.flows.input; | ||
|
||
import io.kestra.core.models.flows.Input; | ||
import io.kestra.core.models.validations.ManualConstraintViolation; | ||
import jakarta.validation.ConstraintViolationException; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class EmailInput extends Input<String> { | ||
|
||
private static final String EMAIL_PATTERN = "^$|^[a-zA-Z0-9_!#$%&’*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; | ||
|
||
@Override | ||
public void validate(String input) throws ConstraintViolationException { | ||
if(!Pattern.matches(EMAIL_PATTERN, input)){ | ||
throw ManualConstraintViolation.toConstraintViolationException( | ||
"The input must be a valid email", | ||
this, | ||
EmailInput.class, | ||
getId(), | ||
input | ||
); | ||
} | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
core/src/main/java/io/kestra/core/models/validations/KestraConstraintViolationException.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,46 @@ | ||
package io.kestra.core.models.validations; | ||
|
||
import io.kestra.core.models.flows.Input; | ||
import io.kestra.core.models.tasks.Task; | ||
import jakarta.validation.ConstraintViolation; | ||
import jakarta.validation.ConstraintViolationException; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class KestraConstraintViolationException extends ConstraintViolationException { | ||
|
||
public KestraConstraintViolationException(Set<? extends ConstraintViolation<?>> constraintViolations) { | ||
super(constraintViolations); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
StringBuilder message = new StringBuilder(); | ||
for (ConstraintViolation<?> violation : getConstraintViolations()) { | ||
String errorMessage = violation.getPropertyPath() + ": " + violation.getMessage(); | ||
try { | ||
if (violation.getLeafBean() instanceof Task) { | ||
errorMessage = replaceId("tasks", violation.getPropertyPath().toString(), ((Task) violation.getLeafBean()).getId()) + ": " + violation.getMessage(); | ||
} | ||
if (violation.getLeafBean() instanceof Input) { | ||
errorMessage = replaceId("inputs", violation.getPropertyPath().toString(), ((Input) violation.getLeafBean()).getId()) + ": " + violation.getMessage(); | ||
|
||
} | ||
} catch (Exception e) { | ||
// In case we don't succeed at replacing the id, we just use the default message | ||
} | ||
message.append(errorMessage).append("\n"); | ||
} | ||
return message.toString(); | ||
} | ||
|
||
private String replaceId(String type, String errorMessage, String taskId) { | ||
String regex = type + "\\[\\d+\\]"; | ||
Pattern pattern = Pattern.compile(regex); | ||
Matcher matcher = pattern.matcher(errorMessage); | ||
|
||
return matcher.replaceAll(taskId); | ||
} | ||
} |
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.