Skip to content

Commit

Permalink
Fixed issues with ucc helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
VatsalJagani committed Nov 15, 2024
1 parent f7a6e81 commit d7d5b6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def modify_original_input_py_file(addon_name, input_name):

# Update validate_input method
pattern_validate_input_fun = r"def validate_input[\w\W]*return\n"
replacement_content_validate_input_fun = f"def validate_input(self, definition: smi.ValidationDefinition):\n {input_class_name}(self).validate_input(definition)\n\n"
replacement_content_validate_input_fun = f"def validate_input(self, definition: smi.ValidationDefinition):\n {input_class_name}(self, definition).validate_input(definition)\n\n"

file_content = re.sub(pattern_validate_input_fun, replacement_content_validate_input_fun, file_content)

Expand Down
33 changes: 19 additions & 14 deletions src/utilities/ucc_additional_packaging/ucc_ta_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,21 @@ class UCCTAInput:
- write_event() - keeps changing based on the input being processed
'''
def __init__(self, input_script: smi.Script) -> None:
def __init__(self, input_script: smi.Script, definition: smi.ValidationDefinition = None) -> None:
self.input_script = input_script
self.session_key = input_script._input_definition.metadata["session_key"]

log_level = get_ucc_ta_log_level(self.session_key)
self.logger = logger_manager.setup_logging(self.normalized_input_name, log_level)
self.logger.info(f"Logger initiated. Logging level = {log_level}")
if input_script._input_definition:
self.session_key = input_script._input_definition.metadata["session_key"]
else:
self.session_key = definition.metadata["session_key"]

self.log_level = get_ucc_ta_log_level(self.session_key)
self.ucc_ta_settings = get_ucc_ta_settings(self.session_key)

# self.proxy_settings = get_proxy_settings(session_key, self.logger) # TODO
self.proxy_settings = None

self.logger = logger_manager.setup_logging("generic_input", self.log_level)


def validate_input(self, definition: smi.ValidationDefinition):
self.logger.warning("You can override validate_input(input_script: smi.Script, definition: smi.ValidationDefinition) function into the subclass of VJ_UCC_TA_Input to validate the input in UCC built Add-on.")
Expand All @@ -196,18 +198,21 @@ def stream_events(self, inputs: smi.InputDefinition, event_writer: smi.EventWrit
for input_name, input_details in inputs.inputs.items():
normalized_input_name = input_name.split("/")[-1]

logger = logger_manager.setup_logging(normalized_input_name, self.log_level)
logger.info(f"Logger initiated. Logging level = {self.log_level}")

try:
self.logger.info(f'Modular input "{normalized_input_name}" started.')
logger.info(f'Modular input "{normalized_input_name}" started.')

self.logger.debug(f"input_name={input_name}, input_item={input_details}")
logger.debug(f"input_name={input_name}, input_item={input_details}")

account_name = input_details.get('account')
account_details = get_ucc_ta_account_details(self.session_key, self.logger, account_name)
account_details = get_ucc_ta_account_details(self.session_key, logger, account_name)

input_checkpointer = UCCTAInputCheckpointer(self.session_key, self.logger, normalized_input_name)
input_checkpointer = UCCTAInputCheckpointer(self.session_key, logger, normalized_input_name)

# Create event writer for this Input
def write_event(data, timestamp, index=None, sourcetype=None, source=None):
def write_event(data, timestamp=None, index=None, sourcetype=None, source=None):
_index = index if index else input_details.get("index")
_sourcetype = index if sourcetype else input_details.get("sourcetype")
_source = index if source else input_details.get("source")
Expand All @@ -226,11 +231,11 @@ def write_event(data, timestamp, index=None, sourcetype=None, source=None):
# so it has all the necessary parameters, so user don't have to pass the parameters

self.collect(input_name, normalized_input_name, input_details, account_details, input_checkpointer, event_writer)
self.logger.info(f'Modular input "{normalized_input_name}" ended.')
logger.info(f'Modular input "{normalized_input_name}" ended.')

except Exception as e:
self.logger.error(
f'Exception raised while ingesting data for input="{self.normalized_input_name}" {e}. Traceback: {traceback.format_exc()}'
logger.error(
f'Exception raised while ingesting data for input="{normalized_input_name}" {e}. Traceback: {traceback.format_exc()}'
)


Expand Down

0 comments on commit d7d5b6f

Please sign in to comment.