Exemplo n.º 1
0
    def write_to_zookeeper(self):
        with zk_utils.connection() as zk:

            base_node = os.path.join('kolla', self.deployment_id)
            if zk.exists(base_node) and CONF.force:
                LOG.info('Deleting "%s" ZK node tree' % base_node)
                zk.delete(base_node, recursive=True)
            elif zk.exists(base_node) and not CONF.force:
                LOG.info('"%s" ZK node tree is already exists. If you'
                         ' want to delete it, use --force' % base_node)
                sys.exit(1)

            self.write_config_to_zookeeper(zk)

            filter_out = ['groups', 'hostvars', 'kolla_config',
                          'inventory_hostname']
            for var in self.required_vars:
                if (var in filter_out):
                    LOG.debug('Var "%s" with value "%s" is filtered out' %
                              (var, self.required_vars[var]))
                    continue
                var_value = self.required_vars[var]
                if isinstance(self.required_vars[var], dict):
                    var_value = json.dumps(self.required_vars[var])
                var_path = os.path.join(base_node, 'variables', var)
                zk.ensure_path(var_path)
                try:
                    zk.set(var_path, "" if var_value is None else var_value)
                    LOG.debug('Updated "%s" node in zookeeper.' % var_path)
                except Exception as te:
                    LOG.error('Cant create "%s" node with "%s" item in '
                              'Zookeeper. Error was: "%s"' %
                              (var_path, var_value, te))
Exemplo n.º 2
0
def main():
    CONF(sys.argv[1:], project='kolla-mesos')
    with zk_utils.connection(CONF.zookeeper.host) as zk:
        if CONF.show:
            zk_utils.cat(zk, CONF.path)
        else:
            zk_utils.tree(zk, CONF.path)
Exemplo n.º 3
0
def get_deployment_ids():
    ids = []
    with zk_utils.connection() as zk:
        children = zk.get_children('/kolla')
        for child in children:
            if child not in ['groups', 'variables', 'common',
                             'config', 'commands']:
                ids.append(child)
    return ids
Exemplo n.º 4
0
def get_status(tasks):
    """Get status from zookeeper

    Returns the status of for each task
    {
        task1: {
            'register': (register_path, reg_status)
            'requirements': {
                reqt1_path: reqt_status
                reqt2_path: reqt_status
                ...
            }
        }

    Where:
        reg_status = 'done', 'running', 'waiting'
        reqt_status = '', 'done'
    """
    status = {}
    with zk_utils.connection() as zk:
        # get status of requirements
        for task, info in tasks.items():
            status[task] = {}
            if 'requires' in info:
                status[task]['requirements'] = {}
                for path in info['requires']:
                    reqt_status = ''
                    if zk.exists(path):
                        reqt_status = 'done'
                    status[task]['requirements'][path] = reqt_status

        # get status of registrations
        for task, info in tasks.items():
            if 'register' in info:
                status[task]['register'] = {}
                reg_status = 'NOT DONE'
                reg_path = info['register']
                if zk.exists(reg_path):
                    reg_status = 'done'
                elif 'requires' in info:
                    all_done = True
                    for path in info['requires']:
                        if not status[task]['requirements'][path]:
                            all_done = False
                            break
                    if not all_done:
                        reg_status = 'waiting'

                status[task]['register'] = (reg_path, reg_status)
    return status
Exemplo n.º 5
0
def get_status(tasks):
    """Get status from zookeeper.

    :returns: the status for each task

    Below is an example of what can be returned::

        {
            task1: {
                'register': (register_path, reg_status)
                'requirements': {
                    reqt1_path: reqt_status
                    reqt2_path: reqt_status
                    ...
                }
            }
        }
        Where:
            reg_status = 'done', 'running', 'waiting'
            reqt_status = '', 'done'
    """
    status = {}
    with zk_utils.connection() as zk:
        # get status of requirements
        for task, info in tasks.items():
            status[task] = {}
            status[task]['requirements'] = {}
            for path in info['requires']:
                req_status = ''.encode('utf-8')
                if zk.exists(path):
                    req_status, _ = zk.get(path)
                status[task]['requirements'][path] = req_status.decode('utf-8')

        # get status of registrations
        for task, info in tasks.items():
            status[task]['register'] = {}
            reg_path = info['register']
            reg_status = ''.encode('utf-8')
            if zk.exists(reg_path):
                reg_status, _ = zk.get(reg_path)

            status[task]['register'] = (reg_path, reg_status.decode('utf-8'))
    return status
Exemplo n.º 6
0
def cleanup():
    LOG.info("Starting cleanup...")
    marathon_client = marathon.Client()
    chronos_client = chronos.Client()

    with zk_utils.connection() as zk:
        zk_utils.clean(zk)
    LOG.info("Starting cleanup of apps")
    marathon_client.remove_all_apps()
    LOG.info("Starting cleanup of groups")
    marathon_client.remove_all_groups()
    LOG.info("Starting cleanup of chronos jobs")
    chronos_client.remove_all_jobs()

    LOG.info("Checking whether all tasks in Mesos are exited")
    wait_for_mesos_cleanup()

    LOG.info("Starting cleanup of Docker containers")
    remove_all_containers()
    LOG.info("Starting cleanup of Docker volumes")
    remove_all_volumes()
Exemplo n.º 7
0
    def write_to_zookeeper(self):
        with zk_utils.connection(CONF.zookeeper.host) as zk:
            # to clean these up, uncomment
            zk.delete('/kolla', recursive=True)

            self.write_config_to_zookeeper(zk)

            filter_out = ['groups', 'hostvars', 'kolla_config',
                          'inventory_hostname']
            for var in self.required_vars:
                if (var in filter_out):
                    LOG.info('set(%s) = %s' % (var, self.required_vars[var]))
                    continue
                var_value = self.required_vars[var]
                if isinstance(self.required_vars[var], dict):
                    var_value = json.dumps(self.required_vars[var])
                var_path = os.path.join('kolla', 'variables', var)
                zk.ensure_path(var_path)
                try:
                    zk.set(var_path, var_value)
                except Exception as te:
                    LOG.error('%s=%s -> %s' % (var_path, var_value, te))
Exemplo n.º 8
0
def _build_runner(service_name, service_dir, variables=None):
    config_dir = os.path.join(service_dir, '..', 'config')
    base_node = os.path.join('kolla', CONF.kolla.deployment_id)
    filename = service_definition.find_service_file(service_name,
                                                    service_dir)
    proj_name = filename.split('/')[-2]
    proj_yml_name = os.path.join(config_dir, proj_name,
                                 'defaults', 'main.yml')

    # is this a snapshot or from original src?
    var_path = os.path.join(service_dir, 'variables.yml')
    is_snapshot = (os.path.exists(var_path) and
                   not os.path.exists(proj_yml_name))

    if variables is None:
        if not is_snapshot:
            variables = _load_variables_from_file(service_dir, proj_name)
        else:
            variables = _load_variables_from_snapshot(service_dir)

    # 1. validate the definition with the given variables
    service_definition.validate(service_name, service_dir, variables)
    runner = Runner.load_from_file(filename, variables)
    with zk_utils.connection() as zk:
        # 2. write variables to zk (globally)
        config.write_variables_zookeeper(zk, variables,
                                         overwrite=not is_snapshot)
        # 3. write common config and start script
        config.write_common_config_to_zookeeper(config_dir, zk, variables,
                                                overwrite=not is_snapshot)

        # 4. write files/config to zk
        runner.write_to_zookeeper(zk, base_node)

    # 5. generate the deployment files
    kolla_config = config.get_start_config(config_dir, variables)
    runner.generate_deployment_files(kolla_config, variables)
    return runner
Exemplo n.º 9
0
def scale_service(service_name, instances, force=False):
    with zk_utils.connection() as zk:
        runner = Runner.load_from_zk(zk, service_name)
        return runner.scale(instances, force)
Exemplo n.º 10
0
def get_service(service_name, version=None):
    with zk_utils.connection() as zk:
        runner = Runner.load_from_zk(zk, service_name)
        return runner.get_state(version)
Exemplo n.º 11
0
def snapshot_service(service_name, output_dir):
    with zk_utils.connection() as zk:
        runner = Runner.load_from_zk(zk, service_name)
        variables = _load_variables_from_zk(zk)
        runner.snapshot(zk, output_dir, variables)
Exemplo n.º 12
0
def kill_service(service_name):
    with zk_utils.connection() as zk:
        runner = Runner.load_from_zk(zk, service_name)
        runner.kill(zk)