Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 5579d95

Browse files
Fix: Worker on master flag ignored and standardize boolean environment (#514)
1 parent 3cc43c3 commit 5579d95

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

aztk/node_scripts/install/install.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def setup_host(docker_repo: str):
1818
client = config.batch_client
1919

2020
create_user.create_user(batch_client=client)
21-
if os.environ['AZ_BATCH_NODE_IS_DEDICATED'] == "true" or os.environ['AZTK_MIXED_MODE'] == "False":
21+
if os.environ['AZ_BATCH_NODE_IS_DEDICATED'] == "true" or os.environ['AZTK_MIXED_MODE'] == "false":
2222
is_master = pick_master.find_master(client)
2323
else:
2424
is_master = False
2525
wait_until_master_selected.main()
2626

27-
is_worker = not is_master or os.environ["AZTK_WORKER_ON_MASTER"]
27+
is_worker = not is_master or os.environ.get("AZTK_WORKER_ON_MASTER") == "true"
2828
master_node_id = pick_master.get_master_node_id(config.batch_client.pool.get(config.pool_id))
2929
master_node = config.batch_client.compute_node.get(config.pool_id, master_node_id)
3030

@@ -61,9 +61,6 @@ def setup_spark_container():
6161
spark.setup_conf()
6262
print("Done copying spark setup config")
6363

64-
master_node_id = pick_master.get_master_node_id(config.batch_client.pool.get(config.pool_id))
65-
master_node = config.batch_client.compute_node.get(config.pool_id, master_node_id)
66-
6764
spark.setup_connection()
6865

6966
if is_master:

aztk/node_scripts/setup_host.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-c
3838
sudo chmod +x /usr/local/bin/docker-compose
3939
echo "Done installing Docker-Compose"
4040

41-
if [ $AZTK_GPU_ENABLED == "True" ]; then
41+
if [ $AZTK_GPU_ENABLED == "true" ]; then
4242
echo "running nvidia install"
4343
sudo apt-get -y install nvidia-384
4444
sudo apt-get -y install nvidia-modprobe

aztk/spark/helpers/create_cluster.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313

1414
def _get_aztk_environment(worker_on_master, mixed_mode):
1515
envs = []
16-
envs.append(batch_models.EnvironmentSetting(name="AZTK_MIXED_MODE", value=mixed_mode))
17-
if worker_on_master is not None:
18-
envs.append(batch_models.EnvironmentSetting(
19-
name="AZTK_WORKER_ON_MASTER", value=worker_on_master))
20-
else:
21-
envs.append(batch_models.EnvironmentSetting(
22-
name="AZTK_WORKER_ON_MASTER", value=False))
16+
envs.append(batch_models.EnvironmentSetting(name="AZTK_MIXED_MODE", value=helpers.bool_env(mixed_mode)))
17+
envs.append(batch_models.EnvironmentSetting(
18+
name="AZTK_WORKER_ON_MASTER", value=helpers.bool_env(worker_on_master)))
2319
return envs
2420

2521
def __get_docker_credentials(spark_client):
@@ -152,7 +148,7 @@ def generate_cluster_start_task(
152148
batch_models.EnvironmentSetting(
153149
name="SPARK_SUBMIT_LOGS_FILE", value=spark_submit_logs_file),
154150
batch_models.EnvironmentSetting(
155-
name="AZTK_GPU_ENABLED", value=gpu_enabled),
151+
name="AZTK_GPU_ENABLED", value=helpers.bool_env(gpu_enabled)),
156152
] + __get_docker_credentials(spark_client) + _get_aztk_environment(worker_on_master, mixed_mode)
157153

158154
# start task command

aztk/utils/helpers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,24 @@ def read_cluster_config(cluster_id: str, blob_client: blob.BlockBlobService):
400400
logging.warn(
401401
"Cluster %s contains invalid cluster configuration in blob",
402402
cluster_id)
403+
404+
405+
def bool_env(value: bool):
406+
"""
407+
Takes a boolean value(or None) and return the serialized version to be used as an environemnt variable
408+
409+
Examples:
410+
>>> bool_env(True)
411+
"true"
412+
413+
>>> bool_env(False)
414+
"false"
415+
416+
>>> bool_env(None)
417+
"false"
418+
"""
419+
420+
if value is True:
421+
return "true"
422+
else:
423+
return "false"

tests/utils/test_helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from aztk.utils import helpers
2+
3+
def test_bool_env():
4+
assert helpers.bool_env(True) == "true"
5+
assert helpers.bool_env(False) == "false"
6+
assert helpers.bool_env(None) == "false"
7+
assert helpers.bool_env("some") == "false"

0 commit comments

Comments
 (0)