Skip to content

Conversation

@srsaikumarreddy
Copy link
Contributor

Implemented Happy Path client functionality along with Request Marshaller Class

Motivation and Context

Implemented Happy Path client functionality along with Request Marshaller Class

Modifications

Implemented Happy Path client functionality along with Request Marshaller Class. Wrote test cases to check exception handling behavior

Testing

Ran test cases locally in development environment.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • [X ] I have read the CONTRIBUTING document
  • [ X] Local run of mvn install succeeds
  • [ X] My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • [ X] I have added tests to cover my changes
  • [ X] All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • [ X] I confirm that this pull request can be released under the Apache 2 license

@srsaikumarreddy srsaikumarreddy requested a review from a team as a code owner July 1, 2022 05:47

private final SdkHttpClient httpClient;

private final Logger log = LoggerFactory.getLogger(DefaultEc2Metadata.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.


private final Logger log = LoggerFactory.getLogger(DefaultEc2Metadata.class);

private RequestMarshaller requestMarshaller = new RequestMarshaller();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

try {
String token = getToken();
URI uri = URI.create(endpoint + path);
HttpExecuteRequest httpExecuteRequest = requestMarshaller.createDataRequest(uri , SdkHttpMethod.GET, token,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space before comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch . Surprising that when I ran checkstyle during local build , it did not show up as warning/error.

URI uri = URI.create(endpoint + path);
HttpExecuteRequest httpExecuteRequest = requestMarshaller.createDataRequest(uri , SdkHttpMethod.GET, token,
tokenTtl);
HttpExecuteResponse response = httpClient.prepareRequest(httpExecuteRequest).call();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space after =

Comment on lines 195 to 196
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN || statusCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw SdkServiceException.builder().message("Could not retrieve token").build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log the status code? Any reason to have this be a different case than just the else clause below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status codes mentioned , should not have retries enabled on them. But for the below else case , retries can happen.

throw SdkServiceException.builder().message("Could not retrieve token").build();
} else {
throw SdkClientException.builder()
.message("Unexpected Exception during token retrieval with Status Code " + statusCode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

} else {
throw SdkClientException.builder()
.message("Unexpected Exception during token retrieval with Status Code " + statusCode)
.message("Instance metadata service returned unexpected status code " + statusCode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the response body isn't present then we'd get unexpected status code 200. Should we special-case the response body not being present with a better error message?

@srsaikumarreddy srsaikumarreddy force-pushed the saikred/feature/happy_path branch from bd36583 to cb67094 Compare July 6, 2022 23:45
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 7, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

18.3% 18.3% Coverage
0.0% 0.0% Duplication

@millems millems merged commit bca70cf into aws:feature/master/imds Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants