Exemplo n.º 1
0
def main():
    arguments = parse_arguments()
    environment_instance = environment.load_environment()
    environment.configure_logging(environment_instance, arguments)

    environment_instance["orchestra_worker_configuration"] = os.path.join(
        os.getcwd(), "worker.json").replace("\\", "/")
    environment_instance[
        "orchestra_worker_python_executable"] = sys.executable.replace(
            "\\", "/")

    application_title = bhamon_orchestra_worker.__product__ + " " + "Executor"
    application_version = bhamon_orchestra_worker.__version__

    with open(arguments.configuration, mode="r",
              encoding="utf-8") as configuration_file:
        configuration = json.load(configuration_file)
    with open(configuration["authentication_file_path"],
              mode="r",
              encoding="utf-8") as authentication_file:
        authentication = json.load(authentication_file)

    with filelock.FileLock(
            os.path.join("runs", arguments.run_identifier, "executor.lock"),
            5):
        executor_instance = create_application(arguments.run_identifier,
                                               configuration, authentication)
        asyncio_application = AsyncioApplication(application_title,
                                                 application_version)
        asyncio_application.run_as_standalone(
            executor_instance.run(arguments.run_identifier,
                                  environment_instance))
Exemplo n.º 2
0
def main():
	arguments = parse_arguments()
	environment_instance = environment.load_environment()
	environment.configure_logging(environment_instance, arguments)

	application_title = bhamon_orchestra_master.__product__ + " " + "Master"
	application_version = bhamon_orchestra_master.__version__

	configuration_title = bhamon_orchestra_master.__product__ + " " + "Master Configuration"
	configuration_version = bhamon_orchestra_configuration.__version__

	with open(arguments.configuration, mode = "r", encoding = "utf-8") as configuration_file:
		configuration = json.load(configuration_file)

	with filelock.FileLock("master.lock", 5):
		environment.configure_log_file(environment_instance, configuration["orchestra_master_log_file_path"])

		logging.getLogger("Application").info("%s %s", configuration_title, configuration_version)

		master_environment = {
			"artifact_server_url": configuration["artifact_server_web_url"],
			"python_package_repository_url": configuration["python_package_repository_web_url"],
		}

		master_application = create_application(configuration)
		master_application.apply_configuration(master_configuration.configure(master_environment))
		asyncio_application = AsyncioApplication(application_title, application_version)
		asyncio_application.run_as_standalone(master_application.run())
def test_run_cancellation():
    """ Test run with a main function which gets cancelled """
    class DummyMain:
        def __init__(self) -> None:
            self.future = None

        async def run(self) -> None:
            await asyncio.sleep(1)

        async def run_as_future(self) -> None:
            self.future = asyncio.ensure_future(self.run())
            await asyncio.sleep(0.1)
            self.future.cancel()
            await self.future

    main_instance = DummyMain()
    application_instance = AsyncioApplication(None, None)

    application_instance.run(main_instance.run_as_future())

    assert main_instance.future is not None
    assert main_instance.future.done()
    assert main_instance.future.cancelled()

    with pytest.raises(asyncio.CancelledError):
        main_instance.future.exception()
def main():
    arguments = parse_arguments()
    environment_instance = environment.load_environment()
    environment.configure_logging(environment_instance, arguments)

    application_title = bhamon_orchestra_worker.__product__ + " " + "Worker"
    application_version = bhamon_orchestra_worker.__version__
    executor_script = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "executor_main.py"))

    with open(arguments.configuration, mode="r",
              encoding="utf-8") as configuration_file:
        configuration = json.load(configuration_file)

    worker_path = configuration["orchestra_workers"][
        arguments.identifier]["path"]
    worker_log_path = configuration["orchestra_workers"][
        arguments.identifier]["log"]

    os.makedirs(worker_path, exist_ok=True)

    os.chdir(worker_path)

    with filelock.FileLock("worker.lock", 5):
        environment.configure_log_file(environment_instance, worker_log_path)
        worker_application = create_application(arguments.identifier,
                                                configuration, executor_script)
        asyncio_application = AsyncioApplication(application_title,
                                                 application_version)
        asyncio_application.run_as_standalone(worker_application.run())
Exemplo n.º 5
0
def main():
    arguments = parse_arguments()
    environment_instance = environment.load_environment()
    environment.configure_logging(environment_instance, arguments)

    application_title = bhamon_orchestra_master.__product__ + " " + "Master"
    application_version = bhamon_orchestra_master.__version__

    with filelock.FileLock("master.lock", 5):
        master_application = create_application(arguments)
        master_application.apply_configuration(configuration.configure())
        asyncio_application = AsyncioApplication(application_title,
                                                 application_version)
        asyncio_application.run_as_standalone(master_application.run())
Exemplo n.º 6
0
def main():
    arguments = parse_arguments()
    environment_instance = environment.load_environment()
    environment.configure_logging(environment_instance, arguments)

    application_title = bhamon_orchestra_worker.__product__ + " " + "Worker"
    application_version = bhamon_orchestra_worker.__version__

    with open("authentication.json", mode="r",
              encoding="utf-8") as authentication_file:
        authentication = json.load(authentication_file)

    with filelock.FileLock("worker.lock", 5):
        worker_application = create_application(arguments, authentication)
        asyncio_application = AsyncioApplication(application_title,
                                                 application_version)
        asyncio_application.run_as_standalone(worker_application.run())
Exemplo n.º 7
0
def main():
	arguments = parse_arguments()
	environment_instance = environment.load_environment()
	environment_instance["orchestra_worker_authentication"] = os.path.join(os.getcwd(), "authentication.json")
	environment.configure_logging(environment_instance, arguments)

	application_title = bhamon_orchestra_worker.__product__ + " " + "Executor"
	application_version = bhamon_orchestra_worker.__version__

	configuration = {
		"orchestra_service_url": environment_instance["orchestra_service_url"],
	}

	with open("authentication.json", mode = "r", encoding = "utf-8") as authentication_file:
		authentication = json.load(authentication_file)

	with filelock.FileLock(os.path.join("runs", arguments.run_identifier, "executor.lock"), 5):
		executor_application = create_application(arguments.run_identifier, configuration, authentication)
		asyncio_application = AsyncioApplication(application_title, application_version)
		asyncio_application.run_as_standalone(executor_application.run(arguments.run_identifier, environment_instance))
def test_run_success():
    """ Test run with a main function which succeeds """
    class DummyMain:
        def __init__(self) -> None:
            self.future = None

        async def run(self) -> None:
            await asyncio.sleep(0.1)

        async def run_as_future(self) -> None:
            self.future = asyncio.ensure_future(self.run())
            await self.future

    main_instance = DummyMain()
    application_instance = AsyncioApplication(None, None)

    application_instance.run(main_instance.run_as_future())

    assert main_instance.future is not None
    assert main_instance.future.done()
    assert not main_instance.future.cancelled()
    assert main_instance.future.exception() is None
def test_run_exception():
    """ Test run with a main function which raises an exception """
    class DummyMain:
        def __init__(self) -> None:
            self.future = None

        async def run(self) -> None:
            raise MockException()

        async def run_as_future(self) -> None:
            self.future = asyncio.ensure_future(self.run())
            await self.future

    main_instance = DummyMain()
    application_instance = AsyncioApplication(None, None)

    with pytest.raises(MockException):
        application_instance.run(main_instance.run_as_future())

    assert main_instance.future is not None
    assert main_instance.future.done()
    assert not main_instance.future.cancelled()
    assert main_instance.future.exception() is not None
    assert isinstance(main_instance.future.exception(), MockException)