
[id='proc-generating-reassignment-json-files-{context}']
= Generating reassignment JSON files

This procedure describes how to generate a reassignment JSON file that reassigns all the partitions for a given set of topics using the `kafka-reassign-partitions.sh` tool.

.Prerequisites

* A running Cluster Operator
* A `Kafka` resource
* A set of topics to reassign the partitions of

.Procedure

. Prepare a JSON file named `_topics.json_` that lists the topics to move.
It must have the following structure:
+
[source,subs=+quotes]
----
{
  "version": 1,
  "topics": [
    _<TopicObjects>_
  ]
}
----
+
where _<TopicObjects>_ is a comma-separated list of objects like:
+
[source,subs=+quotes]
----
{
  "topic": _<TopicName>_
}
----
+
For example if you want to reassign all the partitions of `topic-a` and `topic-b`, you would need to prepare a `_topics.json_` file like this:
+
[source,json]
----
{
  "version": 1,
  "topics": [
    { "topic": "topic-a"},
    { "topic": "topic-b"}
  ]
}
----

. Copy the `_topics.json_` file to one of the broker pods:
+
[source,subs=+quotes]
----
cat _topics.json_ | kubectl exec -c kafka _<BrokerPod>_ -i -- \
  /bin/bash -c \
  'cat > /tmp/topics.json'
----

. Use the `kafka-reassign-partitions.sh` command to generate the reassignment JSON.
+
[source,subs=+quotes]
----
kubectl exec _<BrokerPod>_ -c kafka -it -- \
  bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 \
  --topics-to-move-json-file /tmp/topics.json \
  --broker-list _<BrokerList>_ \
  --generate
----
+
For example, to move all the partitions of `topic-a` and `topic-b` to brokers `4` and `7`
+
[source,shell,subs=+quotes]
----
kubectl exec _<BrokerPod>_ -c kafka -it -- \
  bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 \
  --topics-to-move-json-file /tmp/topics.json \
  --broker-list 4,7 \
  --generate
----
