use of kafka.server.KafkaServerStartable in project testcases by coheigea.
the class KafkaAuthorizerTest method setup.
@org.junit.BeforeClass
public static void setup() throws Exception {
zkServer = new TestingServer();
// Get a random port
ServerSocket serverSocket = new ServerSocket(0);
port = serverSocket.getLocalPort();
serverSocket.close();
final Properties props = new Properties();
props.put("broker.id", 1);
props.put("host.name", "localhost");
props.put("port", port);
props.put("log.dir", "/tmp/kafka");
props.put("zookeeper.connect", zkServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
// Enable SSL
props.put("listeners", "SSL://localhost:" + port);
props.put("ssl.keystore.location", KafkaAuthorizerTest.class.getResource("/brokerstore.jks").getPath());
props.put("ssl.keystore.password", "bspass");
props.put("ssl.key.password", "bkpass");
props.put("ssl.truststore.location", KafkaAuthorizerTest.class.getResource("/truststore.jks").getPath());
props.put("ssl.truststore.password", "security");
props.put("security.inter.broker.protocol", "SSL");
props.put("ssl.client.auth", "required");
// Plug in custom authorizer
props.put("authorizer.class.name", "org.apache.coheigea.bigdata.kafka.CustomAuthorizer");
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// Create some topics
ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "dev", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
use of kafka.server.KafkaServerStartable in project testcases by coheigea.
the class KafkaRangerGSSAuthorizerTest method setup.
@org.junit.BeforeClass
public static void setup() throws Exception {
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
configureKerby(basedir);
// JAAS Config file - We need to point to the correct keytab files
Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/kafka_kerberos.jaas");
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
content = content.replaceAll("<basedir>", basedir);
Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/kafka_kerberos.jaas");
Files.write(path2, content.getBytes(StandardCharsets.UTF_8));
System.setProperty("java.security.auth.login.config", path2.toString());
// Set up Zookeeper to require SASL
Map<String, Object> zookeeperProperties = new HashMap<>();
zookeeperProperties.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
zookeeperProperties.put("requireClientAuthScheme", "sasl");
zookeeperProperties.put("jaasLoginRenew", "3600000");
InstanceSpec instanceSpec = new InstanceSpec(null, -1, -1, -1, true, 1, -1, -1, zookeeperProperties);
zkServer = new TestingServer(instanceSpec, true);
// Get a random port
ServerSocket serverSocket = new ServerSocket(0);
port = serverSocket.getLocalPort();
serverSocket.close();
final Properties props = new Properties();
props.put("broker.id", 1);
props.put("host.name", "localhost");
props.put("port", port);
props.put("log.dir", "/tmp/kafka");
props.put("zookeeper.connect", zkServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
// Enable SASL_PLAINTEXT
props.put("listeners", "SASL_PLAINTEXT://localhost:" + port);
props.put("security.inter.broker.protocol", "SASL_PLAINTEXT");
props.put("sasl.enabled.mechanisms", "GSSAPI");
props.put("sasl.mechanism.inter.broker.protocol", "GSSAPI");
props.put("sasl.kerberos.service.name", "kafka");
// Plug in Apache Ranger authorizer
props.put("authorizer.class.name", "org.apache.ranger.authorization.kafka.authorizer.RangerKafkaAuthorizer");
// Create users for testing
UserGroupInformation.createUserForTesting("client@kafka.apache.org", new String[] { "public" });
UserGroupInformation.createUserForTesting("kafka/localhost@kafka.apache.org", new String[] { "IT" });
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// Create some topics
ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "dev", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "messages", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
use of kafka.server.KafkaServerStartable in project beam by apache.
the class EmbeddedKafkaCluster method startup.
public void startup() {
for (int i = 0; i < ports.size(); i++) {
Integer port = ports.get(i);
File logDir = TestUtils.constructTempDir("kafka-local");
Properties properties = new Properties();
properties.putAll(baseProperties);
properties.setProperty("zookeeper.connect", zkConnection);
properties.setProperty("broker.id", String.valueOf(i + 1));
properties.setProperty("advertised.host.name", "127.0.0.1");
properties.setProperty("host.name", "127.0.0.1");
properties.setProperty("advertised.port", Integer.toString(port));
properties.setProperty("port", Integer.toString(port));
properties.setProperty("log.dirs", logDir.getAbsolutePath());
properties.setProperty("offsets.topic.num.partitions", "1");
properties.setProperty("offsets.topic.replication.factor", "1");
properties.setProperty("log.flush.interval.messages", String.valueOf(1));
KafkaServerStartable broker = startBroker(properties);
brokers.add(broker);
logDirs.add(logDir);
}
}
use of kafka.server.KafkaServerStartable in project jmxtrans by jmxtrans.
the class EmbeddedKafka method before.
@Override
public void before() throws IOException {
LOGGER.info("Starting Kafka");
logDir = temporaryFolder.newFolder("kafka");
Properties properties = getResourceAsProperties("kafka.properties");
properties.setProperty("log.dirs", logDir.getAbsolutePath());
properties.setProperty("listeners", "PLAINTEXT://:9092");
KafkaConfig config = new KafkaConfig(properties);
server = new KafkaServerStartable(config);
server.startup();
}
use of kafka.server.KafkaServerStartable in project apex-malhar by apache.
the class KafkaOperatorTestBase method startKafkaServer.
public static void startKafkaServer(int clusterid, int brokerid) {
Properties props = new Properties();
props.setProperty("broker.id", "" + clusterid * 10 + brokerid);
props.setProperty("log.dirs", new File(baseDir, kafkadir[clusterid]).toString());
props.setProperty("zookeeper.connect", "localhost:" + TEST_ZOOKEEPER_PORT[clusterid]);
props.setProperty("port", "" + TEST_KAFKA_BROKER_PORT[clusterid]);
props.setProperty("default.replication.factor", "1");
// set this to 50000 to boost the performance so most test data are in memory before flush to disk
props.setProperty("log.flush.interval.messages", "50000");
broker[clusterid] = new KafkaServerStartable(new KafkaConfig(props));
broker[clusterid].startup();
}
Aggregations