本文整理汇总了Python中apache.aurora.config.loader.AuroraConfigLoader.load_json方法的典型用法代码示例。如果您正苦于以下问题:Python AuroraConfigLoader.load_json方法的具体用法?Python AuroraConfigLoader.load_json怎么用?Python AuroraConfigLoader.load_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apache.aurora.config.loader.AuroraConfigLoader
的用法示例。
在下文中一共展示了AuroraConfigLoader.load_json方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_memoized_load_json_cache_hit
# 需要导入模块: from apache.aurora.config.loader import AuroraConfigLoader [as 别名]
# 或者: from apache.aurora.config.loader.AuroraConfigLoader import load_json [as 别名]
def test_memoized_load_json_cache_hit(mock_gen_content_key):
expected_env = AuroraConfigLoader.load(BytesIO(MESOS_CONFIG))
expected_job_json = json.dumps(expected_env['jobs'][0].get())
mock_gen_content_key.return_value = MESOS_CONFIG_MD5
AuroraConfigLoader.CACHED_JSON = {MESOS_CONFIG_MD5: expected_job_json}
loaded_job_json = AuroraConfigLoader.load_json('a/path', is_memoized=True)
assert loaded_job_json == expected_job_json, "Test cache hit load_json"
示例2: test_load_json_memoized
# 需要导入模块: from apache.aurora.config.loader import AuroraConfigLoader [as 别名]
# 或者: from apache.aurora.config.loader.AuroraConfigLoader import load_json [as 别名]
def test_load_json_memoized():
AuroraConfigLoader.CACHED_JSON = {}
env = AuroraConfigLoader.load(BytesIO(MESOS_CONFIG_MULTI))
jobs = env['jobs']
content = json.dumps(jobs[0].get())
expected_md5 = hashlib.md5(content).hexdigest()
with temporary_dir() as d:
filename = os.path.join(d, 'config.json')
with open(filename, 'w+') as fp:
fp.write(json.dumps(jobs[0].get()))
fp.close()
loaded_job = AuroraConfigLoader.load_json(fp.name, is_memoized=False)['jobs'][0]
assert loaded_job == jobs[0]
assert expected_md5 not in AuroraConfigLoader.CACHED_JSON, (
"No key is cached when is_memoized=False")
loaded_job = AuroraConfigLoader.load_json(fp.name, is_memoized=True)['jobs'][0]
assert loaded_job == jobs[0]
assert expected_md5 in AuroraConfigLoader.CACHED_JSON, (
"Key is cached when is_memoized=True")
示例3: test_load_json
# 需要导入模块: from apache.aurora.config.loader import AuroraConfigLoader [as 别名]
# 或者: from apache.aurora.config.loader.AuroraConfigLoader import load_json [as 别名]
def test_load_json():
with temporary_file() as fp:
fp.write(MESOS_CONFIG)
fp.flush()
env = AuroraConfigLoader.load(fp.name)
job = env['jobs'][0]
with temporary_file() as fp:
fp.write(json.dumps(job.get()))
fp.flush()
new_job = AuroraConfigLoader.load_json(fp.name)
assert new_job == job
示例4: execute
# 需要导入模块: from apache.aurora.config.loader import AuroraConfigLoader [as 别名]
# 或者: from apache.aurora.config.loader.AuroraConfigLoader import load_json [as 别名]
def execute(self, context):
def maybe_bind(j):
return j.bind(*bindings) if bindings else j
def get_jobkey(job):
return "/".join([job.cluster().get(), job.role().get(), job.environment().get(), job.name().get()])
try:
if context.options.read_json:
env = AuroraConfigLoader.load_json(context.options.config_file)
else:
env = AuroraConfigLoader.load(context.options.config_file)
except (AuroraConfig.Error, AuroraConfigLoader.Error, ValueError) as e:
context.print_err("Error loading configuration file: %s" % e)
return EXIT_COMMAND_FAILURE
bindings = context.options.bindings
job_list = env.get("jobs", [])
if not job_list:
context.print_out("jobs=[]")
else:
bound_jobs = map(maybe_bind, job_list)
job_names = map(get_jobkey, bound_jobs)
context.print_out("jobs=[%s]" % (", ".join(job_names)))
return EXIT_OK