Skip to content
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

Solace Read connector: adding implementations of SempClient and SempClientFactory #31542

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

bzablocki
Copy link
Contributor

@bzablocki bzablocki commented Jun 7, 2024

This is the 4th PR for the Solace Read connector (addresses #31440).
It depends on the #31541, #31539 and #31476 (root).

The files that are added/modified in this PR, comparing to the #31541:

  • build.gradle
  • BasicAuthSempClient.java
  • BasicAuthSempClientFactory.java
  • BrokerResponse.java
  • SempBasicAuthClientExecutor.java
  • Semp.java
  • package-info.java
  • SerializableSupplier.java
  • SempBasicAuthClientExecutorTest.java

These are implementations of SempClient and SempClientFactory. SempClientFactory can be used as an argument to SolaceIO.Read.withSempClientFactory(...).


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@bzablocki
Copy link
Contributor Author

assign set of reviewers

Copy link
Contributor

github-actions bot commented Jul 2, 2024

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @Abacn for label java.
R: @shunping for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

Thanks, left a few comments

}

private HttpResponse execute(HttpRequest request) throws IOException {
request.setNumberOfRetries(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

what consideration here for retry twice? Good to have comment for occurrence of hardcoded numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extracted the variable and added a comment.

COOKIE_MANAGER.getCookieStore().removeAll();
// execute again without cookies to refresh the token.
return execute(request);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

there may be other retriable return codes? e.g. from the spec does it possible to return server side error 50X, rate limiting 429, etc. Fine to leave as is for now but good to comment here if we do want to handle them in the future what should be done

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 point, I'll leave a comment to consider handling it in the future

try {
response = request.execute();
} catch (HttpResponseException e) {
if (authFromCookie && e.getStatusCode() == 401) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this (make a request and check for 401) the only way to refresh token?

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 Solace documentation lacks guidance on detecting token expiration. Typically, tokens include an expires_in field for calculating refresh times. However, Solace seems to omit this information. Currently, the only way to check token validity is by sending a request and looking for a 401 Unauthorized response, which would then trigger token refresh.

private HttpResponse execute(HttpRequest request) throws IOException {
request.setNumberOfRetries(2);
HttpHeaders httpHeaders = new HttpHeaders();
boolean authFromCookie = COOKIE_MANAGER.getCookieStore().getCookies().size() > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

The COOKIE_MANAGER is worker wide, suppose there are two SolaceIO sources from different servers, could there be conflict? Should the static COOKIE_MANAGER be a map keyed with destination?

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 point, changed to a ConcurrentHashMap to make sure it's thread-safe.

@Abacn Abacn merged commit 8a88f15 into apache:master Jul 8, 2024
23 checks passed
acrites pushed a commit to acrites/beam that referenced this pull request Jul 17, 2024
…lientFactory (apache#31542)

* Adding implementations of SempClient and SempClientFactory

* Use core SerializableSupplier, remove SuppressWarnings, extract number to a variable, cookie store map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants