const consumerGroupDescribe = containerId => { const cmd = ` docker exec \ ${containerId} \ bash -c "JMX_PORT=9998 kafka-consumer-groups --bootstrap-server kafka1:9092 --group test-group-${secureRandom()} --describe > /dev/null 2>&1" sleep 1 ` return execa.commandSync(cmd, { shell: true }).stdout.toString('utf-8') }
const waitForNode = containerId => { const cmd = ` docker exec \ ${containerId} \ bash -c "JMX_PORT=9998 kafka-topics --zookeeper zookeeper:2181 --list 2> /dev/null" sleep 5 ` execa.commandSync(cmd, { shell: true }) console.log(`Kafka container ${containerId} is running`) }
const createTopic = (containerId, topicName) => { const cmd = ` docker exec \ ${containerId} \ bash -c "JMX_PORT=9998 kafka-topics --create --if-not-exists --topic ${topicName} --replication-factor 1 --partitions 2 --zookeeper zookeeper:2181 2> /dev/null" ` return execa.commandSync(cmd, { shell: true }).stdout.toString('utf-8') }
const addPartitions = async ({ topic, partitions }) => { const cmd = `TOPIC=${topic} PARTITIONS=${partitions} ./scripts/addPartitions.sh` const cluster = createCluster() await cluster.connect() await cluster.addTargetTopic(topic) execa.commandSync(cmd, { shell: true }) waitFor(async () => { await cluster.refreshMetadata() const partitionMetadata = cluster.findTopicPartitionMetadata(topic) return partitionMetadata.length === partitions }) }
BUILD_SOURCEVERSIONMESSAGE || execa .commandSync('git log -1 --pretty=%B', { shell: true }) .stdout.toString('utf-8') .trim()
const findContainerId = node => { const cmd = ` docker ps \ --filter "status=running" \ --filter "label=custom.project=kafkajs" \ --filter "label=custom.service=${node}" \ --no-trunc \ -q ` const containerId = execa.commandSync(cmd, { shell: true }).stdout.toString('utf-8') console.log(`${node}: ${containerId}`) return containerId }
/** * Check for yarn installation * @returns {Boolean} */ const hasYarn = () => { try { execa.commandSync("yarn --version"); return true; } catch (err) { return false; } }