-
Notifications
You must be signed in to change notification settings - Fork 909
[Default Configuration Part 2]:Implement auto mode discovery #2786
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
Merged
zoewangg
merged 4 commits into
feature/master/defaults-mode
from
zoewang/defaults-mode-2
Oct 26, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,15 @@ | |
import software.amazon.awssdk.regions.util.ResourcesEndpointProvider; | ||
|
||
/** | ||
* Utility class for retrieving Amazon EC2 instance metadata.<br> | ||
|
||
* | ||
* Utility class for retrieving Amazon EC2 instance metadata. | ||
* | ||
* <p> | ||
* <b>Note</b>: this is an internal API subject to change. Users of the SDK | ||
* should not depend on this. | ||
* | ||
* <p> | ||
* You can use the data to build more generic AMIs that can be modified by | ||
* configuration files supplied at launch time. For example, if you run web | ||
* servers for various small businesses, they can all use the same AMI and | ||
|
@@ -361,7 +369,7 @@ public static List<String> getItems(String path, int tries) { | |
} | ||
|
||
@SdkTestInternalApi | ||
static void clearCache() { | ||
public static void clearCache() { | ||
CACHE.clear(); | ||
} | ||
|
||
|
@@ -391,6 +399,11 @@ private static List<String> getItems(String path, int tries, boolean slurp) { | |
log.warn("Unable to retrieve the requested metadata."); | ||
return null; | ||
} catch (IOException | URISyntaxException | RuntimeException e) { | ||
// If there is no retry available, just throw exception instead of pausing. | ||
if (tries - 1 == 0) { | ||
throw SdkClientException.builder().message("Unable to contact EC2 metadata service.").cause(e).build(); | ||
} | ||
|
||
// Retry on any other exceptions | ||
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. I think this comment got slightly lost from what it was referencing, on line 401. Edit: Upon second read, maybe it's fine. |
||
int pause = (int) (Math.pow(2, DEFAULT_QUERY_RETRIES - tries) * MINIMUM_RETRY_WAIT_TIME_MILLISECONDS); | ||
try { | ||
|
@@ -427,19 +440,30 @@ public static String getToken() { | |
} | ||
} | ||
|
||
|
||
private static String fetchData(String path) { | ||
return fetchData(path, false); | ||
} | ||
|
||
private static String fetchData(String path, boolean force) { | ||
return fetchData(path, force, DEFAULT_QUERY_RETRIES); | ||
zoewangg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Fetch data using the given path | ||
* | ||
* @param path the path | ||
* @param force whether to force to override the value in the cache | ||
* @param attempts the number of attempts that should be executed. | ||
* @return the value retrieved from the path | ||
*/ | ||
public static String fetchData(String path, boolean force, int attempts) { | ||
if (SdkSystemSetting.AWS_EC2_METADATA_DISABLED.getBooleanValueOrThrow()) { | ||
throw SdkClientException.builder().message("EC2 metadata usage is disabled.").build(); | ||
} | ||
|
||
try { | ||
if (force || !CACHE.containsKey(path)) { | ||
CACHE.put(path, getData(path)); | ||
CACHE.put(path, getData(path, attempts)); | ||
} | ||
return CACHE.get(path); | ||
} catch (SdkClientException e) { | ||
|
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
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.