-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Support connecting to Kerberos secured Kafka #7990, updated to Kafka 0.10.1.2 #8394
Closed
Closed
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dcc11c9
Merge pull request #1 from prestodb/master
madhurkumar f5a6606
Updated to Kafka 0.10.1.2, support for security protocol through new …
a90dea9
Support connecting to Kerberos secured Kafka #7990, updated to Kafka …
031cd2c
Support connecting to Kerberos secured Kafka #7990, updated to Kafka …
71b8c68
Support connecting to Kerberos secured Kafka #7990, updated to Kafka …
bb9976f
Support for message timestamp @ 0.10.1.1.
6a1db5c
Merge branch 'master' of https://github.com/prestodb/presto
madhurkumar 2c99cf1
fix style check and split manager interface change
madhurkumar 64c68ee
Security protocol values as enum
madhurkumar a0c036a
Fixed test for security protocol enum values
madhurkumar 72c6691
newline added.
madhurkumar e331a78
Merge branch 'master' of https://github.com/prestodb/presto
madhurkumar 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
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
102 changes: 102 additions & 0 deletions
102
presto-kafka/src/main/java/com/facebook/presto/kafka/KafkaConsumerManager.java
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.kafka; | ||
|
||
import com.facebook.presto.spi.HostAddress; | ||
import com.facebook.presto.spi.NodeManager; | ||
import com.google.common.base.Throwables; | ||
import io.airlift.log.Logger; | ||
import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.StringJoiner; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.lang.Math.toIntExact; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Manages connections to the Kafka nodes. A worker may connect to multiple Kafka nodes depending on the segments and partitions | ||
* it needs to process. According to the Kafka source code, a Kafka {@link kafka.javaapi.consumer.SimpleConsumer} is thread-safe. | ||
*/ | ||
public class KafkaConsumerManager | ||
{ | ||
private static final Logger log = Logger.get(KafkaConsumerManager.class); | ||
private static final String messageDeserializer = "org.apache.kafka.common.serialization.ByteArrayDeserializer"; | ||
|
||
private final String connectorId; | ||
private final NodeManager nodeManager; | ||
private final int connectTimeoutMillis; | ||
private final int bufferSizeBytes; | ||
private final String securityProtocol; | ||
private final boolean autoCommit; | ||
private final String bootStrapServers; | ||
|
||
@Inject | ||
public KafkaConsumerManager( | ||
KafkaConnectorId connectorId, | ||
KafkaConnectorConfig kafkaConnectorConfig, | ||
NodeManager nodeManager) | ||
{ | ||
this.connectorId = requireNonNull(connectorId, "connectorId is null").toString(); | ||
this.nodeManager = requireNonNull(nodeManager, "nodeManager is null"); | ||
requireNonNull(kafkaConnectorConfig, "kafkaConfig is null"); | ||
this.connectTimeoutMillis = toIntExact(kafkaConnectorConfig.getKafkaConnectTimeout().toMillis()); | ||
this.bufferSizeBytes = toIntExact(kafkaConnectorConfig.getKafkaBufferSize().toBytes()); | ||
this.securityProtocol = kafkaConnectorConfig.getSecurityProtocol(); | ||
this.autoCommit = kafkaConnectorConfig.isAutoCommit(); | ||
this.bootStrapServers = bootstrapServers(kafkaConnectorConfig.getNodes()); | ||
} | ||
|
||
public KafkaConsumer<byte[], byte[]> getConsumer() | ||
{ | ||
return getConsumer(bootStrapServers); | ||
} | ||
|
||
public KafkaConsumer<byte[], byte[]> getConsumer(Set<HostAddress> nodes) | ||
{ | ||
return getConsumer(bootstrapServers(nodes)); | ||
} | ||
|
||
private KafkaConsumer<byte[], byte[]> getConsumer(String bootstrapServers) | ||
{ | ||
try { | ||
Thread.currentThread().setContextClassLoader(null); | ||
Properties prop = new Properties(); | ||
prop.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootStrapServers); | ||
prop.put(ConsumerConfig.GROUP_ID_CONFIG, connectorId + "-presto"); | ||
prop.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, String.valueOf(autoCommit)); | ||
prop.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, messageDeserializer); | ||
prop.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, messageDeserializer); | ||
prop.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); | ||
prop.put(ConsumerConfig.CLIENT_ID_CONFIG, "consumer_" + connectorId + "_" + ThreadLocalRandom.current().nextInt() + "_" + System.currentTimeMillis()); | ||
prop.put("security.protocol", securityProtocol); | ||
return new KafkaConsumer<byte[], byte[]>(prop); | ||
} | ||
catch (Exception e) { | ||
throw Throwables.propagate(e.getCause()); | ||
} | ||
} | ||
|
||
private String bootstrapServers(Set<HostAddress> nodes) | ||
{ | ||
return nodes.stream().map(ha -> new StringJoiner(":").add(ha.getHostText()).add(String.valueOf(ha.getPort())).toString()) | ||
.collect(Collectors.joining(",")); | ||
} | ||
} |
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
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.
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.
This should be an enum, so that the possible values can be validated