class ReplicaVerificationTool(BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/replica_verification_tool.log", "collect_default": False} } def __init__(self, context, num_nodes, kafka, topic, report_interval_ms, security_protocol="PLAINTEXT"): super(ReplicaVerificationTool, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.report_interval_ms = report_interval_ms self.security_protocol = security_protocol self.security_config = SecurityConfig(security_protocol) self.partition_lag = {} def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("ReplicaVerificationTool %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) for line in node.account.ssh_capture(cmd): self.logger.debug("Parsing line:{}".format(line)) parsed = re.search('.*max lag is (.+?) for partition \[(.+?)\] at', line) if parsed: lag = int(parsed.group(1)) topic_partition = parsed.group(2) self.logger.debug("Setting max lag for {} as {}".format(topic_partition, lag)) self.partition_lag[topic_partition] = lag def get_lag_for_partition(self, topic, partition): """ Get latest lag for given topic-partition Args: topic: a topic partition: a partition of the topic """ topic_partition = topic + ',' + str(partition) lag = self.partition_lag[topic_partition] self.logger.debug("Retuning lag for {} as {}".format(topic_partition, lag)) return lag def start_cmd(self, node): cmd = "/opt/%s/bin/" % kafka_dir(node) cmd += "kafka-run-class.sh kafka.tools.ReplicaVerificationTool" cmd += " --broker-list %s --topic-white-list %s --time -2 --report-interval-ms %s" % (self.kafka.bootstrap_servers(self.security_protocol), self.topic, self.report_interval_ms) cmd += " 2>> /mnt/replica_verification_tool.log | tee -a /mnt/replica_verification_tool.log &" return cmd def stop_node(self, node): node.account.kill_process("java", clean_shutdown=True, allow_fail=True) def clean_node(self, node): node.account.kill_process("java", clean_shutdown=False, allow_fail=True) node.account.ssh("rm -rf /mnt/replica_verification_tool.log", allow_fail=False)
class KafkaLog4jAppender(KafkaPathResolverMixin, BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/kafka_log4j_appender.log", "collect_default": False} } def __init__(self, context, num_nodes, kafka, topic, max_messages=-1, security_protocol="PLAINTEXT"): super(KafkaLog4jAppender, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.max_messages = max_messages self.security_protocol = security_protocol self.security_config = SecurityConfig(security_protocol) def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("VerifiableLog4jAppender %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) node.account.ssh(cmd) def start_cmd(self, node): cmd = self.path.script("kafka-run-class.sh", node) cmd += " org.apache.kafka.tools.VerifiableLog4jAppender" cmd += " --topic %s --broker-list %s" % (self.topic, self.kafka.bootstrap_servers(self.security_protocol)) if self.max_messages > 0: cmd += " --max-messages %s" % str(self.max_messages) if self.security_protocol != SecurityConfig.PLAINTEXT: cmd += " --security-protocol %s" % str(self.security_protocol) if self.security_protocol == SecurityConfig.SSL or self.security_protocol == SecurityConfig.SASL_SSL: cmd += " --ssl-truststore-location %s" % str(SecurityConfig.TRUSTSTORE_PATH) cmd += " --ssl-truststore-password %s" % str(SecurityConfig.ssl_stores.truststore_passwd) if self.security_protocol == SecurityConfig.SASL_PLAINTEXT or \ self.security_protocol == SecurityConfig.SASL_SSL or \ self.security_protocol == SecurityConfig.SASL_MECHANISM_GSSAPI or \ self.security_protocol == SecurityConfig.SASL_MECHANISM_PLAIN: cmd += " --sasl-kerberos-service-name %s" % str('kafka') cmd += " --client-jaas-conf-path %s" % str(SecurityConfig.JAAS_CONF_PATH) cmd += " --kerb5-conf-path %s" % str(SecurityConfig.KRB5CONF_PATH) cmd += " 2>> /mnt/kafka_log4j_appender.log | tee -a /mnt/kafka_log4j_appender.log &" return cmd def stop_node(self, node): node.account.kill_process("VerifiableLog4jAppender", allow_fail=False) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_process("VerifiableLog4jAppender", clean_shutdown=False, allow_fail=False) node.account.ssh("rm -rf /mnt/kafka_log4j_appender.log", allow_fail=False)
class KafkaLog4jAppender(KafkaPathResolverMixin, BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/kafka_log4j_appender.log", "collect_default": False} } def __init__(self, context, num_nodes, kafka, topic, max_messages=-1, security_protocol="PLAINTEXT"): super(KafkaLog4jAppender, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.max_messages = max_messages self.security_protocol = security_protocol self.security_config = SecurityConfig(security_protocol) def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("VerifiableLog4jAppender %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) node.account.ssh(cmd) def start_cmd(self, node): cmd = self.path.script("kafka-run-class.sh", node) cmd += " org.apache.kafka.tools.VerifiableLog4jAppender" cmd += " --topic %s --broker-list %s" % (self.topic, self.kafka.bootstrap_servers(self.security_protocol)) if self.max_messages > 0: cmd += " --max-messages %s" % str(self.max_messages) if self.security_protocol != SecurityConfig.PLAINTEXT: cmd += " --security-protocol %s" % str(self.security_protocol) if self.security_protocol == SecurityConfig.SSL or self.security_protocol == SecurityConfig.SASL_SSL: cmd += " --ssl-truststore-location %s" % str(SecurityConfig.TRUSTSTORE_PATH) cmd += " --ssl-truststore-password %s" % str(SecurityConfig.ssl_stores['ssl.truststore.password']) if self.security_protocol == SecurityConfig.SASL_PLAINTEXT or \ self.security_protocol == SecurityConfig.SASL_SSL or \ self.security_protocol == SecurityConfig.SASL_MECHANISM_GSSAPI or \ self.security_protocol == SecurityConfig.SASL_MECHANISM_PLAIN: cmd += " --sasl-kerberos-service-name %s" % str('kafka') cmd += " --client-jaas-conf-path %s" % str(SecurityConfig.JAAS_CONF_PATH) cmd += " --kerb5-conf-path %s" % str(SecurityConfig.KRB5CONF_PATH) cmd += " 2>> /mnt/kafka_log4j_appender.log | tee -a /mnt/kafka_log4j_appender.log &" return cmd def stop_node(self, node): node.account.kill_process("VerifiableLog4jAppender", allow_fail=False) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_process("VerifiableLog4jAppender", clean_shutdown=False, allow_fail=False) node.account.ssh("rm -rf /mnt/kafka_log4j_appender.log", allow_fail=False)
class KafkaLog4jAppender(BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/kafka_log4j_appender.log", "collect_default": False} } def __init__(self, context, num_nodes, kafka, topic, max_messages=-1, security_protocol="PLAINTEXT"): super(KafkaLog4jAppender, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.max_messages = max_messages self.security_protocol = security_protocol self.security_config = SecurityConfig(security_protocol) def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("VerifiableLog4jAppender %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) node.account.ssh(cmd) def start_cmd(self, node): cmd = "/opt/%s/bin/" % kafka_dir(node) cmd += "kafka-run-class.sh org.apache.kafka.tools.VerifiableLog4jAppender" cmd += " --topic %s --broker-list %s" % (self.topic, self.kafka.bootstrap_servers(self.security_protocol)) if self.max_messages > 0: cmd += " --max-messages %s" % str(self.max_messages) if self.security_protocol == SecurityConfig.SSL: cmd += " --security-protocol SSL" cmd += " --ssl-truststore-location %s" % str(SecurityConfig.TRUSTSTORE_PATH) cmd += " --ssl-truststore-password %s" % str(SecurityConfig.ssl_stores['ssl.truststore.password']) cmd += " 2>> /mnt/kafka_log4j_appender.log | tee -a /mnt/kafka_log4j_appender.log &" return cmd def stop_node(self, node): node.account.kill_process("VerifiableLog4jAppender", allow_fail=False) if self.worker_threads is None: return # block until the corresponding thread exits if len(self.worker_threads) >= self.idx(node): # Need to guard this because stop is preemptively called before the worker threads are added and started self.worker_threads[self.idx(node) - 1].join() def clean_node(self, node): node.account.kill_process("VerifiableLog4jAppender", clean_shutdown=False, allow_fail=False) node.account.ssh("rm -rf /mnt/kafka_log4j_appender.log", allow_fail=False)
class ReplicaVerificationTool(KafkaPathResolverMixin, BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/replica_verification_tool.log", "collect_default": False } } def __init__(self, context, num_nodes, kafka, topic, report_interval_ms, security_protocol="PLAINTEXT", stop_timeout_sec=30, tls_version=None): super(ReplicaVerificationTool, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.report_interval_ms = report_interval_ms self.security_protocol = security_protocol self.tls_version = tls_version self.security_config = SecurityConfig(self.context, security_protocol, tls_version=tls_version) self.partition_lag = {} self.stop_timeout_sec = stop_timeout_sec def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("ReplicaVerificationTool %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) for line in node.account.ssh_capture(cmd): self.logger.debug("Parsing line:{}".format(line)) parsed = re.search( '.*max lag is (.+?) for partition ([a-zA-Z0-9._-]+-[0-9]+) at', line) if parsed: lag = int(parsed.group(1)) topic_partition = parsed.group(2) self.logger.debug("Setting max lag for {} as {}".format( topic_partition, lag)) self.partition_lag[topic_partition] = lag def get_lag_for_partition(self, topic, partition): """ Get latest lag for given topic-partition Args: topic: a topic partition: a partition of the topic """ topic_partition = topic + '-' + str(partition) lag = self.partition_lag.get(topic_partition, -1) self.logger.debug("Returning lag for {} as {}".format( topic_partition, lag)) return lag def start_cmd(self, node): cmd = self.path.script("kafka-run-class.sh", node) cmd += " %s" % self.java_class_name() cmd += " --broker-list %s --topic-white-list %s --time -2 --report-interval-ms %s" % ( self.kafka.bootstrap_servers( self.security_protocol), self.topic, self.report_interval_ms) cmd += " 2>> /mnt/replica_verification_tool.log | tee -a /mnt/replica_verification_tool.log &" return cmd def stop_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=True, allow_fail=True) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=False, allow_fail=True) node.account.ssh("rm -rf /mnt/replica_verification_tool.log", allow_fail=False) def java_class_name(self): return "kafka.tools.ReplicaVerificationTool"
class KafkaLog4jAppender(BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/kafka_log4j_appender.log", "collect_default": False } } def __init__(self, context, num_nodes, kafka, topic, max_messages=-1, security_protocol="PLAINTEXT"): super(KafkaLog4jAppender, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.max_messages = max_messages self.security_protocol = security_protocol self.security_config = SecurityConfig(security_protocol) def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("VerifiableLog4jAppender %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) node.account.ssh(cmd) def start_cmd(self, node): cmd = "/opt/%s/bin/" % kafka_dir(node) cmd += "kafka-run-class.sh org.apache.kafka.tools.VerifiableLog4jAppender" cmd += " --topic %s --broker-list %s" % ( self.topic, self.kafka.bootstrap_servers(self.security_protocol)) if self.max_messages > 0: cmd += " --max-messages %s" % str(self.max_messages) if self.security_protocol == SecurityConfig.SSL: cmd += " --security-protocol SSL" cmd += " --ssl-truststore-location %s" % str( SecurityConfig.TRUSTSTORE_PATH) cmd += " --ssl-truststore-password %s" % str( SecurityConfig.ssl_stores['ssl.truststore.password']) cmd += " 2>> /mnt/kafka_log4j_appender.log | tee -a /mnt/kafka_log4j_appender.log &" return cmd def stop_node(self, node): node.account.kill_process("VerifiableLog4jAppender", allow_fail=False) if self.worker_threads is None: return # block until the corresponding thread exits if len(self.worker_threads) >= self.idx(node): # Need to guard this because stop is preemptively called before the worker threads are added and started self.worker_threads[self.idx(node) - 1].join() def clean_node(self, node): node.account.kill_process("VerifiableLog4jAppender", clean_shutdown=False, allow_fail=False) node.account.ssh("rm -rf /mnt/kafka_log4j_appender.log", allow_fail=False)
class LogCompactionTester(KafkaPathResolverMixin, BackgroundThreadService): OUTPUT_DIR = "/mnt/logcompaction_tester" LOG_PATH = os.path.join(OUTPUT_DIR, "logcompaction_tester_stdout.log") VERIFICATION_STRING = "Data verification is completed" logs = { "tool_logs": { "path": LOG_PATH, "collect_default": True} } def __init__(self, context, kafka, security_protocol="PLAINTEXT", stop_timeout_sec=30): super(LogCompactionTester, self).__init__(context, 1) self.kafka = kafka self.security_protocol = security_protocol self.security_config = SecurityConfig(self.context, security_protocol) self.stop_timeout_sec = stop_timeout_sec self.log_compaction_completed = False def _worker(self, idx, node): node.account.ssh("mkdir -p %s" % LogCompactionTester.OUTPUT_DIR) cmd = self.start_cmd(node) self.logger.info("LogCompactionTester %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) for line in node.account.ssh_capture(cmd): self.logger.debug("Checking line:{}".format(line)) if line.startswith(LogCompactionTester.VERIFICATION_STRING): self.log_compaction_completed = True def start_cmd(self, node): core_libs_jar = self.path.jar(CORE_LIBS_JAR_NAME, DEV_BRANCH) core_dependant_test_libs_jar = self.path.jar(CORE_DEPENDANT_TEST_LIBS_JAR_NAME, DEV_BRANCH) cmd = "for file in %s; do CLASSPATH=$CLASSPATH:$file; done;" % core_libs_jar cmd += " for file in %s; do CLASSPATH=$CLASSPATH:$file; done;" % core_dependant_test_libs_jar cmd += " export CLASSPATH;" cmd += self.path.script("kafka-run-class.sh", node) cmd += " %s" % self.java_class_name() cmd += " --bootstrap-server %s --messages 1000000 --sleep 20 --duplicates 10 --percent-deletes 10" % (self.kafka.bootstrap_servers(self.security_protocol)) cmd += " 2>> %s | tee -a %s &" % (self.logs["tool_logs"]["path"], self.logs["tool_logs"]["path"]) return cmd def stop_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=True, allow_fail=True) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=False, allow_fail=True) node.account.ssh("rm -rf %s" % LogCompactionTester.OUTPUT_DIR, allow_fail=False) def java_class_name(self): return "kafka.tools.LogCompactionTester" @property def is_done(self): return self.log_compaction_completed
class ReplicaVerificationTool(KafkaPathResolverMixin, BackgroundThreadService): logs = { "producer_log": { "path": "/mnt/replica_verification_tool.log", "collect_default": False} } def __init__(self, context, num_nodes, kafka, topic, report_interval_ms, security_protocol="PLAINTEXT", stop_timeout_sec=30): super(ReplicaVerificationTool, self).__init__(context, num_nodes) self.kafka = kafka self.topic = topic self.report_interval_ms = report_interval_ms self.security_protocol = security_protocol self.security_config = SecurityConfig(self.context, security_protocol) self.partition_lag = {} self.stop_timeout_sec = stop_timeout_sec def _worker(self, idx, node): cmd = self.start_cmd(node) self.logger.debug("ReplicaVerificationTool %d command: %s" % (idx, cmd)) self.security_config.setup_node(node) for line in node.account.ssh_capture(cmd): self.logger.debug("Parsing line:{}".format(line)) parsed = re.search('.*max lag is (.+?) for partition ([a-zA-Z0-9._-]+-[0-9]+) at', line) if parsed: lag = int(parsed.group(1)) topic_partition = parsed.group(2) self.logger.debug("Setting max lag for {} as {}".format(topic_partition, lag)) self.partition_lag[topic_partition] = lag def get_lag_for_partition(self, topic, partition): """ Get latest lag for given topic-partition Args: topic: a topic partition: a partition of the topic """ topic_partition = topic + '-' + str(partition) lag = self.partition_lag.get(topic_partition, -1) self.logger.debug("Returning lag for {} as {}".format(topic_partition, lag)) return lag def start_cmd(self, node): cmd = self.path.script("kafka-run-class.sh", node) cmd += " %s" % self.java_class_name() cmd += " --broker-list %s --topic-white-list %s --time -2 --report-interval-ms %s" % (self.kafka.bootstrap_servers(self.security_protocol), self.topic, self.report_interval_ms) cmd += " 2>> /mnt/replica_verification_tool.log | tee -a /mnt/replica_verification_tool.log &" return cmd def stop_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=True, allow_fail=True) stopped = self.wait_node(node, timeout_sec=self.stop_timeout_sec) assert stopped, "Node %s: did not stop within the specified timeout of %s seconds" % \ (str(node.account), str(self.stop_timeout_sec)) def clean_node(self, node): node.account.kill_java_processes(self.java_class_name(), clean_shutdown=False, allow_fail=True) node.account.ssh("rm -rf /mnt/replica_verification_tool.log", allow_fail=False) def java_class_name(self): return "kafka.tools.ReplicaVerificationTool"