Repository navigation
Async step timeouts #1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vkalapov
wants to merge
7
commits into
master
Choose a base branch
from
async-step-timeouts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Async step timeouts #1834
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27813ac
Add service timeout parameters and resolution model
vkalapov 366b97d
Resolve async step timeouts from CLI, resource and global sources
vkalapov 2006142
Enforce resolved timeouts in service and app lifecycle steps
vkalapov 5346dd0
Register service timeout parameters in deploy metadata
vkalapov 7f1c661
Forward service timeout variables into deploy subprocesses
vkalapov f6d8338
Log per-operation timeout without emitting a progress message
vkalapov 8ef2b64
Address review comments: extract constants and messages, rename method
vkalapov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
...ller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/util/DurationUtil.java
This file contains hidden or 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,37 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.util; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Optional; | ||
|
|
||
| import org.cloudfoundry.multiapps.common.ContentException; | ||
| import org.cloudfoundry.multiapps.controller.core.Messages; | ||
|
|
||
| public final class DurationUtil { | ||
|
|
||
| private DurationUtil() { | ||
| // utility class | ||
| } | ||
|
|
||
| public static Duration parseDuration(Object timeout, String parameterName, int maxAllowedValue) { | ||
| if (timeout == null) { | ||
| return null; | ||
| } | ||
| if (!(timeout instanceof Number number)) { | ||
| throw new ContentException(Messages.PARAMETER_0_MUST_BE_A_NUMBER, parameterName); | ||
| } | ||
| int value = number.intValue(); | ||
| if (value < 0 || value > maxAllowedValue) { | ||
| throw new ContentException(Messages.PARAMETER_0_MUST_BE_POSITIVE_WITH_MAX_VALUE_1, parameterName, maxAllowedValue); | ||
| } | ||
| return Duration.ofSeconds(value); | ||
| } | ||
|
|
||
| public static Optional<Duration> parseDurationSafely(Object timeout) { | ||
| if (timeout == null || !(timeout instanceof Number number)) { | ||
| return Optional.empty(); | ||
| } | ||
| long seconds = number.longValue(); | ||
| return seconds > 0 ? Optional.of(Duration.ofSeconds(seconds)) : Optional.empty(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the method above we have max value, don't we need here also a max value? |
||
| } | ||
| } | ||
|
|
||
89 changes: 89 additions & 0 deletions
89
...-core/src/test/java/org/cloudfoundry/multiapps/controller/core/util/DurationUtilTest.java
This file contains hidden or 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,89 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.util; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Optional; | ||
|
|
||
| import org.cloudfoundry.multiapps.common.ContentException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class DurationUtilTest { | ||
|
|
||
| private static final String PARAM_NAME = "test-timeout"; | ||
| private static final int MAX_VALUE = 3600; | ||
|
|
||
| @Test | ||
| void testParseDurationWithValidValue() { | ||
| Duration result = DurationUtil.parseDuration(300, PARAM_NAME, MAX_VALUE); | ||
| assertEquals(Duration.ofSeconds(300), result); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithZero() { | ||
| Duration result = DurationUtil.parseDuration(0, PARAM_NAME, MAX_VALUE); | ||
| assertEquals(Duration.ZERO, result); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithMaxValue() { | ||
| Duration result = DurationUtil.parseDuration(MAX_VALUE, PARAM_NAME, MAX_VALUE); | ||
| assertEquals(Duration.ofSeconds(MAX_VALUE), result); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithNull() { | ||
| Duration result = DurationUtil.parseDuration(null, PARAM_NAME, MAX_VALUE); | ||
| assertNull(result); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithNegativeValue() { | ||
| assertThrows(ContentException.class, () -> DurationUtil.parseDuration(-1, PARAM_NAME, MAX_VALUE)); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithValueExceedingMax() { | ||
| assertThrows(ContentException.class, () -> DurationUtil.parseDuration(MAX_VALUE + 1, PARAM_NAME, MAX_VALUE)); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationWithNonNumber() { | ||
| assertThrows(ContentException.class, () -> DurationUtil.parseDuration("invalid", PARAM_NAME, MAX_VALUE)); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationSafelyWithValidValue() { | ||
| Optional<Duration> result = DurationUtil.parseDurationSafely(300); | ||
| assertTrue(result.isPresent()); | ||
| assertEquals(Duration.ofSeconds(300), result.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationSafelyWithNull() { | ||
| Optional<Duration> result = DurationUtil.parseDurationSafely(null); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationSafelyWithZero() { | ||
| Optional<Duration> result = DurationUtil.parseDurationSafely(0); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationSafelyWithNegative() { | ||
| Optional<Duration> result = DurationUtil.parseDurationSafely(-5); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testParseDurationSafelyWithNonNumber() { | ||
| Optional<Duration> result = DurationUtil.parseDurationSafely("invalid"); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.