forked from Data-Science-Platform/cluster-broccoli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Data-Science-Platform/cluster-bro…
…ccoli into DSP-1547
- Loading branch information
Showing
47 changed files
with
1,362 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import json | ||
import glob | ||
import argparse | ||
import os | ||
from copy import deepcopy | ||
|
||
|
||
def update_parameter_infos(parameter_infos): | ||
updated_parameters = deepcopy(parameter_infos) | ||
info_variables = set(parameter_infos.keys()) | ||
for variable in info_variables: | ||
if type(updated_parameters[variable]['type']) == str: | ||
old_type = updated_parameters[variable]['type'] | ||
updated_parameters[variable]['type'] = {"name": old_type} | ||
else: | ||
print("not changing type for " + variable) | ||
return updated_parameters | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("instance_directory") | ||
|
||
opts = parser.parse_args() | ||
|
||
for instance_path in glob.glob(os.path.join(opts.instance_directory, "*.json")): | ||
print("Processing %s" % instance_path) | ||
instance = json.loads(open(instance_path).read()) | ||
|
||
assert "template" in instance | ||
template = instance["template"] | ||
assert "template" in template | ||
assert "parameterInfos" in template | ||
parameter_infos = template["parameterInfos"] | ||
|
||
complete_parameter_infos = update_parameter_infos(parameter_infos) | ||
|
||
parameter_infos_changed = False | ||
if parameter_infos != complete_parameter_infos: | ||
parameter_infos_changed = True | ||
template["parameterInfos"] = complete_parameter_infos | ||
|
||
if parameter_infos_changed: | ||
print("Overwritting instance: %s" % instance_path) | ||
open(instance_path, "w+").write(json.dumps(instance)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
import argparse | ||
import json | ||
from copy import deepcopy | ||
from pyhocon import ConfigFactory, HOCONConverter | ||
|
||
|
||
def update_parameters(parameters): | ||
updated_parameters = deepcopy(parameters) | ||
info_variables = set(updated_parameters.keys()) | ||
for variable in info_variables: | ||
if type(updated_parameters[variable]['type']) == str: | ||
old_type = updated_parameters[variable]['type'] | ||
updated_parameters[variable]['type'] = ConfigFactory.from_dict({"name": old_type}) | ||
else: | ||
print("not changing type for " + variable) | ||
return updated_parameters | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("template_directory") | ||
parser.add_argument("output_format", choices=["json", "hocon"]) | ||
|
||
opts = parser.parse_args() | ||
|
||
for directory_name in os.listdir(os.path.join(opts.template_directory)): | ||
if not os.path.isdir(os.path.join(opts.template_directory, directory_name)): | ||
print(directory_name + " was not a directory. Skipping.") | ||
continue | ||
|
||
directory_path = os.path.join(opts.template_directory, directory_name) | ||
template_path = os.path.join(directory_path, "template.json") | ||
config_path = os.path.join(directory_path, "template.conf") | ||
if not os.path.isfile(template_path): | ||
print("%s is not a template directory (template file is missing)" % directory_path) | ||
continue | ||
|
||
if not os.path.isfile(config_path): | ||
print("%s is not a template directory (config file is missing)" % directory_path) | ||
continue | ||
|
||
template = open(template_path).read() | ||
config = ConfigFactory.parse_file(config_path) | ||
if "parameters" not in config: | ||
config["parameters"] = {} | ||
|
||
complete_parameters = update_parameters(config["parameters"]) | ||
parameters_changed = False | ||
if config["parameters"] != complete_parameters: | ||
parameters_changed = True | ||
config["parameters"] = complete_parameters | ||
|
||
if parameters_changed: | ||
print("Overwriting template.conf: %s" % config_path) | ||
# We can use the HOCONConverter for dumping the json as well but we have more options to control | ||
# the output with the default json writer | ||
if opts.output_format == "hocon": | ||
open(config_path, "w+").write(HOCONConverter.convert(config, "hocon")) | ||
else: | ||
open(config_path, "w+").write( | ||
# This is a config tree but json.dumps uses iterators to go over it thinking it is a dict. | ||
# Since configtree already supports these iterators it works correctly for it. | ||
json.dumps(config, indent=2, separators=(',', ': ', ), ensure_ascii=False) + "\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.