Пример #1
0
def _restart_zookeeper(msg):
    '''
    Restart Zookeeper by re-running the puppet scripts.

    '''
    hookenv.status_set('maintenance', msg)
    zookeeper = Zookeeper()
    zookeeper.install()
    hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check()))
def rest_config():
    hookenv.status_set('maintenance', 'Updating REST service')
    zk = Zookeeper()
    config = hookenv.config()
    if config['rest']:
        zk.start_rest()
    else:
        zk.stop_rest()
    hookenv.status_set('active', 'Ready')
Пример #3
0
def _restart_zookeeper(msg):
    '''
    Restart Zookeeper by re-running the puppet scripts.

    '''
    hookenv.status_set('maintenance', msg)
    zookeeper = Zookeeper()
    zookeeper.install()
    hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check()))
def restart_zookeeper_if_config_changed():
    """Restart Zookeeper if zoo.cfg has changed.

    As peers come and go, zoo.cfg will be updated. When that file changes,
    restart the Zookeeper service and set an appropriate status message.
    """

    # Possibly update bind address
    network_interface = hookenv.config().get('network_interface')
    if data_changed("zookeeper.bind_address", network_interface):
        zk = Zookeeper()
        zk.update_bind_address()

    zoo_cfg = DistConfig().path('zookeeper_conf') / 'zoo.cfg'
    if any_file_changed([zoo_cfg]):
        hookenv.status_set('maintenance', 'Server config changed: restarting Zookeeper')
        zk = Zookeeper()
        zk.stop()
        zk.start()
        zk_count = int(zk.get_zk_count())
        extra_status = ""
        if zk_count < 3:
            extra_status = ": less than 3 is suboptimal"
        elif (zk_count % 2 == 0):
            extra_status = ": even number is suboptimal"
        hookenv.status_set('active', 'Ready (%d zk units%s)' % (zk_count, extra_status))
Пример #5
0
def quorum_remove(zkpeer):
    """Remove a zookeeper peer.

    Remove the unit that just departed, restart Zookeeper, and remove the
    '.departed' state so we don't fall in here again (until another peer leaves).
    """
    nodes = zkpeer.get_nodes()  # single node since we dismiss .departed below
    zk = Zookeeper()
    zk.decrease_quorum(nodes)
    restart_zookeeper_if_config_changed()
    zkpeer.dismiss_departed()
Пример #6
0
def quorum_remove(zkpeer):
    """Remove a zookeeper peer.

    Remove the unit that just departed, restart Zookeeper, and remove the
    '.departed' state so we don't fall in here again (until another peer leaves).
    """
    nodes = zkpeer.get_nodes()  # single node since we dismiss .departed below
    zk = Zookeeper()
    zk.decrease_quorum(nodes)
    restart_zookeeper_if_config_changed()
    zkpeer.dismiss_departed()
Пример #7
0
def quorum_add(zkpeer):
    """Add a zookeeper peer.

    Add the unit that just joined, restart Zookeeper, and remove the
    '.joined' state so we don't fall in here again (until another peer joins).
    """
    nodes = zkpeer.get_nodes()  # single node since we dismiss .joined below
    zk = Zookeeper()
    zk.increase_quorum(nodes)
    restart_zookeeper_if_config_changed()
    zkpeer.dismiss_joined()
Пример #8
0
def quorum_add(zkpeer):
    """Add a zookeeper peer.

    Add the unit that just joined, restart Zookeeper, and remove the
    '.joined' state so we don't fall in here again (until another peer joins).
    """
    nodes = zkpeer.get_nodes()  # single node since we dismiss .joined below
    zk = Zookeeper()
    zk.increase_quorum(nodes)
    restart_zookeeper_if_config_changed()
    zkpeer.dismiss_joined()
Пример #9
0
def check_cluster(zkpeer):
    '''
    Checkup on the state of the cluster. Start a rolling restart if
    the peers have changed.

    '''
    zk = Zookeeper()
    if data_changed('zkpeer.nodes', zk.read_peers()):
        peers = _ip_list(zk.sort_peers(zkpeer))
        nonce = time.time()
        hookenv.log('Quorum changed. Restart queue: {}'.format(peers))
        leader_set(restart_queue=json.dumps(peers),
                   restart_nonce=json.dumps(nonce))
Пример #10
0
def check_cluster(zkpeer):
    '''
    Checkup on the state of the cluster. Start a rolling restart if
    the peers have changed.

    '''
    zk = Zookeeper()
    if data_changed('zkpeer.nodes', zk.read_peers()):
        peers = _ip_list(zk.sort_peers(zkpeer))
        nonce = time.time()
        hookenv.log('Quorum changed. Restart queue: {}'.format(peers))
        leader_set(
            restart_queue=json.dumps(peers),
            restart_nonce=json.dumps(nonce)
        )
Пример #11
0
def install_zookeeper(*args):
    zk = Zookeeper()
    if zk.verify_resources():
        hookenv.status_set('maintenance', 'Installing Zookeeper')
        zk.install()
        zk.initial_config()
        set_state('zookeeper.installed')
        hookenv.status_set('maintenance', 'Zookeeper Installed')
Пример #12
0
def storage_detaching():
    unitdata.kv().unset('zookeeper.storage.data_dir')
    zookeeper = Zookeeper()
    zookeeper.close_ports()
    zookeeper.stop()
    clear_flag('zookeeper.configured')
    hookenv.status_set('waiting', 'reconfiguring to use temporary storage')
    clear_flag('zookeeper.storage.data.attached')
def install_zookeeper(*args):
    zk = Zookeeper()
    if zk.verify_resources():
        hookenv.status_set('maintenance', 'Installing Zookeeper')
        zk.install()
        zk.initial_config()
        set_state('zookeeper.installed')
        hookenv.status_set('maintenance', 'Zookeeper Installed')
Пример #14
0
def rest_config():
    hookenv.status_set('maintenance', 'Updating REST service')
    zk = Zookeeper()
    config = hookenv.config()
    if config['rest']:
        zk.start_rest()
    else:
        zk.stop_rest()
    hookenv.status_set('active', 'Ready')
Пример #15
0
def install_zookeeper():
    '''
    After Bigtop has done the initial setup, trigger a puppet install,
    via our Zooekeeper library.

    puppet will start the service, as a side effect.

    '''
    hookenv.status_set('maintenance', 'installing zookeeper')
    zookeeper = Zookeeper()
    # Prime data changed
    data_changed('zkpeer.nodes', zookeeper.read_peers())
    data_changed('zk.network_interface',
                 hookenv.config().get('network_interface'))
    zookeeper.install()
    zookeeper.open_ports()
    set_state('zookeeper.installed')
    set_state('zookeeper.started')
    hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check()))
Пример #16
0
def configure():
    cfg = hookenv.config()
    zookeeper = Zookeeper()
    changed = any((
        data_changed('zkpeer.nodes', zookeeper.read_peers()),
        data_changed('zk.autopurge_purge_interval',
                     cfg.get('autopurge_purge_interval')),
        data_changed('zk.autopurge_snap_retain_count',
                     cfg.get('autopurge_snap_retain_count')),
        data_changed('zk.storage.data_dir',
                     unitdata.kv().get('zookeeper.storage.data_dir')),
    ))
    if changed or is_flag_set('zookeeper.force-reconfigure'):
        zookeeper.install()
        zookeeper.open_ports()
    clear_flag('zookeeper.force-reconfigure')
    set_flag('zookeeper.started')
    set_flag('zookeeper.configured')
    hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check()))
    # set app version string for juju status output
    zoo_version = get_installed_version(SNAP_NAME) or 'unknown'
    hookenv.application_version_set(zoo_version)
Пример #17
0
def autostart_service():
    '''
    Attempt to restart the service if it is not running.

    '''
    zookeeper = Zookeeper()
    if zookeeper.is_running():
        hookenv.status_set('active',
                           'ready {}'.format(zookeeper.quorum_check()))
        return

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

    hookenv.status_set('blocked', 'failed to start zookeeper; check syslog')
Пример #18
0
def install_zookeeper():
    '''
    After Bigtop has done the initial setup, trigger a puppet install,
    via our Zooekeeper library.

    puppet will start the service, as a side effect.

    '''
    hookenv.status_set('maintenance', 'installing zookeeper')
    zookeeper = Zookeeper()
    # Prime data changed
    data_changed('zkpeer.nodes', zookeeper.read_peers())
    data_changed(
        'zk.network_interface',
        hookenv.config().get('network_interface'))
    zookeeper.install()
    zookeeper.open_ports()
    set_state('zookeeper.installed')
    set_state('zookeeper.started')
    hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check()))
Пример #19
0
def storage_attach():
    storageids = hookenv.storage_list('data')
    if not storageids:
        hookenv.status_set('blocked', 'cannot locate attached storage')
        return
    storageid = storageids[0]

    mount = hookenv.storage_get('location', storageid)
    if not mount:
        hookenv.status_set('blocked', 'cannot locate attached storage mount')
        return

    data_dir = os.path.join(mount, "data")
    unitdata.kv().set('zookeeper.storage.data_dir', data_dir)
    hookenv.log('Zookeeper data storage attached at {}'.format(data_dir))
    # Stop Zookeeper; removing zookeeper.configured state will trigger
    # a reconfigure if/when it's ready
    zookeeper = Zookeeper()
    zookeeper.close_ports()
    zookeeper.stop()
    clear_flag('zookeeper.configured')
    hookenv.status_set('waiting', 'reconfiguring to use attached storage')
    set_flag('zookeeper.storage.data.attached')
Пример #20
0
def serve_client(client):
    config = Zookeeper().dist_config
    port = config.port('zookeeper')
    rest_port = config.port('zookeeper-rest')  # TODO: add zookeeper REST
    client.send_port(port, rest_port)
Пример #21
0
def serve_client(client):
    config = Zookeeper().dist_config
    port = config.port('zookeeper')
    rest_port = config.port('zookeeper-rest')  # TODO: add zookeeper REST
    client.send_port(port, rest_port)
Пример #22
0
def start_zookeeper():
    zk = Zookeeper()
    zk.start()
    zk.open_ports()
    set_state('zookeeper.started')
    hookenv.status_set('active', 'Ready')
Пример #23
0
def restart_zookeeper_if_config_changed():
    """Restart Zookeeper if zoo.cfg has changed.

    As peers come and go, zoo.cfg will be updated. When that file changes,
    restart the Zookeeper service and set an appropriate status message.
    """

    # Possibly update bind address
    network_interface = hookenv.config().get('network_interface')
    if data_changed("zookeeper.bind_address", network_interface):
        zk = Zookeeper()
        zk.update_bind_address()

    zoo_cfg = DistConfig().path('zookeeper_conf') / 'zoo.cfg'
    if any_file_changed([zoo_cfg]):
        hookenv.status_set('maintenance',
                           'Server config changed: restarting Zookeeper')
        zk = Zookeeper()
        zk.stop()
        zk.start()
        zk_count = int(zk.get_zk_count())
        extra_status = ""
        if zk_count < 3:
            extra_status = ": less than 3 is suboptimal"
        elif (zk_count % 2 == 0):
            extra_status = ": even number is suboptimal"
        hookenv.status_set('active',
                           'Ready (%d zk units%s)' % (zk_count, extra_status))
    else:
        # Make sure zookeeper is running in any case
        zk = Zookeeper()
        zk.start()
        zk.open_ports()
def quorum_remove(zkpeer):
    nodes = zkpeer.get_nodes()
    zk = Zookeeper()
    zk.decrease_quorum(nodes)
    zkpeer.dismiss_departed()
def quorum_add(zkpeer):
    nodes = zkpeer.get_nodes()
    zk = Zookeeper()
    zk.increase_quorum(nodes)
    zkpeer.dismiss_joined()
def start_zookeeper():
    zk = Zookeeper()
    zk.start()
    zk.open_ports()
    set_state('zookeeper.started')
    hookenv.status_set('active', 'Ready')
def restart_zookeeper():
    hookenv.status_set('maintenance', 'Server config changed: restarting Zookeeper')
    zk = Zookeeper()
    zk.stop()
    zk.start()
    hookenv.status_set('active', 'Ready')