本文整理匯總了Java中org.apache.kafka.common.security.JaasUtils類的典型用法代碼示例。如果您正苦於以下問題:Java JaasUtils類的具體用法?Java JaasUtils怎麽用?Java JaasUtils使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
JaasUtils類屬於org.apache.kafka.common.security包,在下文中一共展示了JaasUtils類的36個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: setUpClass
點讚 4
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
@BeforeClass
public static void setUpClass() throws Exception {
int zkConnectionTimeout = 6000;
int zkSessionTimeout = 6000;
zookeeper = new EmbeddedZookeeper();
zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
zkUtils = ZkUtils.apply(
zkConnect, zkSessionTimeout, zkConnectionTimeout,
JaasUtils.isZkSecurityEnabled());
port = NetworkUtils.getRandomPort();
kafkaServer = TestUtil09.createKafkaServer(port, zkConnect);
for (int i = 0; i < topics.length; i++) {
topics[i] = UUID.randomUUID().toString();
AdminUtils.createTopic(zkUtils, topics[i], 1, 1, new Properties());
TestUtils.waitUntilMetadataIsPropagated(
scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(kafkaServer)),
topics[i], 0, 5000);
}
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:23,
示例2: createJaasConfiguration
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private void createJaasConfiguration( String userName, String password) throws Throwable{
//Create the jaas configuration
String packageName = MessageHubConfig.class.getPackage().getName().replace('.', File.separatorChar);
try(InputStream is = MessageHubConfig.class.getClassLoader().getResourceAsStream( packageName + "/jaas.conf")){
BufferedReader br = new BufferedReader(new InputStreamReader( is ) );
StringBuilder sb = new StringBuilder();
String line = null;
while ( (line = br.readLine()) != null ){
sb.append( line.replace( "$USERNAME", userName).replace( "$PASSWORD", password ));
}
File confDir= new File( System.getProperty("java.io.tmpdir") + File.separator + fixPath( userName ) );
confDir.mkdirs();
File confFile = new File( confDir, "jaas.conf");
FileWriter fw = new FileWriter( confFile );
fw.write( sb.toString() );
fw.close();
//Set the jaas login config property
System.out.println("Registering JaasConfiguration: " + confFile.getAbsolutePath());
System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, confFile.getAbsolutePath() );
}catch (Throwable t){
t.printStackTrace();
throw t;
}
}
開發者ID:ibm-watson-data-lab,項目名稱:advo-beta-producer,代碼行數:27,
示例3: lookupBootstrap
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* Generates the Kafka bootstrap connection string from the metadata stored in Zookeeper.
* Allows for backwards compatibility of the zookeeperConnect configuration.
*/
private String lookupBootstrap(String zookeeperConnect, SecurityProtocol securityProtocol) {
ZkUtils zkUtils = ZkUtils.apply(zookeeperConnect, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT,
JaasUtils.isZkSecurityEnabled());
try {
List endPoints =
asJavaListConverter(zkUtils.getAllBrokerEndPointsForChannel(securityProtocol)).asJava();
List connections = new ArrayList<>();
for (BrokerEndPoint endPoint : endPoints) {
connections.add(endPoint.connectionString());
}
return StringUtils.join(connections, ',');
} finally {
zkUtils.close();
}
}
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:20,
示例4: getServiceName
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private static String getServiceName(Map configs, JaasContext jaasContext) {
String jaasServiceName = jaasContext.configEntryOption(JaasUtils.SERVICE_NAME, null);
String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
String message = String.format("Conflicting serviceName values found in JAAS and Kafka configs " +
"value in JAAS file %s, value in Kafka config %s", jaasServiceName, configServiceName);
throw new IllegalArgumentException(message);
}
if (jaasServiceName != null)
return jaasServiceName;
if (configServiceName != null)
return configServiceName;
throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:17,
示例5: login
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
@Override
public LoginContext login() throws LoginException {
String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);
if (jaasConfigFile == null) {
log.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is not set, using default JAAS configuration.");
}
AppConfigurationEntry[] configEntries = Configuration.getConfiguration().getAppConfigurationEntry(loginContextName);
if (configEntries == null) {
String errorMessage = "Could not find a '" + loginContextName + "' entry in the JAAS configuration. System property '" +
JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is " + (jaasConfigFile == null ? "not set" : jaasConfigFile);
throw new IllegalArgumentException(errorMessage);
}
loginContext = new LoginContext(loginContextName, new LoginCallbackHandler());
loginContext.login();
log.info("Successfully logged in.");
return loginContext;
}
開發者ID:txazo,項目名稱:kafka,代碼行數:19,
示例6: getServiceName
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private String getServiceName(Map configs, String loginContext) {
String jaasServiceName;
try {
jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);
} catch (IOException e) {
throw new KafkaException("Jaas configuration not found", e);
}
String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
String message = "Conflicting serviceName values found in JAAS and Kafka configs " +
"value in JAAS file " + jaasServiceName + ", value in Kafka config " + configServiceName;
throw new IllegalArgumentException(message);
}
if (jaasServiceName != null)
return jaasServiceName;
if (configServiceName != null)
return configServiceName;
throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
開發者ID:txazo,項目名稱:kafka,代碼行數:22,
示例7: createMonitoringTopicIfNotExists
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* Create the topic that the monitor uses to monitor the cluster. This method attempts to create a topic so that all
* the brokers in the cluster will have partitionToBrokerRatio partitions. If the topic exists, but has different parameters
* then this does nothing to update the parameters.
*
* TODO: Do we care about rack aware mode? I would think no because we want to spread the topic over all brokers.
* @param zkUrl zookeeper connection url
* @param topic topic name
* @param replicationFactor the replication factor for the topic
* @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic.
* @param topicConfig additional parameters for the topic for example min.insync.replicas
* @return the number of partitions created
*/
public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor,
double partitionToBrokerRatio, Properties topicConfig) {
ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
try {
if (AdminUtils.topicExists(zkUtils, topic)) {
return getPartitionNumForTopic(zkUrl, topic);
}
int brokerCount = zkUtils.getAllBrokersInCluster().size();
int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio);
try {
AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$);
} catch (TopicExistsException e) {
//There is a race condition with the consumer.
LOG.debug("Monitoring topic " + topic + " already exists in cluster " + zkUrl, e);
return getPartitionNumForTopic(zkUrl, topic);
}
LOG.info("Created monitoring topic " + topic + " in cluster " + zkUrl + " with " + partitionCount + " partitions, min ISR of "
+ topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + ".");
return partitionCount;
} finally {
zkUtils.close();
}
}
開發者ID:linkedin,項目名稱:kafka-monitor,代碼行數:39,
示例8: initKafka
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
@BeforeClass
public static void initKafka() throws Exception {
synchronized (TestKafkaSuit.class) {
if (initCount.get() == 0) {
ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, ClassLoader.getSystemResource(LOGIN_CONF_RESOURCE_PATHNAME).getFile());
embeddedKafkaCluster = new EmbeddedKafkaCluster();
Properties topicProps = new Properties();
zkClient = new ZkClient(embeddedKafkaCluster.getZkServer().getConnectionString(), SESSION_TIMEOUT, CONN_TIMEOUT, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(embeddedKafkaCluster.getZkServer().getConnectionString()), false);
AdminUtils.createTopic(zkUtils, QueryConstants.JSON_TOPIC, 1, 1, topicProps, RackAwareMode.Disabled$.MODULE$);
org.apache.kafka.common.requests.MetadataResponse.TopicMetadata fetchTopicMetadataFromZk = AdminUtils
.fetchTopicMetadataFromZk(QueryConstants.JSON_TOPIC, zkUtils);
logger.info("Topic Metadata: " + fetchTopicMetadataFromZk);
KafkaMessageGenerator generator = new KafkaMessageGenerator(embeddedKafkaCluster.getKafkaBrokerList(),
StringSerializer.class);
generator.populateJsonMsgIntoKafka(QueryConstants.JSON_TOPIC, NUM_JSON_MSG);
}
initCount.incrementAndGet();
runningSuite = true;
}
logger.info("Initialized Embedded Zookeeper and Kafka");
}
開發者ID:axbaretto,項目名稱:drill,代碼行數:26,
示例9: alterTopic
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
*
Title: alterTopic
*
Description: 修改隊列操作
*
* @param zookeeperStr zookeeper地址
* @param topic 隊列名稱
* @param config 配置參數
*/
public static void alterTopic(String zookeeperStr, String topic,
String... config) {
StringBuffer updateOptions = new StringBuffer();
updateOptions.append("--alter").append(space)
.append("--topic").append(space).append(topic);
for (int i = 0; i < config.length; i++) {
if (config[i].indexOf("=") > 0)
updateOptions.append(space).append("--config").append(space)
.append(config[i]);
else
updateOptions.append(space).append("--delete-config")
.append(space).append(config[i]);
}
TopicCommand.alterTopic(ZkUtils.apply(zookeeperStr,
sessionTimeout, connectionTimeout,
JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
updateOptions.toString().split(space)));
}
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:33,
示例10: before
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
@Override
protected void before() throws Throwable {
logDirectory = tempDir(perTest("kafka-log"));
Properties properties = brokerDefinition.getProperties();
properties.setProperty(KafkaConfig.LogDirProp(), logDirectory.getCanonicalPath());
kafkaServer = new KafkaServer(new KafkaConfig(properties),
SystemTime$.MODULE$, Some$.MODULE$.apply("kafkaServer"));
kafkaServer.startup();
List topicDefinitions = brokerDefinition.getTopicDefinitions();
if (!topicDefinitions.isEmpty()) {
ZkUtils zkUtils = ZkUtils.apply(brokerDefinition.getZookeeperConnect(), 30000, 30000,
JaasUtils.isZkSecurityEnabled());
for (TopicDefinition topicDefinition : topicDefinitions) {
String name = topicDefinition.getName();
log.info("Creating topic {}", name);
AdminUtils.createTopic(zkUtils,
name,
topicDefinition.getPartitions(),
topicDefinition.getReplicationFactor(),
topicDefinition.getProperties());
}
}
}
開發者ID:jkorab,項目名稱:ameliant-tools,代碼行數:25,
示例11: login
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private synchronized LoginContext login(final String loginContextName) throws LoginException {
String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);
if (jaasConfigFile == null) {
throw new IllegalArgumentException("You must pass " + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + " in secure mode.");
}
AppConfigurationEntry[] configEntries = Configuration.getConfiguration().getAppConfigurationEntry(loginContextName);
if (configEntries == null) {
String errorMessage = "Could not find a '" + loginContextName + "' entry in `" + jaasConfigFile + "`.";
throw new IllegalArgumentException(errorMessage);
}
LoginContext loginContext = new LoginContext(loginContextName, callbackHandler);
loginContext.login();
log.info("Successfully logged in.");
return loginContext;
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:17,
示例12: getServiceName
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private String getServiceName(Map configs, String loginContext) {
String jaasServiceName = null;
try {
jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);
} catch (IOException e) {
//throw new KafkaException("Jaas configuration not found", e);
log.warn("Jaas configuration not found", e);
}
String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
String message = "Conflicting serviceName values found in JAAS and Kafka configs " +
"value in JAAS file " + jaasServiceName + ", value in Kafka config " + configServiceName;
throw new IllegalArgumentException(message);
}
if (jaasServiceName != null)
return jaasServiceName;
if (configServiceName != null)
return configServiceName;
throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:23,
示例13: LocalKafkaServer
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public LocalKafkaServer() throws IOException {
while (new File(logDir).exists()) {
FileUtils.deleteDirectory(new File(logDir));
}
Properties props = new Properties();
props.put("broker.id", nodeId);
props.put("port", port);
props.put("log.dir", logDir);
props.put("zookeeper.connect", zkConnect);
props.put("host.name", "127.0.0.1");
KafkaConfig conf = new KafkaConfig(props);
zkUtils = ZkUtils.apply(props.getProperty("zookeeper.connect"),
30000,
30000,
JaasUtils.isZkSecurityEnabled());
server = new KafkaServerStartable(conf);
server.startup();
}
開發者ID:blackberry,項目名稱:Krackle,代碼行數:24,
示例14: createTopic
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public static void createTopic(String topicName, int numPartitions, int zkPort) {
// setup
String[] arguments = new String[9];
arguments[0] = "--create";
arguments[1] = "--zookeeper";
arguments[2] = "127.0.0.1:" + zkPort;
arguments[3] = "--replication-factor";
arguments[4] = "1";
arguments[5] = "--partitions";
arguments[6] = "" + Integer.valueOf(numPartitions);
arguments[7] = "--topic";
arguments[8] = topicName;
TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments);
ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000,
JaasUtils.isZkSecurityEnabled());
TopicCommand.createTopic(zkUtils, opts);
}
開發者ID:DDTH,項目名稱:ddth-kafka,代碼行數:19,
示例15: createTopic
點讚 3
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private static void createTopic(String topicName, int numPartitions, int zkPort) {
// setup
String[] arguments = new String[9];
arguments[0] = "--create";
arguments[1] = "--zookeeper";
arguments[2] = "127.0.0.1:" + zkPort;
arguments[3] = "--replication-factor";
arguments[4] = "1";
arguments[5] = "--partitions";
arguments[6] = "" + Integer.valueOf(numPartitions);
arguments[7] = "--topic";
arguments[8] = topicName;
TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments);
ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000,
JaasUtils.isZkSecurityEnabled());
TopicCommand.createTopic(zkUtils, opts);
}
開發者ID:DDTH,項目名稱:ddth-kafka,代碼行數:19,
示例16: createKafkaTopicIfNecessary
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public static boolean createKafkaTopicIfNecessary(String brokerUri, int replFactor, int numPartitions, String topic)
throws IOException {
URI zkUri = URI.create(brokerUri);
Preconditions.checkArgument("zk".equals(zkUri.getScheme()));
String zkServerList = zkUri.getAuthority() + zkUri.getPath();
ZkUtils zkUtils = ZkUtils.apply(zkServerList, ZK_SESSION_TIMEOUT_MS,
ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
try {
if (AdminUtils.topicExists(zkUtils, topic)) {
return false;
}
try {
AdminUtils.createTopic(zkUtils, topic, numPartitions, replFactor, new Properties());
} catch (TopicExistsException ignored) {
return false;
} catch (RuntimeException e) {
throw new IOException(e);
}
} finally {
if (zkUtils != null) {
zkUtils.close();
}
}
return true;
}
開發者ID:uber,項目名稱:AthenaX,代碼行數:28,
示例17: migrateOffsets
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private void migrateOffsets(String topicStr) {
ZkUtils zkUtils = ZkUtils.apply(zookeeperConnect, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT,
JaasUtils.isZkSecurityEnabled());
KafkaConsumer consumer = new KafkaConsumer<>(kafkaProps);
try {
Map kafkaOffsets =
getKafkaOffsets(consumer, topicStr);
if (!kafkaOffsets.isEmpty()) {
log.info("Found Kafka offsets for topic " + topicStr +
". Will not migrate from zookeeper");
log.debug("Offsets found: {}", kafkaOffsets);
return;
}
log.info("No Kafka offsets found. Migrating zookeeper offsets");
Map zookeeperOffsets =
getZookeeperOffsets(zkUtils, topicStr);
if (zookeeperOffsets.isEmpty()) {
log.warn("No offsets to migrate found in Zookeeper");
return;
}
log.info("Committing Zookeeper offsets to Kafka");
log.debug("Offsets to commit: {}", zookeeperOffsets);
consumer.commitSync(zookeeperOffsets);
// Read the offsets to verify they were committed
Map newKafkaOffsets =
getKafkaOffsets(consumer, topicStr);
log.debug("Offsets committed: {}", newKafkaOffsets);
if (!newKafkaOffsets.keySet().containsAll(zookeeperOffsets.keySet())) {
throw new FlumeException("Offsets could not be committed");
}
} finally {
zkUtils.close();
consumer.close();
}
}
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:38,
示例18: migrateOffsets
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private void migrateOffsets() {
ZkUtils zkUtils = ZkUtils.apply(zookeeperConnect, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT,
JaasUtils.isZkSecurityEnabled());
KafkaConsumer consumer = new KafkaConsumer<>(consumerProps);
try {
Map kafkaOffsets = getKafkaOffsets(consumer);
if (!kafkaOffsets.isEmpty()) {
logger.info("Found Kafka offsets for topic " + topicStr +
". Will not migrate from zookeeper");
logger.debug("Offsets found: {}", kafkaOffsets);
return;
}
logger.info("No Kafka offsets found. Migrating zookeeper offsets");
Map zookeeperOffsets = getZookeeperOffsets(zkUtils);
if (zookeeperOffsets.isEmpty()) {
logger.warn("No offsets to migrate found in Zookeeper");
return;
}
logger.info("Committing Zookeeper offsets to Kafka");
logger.debug("Offsets to commit: {}", zookeeperOffsets);
consumer.commitSync(zookeeperOffsets);
// Read the offsets to verify they were committed
Map newKafkaOffsets = getKafkaOffsets(consumer);
logger.debug("Offsets committed: {}", newKafkaOffsets);
if (!newKafkaOffsets.keySet().containsAll(zookeeperOffsets.keySet())) {
throw new FlumeException("Offsets could not be committed");
}
} finally {
zkUtils.close();
consumer.close();
}
}
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:35,
示例19: start
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* Creates and starts a Kafka cluster.
*/
public void start() throws IOException, InterruptedException {
log.debug("Initiating embedded Kafka cluster startup");
log.debug("Starting a ZooKeeper instance");
zookeeper = new EmbeddedZookeeper();
log.debug("ZooKeeper instance is running at {}", zKConnectString());
zkUtils = ZkUtils.apply(
zKConnectString(),
30000,
30000,
JaasUtils.isZkSecurityEnabled());
brokerConfig.put(KafkaConfig$.MODULE$.ZkConnectProp(), zKConnectString());
brokerConfig.put(KafkaConfig$.MODULE$.PortProp(), DEFAULT_BROKER_PORT);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.DeleteTopicEnableProp(), true);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.LogCleanerDedupeBufferSizeProp(), 2 * 1024 * 1024L);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.GroupMinSessionTimeoutMsProp(), 0);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.GroupInitialRebalanceDelayMsProp(), 0);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.OffsetsTopicReplicationFactorProp(), (short) 1);
putIfAbsent(brokerConfig, KafkaConfig$.MODULE$.AutoCreateTopicsEnableProp(), true);
for (int i = 0; i < brokers.length; i++) {
brokerConfig.put(KafkaConfig$.MODULE$.BrokerIdProp(), i);
log.debug("Starting a Kafka instance on port {} ...", brokerConfig.getProperty(KafkaConfig$.MODULE$.PortProp()));
brokers[i] = new KafkaEmbedded(brokerConfig, time);
log.debug("Kafka instance is running at {}, connected to ZooKeeper at {}",
brokers[i].brokerList(), brokers[i].zookeeperConnect());
}
}
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:34,
示例20: assertInternalTopicsGotDeleted
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
private void assertInternalTopicsGotDeleted(final String intermediateUserTopic) {
final Set expectedRemainingTopicsAfterCleanup = new HashSet<>();
expectedRemainingTopicsAfterCleanup.add(INPUT_TOPIC);
if (intermediateUserTopic != null) {
expectedRemainingTopicsAfterCleanup.add(intermediateUserTopic);
}
expectedRemainingTopicsAfterCleanup.add(OUTPUT_TOPIC);
expectedRemainingTopicsAfterCleanup.add(OUTPUT_TOPIC_2);
expectedRemainingTopicsAfterCleanup.add(OUTPUT_TOPIC_2_RERUN);
expectedRemainingTopicsAfterCleanup.add("__consumer_offsets");
Set allTopics;
ZkUtils zkUtils = null;
try {
zkUtils = ZkUtils.apply(CLUSTER.zKConnectString(),
30000,
30000,
JaasUtils.isZkSecurityEnabled());
do {
Utils.sleep(100);
allTopics = new HashSet<>();
allTopics.addAll(scala.collection.JavaConversions.seqAsJavaList(zkUtils.getAllTopics()));
} while (allTopics.size() != expectedRemainingTopicsAfterCleanup.size());
} finally {
if (zkUtils != null) {
zkUtils.close();
}
}
assertThat(allTopics, equalTo(expectedRemainingTopicsAfterCleanup));
}
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:32,
示例21: configure
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public void configure(Map configs) throws KafkaException {
try {
this.configs = configs;
boolean hasKerberos;
if (mode == Mode.SERVER) {
List enabledMechanisms = (List) this.configs.get(SaslConfigs.SASL_ENABLED_MECHANISMS);
hasKerberos = enabledMechanisms == null || enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM);
} else {
hasKerberos = clientSaslMechanism.equals(SaslConfigs.GSSAPI_MECHANISM);
}
if (hasKerberos) {
String defaultRealm;
try {
defaultRealm = JaasUtils.defaultKerberosRealm();
} catch (Exception ke) {
defaultRealm = "";
}
@SuppressWarnings("unchecked")
List principalToLocalRules = (List) configs.get(SaslConfigs.SASL_KERBEROS_PRINCIPAL_TO_LOCAL_RULES);
if (principalToLocalRules != null)
kerberosShortNamer = KerberosShortNamer.fromUnparsedRules(defaultRealm, principalToLocalRules);
}
this.loginManager = LoginManager.acquireLoginManager(loginType, hasKerberos, configs);
if (this.securityProtocol == SecurityProtocol.SASL_SSL) {
// Disable SSL client authentication as we are using SASL authentication
this.sslFactory = new SslFactory(mode, "none");
this.sslFactory.configure(configs);
}
} catch (Exception e) {
throw new KafkaException(e);
}
}
開發者ID:txazo,項目名稱:kafka,代碼行數:35,
示例22: testInvalidLoginModule
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* Tests that connections cannot be created if the login module class is unavailable.
*/
@Test
public void testInvalidLoginModule() throws Exception {
TestJaasConfig jaasConfig = configureMechanisms("PLAIN", Arrays.asList("PLAIN"));
jaasConfig.createOrUpdateEntry(JaasUtils.LOGIN_CONTEXT_CLIENT, "InvalidLoginModule", TestJaasConfig.defaultClientOptions());
SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;
server = NetworkTestUtils.createEchoServer(securityProtocol, saslServerConfigs);
try {
createSelector(securityProtocol, saslClientConfigs);
fail("SASL/PLAIN channel created without valid login module");
} catch (KafkaException e) {
// Expected exception
}
}
開發者ID:txazo,項目名稱:kafka,代碼行數:18,
示例23: createConfiguration
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public static TestJaasConfig createConfiguration(String clientMechanism, List serverMechanisms) {
TestJaasConfig config = new TestJaasConfig();
config.createOrUpdateEntry(JaasUtils.LOGIN_CONTEXT_CLIENT, loginModule(clientMechanism), defaultClientOptions());
for (String mechanism : serverMechanisms) {
config.createOrUpdateEntry(JaasUtils.LOGIN_CONTEXT_SERVER, loginModule(mechanism), defaultServerOptions());
}
Configuration.setConfiguration(config);
return config;
}
開發者ID:txazo,項目名稱:kafka,代碼行數:10,
示例24: setPlainClientOptions
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public void setPlainClientOptions(String clientUsername, String clientPassword) {
Map options = new HashMap<>();
if (clientUsername != null)
options.put("username", clientUsername);
if (clientPassword != null)
options.put("password", clientPassword);
createOrUpdateEntry(JaasUtils.LOGIN_CONTEXT_CLIENT, PlainLoginModule.class.getName(), options);
}
開發者ID:txazo,項目名稱:kafka,代碼行數:9,
示例25: maybeAddPartitions
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
void maybeAddPartitions(int minPartitionNum) {
ZkUtils zkUtils = ZkUtils.apply(_zkConnect, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
try {
int partitionNum = getPartitionInfo(zkUtils, _topic).size();
if (partitionNum < minPartitionNum) {
LOG.info("MultiClusterTopicManagementService will increase partition of the topic {} "
+ "in cluster {} from {} to {}.", _topic, _zkConnect, partitionNum, minPartitionNum);
AdminUtils.addPartitions(zkUtils, _topic, minPartitionNum, null, false, RackAwareMode.Enforced$.MODULE$);
}
} finally {
zkUtils.close();
}
}
開發者ID:linkedin,項目名稱:kafka-monitor,代碼行數:14,
示例26: getPartitionNumForTopic
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* Read number of partitions for the given topic on the specified zookeeper
* @param zkUrl zookeeper connection url
* @param topic topic name
*
* @return the number of partitions of the given topic
*/
public static int getPartitionNumForTopic(String zkUrl, String topic) {
ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
try {
Seq topics = scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(topic));
return zkUtils.getPartitionsForTopics(topics).apply(topic).size();
} catch (NoSuchElementException e) {
return 0;
} finally {
zkUtils.close();
}
}
開發者ID:linkedin,項目名稱:kafka-monitor,代碼行數:19,
示例27: getBrokerCount
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
* @param zkUrl zookeeper connection url
* @return number of brokers in this cluster
*/
public static int getBrokerCount(String zkUrl) {
ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
try {
return zkUtils.getAllBrokersInCluster().size();
} finally {
zkUtils.close();
}
}
開發者ID:linkedin,項目名稱:kafka-monitor,代碼行數:13,
示例28: listTopics
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
*
Title: listTopics
*
Description: 查詢隊列列表操作
*
* @param zookeeperStr zookeeper地址
*/
public static void listTopics(String zookeeperStr) {
TopicCommand.listTopics(ZkUtils.apply(zookeeperStr,
sessionTimeout, connectionTimeout,
JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
new String[]{"--list"}));
}
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:14,
示例29: createTopic
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
*
Title: createTopic
*
Description: 創建隊列操作
*
* @param zookeeperStr zookeeper地址
* @param topic 隊列名稱
* @param replications 複製個數
* @param partitions 分區個數
*/
public static void createTopic(String zookeeperStr, String topic,
int replications, int partitions) {
TopicCommand.createTopic(ZkUtils.apply(zookeeperStr,
sessionTimeout, connectionTimeout,
JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
new String[]{"--create", "--topic", topic,
"--replication-factor", String.valueOf(replications),
"--partitions", String.valueOf(partitions)}));
}
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:20,
示例30: describeTopic
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
*
Title: describeTopic
*
Description: 查詢隊列操作
*
* @param zookeeperStr zookeeper地址
* @param topic 隊列名稱
*/
public static void describeTopic(String zookeeperStr, String topic) {
TopicCommand.describeTopic(ZkUtils.apply(zookeeperStr,
sessionTimeout, connectionTimeout,
JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
new String[]{"--describe", "--topic", topic}));
}
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:15,
示例31: deleteTopic
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
/**
*
Title: deleteTopic
*
Description: 刪除隊列操作
*
* @param zookeeperStr zookeeper地址
* @param topic 隊列名稱
*/
public static void deleteTopic(String zookeeperStr, String topic) {
TopicCommand.deleteTopic(ZkUtils.apply(zookeeperStr,
sessionTimeout, connectionTimeout,
JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
new String[]{"--delete", "--topic", topic}));
}
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:15,
示例32: startZookeeper
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public void startZookeeper() {
int zkConnectionTimeout = 6000;
int zkSessionTimeout = 6000;
zookeeper = new EmbeddedZookeeper();
zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
zkUtils = ZkUtils.apply(
zkConnect, zkSessionTimeout, zkConnectionTimeout,
JaasUtils.isZkSecurityEnabled());
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:10,
示例33: setUp
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws IOException {
int zkConnectionTimeout = 6000;
int zkSessionTimeout = 6000;
zookeeper = new EmbeddedZookeeper();
zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
zkUtils = ZkUtils.apply(
zkConnect, zkSessionTimeout, zkConnectionTimeout,
JaasUtils.isZkSecurityEnabled());
port = NetworkUtils.getRandomPort();
kafkaServer = TestUtil09.createKafkaServer(port, zkConnect, false);
sdcKafkaValidationUtil = SdcKafkaValidationUtilFactory.getInstance().create();
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:16,
示例34: startZookeeper
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public void startZookeeper() {
int zkConnectionTimeout = 6000;
int zkSessionTimeout = 6000;
zookeeper = new EmbeddedZookeeper();
zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
zkUtils = ZkUtils.apply(
zkConnect, zkSessionTimeout, zkConnectionTimeout,
JaasUtils.isZkSecurityEnabled());
}
開發者ID:streamsets,項目名稱:datacollector,代碼行數:10,
示例35: run
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public int run(final String[] args, final Properties config) {
consumerConfig.clear();
consumerConfig.putAll(config);
int exitCode = EXIT_CODE_SUCCESS;
AdminClient adminClient = null;
ZkUtils zkUtils = null;
try {
parseArguments(args);
dryRun = options.has(dryRunOption);
adminClient = AdminClient.createSimplePlaintext(options.valueOf(bootstrapServerOption));
final String groupId = options.valueOf(applicationIdOption);
zkUtils = ZkUtils.apply(options.valueOf(zookeeperOption),
30000,
30000,
JaasUtils.isZkSecurityEnabled());
allTopics.clear();
allTopics.addAll(scala.collection.JavaConversions.seqAsJavaList(zkUtils.getAllTopics()));
if (!adminClient.describeConsumerGroup(groupId, 0).consumers().get().isEmpty()) {
throw new IllegalStateException("Consumer group '" + groupId + "' is still active. " +
"Make sure to stop all running application instances before running the reset tool.");
}
if (dryRun) {
System.out.println("----Dry run displays the actions which will be performed when running Streams Reset Tool----");
}
maybeResetInputAndSeekToEndIntermediateTopicOffsets();
maybeDeleteInternalTopics(zkUtils);
} catch (final Throwable e) {
exitCode = EXIT_CODE_ERROR;
System.err.println("ERROR: " + e.getMessage());
} finally {
if (adminClient != null) {
adminClient.close();
}
if (zkUtils != null) {
zkUtils.close();
}
}
return exitCode;
}
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:51,
示例36: SaslServerCallbackHandler
點讚 2
import org.apache.kafka.common.security.JaasUtils; //導入依賴的package包/類
public SaslServerCallbackHandler(Configuration configuration, KerberosShortNamer kerberosNameParser) throws IOException {
AppConfigurationEntry[] configurationEntries = configuration.getAppConfigurationEntry(JaasUtils.LOGIN_CONTEXT_SERVER);
if (configurationEntries == null)
throw new IOException("Could not find a 'KafkaServer' entry in this configuration: Kafka Server cannot start.");
this.kerberosShortNamer = kerberosNameParser;
}
開發者ID:txazo,項目名稱:kafka,代碼行數:7,
注:本文中的org.apache.kafka.common.security.JaasUtils類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。