-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
pulsar connector accepts auth params #22028
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,18 +53,23 @@ public class ReadFromPulsarDoFn extends DoFn<PulsarSourceDescriptor, PulsarMessa | |
private PulsarAdmin admin; | ||
private String clientUrl; | ||
private String adminUrl; | ||
private String authPluginClassName; | ||
private String authParameters; | ||
|
||
private final SerializableFunction<Message<byte[]>, Instant> extractOutputTimestampFn; | ||
|
||
public ReadFromPulsarDoFn(PulsarIO.Read transform) { | ||
this.extractOutputTimestampFn = transform.getExtractOutputTimestampFn(); | ||
this.clientUrl = transform.getClientUrl(); | ||
this.adminUrl = transform.getAdminUrl(); | ||
this.authPluginClassName = transform.getAuthPluginClassName(); | ||
this.authParameters = transform.getAuthParameters(); | ||
this.pulsarClientSerializableFunction = transform.getPulsarClient(); | ||
} | ||
|
||
// Open connection to Pulsar clients | ||
@Setup | ||
// TODO add auth related | ||
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. What is TODO here? |
||
public void initPulsarClients() throws Exception { | ||
if (this.clientUrl == null) { | ||
this.clientUrl = PulsarIOUtils.SERVICE_URL; | ||
|
@@ -76,14 +81,19 @@ public void initPulsarClients() throws Exception { | |
if (this.client == null) { | ||
this.client = pulsarClientSerializableFunction.apply(this.clientUrl); | ||
if (this.client == null) { | ||
this.client = PulsarClient.builder().serviceUrl(clientUrl).build(); | ||
this.client = | ||
PulsarClient.builder() | ||
.serviceUrl(clientUrl) | ||
.authentication(authPluginClassName, authParameters) | ||
.build(); | ||
} | ||
} | ||
|
||
if (this.admin == null) { | ||
this.admin = | ||
PulsarAdmin.builder() | ||
.serviceHttpUrl(adminUrl) | ||
.authentication(authPluginClassName, authParameters) | ||
.tlsTrustCertsFilePath(null) | ||
.allowTlsInsecureConnection(false) | ||
.build(); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ public void testInitialRestrictionWhenHasStartOffset() throws Exception { | |
OffsetRange result = | ||
dofnInstance.getInitialRestriction( | ||
PulsarSourceDescriptor.of( | ||
TOPIC, expectedStartOffset, null, null, SERVICE_URL, ADMIN_URL)); | ||
TOPIC, expectedStartOffset, null, null, SERVICE_URL, ADMIN_URL, null, null)); | ||
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. Please, add the tests with non-null auth values. |
||
assertEquals(new OffsetRange(expectedStartOffset, Long.MAX_VALUE), result); | ||
} | ||
|
||
|
@@ -87,7 +87,7 @@ public void testInitialRestrictionWithConsumerPosition() throws Exception { | |
OffsetRange result = | ||
dofnInstance.getInitialRestriction( | ||
PulsarSourceDescriptor.of( | ||
TOPIC, expectedStartOffset, null, null, SERVICE_URL, ADMIN_URL)); | ||
TOPIC, expectedStartOffset, null, null, SERVICE_URL, ADMIN_URL, null, null)); | ||
assertEquals(new OffsetRange(expectedStartOffset, Long.MAX_VALUE), result); | ||
} | ||
|
||
|
@@ -97,7 +97,8 @@ public void testInitialRestrictionWithConsumerEndPosition() throws Exception { | |
long endOffset = fakePulsarReader.getEndTimestamp(); | ||
OffsetRange result = | ||
dofnInstance.getInitialRestriction( | ||
PulsarSourceDescriptor.of(TOPIC, startOffset, endOffset, null, SERVICE_URL, ADMIN_URL)); | ||
PulsarSourceDescriptor.of( | ||
TOPIC, startOffset, endOffset, null, SERVICE_URL, ADMIN_URL, null, null)); | ||
assertEquals(new OffsetRange(startOffset, endOffset), result); | ||
} | ||
|
||
|
@@ -108,7 +109,8 @@ public void testProcessElement() throws Exception { | |
long endOffset = fakePulsarReader.getEndTimestamp(); | ||
OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(startOffset, endOffset)); | ||
PulsarSourceDescriptor descriptor = | ||
PulsarSourceDescriptor.of(TOPIC, startOffset, endOffset, null, SERVICE_URL, ADMIN_URL); | ||
PulsarSourceDescriptor.of( | ||
TOPIC, startOffset, endOffset, null, SERVICE_URL, ADMIN_URL, null, null); | ||
DoFn.ProcessContinuation result = | ||
dofnInstance.processElement(descriptor, tracker, null, (DoFn.OutputReceiver) receiver); | ||
int expectedResultWithoutCountingLastOffset = NUMBEROFMESSAGES - 1; | ||
|
@@ -123,7 +125,8 @@ public void testProcessElementWhenEndMessageIdIsDefined() throws Exception { | |
MessageId endMessageId = DefaultImplementation.newMessageId(50L, 50L, 50); | ||
DoFn.ProcessContinuation result = | ||
dofnInstance.processElement( | ||
PulsarSourceDescriptor.of(TOPIC, null, null, endMessageId, SERVICE_URL, ADMIN_URL), | ||
PulsarSourceDescriptor.of( | ||
TOPIC, null, null, endMessageId, SERVICE_URL, ADMIN_URL, null, null), | ||
tracker, | ||
null, | ||
(DoFn.OutputReceiver) receiver); | ||
|
@@ -138,7 +141,7 @@ public void testProcessElementWithEmptyRecords() throws Exception { | |
OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(0L, Long.MAX_VALUE)); | ||
DoFn.ProcessContinuation result = | ||
dofnInstance.processElement( | ||
PulsarSourceDescriptor.of(TOPIC, null, null, null, SERVICE_URL, ADMIN_URL), | ||
PulsarSourceDescriptor.of(TOPIC, null, null, null, SERVICE_URL, ADMIN_URL, null, null), | ||
tracker, | ||
null, | ||
(DoFn.OutputReceiver) receiver); | ||
|
@@ -153,7 +156,7 @@ public void testProcessElementWhenHasReachedEndTopic() throws Exception { | |
OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(0L, Long.MAX_VALUE)); | ||
DoFn.ProcessContinuation result = | ||
dofnInstance.processElement( | ||
PulsarSourceDescriptor.of(TOPIC, null, null, null, SERVICE_URL, ADMIN_URL), | ||
PulsarSourceDescriptor.of(TOPIC, null, null, null, SERVICE_URL, ADMIN_URL, null, null), | ||
tracker, | ||
null, | ||
(DoFn.OutputReceiver) receiver); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a public method then it would be better to provide another an overloaded method with the same name and additional arguments.
If this class and method are not supposed to be used by user then it should be private or package private to avoid potential breaking changes like this.