org.apache.kafka.common.network.ListenerName Java Examples

The following examples show how to use org.apache.kafka.common.network.ListenerName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterTestHarness.java    From kareldb with Apache License 2.0 7 votes vote down vote up
@Before
public void setUp() throws Exception {
    zookeeper = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zookeeper.port());

    configs = new Vector<>();
    servers = new Vector<>();
    for (int i = 0; i < numBrokers; i++) {
        KafkaConfig config = getKafkaConfig(i);
        configs.add(config);

        KafkaServer server = TestUtils.createServer(config, Time.SYSTEM);
        servers.add(server);
    }

    String[] serverUrls = new String[servers.size()];
    ListenerName listenerType = ListenerName.forSecurityProtocol(getSecurityProtocol());
    for (int i = 0; i < servers.size(); i++) {
        serverUrls[i] =
            Utils.formatAddress(
                servers.get(i).config().advertisedListeners().head().host(),
                servers.get(i).boundPort(listenerType)
            );
    }
    bootstrapServers = Utils.join(serverUrls, ",");
}
 
Example #2
Source File: ClusterTestHarness.java    From kcache with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    zookeeper = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zookeeper.port());

    configs = new Vector<>();
    servers = new Vector<>();
    for (int i = 0; i < numBrokers; i++) {
        KafkaConfig config = getKafkaConfig(i);
        configs.add(config);

        KafkaServer server = TestUtils.createServer(config, Time.SYSTEM);
        servers.add(server);
    }

    String[] serverUrls = new String[servers.size()];
    ListenerName listenerType = ListenerName.forSecurityProtocol(getSecurityProtocol());
    for (int i = 0; i < servers.size(); i++) {
        serverUrls[i] =
            Utils.formatAddress(
                servers.get(i).config().advertisedListeners().head().host(),
                servers.get(i).boundPort(listenerType)
            );
    }
    bootstrapServers = Utils.join(serverUrls, ",");
}
 
Example #3
Source File: OperatorUtil.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
public static String getBrokers(String zkUrl, SecurityProtocol securityProtocol) {
  ZkUtils zkUtils = getZkUtils(zkUrl);
  Seq<Broker> brokersSeq = zkUtils.getAllBrokersInCluster();
  Broker[] brokers = new Broker[brokersSeq.size()];
  brokersSeq.copyToArray(brokers);

  String brokersStr = Arrays.stream(brokers)
      .map(b -> b.brokerEndPoint(
          ListenerName.forSecurityProtocol(securityProtocol)).connectionString())
      .reduce(null, (a, b) -> (a == null) ? b : a + "," + b);
  return brokersStr;
}
 
Example #4
Source File: ZkConsumerCommand.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public List<BrokerInfo> fetchAllBrokers(){
	List<BrokerInfo> result = new ArrayList<>();
	Seq<Broker> brokers = zkUtils.getAllBrokersInCluster();
	Iterator<Broker> iterator = brokers.toList().iterator();
	while(iterator.hasNext()){
		Broker broker = iterator.next();
		Node node = broker.getNode(ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT)).get();
		result.add(new BrokerInfo(node.idString(), node.host(), node.port()));
	}
	return result;
}
 
Example #5
Source File: RangerKafkaAuthorizer.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Map<String, ?> configs) {
	RangerBasePlugin me = rangerPlugin;
	if (me == null) {
		synchronized(RangerKafkaAuthorizer.class) {
			me = rangerPlugin;
			if (me == null) {
				try {
					// Possible to override JAAS configuration which is used by Ranger, otherwise
					// SASL_PLAINTEXT is used, which force Kafka to use 'sasl_plaintext.KafkaServer',
					// if it's not defined, then it reverts to 'KafkaServer' configuration.
					final Object jaasContext = configs.get("ranger.jaas.context");
					final String listenerName = (jaasContext instanceof String
							&& StringUtils.isNotEmpty((String) jaasContext)) ? (String) jaasContext
									: SecurityProtocol.SASL_PLAINTEXT.name();
					final String saslMechanism = SaslConfigs.GSSAPI_MECHANISM;
					JaasContext context = JaasContext.loadServerContext(new ListenerName(listenerName), saslMechanism, configs);
					LoginManager loginManager = LoginManager.acquireLoginManager(context, saslMechanism, KerberosLogin.class, configs);
					Subject subject = loginManager.subject();
					UserGroupInformation ugi = MiscUtil
							.createUGIFromSubject(subject);
					if (ugi != null) {
						MiscUtil.setUGILoginUser(ugi, subject);
					}
					logger.info("LoginUser=" + MiscUtil.getUGILoginUser());
				} catch (Throwable t) {
					logger.error("Error getting principal.", t);
				}
				me = rangerPlugin = new RangerBasePlugin("kafka", "kafka");
			}
		}
	}
	logger.info("Calling plugin.init()");
	rangerPlugin.init();
	auditHandler = new RangerKafkaAuditHandler();
	rangerPlugin.setResultProcessor(auditHandler);
}
 
Example #6
Source File: MiniKafkaCluster.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public int getKafkaServerPort(int index) {
  return kafkaServer.get(index).socketServer()
      .boundPort(ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT));
}
 
Example #7
Source File: KafkaEmbedded.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 2 votes vote down vote up
/**
 * This broker's `metadata.broker.list` value.  Example: `127.0.0.1:9092`.
 *
 * You can use this to tell Kafka producers and consumers how to connect to this instance.
 *
 * This version returns the port of the first listener.
 * @return the broker list
 */
public String brokerList() {
  final ListenerName listenerName = kafka.config().advertisedListeners().apply(0).listenerName();
  return kafka.config().hostName() + ":" + kafka.boundPort(listenerName);
}
 
Example #8
Source File: KafkaEmbedded.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 2 votes vote down vote up
/**
 * The broker's `metadata.broker.list` value.  Example: `127.0.0.1:9092`.
 *
 * You can use this to tell Kafka producers and consumers how to connect to this instance.
 *
 * @param securityProtocol the security protocol the returned broker list should use.
 * @return the broker list
 */
public String brokerList(final SecurityProtocol securityProtocol) {
  return kafka.config().hostName() + ":"
         + kafka.boundPort(new ListenerName(securityProtocol.toString()));
}