private void deleteInternalTopics(final ZkUtils zkUtils) { System.out.println("Deleting all internal/auto-created topics for application " + options.valueOf(applicationIdOption)); for (final String topic : allTopics) { if (isInternalTopic(topic)) { final TopicCommand.TopicCommandOptions commandOptions = new TopicCommand.TopicCommandOptions(new String[]{ "--zookeeper", options.valueOf(zookeeperOption), "--delete", "--topic", topic}); try { TopicCommand.deleteTopic(zkUtils, commandOptions); } catch (final RuntimeException e) { System.err.println("ERROR: Deleting topic " + topic + " failed."); throw e; } } } System.out.println("Done."); }
TopicCommand.createTopic( zkUtils, new TopicCommand.TopicCommandOptions(argsList.stream().toArray(String[]::new))); } catch (Exception exception) { throw new ApiException("Create topic exception." + exception);
arguments[1] = zookeeperString; arguments[2] = "--list"; TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments); ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); final List<String> topics = new ArrayList<>();
public void createTopic(String topicName, Integer numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; 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); /* // v0.9.0.1 ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); TopicCommand.createTopic(zkUtils, opts); */ // v0.8.2.1 ZkClient zkClient = new ZkClient(zookeeperString, 3000, 3000, ZKStringSerializer$.MODULE$); TopicCommand.createTopic(zkClient,opts); // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); }
public void createTopic(String topicName, int numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; arguments[3] = "--replication-factor"; arguments[4] = "1"; arguments[5] = "--partitions"; arguments[6] = String.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()); try{ // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); TopicCommand.createTopic(zkUtils, opts); } finally { zkUtils.close(); } }
/** * Delete a topic. * @param topicName The name of the topic to delete */ public void deleteTopic(String topicName) { String[] arguments = new String[5]; arguments[0] = "--zookeeper"; arguments[1] = zookeeperString; arguments[2] = "--delete"; arguments[3] = "--topic"; arguments[4] = topicName; TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments); ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); try { // run LOGGER.info("Executing: DeleteTopic " + Arrays.toString(arguments)); TopicCommand.deleteTopic(zkUtils, opts); } finally { zkUtils.close(); } }
public void createTopic(int clusterid, String topicName) { String[] args = new String[9]; args[0] = "--zookeeper"; args[1] = "localhost:" + TEST_ZOOKEEPER_PORT[clusterid]; args[2] = "--replication-factor"; args[3] = "1"; args[4] = "--partitions"; if (hasMultiPartition) { args[5] = "2"; } else { args[5] = "1"; } args[6] = "--topic"; args[7] = topicName; args[8] = "--create"; ZkUtils zu = ZkUtils.apply("localhost:" + TEST_ZOOKEEPER_PORT[clusterid], 30000, 30000, false); TopicCommand.createTopic(zu, new TopicCommand.TopicCommandOptions(args)); }
public void createTopic(String topicName, Integer numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; 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()); // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); TopicCommand.createTopic(zkUtils, opts); }
public void createTopic(int clusterid, String topicName) { String[] args = new String[9]; args[0] = "--zookeeper"; args[1] = "localhost:" + TEST_ZOOKEEPER_PORT[clusterid]; args[2] = "--replication-factor"; args[3] = "1"; args[4] = "--partitions"; if (hasMultiPartition) { args[5] = "2"; } else { args[5] = "1"; } args[6] = "--topic"; args[7] = topicName; args[8] = "--create"; ZkUtils zu = ZkUtils.apply("localhost:" + TEST_ZOOKEEPER_PORT[clusterid], 30000, 30000, false); TopicCommand.createTopic(zu, new TopicCommand.TopicCommandOptions(args)); }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }