easy-utils-dev 2.144__tar.gz → 2.145__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.
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/PKG-INFO +1 -1
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/temp_memory.py +1 -2
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/utils.py +15 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/wsnoclib.py +49 -16
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev.egg-info/PKG-INFO +1 -1
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/setup.py +1 -1
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/MANIFEST.in +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/EasySsh.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/Events.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/FastQueue.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/NameObject.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/__init__.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/abortable.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/brevosmtp.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/check_license.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/cplib.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/custom_env.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/debugger-C-PF4PAMMP.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/debugger.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/easy_oracle.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/encryptor.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/ept.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/ept_sql/create_dirs.sql +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/ept_sql/create_ept_tables.sql +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/exceptions.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/filescompressor.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/generate_license.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/keycloakapi.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/lralib.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/ne1830PSS.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/nsp_kafka.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/openid_server.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/optics_utils.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/require_auth.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/simple_sqlite.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/uiserver.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/winserviceapi.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev/wsselib.py +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev.egg-info/SOURCES.txt +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev.egg-info/dependency_links.txt +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev.egg-info/requires.txt +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/easy_utils_dev.egg-info/top_level.txt +0 -0
- {easy_utils_dev-2.144 → easy_utils_dev-2.145}/setup.cfg +0 -0
|
@@ -35,10 +35,9 @@ class TemporaryMemory :
|
|
|
35
35
|
|
|
36
36
|
def save(self, item , custom_key=None ,auto_destroy_period=60 , store_deleted_key=True) :
|
|
37
37
|
now = getTimestamp()
|
|
38
|
+
later = None
|
|
38
39
|
if auto_destroy_period :
|
|
39
40
|
later = getTimestamp(after_seconds=auto_destroy_period)
|
|
40
|
-
else :
|
|
41
|
-
later = None
|
|
42
41
|
if not custom_key :
|
|
43
42
|
custom_key = f"{getTimestamp()}-{generateToken(iter=4)}".upper()
|
|
44
43
|
self.store[custom_key] = {
|
|
@@ -476,6 +476,21 @@ def get_free_space(path: str , in_mb = True) -> int:
|
|
|
476
476
|
return convert_bytes_to_mb(free)
|
|
477
477
|
return free # in bytes
|
|
478
478
|
|
|
479
|
+
def can_be_int(string) :
|
|
480
|
+
"""
|
|
481
|
+
Check if a string can be converted to an integer.
|
|
482
|
+
|
|
483
|
+
Args:
|
|
484
|
+
string (str): String to check.
|
|
485
|
+
|
|
486
|
+
Returns:
|
|
487
|
+
bool: True if string can be converted to an integer, False otherwise.
|
|
488
|
+
"""
|
|
489
|
+
try :
|
|
490
|
+
int(string)
|
|
491
|
+
return True
|
|
492
|
+
except :
|
|
493
|
+
return False
|
|
479
494
|
|
|
480
495
|
if __name__ == "__main__":
|
|
481
496
|
pass
|
|
@@ -9,7 +9,6 @@ from urllib3 import disable_warnings
|
|
|
9
9
|
from threading import Thread
|
|
10
10
|
from easy_utils_dev.Events import EventEmitter
|
|
11
11
|
from .EasySsh import CREATESSH
|
|
12
|
-
import traceback
|
|
13
12
|
import xmltodict
|
|
14
13
|
from .FastQueue import FastQueue
|
|
15
14
|
import tempfile , os
|
|
@@ -67,7 +66,6 @@ class WSNOCLIB :
|
|
|
67
66
|
self.api_count_limit = 999999999999
|
|
68
67
|
self.temp_dir = os.path.join(tmp_dir , 'wsnoclib' )
|
|
69
68
|
self.baseUrl = self.createBaseUrl()
|
|
70
|
-
self.session = requests.Session()
|
|
71
69
|
self.numberOfRequests=0
|
|
72
70
|
self.request_max_count = request_max_count
|
|
73
71
|
self.onGoingRequests=0
|
|
@@ -85,6 +83,8 @@ class WSNOCLIB :
|
|
|
85
83
|
self.refresh_thread = None
|
|
86
84
|
self.token_refresh_count = 0
|
|
87
85
|
self.session = WSNOCSession(self)
|
|
86
|
+
self.max_concurrent_requests = 40
|
|
87
|
+
self.current_requests = 0
|
|
88
88
|
self.connected = False
|
|
89
89
|
self.pm_hadoop = PmHadoopClient(self)
|
|
90
90
|
if register_atexit :
|
|
@@ -662,15 +662,28 @@ class WSNOCSession(requests.Session):
|
|
|
662
662
|
def rebuild_auth(self, prepared_request, response):
|
|
663
663
|
return
|
|
664
664
|
|
|
665
|
+
def _refactor_url(self , url) :
|
|
666
|
+
if str(url).startswith('/') :
|
|
667
|
+
url = f"{self._wsnoc.baseUrl}/{url}"
|
|
668
|
+
return url
|
|
669
|
+
|
|
665
670
|
def hold_for_token_refresh(self, url=None) :
|
|
666
671
|
while self._wsnoc.refresh_inprogress :
|
|
667
672
|
self._wsnoc.logger.info(f'Waiting for token refresh. {url if url else "No URL"}')
|
|
668
673
|
sleep(.5)
|
|
669
674
|
|
|
675
|
+
def hold_for_max_concurrent_requests(self, url=None) :
|
|
676
|
+
while self._wsnoc.current_requests >= self._wsnoc.max_concurrent_requests :
|
|
677
|
+
self._wsnoc.logger.info(f'Max concurrent requests reached. Waiting for a request to complete. {url if url else "No URL"}')
|
|
678
|
+
self._wsnoc.logger.debug(f'Max concurrent requests reached. Waiting for a request to complete. {url if url else "No URL"} [current_requests={self._wsnoc.current_requests}] [max_concurrent_requests={self._wsnoc.max_concurrent_requests}]')
|
|
679
|
+
sleep(1)
|
|
680
|
+
|
|
670
681
|
def request(self, method, url , retries=0 , skip_hold_for_token_refresh=False , debug_this_request=False , **kwargs):
|
|
682
|
+
url = self._refactor_url(url)
|
|
671
683
|
self._wsnoc.logger.debug(f'[{method}] : {url}')
|
|
672
684
|
if not skip_hold_for_token_refresh :
|
|
673
685
|
self.hold_for_token_refresh(url)
|
|
686
|
+
self.hold_for_max_concurrent_requests(url)
|
|
674
687
|
self._wsnoc.api_count += 1
|
|
675
688
|
token = self._wsnoc.getLatestToken().get('bearer_token')
|
|
676
689
|
request_headers = kwargs.get('headers' , {})
|
|
@@ -678,6 +691,8 @@ class WSNOCSession(requests.Session):
|
|
|
678
691
|
if not request_headers.get('Authorization') :
|
|
679
692
|
request_headers['Authorization'] = token
|
|
680
693
|
kwargs['headers'] = request_headers
|
|
694
|
+
start_ts = getTimestamp()
|
|
695
|
+
self._wsnoc.current_requests += 1
|
|
681
696
|
request = super().request(method, url, **kwargs )
|
|
682
697
|
if debug_this_request :
|
|
683
698
|
self._wsnoc.logger.info(f'''
|
|
@@ -687,6 +702,7 @@ class WSNOCSession(requests.Session):
|
|
|
687
702
|
[DEBUG] Response: {request.text}
|
|
688
703
|
[DEBUG] OK: {request.ok}
|
|
689
704
|
[DEBUG] Method: {request.request.method}
|
|
705
|
+
[DEBUG] StartTs: {start_ts}
|
|
690
706
|
''')
|
|
691
707
|
for i in range(retries) :
|
|
692
708
|
if request.ok :
|
|
@@ -696,7 +712,13 @@ class WSNOCSession(requests.Session):
|
|
|
696
712
|
self.hold_for_token_refresh(url)
|
|
697
713
|
request = super().request(method, url, **kwargs )
|
|
698
714
|
self._wsnoc.logger.debug(f'[Try-{i}] [{method}] : {url}- {request.status_code}')
|
|
699
|
-
|
|
715
|
+
end_ts = getTimestamp()
|
|
716
|
+
execution_secs = round(end_ts - start_ts, 2)
|
|
717
|
+
self._wsnoc.logger.info(f'[{method}] : {url} - [{request.status_code}][{execution_secs}sec]')
|
|
718
|
+
request.start_ts = start_ts
|
|
719
|
+
request.end_ts = end_ts
|
|
720
|
+
request.execution = execution_secs
|
|
721
|
+
self._wsnoc.current_requests -= 1
|
|
700
722
|
return request
|
|
701
723
|
|
|
702
724
|
class PmHadoopClient :
|
|
@@ -718,6 +740,8 @@ class PmHadoopClient :
|
|
|
718
740
|
self.logger : DEBUGGER = self.wsnoc.logger
|
|
719
741
|
self.FREE_STORAGE_STRICT = True
|
|
720
742
|
self.FREE_STORAGE_THRESHOLD_MB = 30000
|
|
743
|
+
self.jhost = False
|
|
744
|
+
self.jhost_obj = None
|
|
721
745
|
|
|
722
746
|
|
|
723
747
|
def connect(self) :
|
|
@@ -774,27 +798,36 @@ class PmHadoopClient :
|
|
|
774
798
|
raise Exception("Invalid TARGET_PM")
|
|
775
799
|
self.logger.info(f"Getting available PM dates for {_target}/{_mode}" , source='PmHadoopClient')
|
|
776
800
|
dirs = list(self.client.ls([f'/{_target}/{_mode}']))
|
|
777
|
-
ts_now = getTimestamp()
|
|
778
801
|
if date_range_in_days :
|
|
802
|
+
ts_now = getTimestamp() # this is in seconds
|
|
779
803
|
self.logger.info(f"Setting date range to last {date_range_in_days} days" , source='PmHadoopClient')
|
|
780
804
|
date_range = [ts_now - date_range_in_days * 24 * 60 * 60, ts_now]
|
|
781
805
|
self.logger.info(f"Date range: {tuple(date_range)}" , source='PmHadoopClient')
|
|
782
806
|
for index , dir in enumerate(dirs) :
|
|
783
807
|
self.logger.info(f"Processing {dir.get('path')}" , source='PmHadoopClient')
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
if
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
808
|
+
if 'ds' in dir.get('path' , '') :
|
|
809
|
+
date_str = dir.get('path').split('=')[-1]
|
|
810
|
+
dir['pm_date'] = int(date_str)
|
|
811
|
+
dir['mode'] = _mode
|
|
812
|
+
dt = datetime.strptime(date_str, "%Y%m%d")
|
|
813
|
+
dir['pm_date_timestamp'] = int(dt.timestamp())
|
|
814
|
+
if len(date_range) > 0 :
|
|
815
|
+
if dir['pm_date_timestamp'] < date_range[0] :
|
|
816
|
+
del dirs[index]
|
|
817
|
+
if dir['pm_date_timestamp'] > date_range[1] :
|
|
818
|
+
del dirs[index]
|
|
794
819
|
return dirs
|
|
795
820
|
|
|
796
|
-
def use_jump_host(self , jhost) :
|
|
797
|
-
|
|
821
|
+
def use_jump_host(self , jhost , use=True) :
|
|
822
|
+
'''
|
|
823
|
+
not yet implemented
|
|
824
|
+
'''
|
|
825
|
+
self.jhost = use
|
|
826
|
+
if use :
|
|
827
|
+
self.jhost_obj = None
|
|
828
|
+
else :
|
|
829
|
+
self.jhost_obj = None
|
|
830
|
+
|
|
798
831
|
|
|
799
832
|
def _download_dir(self , hdfs_path, local_path):
|
|
800
833
|
for entry in self.client.ls([hdfs_path]):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|