def configure_kafka_zookeepers(zk): """Configure ready zookeepers and restart kafka if needed. As zks come and go, server.properties will be updated. When that file changes, restart Kafka and set appropriate status messages. This method also handles the restart if our network_interface config has changed. """ zks = zk.zookeepers() network_interface = hookenv.config().get('network_interface') log_dir = unitdata.kv().get('kafka.storage.log_dir') if not(any(( data_changed('zookeepers', zks), data_changed('kafka.network_interface', network_interface), data_changed('kafka.storage.log_dir', log_dir)))): return hookenv.log('Checking Zookeeper configuration') hookenv.status_set('maintenance', 'updating zookeeper instances') kafka = Kafka() kafka.configure_kafka(zks, network_interface=network_interface, log_dir=log_dir) hookenv.status_set('active', 'ready')
def reconfigure_kafka_new_zk_instances(zkjoining, zkavailable): try: zk_units = zkavailable.get_zookeeper_units() hookenv.status_set('maintenance', 'Updating Kafka with new Zookeeper instances') kafka = Kafka(DistConfig()) kafka.configure_kafka(zk_units) kafka.restart() zkjoining.dismiss_joining() hookenv.status_set('active', 'Ready') except: hookenv.log("Relation with Zookeeper not established")
def configure_kafka(zkjoining, zkavailable): try: zk_units = zkavailable.get_zookeeper_units() hookenv.status_set('maintenance', 'Setting up Kafka') kafka = Kafka(DistConfig()) kafka.configure_kafka(zk_units) kafka.start() zkjoining.dismiss_joining() hookenv.status_set('active', 'Ready') set_state('kafka.started') except: hookenv.log("Relation with Zookeeper not established")
def configure_kafka(zk): hookenv.status_set('maintenance', 'setting up kafka') data_changed( # Prime data changed for network interface 'kafka.network_interface', hookenv.config().get('network_interface')) log_dir = unitdata.kv().get('kafka.storage.log_dir') data_changed('kafka.storage.log_dir', log_dir) kafka = Kafka() zks = zk.zookeepers() kafka.configure_kafka(zks, log_dir=log_dir) kafka.open_ports() set_state('kafka.started') hookenv.status_set('active', 'ready') # set app version string for juju status output kafka_version = get_package_version(KAFKA_SNAP) or 'unknown' hookenv.application_version_set(kafka_version)
def reconfigure_kafka_zk_instances_leaving(zkdeparting, zkavailable): try: zk_units = zkavailable.get_zookeeper_units() hookenv.status_set('maintenance', 'Updating Kafka with departing Zookeeper instances ') kafka = Kafka(DistConfig()) kafka.configure_kafka(zk_units) kafka.restart() zkdeparting.dismiss_departing() hookenv.status_set('active', 'Ready') except: hookenv.log("Relation with Zookeeper not established. Stopping Kafka.") kafka = Kafka(DistConfig()) kafka.stop() remove_state('kafka.started') hookenv.status_set('blocked', 'Waiting for connection to Zookeeper')