Beispiel #1
0
def _setup_bootstrap_repositories(logger: Callable, config: dict, settings: dict):
    exitcode = 0
    logger(bold("Bootstrapping repositories ..."))

    try:
        nested_repositories = group_by_key(settings["repositories"], "run-order", include_missing=True)
        for repo_name in itertools.chain.from_iterable(nested_repositories):
            if "bootstrap" in settings["repositories"][repo_name]:
                app_info = get_app_info(repo_name, config, settings, {})

                logger(green("* Starting bootstrap of") + " " + app_info["name"] + " ...", log_name="setup")

                bootstrap_command = settings["repositories"][repo_name]["bootstrap"]
                exitcode = DMProcess(app=app_info, logger=logger, app_command=bootstrap_command).wait()

                if exitcode:
                    logger(
                        red("* Bootstrap failed for ") + app_info["name"] + red(" with exit code {}").format(exitcode)
                    )
                    exitcode = EXITCODE_BOOTSTRAP_FAILED
                    break

                else:
                    logger(green("* Bootstrap completed for") + " " + app_info["name"] + " ", log_name="setup")

    except KeyboardInterrupt:
        exitcode = EXITCODE_SETUP_ABORT

    return exitcode
def _setup_indices(logger: Callable, config: dict, settings: dict):
    exitcode = 0
    manager = multiprocessing.Manager()

    logger(bold("Bootstrapping search indices ..."))

    dependencies = []
    for dependency in settings["index"]["dependencies"]:
        dependency_app_info = get_app_info(dependency, config, settings,
                                           manager.dict())
        dependencies.append(
            (DMProcess(app=dependency_app_info,
                       logger=nologger,
                       app_command=APP_COMMAND_RESTART), dependency_app_info))

    time.sleep(10)

    for index in settings["index"]["indices"]:
        index_name = index["keyword"]["index"]

        app_info = get_app_info(settings["index"]["repository"], config,
                                settings, manager.dict())
        try:
            assert requests.get(settings["index"]["test"].format(
                index=index_name)).status_code == 200

        except Exception:
            index_command = "{command} {keyword} {positional}".format(
                command=settings["index"]["command"],
                keyword=" ".join([
                    "--{k}={v}".format(k=k, v=v)
                    for k, v in index["keyword"].items()
                ]),
                positional=" ".join(index["positional"]),
            )

            logger("* Creating index '{}' ...".format(index_name))

            exitcode = DMProcess(app=app_info,
                                 logger=logger,
                                 app_command=index_command).wait()
            if exitcode:
                logger(
                    red("* Something went wrong when creating the '{}' index: exitcode "
                        "{}".format(index_name, exitcode)))
                exitcode = EXITCODE_BOOTSTRAP_FAILED
                break

            else:
                logger(
                    green("* Index '{}' created successfully.".format(
                        index_name)))

        else:
            logger(green("* Index '{}' already exists.".format(index_name)))

    for dependency, dependency_app_info in dependencies:
        try:
            p = psutil.Process(dependency_app_info["process"])

            for child in p.children(recursive=True):
                child.kill()

            p.kill()

        except Exception as e:
            logger(str(e))
            exitcode = EXITCODE_BOOTSTRAP_FAILED

    return exitcode