hid_data_transfer_lib 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/PKG-INFO +1 -1
  2. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/hid_dt_configuration.cpython-311.pyc +0 -0
  3. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/hid_dt_configuration.py +17 -0
  4. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/hid_dt_lib.py +36 -40
  5. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/keycloak/__pycache__/keycloak_rest.cpython-311.pyc +0 -0
  6. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/keycloak/keycloak_rest.py +9 -4
  7. hid_data_transfer_lib-0.2.2/hid_data_transfer_lib/nifi/__pycache__/nifi_client.cpython-311.pyc +0 -0
  8. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__pycache__/nifi_rest.cpython-311.pyc +0 -0
  9. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/nifi_client.py +77 -79
  10. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/pyproject.toml +1 -1
  11. hid_data_transfer_lib-0.2.0/hid_data_transfer_lib/nifi/__pycache__/nifi_client.cpython-311.pyc +0 -0
  12. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/README.md +0 -0
  13. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/.env +0 -0
  14. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/__init__.py +0 -0
  15. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__init__.py +0 -0
  16. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/__init__.cpython-311.pyc +0 -0
  17. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/__init__.cpython-39.pyc +0 -0
  18. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/cli_configuration.cpython-311.pyc +0 -0
  19. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/cli_configuration.cpython-39.pyc +0 -0
  20. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/__pycache__/conf.cpython-39.pyc +0 -0
  21. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/hid_dt.cfg +0 -0
  22. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/hid_dt_local.cfg +0 -0
  23. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/conf/hid_dt_psnc.cfg +0 -0
  24. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/exceptions/__init__.py +0 -0
  25. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/exceptions/__pycache__/__init__.cpython-311.pyc +0 -0
  26. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/exceptions/__pycache__/cli_exceptions.cpython-311.pyc +0 -0
  27. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/exceptions/__pycache__/hid_dt_exceptions.cpython-311.pyc +0 -0
  28. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/exceptions/hid_dt_exceptions.py +0 -0
  29. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/keycloak/__init__.py +0 -0
  30. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/keycloak/__pycache__/__init__.cpython-311.pyc +0 -0
  31. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/keycloak/__pycache__/keycloak_api.cpython-311.pyc +0 -0
  32. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__init__.py +0 -0
  33. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__pycache__/__init__.cpython-311.pyc +0 -0
  34. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__pycache__/__init__.cpython-39.pyc +0 -0
  35. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__pycache__/client.cpython-311.pyc +0 -0
  36. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/__pycache__/client.cpython-39.pyc +0 -0
  37. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/nifi/nifi_rest.py +0 -0
  38. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/py.typed +0 -0
  39. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/__init__.py +0 -0
  40. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/__pycache__/__init__.cpython-311.pyc +0 -0
  41. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/__pycache__/__init__.cpython-39.pyc +0 -0
  42. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/__pycache__/util.cpython-311.pyc +0 -0
  43. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/__pycache__/util.cpython-39.pyc +0 -0
  44. {hid_data_transfer_lib-0.2.0 → hid_data_transfer_lib-0.2.2}/hid_data_transfer_lib/util/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hid_data_transfer_lib
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: HiDALGO Data Transfer library provides methods to transfer data between different data providers and consumers using NIFI pipelines
5
5
  License: APL-2.0
6
6
  Author: Jesús Gorroñogoitia
@@ -191,6 +191,23 @@ class HidDataTransferConfiguration:
191
191
  """Returns the logging level"""
192
192
  return self.__set_logger(self.__logging_level, logger_name)
193
193
 
194
+ def is_logger_valid(self, logger):
195
+ """Check if the logger is valid:
196
+ checks if the FileHandler file is still open
197
+ """
198
+ file_handler = self.__get_file_handler(logger)
199
+ if file_handler is not None:
200
+ return not file_handler.stream.closed
201
+ else:
202
+ return False
203
+
204
+ def __get_file_handler(self, logger):
205
+ '''Returns the FileHandler of the logger'''
206
+ for handler in logger.handlers:
207
+ if isinstance(handler, logging.FileHandler):
208
+ return handler
209
+ return None
210
+
194
211
  def __get_configuration(self):
195
212
  """
196
213
  Reads the configuration file and sets this class' configuration values
@@ -32,6 +32,15 @@ from hid_data_transfer_lib.exceptions.hid_dt_exceptions import (
32
32
  )
33
33
  from hid_data_transfer_lib.nifi.nifi_client import NIFIClient, ExecutionType
34
34
 
35
+ KERBEROS_PRINCIPAL = "kerberos.principal"
36
+ HDFS_DATA_FOLDER = "hdfs.data_folder"
37
+ HDFS_FILENAME = "hdfs.filename"
38
+ HPC_TARGET_FOLDER = "hpc.target_folder"
39
+ HPC_DATA_FOLDER = "hpc.data_folder"
40
+ HPC_FILENAME = "hpc.filename"
41
+
42
+ HPC_ACCOUNT_MSG = "Either hpc_password or hpc_secret_key must be provided"
43
+
35
44
 
36
45
  class HIDDataTransfer:
37
46
  """main HiDALGO API client class
@@ -104,12 +113,12 @@ class HIDDataTransfer:
104
113
  try:
105
114
  arguments: Dict[str, Any] = {}
106
115
  self.__nifi_client.add_default_hpc_parameters(arguments, args)
107
- arguments["hpc.target_folder"] = args.data_target
108
- arguments["hdfs.data_folder"] = \
116
+ arguments[HPC_TARGET_FOLDER] = args.data_target
117
+ arguments[HDFS_DATA_FOLDER] = \
109
118
  "/".join(args.data_source.split("/")[:-1])
110
- arguments["hdfs.filename"] = \
119
+ arguments[HDFS_FILENAME] = \
111
120
  self.process_wildcards(args.data_source.split("/")[-1])
112
- arguments["kerberos.principal"] = args.kerberos_principal
121
+ arguments[KERBEROS_PRINCIPAL] = args.kerberos_principal
113
122
 
114
123
  execution_type = {
115
124
  "ListHDFS": ExecutionType.ONCE,
@@ -138,9 +147,7 @@ class HIDDataTransfer:
138
147
  )
139
148
 
140
149
  if not args.hpc_secret_key and not args.hpc_password:
141
- raise HidDataTransferException(
142
- "Either hpc_password or hpc_secret_key must be provided"
143
- )
150
+ raise HidDataTransferException(HPC_ACCOUNT_MSG)
144
151
 
145
152
  return self.__nifi_client.run_process_group(
146
153
  "hdfs2hpc",
@@ -219,12 +226,12 @@ class HIDDataTransfer:
219
226
  hpc_filename = args.data_source[args.data_source.rfind("/") + 1 :]
220
227
  arguments: Dict[str, Any] = {}
221
228
  self.__nifi_client.add_default_hpc_parameters(arguments, args)
222
- arguments["hpc.filename"] = hpc_filename if hpc_filename else ".*"
223
- arguments["hpc.data_folder"] = args.data_source[
229
+ arguments[HPC_FILENAME] = hpc_filename if hpc_filename else ".*"
230
+ arguments[HPC_DATA_FOLDER] = args.data_source[
224
231
  : args.data_source.rfind("/")
225
232
  ]
226
- arguments["hdfs.data_folder"] = args.data_target
227
- arguments["kerberos.principal"] = args.kerberos_principal
233
+ arguments[HDFS_DATA_FOLDER] = args.data_target
234
+ arguments[KERBEROS_PRINCIPAL] = args.kerberos_principal
228
235
 
229
236
  execution_type = {
230
237
  "ListSFTP": ExecutionType.ONCE,
@@ -253,9 +260,7 @@ class HIDDataTransfer:
253
260
  )
254
261
 
255
262
  if not args.hpc_secret_key and not args.hpc_password:
256
- raise HidDataTransferException(
257
- "Either hpc_password or hpc_secret_key must be provided"
258
- )
263
+ raise HidDataTransferException(HPC_ACCOUNT_MSG)
259
264
 
260
265
  return self.__nifi_client.run_process_group(
261
266
  "hpc2hdfs",
@@ -315,11 +320,11 @@ class HIDDataTransfer:
315
320
  )
316
321
  try:
317
322
  arguments: Dict[str, Any] = {}
318
- arguments["hdfs.data_folder"] = \
323
+ arguments[HDFS_DATA_FOLDER] = \
319
324
  "/".join(args.data_source.split("/")[:-1])
320
- arguments["hdfs.filename"] = \
325
+ arguments[HDFS_FILENAME] = \
321
326
  self.process_wildcards(args.data_source.split("/")[-1])
322
- arguments["kerberos.principal"] = args.kerberos_principal
327
+ arguments[KERBEROS_PRINCIPAL] = args.kerberos_principal
323
328
  self.__nifi_client.add_default_ckan_parameters(arguments, args)
324
329
  arguments[self.__nifi_client.CKAN_RESOURCE] = \
325
330
  self.generate_ckan_resource_name(args)
@@ -371,7 +376,6 @@ class HIDDataTransfer:
371
376
  ) -> str:
372
377
  """
373
378
  transfer data from CKAN to HDFS
374
-
375
379
  Args:
376
380
  ckan_host (str): The CKAN host URL.
377
381
  ckan_api_key (str): The CKAN API key.
@@ -409,9 +413,8 @@ class HIDDataTransfer:
409
413
  self.__nifi_client.add_default_ckan_parameters(arguments, args)
410
414
  arguments[self.__nifi_client.CKAN_RESOURCE] = \
411
415
  self.process_wildcards(args.ckan_resource)
412
-
413
- arguments["hdfs.data_folder"] = args.data_target
414
- arguments["kerberos.principal"] = args.kerberos_principal
416
+ arguments[HDFS_DATA_FOLDER] = args.data_target
417
+ arguments[KERBEROS_PRINCIPAL] = args.kerberos_principal
415
418
 
416
419
  execution_type = {
417
420
  "CKANFileDownloader": ExecutionType.ONCE,
@@ -506,7 +509,7 @@ class HIDDataTransfer:
506
509
  try:
507
510
  arguments: Dict[str, Any] = {}
508
511
  self.__nifi_client.add_default_hpc_parameters(arguments, args)
509
- arguments["hpc.target_folder"] = args.data_target
512
+ arguments[HPC_TARGET_FOLDER] = args.data_target
510
513
  self.__nifi_client.add_default_ckan_parameters(arguments, args)
511
514
  arguments[self.__nifi_client.CKAN_RESOURCE] = \
512
515
  self.process_wildcards(args.ckan_resource)
@@ -531,9 +534,7 @@ class HIDDataTransfer:
531
534
  )
532
535
 
533
536
  if not args.hpc_secret_key and not args.hpc_password:
534
- raise HidDataTransferException(
535
- "Either hpc_password or hpc_secret_key must be provided"
536
- )
537
+ raise HidDataTransferException(HPC_ACCOUNT_MSG)
537
538
 
538
539
  execution_type = {
539
540
  "CKANFileDownloader": ExecutionType.ONCE,
@@ -616,8 +617,8 @@ class HIDDataTransfer:
616
617
  hpc_filename = args.data_source[args.data_source.rfind("/") + 1 :]
617
618
  arguments: Dict[str, Any] = {}
618
619
  self.__nifi_client.add_default_hpc_parameters(arguments, args)
619
- arguments["hpc.filename"] = hpc_filename if hpc_filename else ".*"
620
- arguments["hpc.data_folder"] = args.data_source[
620
+ arguments[HPC_FILENAME] = hpc_filename if hpc_filename else ".*"
621
+ arguments[HPC_DATA_FOLDER] = args.data_source[
621
622
  : args.data_source.rfind("/")
622
623
  ]
623
624
  self.__nifi_client.add_default_ckan_parameters(arguments, args)
@@ -645,9 +646,7 @@ class HIDDataTransfer:
645
646
  )
646
647
 
647
648
  if not args.hpc_secret_key and not args.hpc_password:
648
- raise HidDataTransferException(
649
- "Either hpc_password or hpc_secret_key must be provided"
650
- )
649
+ raise HidDataTransferException(HPC_ACCOUNT_MSG)
651
650
 
652
651
  execution_type = {
653
652
  "ListSFTP": ExecutionType.ONCE,
@@ -915,18 +914,14 @@ class HIDDataTransfer:
915
914
  process_group_id = args.command_id
916
915
 
917
916
  try:
918
- # Get access token, do not forget to cancel
919
- # the token refresh when done with it
920
- token = self.__nifi_client.get_access_token()
921
-
922
917
  # Get all processors in the process group
923
918
  processors = self.__nifi_client.get_process_group_processors(
924
- process_group_id, token
919
+ process_group_id
925
920
  )["processors"]
926
921
 
927
922
  # Order processor by pipeline sequence
928
923
  processors_sequence = self.__nifi_client.get_processors_sequence(
929
- process_group_id, token
924
+ process_group_id
930
925
  )
931
926
  processors = self.__nifi_client.order_processors(
932
927
  processors, processors_sequence
@@ -938,13 +933,14 @@ class HIDDataTransfer:
938
933
  if last_processor:
939
934
  state = \
940
935
  self.__nifi_client.nifi_rest_client.get_processor_state(
941
- last_processor, token
936
+ last_processor, self.__nifi_client.get_access_token()
942
937
  )
943
938
  # Get if there remains pending incoming flowfiles
944
939
  # to be processed
945
940
  are_all_flowfiles_consumed = (
946
- self.__nifi_client.are_all_processor_queued_flowfiles_consumed(
947
- last_processor, process_group_id, token
941
+ self.__nifi_client
942
+ .are_all_processor_queued_flowfiles_consumed(
943
+ last_processor, process_group_id
948
944
  )
949
945
  )
950
946
  if state == "STOPPED" and are_all_flowfiles_consumed:
@@ -958,7 +954,7 @@ class HIDDataTransfer:
958
954
  # in the process.
959
955
  # Get processors on group and display bulletins reports
960
956
  processors = self.__nifi_client.get_process_group_processors(
961
- process_group_id, token
957
+ process_group_id
962
958
  )
963
959
  for processor in processors["processors"]:
964
960
  bulletins = processor["bulletins"]
@@ -74,6 +74,11 @@ class KeycloakRESTClient:
74
74
  )
75
75
  self.__logger = self.__conf.logger("keycloak.keycloak_api")
76
76
 
77
+ def info(self, *args):
78
+ ''' do info logging'''
79
+ if self.__conf.is_logger_valid(self.__logger):
80
+ self.__logger.info(args)
81
+
77
82
  def __del__(self):
78
83
  """Destructor method"""
79
84
  self.cancel_token(do_logging=False)
@@ -81,7 +86,7 @@ class KeycloakRESTClient:
81
86
  def get_token(self):
82
87
  """Get a token that is renewed every time it expires"""
83
88
  if self.__token is None:
84
- self.__logger.info(
89
+ self.info(
85
90
  "Getting Keycloak token for user %s", self.__keycloak_login
86
91
  )
87
92
  self.__expires_in = self.__get_token()
@@ -97,7 +102,7 @@ class KeycloakRESTClient:
97
102
  self.__token = token
98
103
  self.__refresh_token = refresh_token
99
104
  self.__expires_in = expires_in
100
- self.__logger.info(
105
+ self.info(
101
106
  "Setting Keycloak token for user %s with given one", user
102
107
  )
103
108
 
@@ -110,7 +115,7 @@ class KeycloakRESTClient:
110
115
  def cancel_token(self, do_logging=True):
111
116
  """Cancel the token refresh timer"""
112
117
  if do_logging:
113
- self.__logger.info(
118
+ self.info(
114
119
  "Cancelling the token refresh timer for user %s",
115
120
  self.__keycloak_login,
116
121
  )
@@ -135,7 +140,7 @@ class KeycloakRESTClient:
135
140
  """Refresh the token with the expiration period
136
141
  given by the Keycloak server"""
137
142
  if self.__refresh:
138
- self.__logger.info(
143
+ self.info(
139
144
  "Refreshing Keycloak token for user %s", self.__keycloak_login
140
145
  )
141
146
  self.__get_refreshed_token()
@@ -117,26 +117,27 @@ class NIFIClient:
117
117
 
118
118
  # GET requests
119
119
 
120
- def get_process_group(self, group_id, token) -> dict:
120
+ def get_process_group(self, group_id) -> dict:
121
121
  """gets a process group identified by id"""
122
- return self.nifi_rest_client.process_group_get_request(group_id, token)
122
+ return self.nifi_rest_client.process_group_get_request(
123
+ group_id, self.token())
123
124
 
124
- def get_process_group_processors(self, group_id, token) -> dict:
125
+ def get_process_group_processors(self, group_id) -> dict:
125
126
  """gets the processors of a process group identified by id"""
126
127
  return self.nifi_rest_client.process_group_get_request(
127
- group_id, token, "processors"
128
+ group_id, self.token(), "processors"
128
129
  )
129
130
 
130
- def get_process_group_connections(self, group_id, token) -> dict:
131
+ def get_process_group_connections(self, group_id) -> dict:
131
132
  """gets the connetions of a process group identified by id"""
132
133
  return self.nifi_rest_client.process_group_get_request(
133
- group_id, token, "connections"
134
+ group_id, self.token(), "connections"
134
135
  )
135
136
 
136
- def get_processors_sequence(self, group_id, token) -> list:
137
+ def get_processors_sequence(self, group_id) -> list:
137
138
  """computes the sequence of processors of a process group
138
139
  identified by id"""
139
- connections = self.get_process_group_connections(group_id, token)
140
+ connections = self.get_process_group_connections(group_id)
140
141
  connections_pairs = []
141
142
  for connection in connections["connections"]:
142
143
  connections_pairs.append(
@@ -144,10 +145,11 @@ class NIFIClient:
144
145
  )
145
146
  return order_process_group(connections_pairs)
146
147
 
147
- def get_processor_error_bulletins(self, processor_id, token):
148
+ def get_processor_error_bulletins(self, processor_id):
148
149
  """Get the error bulletins of a processor identified by id"""
149
150
  # Retrieve current version of processor
150
- processor = self.nifi_rest_client.get_processor(processor_id, token)
151
+ processor = self.nifi_rest_client.get_processor(
152
+ processor_id, self.token())
151
153
  error_bulletins = []
152
154
  bulletins = processor["bulletins"]
153
155
  for _bulletin in bulletins:
@@ -160,7 +162,7 @@ class NIFIClient:
160
162
 
161
163
  # PUT requests
162
164
 
163
- def update_parameters(self, parameter_context, arguments, token) -> bool:
165
+ def update_parameters(self, parameter_context, arguments) -> bool:
164
166
  """updates the parameters of a parameter context
165
167
  arguments contains the parameters to inject in the context
166
168
  """
@@ -171,7 +173,8 @@ class NIFIClient:
171
173
  parameter_context["component"]["parameters"] = parameters
172
174
  modified_parameter_context_json = json.dumps(parameter_context)
173
175
  return self.nifi_rest_client.save_parameter_context(
174
- modified_parameter_context_json, parameter_context["id"], token
176
+ modified_parameter_context_json, parameter_context["id"],
177
+ self.token()
175
178
  )
176
179
 
177
180
  def update_processor_property(
@@ -185,14 +188,14 @@ class NIFIClient:
185
188
 
186
189
  # MULTI-REQUESTS methods
187
190
 
188
- def run_processor(self, execution_type, token, processor):
191
+ def run_processor(self, execution_type, processor):
189
192
  """run a processor once or forever depending on the execution type"""
190
193
  ok, response = None, None
191
194
  processor_name = processor["component"]["name"]
192
195
  if execution_type[processor_name] == ExecutionType.ONCE:
193
- ok, response = self._run_processor_once(processor, token)
196
+ ok, response = self._run_processor_once(processor)
194
197
  elif execution_type[processor_name] == ExecutionType.FOREVER:
195
- ok, response = self._run_processor_forever(processor, token)
198
+ ok, response = self._run_processor_forever(processor)
196
199
  else:
197
200
  raise HidDataTransferException(
198
201
  f"Incompatible execution type {execution_type[processor_name]}"
@@ -201,31 +204,31 @@ class NIFIClient:
201
204
 
202
205
  return ok, response
203
206
 
204
- def _run_processor_once(self, processor, token) -> tuple[bool, str]:
207
+ def _run_processor_once(self, processor) -> tuple[bool, str]:
205
208
  """run once a given processor"""
206
209
  return self.nifi_rest_client.change_processor_run_status(
207
- processor, token, "RUN_ONCE"
210
+ processor, self.token(), "RUN_ONCE"
208
211
  )
209
212
 
210
- def _run_processor_forever(self, processor, token) -> tuple[bool, str]:
213
+ def _run_processor_forever(self, processor) -> tuple[bool, str]:
211
214
  """run a given processor until it is stopped"""
212
215
  return self.nifi_rest_client.change_processor_run_status(
213
- processor, token, "RUNNING"
216
+ processor, self.token(), "RUNNING"
214
217
  )
215
218
 
216
- def stop_processor(self, processor, token) -> tuple[bool, str]:
219
+ def stop_processor(self, processor) -> tuple[bool, str]:
217
220
  """stop a given processor"""
218
221
  return self.nifi_rest_client.change_processor_run_status(
219
- processor, token, "STOPPED"
222
+ processor, self.token(), "STOPPED"
220
223
  )
221
224
 
222
225
  def are_all_processor_queued_flowfiles_consumed(
223
- self, processor, process_group_id, token
226
+ self, processor, process_group_id
224
227
  ) -> bool:
225
228
  """Check if all queued flowfiles have been consumed by the processor"""
226
229
  # Get the process group connections
227
230
  connections = self.get_process_group_connections(
228
- process_group_id, token)[
231
+ process_group_id)[
229
232
  "connections"
230
233
  ]
231
234
  for connection in connections:
@@ -245,13 +248,12 @@ class NIFIClient:
245
248
  processor,
246
249
  process_group_id,
247
250
  expected_outgoing_flowfiles,
248
- token,
249
251
  ) -> bool:
250
252
  """Check if all expected outgoing flowfiles
251
253
  have been generated by the processor"""
252
254
  # Get the process group connections
253
255
  connections = self.get_process_group_connections(
254
- process_group_id, token)[
256
+ process_group_id)[
255
257
  "connections"
256
258
  ]
257
259
  for connection in connections:
@@ -262,20 +264,19 @@ class NIFIClient:
262
264
  ] == expected_outgoing_flowfiles
263
265
  )
264
266
  raise HidDataTransferException(
265
- f"Incomming connection not found for processor {processor['id']}"
267
+ f"Outgoing connection not found for processor {processor['id']}"
266
268
  )
267
269
 
268
270
  def has_created_outgoing_flowfiles(
269
271
  self,
270
272
  processor,
271
273
  process_group_id,
272
- token,
273
274
  ) -> bool:
274
275
  """Check if at least one outgoing flowfile
275
276
  has been generated by the processor"""
276
277
  # Get the process group connections
277
278
  connections = self.get_process_group_connections(
278
- process_group_id, token)[
279
+ process_group_id)[
279
280
  "connections"
280
281
  ]
281
282
  for connection in connections:
@@ -284,7 +285,7 @@ class NIFIClient:
284
285
  "flowFilesQueued"
285
286
  ] > 0
286
287
  raise HidDataTransferException(
287
- f"Incomming connection not found for processor {processor['id']}"
288
+ f"Outgoing connection not found for processor {processor['id']}"
288
289
  )
289
290
 
290
291
  # Class helper methods
@@ -325,20 +326,20 @@ class NIFIClient:
325
326
  return processor
326
327
  return None
327
328
 
328
- def find_flow_definition_by_name(self, flow_definition_name, token):
329
+ def find_flow_definition_by_name(self, flow_definition_name):
329
330
  """Find a flow definition, registered in the NIFI Registry, by name"""
330
331
  # Assuming there is only one registered Registry
331
- registries = self.nifi_rest_client.get_registries(token)
332
+ registries = self.nifi_rest_client.get_registries(self.token())
332
333
  assert registries is not None
333
334
  registry_id = registries["registries"][0]["id"]
334
335
 
335
336
  # Assuming there is only one registered Bucket
336
- buckets = self.nifi_rest_client.get_buckets(registry_id, token)
337
+ buckets = self.nifi_rest_client.get_buckets(registry_id, self.token())
337
338
  assert buckets is not None
338
339
  bucket_id = buckets["buckets"][0]["id"]
339
340
 
340
341
  flow_definitions = self.nifi_rest_client.get_flow_definitions(
341
- registry_id, bucket_id, token
342
+ registry_id, bucket_id, self.token()
342
343
  )
343
344
  assert flow_definitions is not None
344
345
  flow_definition_id = None
@@ -356,7 +357,7 @@ class NIFIClient:
356
357
  )
357
358
 
358
359
  versions = self.nifi_rest_client.get_flow_definition_versions(
359
- registry_id, bucket_id, flow_definition_id, token
360
+ registry_id, bucket_id, flow_definition_id, self.token()
360
361
  )
361
362
  assert versions is not None
362
363
  # Take the latest verstion of the flow
@@ -372,24 +373,25 @@ class NIFIClient:
372
373
  }
373
374
 
374
375
  def instantiate_process_group(
375
- self, token, flow_definition_name, arguments, keys_arguments
376
+ self, flow_definition_name, arguments, keys_arguments
376
377
  ):
377
378
  """create a process group from a template
378
379
  and its associated parameter context"""
379
380
  try:
380
381
  # Get flow definition metadata by name
381
382
  flow_definition = self.find_flow_definition_by_name(
382
- flow_definition_name, token
383
+ flow_definition_name
383
384
  )
384
385
 
385
386
  # Instantiate flow definition as process group
386
387
  process_group = (
387
- self.nifi_rest_client.instantiate_flow_definition_as_process_group(
388
+ self.nifi_rest_client.
389
+ instantiate_flow_definition_as_process_group(
388
390
  flow_definition["registry_id"],
389
391
  flow_definition["bucket_id"],
390
392
  flow_definition["flow_definition_id"],
391
393
  flow_definition["version"],
392
- token,
394
+ self.token(),
393
395
  )
394
396
  )
395
397
 
@@ -404,11 +406,11 @@ class NIFIClient:
404
406
  # Instantiate parameter context with parameters
405
407
  parameter_context = \
406
408
  self.nifi_rest_client.instantiate_parameter_context(
407
- token
409
+ self.token()
408
410
  )
409
411
 
410
412
  # Update parameters
411
- ok = self.update_parameters(parameter_context, arguments, token)
413
+ ok = self.update_parameters(parameter_context, arguments)
412
414
 
413
415
  if not ok:
414
416
  raise HidDataTransferException(
@@ -418,7 +420,7 @@ class NIFIClient:
418
420
 
419
421
  # Associate parameter context to process group
420
422
  self.nifi_rest_client.associate_parameter_context_to_group(
421
- parameter_context, process_group, token
423
+ parameter_context, process_group, self.token()
422
424
  )
423
425
 
424
426
  return process_group
@@ -427,6 +429,10 @@ class NIFIClient:
427
429
  dtex.set_produced_object(process_group)
428
430
  raise dtex from ex
429
431
 
432
+ def token(self):
433
+ ''' Gets latest updated NIFI access token '''
434
+ return self.get_access_token()
435
+
430
436
  def run_process_group(
431
437
  self,
432
438
  template_name,
@@ -483,29 +489,24 @@ class NIFIClient:
483
489
  # Get access token, do not forget to cancel token refresh
484
490
  # when done with it
485
491
  if keycloak_token:
486
- token = self.set_access_token(keycloak_token)
487
- else:
488
- token = self.get_access_token()
492
+ self.set_access_token(keycloak_token)
489
493
 
490
494
  process_group = self.instantiate_process_group(
491
- token, template_name, arguments, keys_arguments
495
+ template_name, arguments, keys_arguments
492
496
  )
493
497
  self.__logger.info(
494
498
  "Process group %s created\n", process_group["id"])
495
499
 
496
500
  # Get all processors in the process group
497
501
  processors = self.get_process_group_processors(
498
- process_group["id"], token)[
499
- "processors"
500
- ]
502
+ process_group["id"])["processors"]
501
503
 
502
504
  # For each processor in group ordered by the sequence,
503
505
  # execute processor once
504
506
  # Check previous processor has an running instance
505
507
  # before launching next one
506
508
  processors_sequence = self.get_processors_sequence(
507
- process_group["id"], token
508
- )
509
+ process_group["id"])
509
510
  processors = self.order_processors(processors, processors_sequence)
510
511
  index_processor = 0
511
512
 
@@ -517,19 +518,17 @@ class NIFIClient:
517
518
  for processor in processors:
518
519
  # Set sensitive hpc parameters
519
520
  processor = self.set_sensitive_parameters(
520
- sensitive_parameters, token, processor
521
+ sensitive_parameters, processor
521
522
  )
522
523
 
523
524
  # Run the processor once or forever
524
525
  # until all incoming flowfiles are consumed
525
526
  processor_name = processor["component"]["name"]
526
- ok, response = self.run_processor(
527
- execution_type, token, processor)
527
+ ok, response = self.run_processor(execution_type, processor)
528
528
  index_processor += 1
529
529
  if ok:
530
530
  self.wait_for_processor_completion(
531
531
  execution_type,
532
- token,
533
532
  index_processor,
534
533
  len(processors),
535
534
  processor,
@@ -564,11 +563,11 @@ class NIFIClient:
564
563
  self.cancel_access_token()
565
564
  if process_group:
566
565
  # Clean up the process group and associated parameter context
567
- self.clean_process_group_up(process_group["id"], token)
566
+ self.clean_process_group_up(process_group["id"])
568
567
  self.__logger.info("Process group %s cleaned up\n",
569
568
  process_group["id"])
570
569
 
571
- def set_sensitive_parameters(self, sensitive_parameters, token, processor):
570
+ def set_sensitive_parameters(self, sensitive_parameters, processor):
572
571
  """Set sensitive parameters for a processor"""
573
572
  processor_name = processor["component"]["name"]
574
573
  if sensitive_parameters and processor_name in sensitive_parameters:
@@ -579,13 +578,12 @@ class NIFIClient:
579
578
  sensitive_parameters[processor_name][key],
580
579
  )
581
580
  processor = self.nifi_rest_client.update_processor(
582
- processor, token)
581
+ processor, self.token())
583
582
  return processor
584
583
 
585
584
  def wait_for_processor_completion(
586
585
  self,
587
586
  execution_type,
588
- token,
589
587
  index_processor,
590
588
  num_processors,
591
589
  processor,
@@ -603,7 +601,7 @@ class NIFIClient:
603
601
  if index_processor != 1:
604
602
  are_all_flowfiles_consumed = (
605
603
  self.are_all_processor_queued_flowfiles_consumed(
606
- processor, process_group_id, token
604
+ processor, process_group_id
607
605
  )
608
606
  )
609
607
  else:
@@ -618,18 +616,17 @@ class NIFIClient:
618
616
  processor,
619
617
  process_group_id,
620
618
  first_processor_expected_outgoing_flowfiles,
621
- token,
622
619
  )
623
620
  )
624
621
  status = self.nifi_rest_client.get_processor_state(
625
- processor, token)
622
+ processor, self.token())
626
623
  # If processor is stopped and not the last one,
627
624
  # check it has produced at least one flowfile
628
625
  if (
629
626
  status == "STOPPED"
630
627
  and index_processor != num_processors
631
628
  and not self.has_created_outgoing_flowfiles(
632
- processor, process_group_id, token
629
+ processor, process_group_id
633
630
  )
634
631
  ):
635
632
  raise HidDataTransferException(
@@ -639,44 +636,45 @@ class NIFIClient:
639
636
  # Check if processor execution has failed with exception
640
637
  # Collect them all and raise a single exception
641
638
  error_bulletins = self.get_processor_error_bulletins(
642
- processor["id"], token)
639
+ processor["id"])
643
640
  if error_bulletins:
644
641
  # Before raising an exception, stop the processor
645
642
  # if it is running for ever
646
643
  self.stop_forever_running_processor(
647
- execution_type[processor_name], processor, token)
644
+ execution_type[processor_name], processor)
648
645
  # and empty the incoming queue
649
- self.empty_incoming_queue(processor, process_group_id, token)
646
+ self.empty_incoming_queue(processor, process_group_id)
650
647
  raise HidDataTransferException(
651
648
  f"Processor {processor_name} has failed with exception: "
652
649
  f"{error_bulletins}"
653
650
  )
654
651
  sleep(self.__CHECK_STATUS_SLEEP_LAPSE)
655
- self.stop_forever_running_processor(
656
- execution_type[processor_name], processor, token)
652
+ self.stop_forever_running_processor(
653
+ execution_type[processor_name], processor)
657
654
 
658
- def stop_forever_running_processor(self, exec_type, processor, token):
655
+ def stop_forever_running_processor(self, exec_type, processor):
659
656
  '''Stop a processor that is running forever'''
660
657
  # If processor has executed for ever, stop it
661
658
  if exec_type == ExecutionType.FOREVER:
662
659
  # Get current processor version
663
660
  processor = self.nifi_rest_client.get_processor(
664
- processor["id"], token)
665
- self.stop_processor(processor, token)
661
+ processor["id"], self.token())
662
+ self.stop_processor(processor)
666
663
 
667
- def empty_incoming_queue(self, processor, process_group_id, token):
664
+ def empty_incoming_queue(self, processor, process_group_id):
668
665
  '''Empty the incoming queue of a processor'''
669
666
  if not self.are_all_processor_queued_flowfiles_consumed(
670
- processor, process_group_id, token):
667
+ processor, process_group_id):
671
668
  # Get the process group connections
672
669
  connections = self.get_process_group_connections(
673
- process_group_id, token)["connections"]
670
+ process_group_id)["connections"]
674
671
  for connection in connections:
675
672
  if (connection["component"]["destination"]["id"]
676
673
  == processor["id"]
677
674
  and connection["status"]["aggregateSnapshot"]
678
675
  ["flowFilesQueued"] != 0): # Empty the queue
679
- self.nifi_rest_client.empty_queue(connection['id'], token)
676
+ self.nifi_rest_client.empty_queue(
677
+ connection['id'], self.token())
680
678
 
681
679
  def add_default_hpc_parameters(self, arguments, args):
682
680
  """adds default parameters for HPC connection"""
@@ -737,10 +735,10 @@ class NIFIClient:
737
735
  )
738
736
  return sensitive_parameters
739
737
 
740
- def clean_process_group_up(self, process_group_id, token):
738
+ def clean_process_group_up(self, process_group_id):
741
739
  """Clean up the process group and associated parameter context"""
742
740
  # Get process group
743
- process_group = self.get_process_group(process_group_id, token)
741
+ process_group = self.get_process_group(process_group_id)
744
742
 
745
743
  # Remove transferred keys
746
744
  self.__logger.debug("Removing uploaded keys\n")
@@ -753,15 +751,15 @@ class NIFIClient:
753
751
  "parameterContext"
754
752
  ]["id"]
755
753
  parameter_context = self.nifi_rest_client.get_parameter_context(
756
- parameter_context_id, token
754
+ parameter_context_id, self.token()
757
755
  )
758
756
 
759
757
  # Remove parameter_context
760
758
  self.nifi_rest_client.remove_parameter_context(
761
- parameter_context, token)
759
+ parameter_context, self.token())
762
760
 
763
761
  # Remove process_group
764
- self.nifi_rest_client.remove_process_group(process_group, token)
762
+ self.nifi_rest_client.remove_process_group(process_group, self.token())
765
763
 
766
764
  def format_args_to_string(self, args):
767
765
  """Format dtcli command arguments to string for logging"""
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "hid_data_transfer_lib"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "HiDALGO Data Transfer library provides methods to transfer data between different data providers and consumers using NIFI pipelines"
5
5
  authors = ["Jesús Gorroñogoitia <jesus.gorronogoitia@eviden.com>"]
6
6
  license = "APL-2.0"