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

Commit

Permalink
Fix: diagnostics function write error result bug (#649)
Browse files Browse the repository at this point in the history
* fix output writing for diagnostics function

* log on ssh connect
  • Loading branch information
jafreck authored Aug 17, 2018
1 parent 7c14648 commit 293f297
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions aztk/spark/client/cluster/helpers/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
from aztk.utils import helpers


def _write_error(stream, node_output):
stream.write(node_output.error)


def _write_output(stream, node_output):
stream.write(node_output.output)


def _run(spark_cluster_operations, cluster_id, output_directory=None, brief=False):
# copy debug program to each node
output = spark_cluster_operations.copy(
Expand All @@ -18,9 +26,10 @@ def _run(spark_cluster_operations, cluster_id, output_directory=None, brief=Fals
local_path = os.path.join(os.path.abspath(output_directory), "debug.zip")
result = spark_cluster_operations.download(cluster_id, remote_path, local_path, host=True)

# write run output to debug/ directory
with open(os.path.join(output_directory, "debug-output.txt"), 'w', encoding="UTF-8") as f:
[f.write(node_output.output + '\n') for node_output in run_output]
# write run output or error to debug/ directory
with open(os.path.join(output_directory, "debug-output.txt"), 'w', encoding="UTF-8") as stream:
for node_output in run_output:
_write_error(stream, node_output) if node_output.error else _write_output(stream, node_output)
else:
result = spark_cluster_operations.download(cluster_id, remote_path, host=True)

Expand Down
2 changes: 1 addition & 1 deletion aztk/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def connect(hostname, port=22, username=None, password=None, pkey=None, timeout=
ssh_key = None

timeout = timeout or 20
logging.debug("Connecting to {}@{}:{}, timeout={}".format(username, hostname, port, timeout))
try:
client.connect(hostname, port=port, username=username, password=password, pkey=ssh_key, timeout=timeout)
except socket.timeout:
Expand Down Expand Up @@ -206,7 +207,6 @@ def node_copy(node_id,
output = sftp_client.put(source_path, destination_path).__str__()
return NodeOutput(node_id, output, None)
except (IOError, PermissionError) as e:
raise e
return NodeOutput(node_id, None, e)
finally:
sftp_client.close()
Expand Down

0 comments on commit 293f297

Please sign in to comment.