You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spot.apache.org by ev...@apache.org on 2017/03/29 16:52:06 UTC
[42/50] [abbrv] incubator-spot git commit: Adding Exception handler
for HDFS errors
Adding Exception handler for HDFS errors
Project: http://git-wip-us.apache.org/repos/asf/incubator-spot/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spot/commit/b41e9049
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spot/tree/b41e9049
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spot/diff/b41e9049
Branch: refs/heads/SPOT-35_graphql_api
Commit: b41e9049130b6016fe2b1dbcfced80f69d65924d
Parents: dbb5174
Author: Everardo Lopez Sandoval (Intel) <el...@elopezsa-mac02.zpn.intel.com>
Authored: Tue Mar 14 14:51:05 2017 -0600
Committer: Diego Ortiz Huerta <di...@intel.com>
Committed: Wed Mar 15 11:51:23 2017 -0700
----------------------------------------------------------------------
spot-oa/api/resources/hdfs_client.py | 36 +++++++++++++++++++------------
1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/b41e9049/spot-oa/api/resources/hdfs_client.py
----------------------------------------------------------------------
diff --git a/spot-oa/api/resources/hdfs_client.py b/spot-oa/api/resources/hdfs_client.py
index a6da531..ec7fc9f 100644
--- a/spot-oa/api/resources/hdfs_client.py
+++ b/spot-oa/api/resources/hdfs_client.py
@@ -17,22 +17,30 @@ def get_file(hdfs_file):
return results
def put_file_csv(hdfs_file_content,hdfs_path,hdfs_file_name,append_file=False,overwrite_file=False):
- client = _get_client()
- hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
- with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file) as writer:
- for item in hdfs_file_content:
- data = ','.join(str(d) for d in item)
- writer.write("{0}\n".format(data))
-
- return True
+
+ try:
+ client = _get_client()
+ hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
+ with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file) as writer:
+ for item in hdfs_file_content:
+ data = ','.join(str(d) for d in item)
+ writer.write("{0}\n".format(data))
+ return True
+
+ except HdfsError:
+ return False
def put_file_json(hdfs_file_content,hdfs_path,hdfs_file_name,append_file=False,overwrite_file=False):
- client = _get_client()
- hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
- with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file,encoding='utf-8') as writer:
- dump(hdfs_file_content, writer)
-
- return True
+
+ try:
+ client = _get_client()
+ hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
+ with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file,encoding='utf-8') as writer:
+ dump(hdfs_file_content, writer)
+ return True
+ except HdfsError:
+ return False
+
def delete_folder(hdfs_file,user=None):
client = _get_client(user)