kafka.admin.ReassignPartitionsCommand Java Examples

The following examples show how to use kafka.admin.ReassignPartitionsCommand. 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: KafkaHubServiceImpl.java    From kafka-eagle with Apache License 2.0 6 votes vote down vote up
/** Execute reassign topics json. */
public String execute(String clusterAlias, String reassignTopicsJson) {
	JSONObject object = new JSONObject();
	String zkServerAddress = SystemConfigUtils.getProperty(clusterAlias + ".zk.list");
	PrintStream oldPStream = System.out;
	System.setOut(pStream);
	try {
		ReassignPartitionsCommand.main(new String[] { "--zookeeper", zkServerAddress, "--reassignment-json-file", createKafkaTopicTempJson(reassignTopicsJson).getAbsolutePath(), "--execute" });
		object.put("success", true);
	} catch (Exception e) {
		object.put("error", "Execute command has error, msg is " + e.getCause().getMessage());
		LOG.error("Execute command has error, msg is ", e);
	}
	System.out.flush();
	System.setOut(oldPStream);
	object.put("result", baos.toString());
	return object.toJSONString();
}
 
Example #2
Source File: KafkaHubServiceImpl.java    From kafka-eagle with Apache License 2.0 6 votes vote down vote up
/** Verify reassign topics json. */
public String verify(String clusterAlias, String reassignTopicsJson) {
	JSONObject object = new JSONObject();
	String zkServerAddress = SystemConfigUtils.getProperty(clusterAlias + ".zk.list");
	PrintStream oldPStream = System.out;
	System.setOut(pStream);
	try {
		ReassignPartitionsCommand.main(new String[] { "--zookeeper", zkServerAddress, "--reassignment-json-file", createKafkaTopicTempJson(reassignTopicsJson).getAbsolutePath(), "--verify" });
	} catch (Exception e) {
		object.put("error", "Verify command has error, msg is " + e.getCause().getMessage());
		LOG.error("Verify command has error, msg is ", e);
	}
	System.out.flush();
	System.setOut(oldPStream);
	object.put("result", baos.toString());
	return object.toJSONString();
}
 
Example #3
Source File: TopicOperatorReplicationIT.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
private String doReassignmentCommand(String... args) {
    PrintStream originalStdOut = System.out;
    PrintStream originalStdErr = System.err;
    System.setOut(tempStdOut);
    System.setErr(tempStdOut);
    ReassignPartitionsCommand.main(args);
    System.setOut(originalStdOut);
    System.setErr(originalStdErr);
    tempStdOut.flush();
    String s = new String(baos.toByteArray());
    baos.reset();
    return s;
}
 
Example #4
Source File: KafkaTool.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Re-assign topic/partition to remainingBrokers
 * Remaining brokers is a list of id's of the brokers where the topic/partition is to be moved to.
 * 
 *   Thus if remainingBrokers = [1,2] the topic will be moved to brokers 1 and 2 
 *   
 *   @see https://kafka.apache.org/documentation.html#basic_ops_cluster_expansion
 *   @see https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-6.ReassignPartitionsTool
 * */
public boolean reassignPartition(String topic, int partition, List<Object> remainingBrokers) {
  ZkClient client = new ZkClient(zkConnects, 10000, 10000, ZKStringSerializer$.MODULE$);

  TopicAndPartition topicAndPartition = new TopicAndPartition(topic, partition);

  Buffer<Object> seqs = asScalaBuffer(remainingBrokers);
  Map<TopicAndPartition, Seq<Object>> map = new HashMap<>();
  map.put(topicAndPartition, seqs);
  scala.collection.mutable.Map<TopicAndPartition, Seq<Object>> x = asScalaMap(map);
  ReassignPartitionsCommand command = new ReassignPartitionsCommand(client, x);

  return command.reassignPartitions();
}
 
Example #5
Source File: KafkaTool.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean reassignPartitionReplicas(String topic, int partition, Integer ... brokerId) {
  ZkClient client = new ZkClient(zkConnects, 10000, 10000, ZKStringSerializer$.MODULE$);
  TopicAndPartition topicAndPartition = new TopicAndPartition(topic, partition);

  Buffer<Object> seqs = asScalaBuffer(Arrays.asList((Object[])brokerId));
  Map<TopicAndPartition, Seq<Object>> map = new HashMap<>();
  map.put(topicAndPartition, seqs);
  ReassignPartitionsCommand command = new ReassignPartitionsCommand(client, asScalaMap(map));
  return command.reassignPartitions();
}