@@ -41,60 +41,25 @@ def _add_toolkit_dependency(topo):
41
41
# This is important when toolkit is not set with streamsx.spl.toolkit.add_toolkit (selecting toolkit from remote build service)
42
42
streamsx .spl .toolkit .add_toolkit_dependency (topo , _TOOLKIT_NAME , '[5.0.0,6.0.0)' )
43
43
44
- def _read_service_credentials (credentials ):
44
+ def _read_service_credentials (connection ):
45
45
hdfs_uri = ""
46
46
user = ""
47
47
password = ""
48
- if isinstance (credentials , dict ):
49
- # check for Analytics Engine service credentials
50
- if 'cluster' in credentials :
51
- user = credentials .get ('cluster' ).get ('user' )
52
- password = credentials .get ('cluster' ).get ('password' )
53
- hdfs_uri = credentials .get ('cluster' ).get ('service_endpoints' ).get ('webhdfs' )
48
+ if isinstance (connection , dict ):
49
+ type = str (connection .get ('type' ))
50
+ # check the connection type
51
+ if ('GenericWebHDFS' in type ):
52
+ user = connection .get ('username' )
53
+ password = connection .get ('password' )
54
+ host_port = connection .get ('host' ) + ':' + str (connection .get ('port' ))
55
+ hdfs_uri = "webhdfs://" + host_port
54
56
else :
55
- if 'webhdfs' in credentials :
56
- user = credentials .get ('user' )
57
- password = credentials .get ('password' )
58
- hdfs_uri = credentials .get ('webhdfs' )
59
- else :
60
- raise ValueError (credentials )
57
+ host_port = connection .get ('host' ) + ':' + str (connection .get ('port' ))
58
+ hdfs_uri = "hdfs://" + host_port
61
59
else :
62
- raise TypeError (credentials )
63
- # construct expected format for hdfs_uri: webhdfs://host:port
64
- uri_parsed = urlparse (hdfs_uri )
65
- hdfs_uri = 'webhdfs://' + uri_parsed .netloc
66
- return hdfs_uri , user , password
67
-
68
- def _check_vresion_credentials1 (credentials , _op , topology ):
69
- if credentials is not None :
60
+ raise TypeError (connection )
70
61
71
- # check streamsx.hdfs version
72
- _add_toolkit_dependency (topology )
73
- # if credentials is None:
74
- # raise SystemExit("Error: credentials is empty.")
75
- print ( credentials )
76
- topology .stream .name
77
- print ( '------------' + topology .stream .name + " " + str (credentials ))
78
- if isinstance (credentials , dict ):
79
- hdfs_uri , user , password = _read_service_credentials (credentials )
80
- _op .params ['hdfsUri' ] = hdfs_uri
81
- _op .params ['hdfsUser' ] = user
82
- _op .params ['hdfsPassword' ] = password
83
- #check if the credentials is a valid JSON string
84
- elif _is_a_valid_json (credentials ):
85
- _op .params ['credentials' ] = credentials
86
- else :
87
- # expect core-site.xml file in credentials param
88
- try :
89
- print ( '--------------------------*******+++---' + str (credentials ))
90
- # with open(str(credentials)):
91
- print (credentials )
92
- topology .add_file_dependency (credentials , 'etc' )
93
- _op .params ['configPath' ] = 'etc'
94
- _op .params ['credentials' ] = None
95
- except IOError :
96
- raise SystemExit ("Error: File not accessible." )
97
-
62
+ return hdfs_uri , user , password
98
63
99
64
100
65
def _setCredentials (LocalCredentials , topology ):
@@ -117,7 +82,7 @@ def _setCredentials(LocalCredentials, topology):
117
82
except IOError :
118
83
raise ValueError (LocalCredentials )
119
84
else :
120
- if isinstance (credentials , dict ):
85
+ if isinstance (LocalCredentials , dict ):
121
86
hdfsUri , hdfsUser , hdfsPassword = _read_service_credentials (LocalCredentials )
122
87
else :
123
88
credentials = LocalCredentials
0 commit comments