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")
Exemple #2
0
def restart():
    hookenv.status_set('maintenance', 'Rolling restart')
    kafka = Kafka()
    if not kafka.is_running():
        kafka.start()
    else:
        kafka.restart()
    hookenv.open_port(hookenv.config()['port'])
    # set app version string for juju status output
    kafka_version = kafka.version()
    hookenv.application_version_set(kafka_version)
    hookenv.status_set('active', 'ready')
    set_state('kafka.started')
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')
Exemple #4
0
def autostart_service():
    '''
    Attempt to restart the service if it is not running.
    '''
    kafka = Kafka()

    if kafka.is_running():
        hookenv.status_set('active', 'ready')
        return

    for i in range(3):
        hookenv.status_set(
            'maintenance',
            'attempting to restart kafka, '
            'attempt: {}'.format(i+1)
        )
        kafka.restart()
        if kafka.is_running():
            hookenv.status_set('active', 'ready')
            return

    hookenv.status_set('blocked', 'failed to start kafka; check syslog')