Skip to content

Commit

Permalink
Log message updated (#441)
Browse files Browse the repository at this point in the history
Co-authored-by: Sridhar Ramaswamy <[email protected]>
  • Loading branch information
shreyas-damle and srics authored Jul 25, 2024
1 parent a0eb71a commit 445c7c3
Showing 1 changed file with 57 additions and 36 deletions.
93 changes: 57 additions & 36 deletions pebblo/app/service/local_ui_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,27 @@ def __init__(self):

def prepare_loader_response(self, app_dir, app_json):
# Default values
app_name = app_json["name"]
load_ids = app_json.get("load_ids", [])

if not load_ids:
logger.debug(f"No valid loadIds found for app: {app_dir}.")
logger.warning(f"Skipping app '{app_dir}' due to missing or invalid file")
logger.debug(f"[Dashboard]: No valid loadIds found for app: {app_dir}.")
logger.warning(
f"[Dashboard]: No valid loadIs found for the application: {app_name}, skipping application."
)
return

# Fetching latest loadId
latest_load_id, app_detail_json = self.get_latest_load_id(load_ids, app_dir)

if not latest_load_id:
logger.debug(f"No valid loadIds found for app: {app_dir}. Skipping.")
logger.warning(f"Skipping app '{app_dir}' due to missing or invalid file")
logger.debug(
f"[Dashboard]: No valid latest loadIds found for app: {app_dir}, skipping application."
)
logger.warning(
f"[Dashboard]: No metadata file is present for any load ids for application: {app_name},"
f"skipping Application."
)
return

report_summary = app_detail_json.get("reportSummary")
Expand All @@ -79,7 +87,10 @@ def prepare_loader_response(self, app_dir, app_json):

# Skip app if data source details are not present for some reason.
if not data_source_details:
logger.warning(f"Skipping app '{app_dir}' due to missing or invalid file")
logger.warning(
f"[Dashboard]: No Data Source details are present for the application: {app_name},"
f"skipping application."
)
return

# Prepare output data
Expand Down Expand Up @@ -119,8 +130,8 @@ def prepare_loader_response(self, app_dir, app_json):
return app_details.dict()

def prepare_retrieval_response(self, app_dir, app_json):
logger.debug("In prepare retrieval response")

logger.debug("[Dashboard]: In prepare retrieval response")
app_name = app_json["name"]
app_metadata_path = (
f"{CacheDir.HOME_DIR.value}/{app_dir}/"
f"{CacheDir.APPLICATION_METADATA_FILE_PATH.value}"
Expand All @@ -130,10 +141,12 @@ def prepare_retrieval_response(self, app_dir, app_json):
# Skip app if app_metadata details are not present for some reason.
if not app_metadata_content:
logger.debug(
f"Error: Unable to fetch app_metadata.json content for {app_dir} app"
f"[Dashboard]: Error: Unable to fetch app_metadata.json content for {app_dir} app"
)
logger.debug(f"[Dashboard]: App metadata Json : {app_metadata_content}")
logger.warning(
f"[Dashboard]: Application metadata file is not present for application: {app_name}, skipping application"
)
logger.debug(f"App metadata Json : {app_metadata_content}")
logger.warning(f"Skipping app '{app_dir}' due to missing or invalid file")
return

# Sort retrievals data
Expand Down Expand Up @@ -186,23 +199,26 @@ def get_all_apps_details(self):
try:
# Skip hidden folders
if app_dir.startswith("."):
logger.debug(f"Skipping hidden folder {app_dir}")
logger.debug(f"[Dashboard]: Skipping hidden folder {app_dir}")
continue
# Path to metadata.json
app_path = (
f"{CacheDir.HOME_DIR.value}/{app_dir}/"
f"{CacheDir.METADATA_FILE_PATH.value}"
)
logger.debug(f"metadata.json path {app_path}")

logger.debug(f"[Dashboard]: Metadata file path {app_path}")
app_json = read_json_file(app_path)

if not app_json:
# Unable to find json file
logger.debug(
f"Metadata file ({CacheDir.METADATA_FILE_PATH.value}) not found for app: {app_dir}."
f"[Dashboard]: Metadata file {CacheDir.METADATA_FILE_PATH.value} "
f"not found for app: {app_dir}."
)
logger.warning(
f"Skipping app '{app_dir}' due to missing or invalid file"
f"[Dashboard]: Metadata file is not present for application: {app_dir},"
f"skipping application"
)
continue

Expand All @@ -219,9 +235,11 @@ def get_all_apps_details(self):
all_retrieval_apps.append(retrieval_app)

except Exception as err:
logger.warning(f"Error processing app {app_dir}: {err}")
logger.warning(
f"[Dashboard]: Error processing app {app_dir}: {err}"
)

logger.debug("Preparing loader app response object")
logger.debug("[Dashboard]: Preparing loader app response object")
loader_response = LoaderAppModel(
applicationsAtRiskCount=self.loader_apps_at_risk,
findingsCount=self.loader_findings,
Expand All @@ -233,7 +251,7 @@ def get_all_apps_details(self):
dataSource=self.loader_data_source_list,
)

logger.debug("Preparing retrieval app response object")
logger.debug("[Dashboard]: Preparing retrieval app response object")
retrieval_response = RetrievalAppList(
appList=all_retrieval_apps,
retrievals=self.total_retrievals,
Expand All @@ -246,19 +264,20 @@ def get_all_apps_details(self):
"loaderApps": loader_response.dict(),
"retrievalApps": retrieval_response.dict(),
}
logger.debug(f"App Listing Response : {response}")
return json.dumps(response, indent=4)
except Exception as ex:
logger.error(f"Error in Dashboard app Listing. Error:{ex}")
logger.error(f"[Dashboard]: Error in app listing. Error:{ex}")
return json.dumps({})

def get_loader_app_details(self, app_dir, load_ids):
# Fetching latest loadId
latest_load_id, app_detail_json = self.get_latest_load_id(load_ids, app_dir)

if not latest_load_id:
logger.debug(f"No valid loadIds found for app {app_dir}.")
logger.warning(f"Skipping app '{app_dir}' due to missing or invalid file")
logger.debug(f"[App Details]: No valid loadIds found for app {app_dir}.")
logger.warning(
f"[App Details]: No valid latest loadIs found for app: {app_dir}, skipping application."
)
return json.dumps({})

if not app_detail_json:
Expand All @@ -273,32 +292,35 @@ def get_app_details(self, app_dir):
try:
# Path to metadata.json
app_path = f"{CacheDir.HOME_DIR.value}/{app_dir}/{CacheDir.METADATA_FILE_PATH.value}"
logger.debug(f"Metadata file path: {app_path}")
logger.debug(f"[App Details]: Metadata file path: {app_path}")
# Reading metadata.json
app_json = read_json_file(app_path)
# Condition for handling loadId
if not app_json:
# Unable to fetch loadId details
logger.debug(
f"Error: Report Json {CacheDir.METADATA_FILE_PATH.value} not found for app {app_path}"
f"[App Details]: Error: Report Json {CacheDir.METADATA_FILE_PATH.value}"
f"not found for app {app_path}"
)
logger.warning(
f"Skipping app '{app_dir}' due to missing or invalid file"
f"[App Details]: Metadata file is not present for application: {app_dir}, skipping application"
)
return json.dumps({})

app_type = app_json.get("app_type", None)
app_name = app_json.get("name")
if app_type in ["loader", None]:
load_ids = app_json.get("load_ids", [])
if not load_ids:
# Unable to fetch loadId details
logger.debug(f"Error: Details not found for app {app_path}")
logger.debug(
f"[App Details]: Error: Details not found for app {app_path}"
)
logger.warning(
f"Skipping app '{app_dir}' due to missing or invalid file"
f"[App Details]: No valid loadIs found for the application: {app_name}, skipping application."
)
return json.dumps({})
response = self.get_loader_app_details(app_dir, load_ids)
logger.debug(f"App Details: {response}")
return response
elif app_type == "retrieval":
app_metadata_path = (
Expand All @@ -310,19 +332,18 @@ def get_app_details(self, app_dir):
# Skip app if app_metadata details are not present for some reason.
if not app_metadata_content:
logger.debug(
f"Error: Unable to fetch app_metadata.json content for {app_dir} app"
f"[App Details]: Error: Unable to fetch app_metadata.json content for {app_dir} app"
)
logger.debug(f"App metadata Json : {app_metadata_content}")
logger.warning(
f"Skipping app '{app_dir}' due to missing or invalid file"
f"[App Details]: Application metadata file is not present for application: {app_name},"
f"skipping application."
)
return json.dumps({})
response = self.get_retrieval_app_details(app_metadata_content)
logger.debug(f"Retrieval App Details for {app_dir} app: {response}")
return response

except Exception as ex:
logger.error(f"Error in app detail. Error: {ex}")
logger.error(f"[App Details]: Error in getting app details. Error: {ex}")

@staticmethod
def delete_application(app_name):
Expand All @@ -332,11 +353,11 @@ def delete_application(app_name):
try:
# Path to application directory
app_dir_path = f"{CacheDir.HOME_DIR.value}/{app_name}"
logger.debug(f"App directory path: {app_dir_path}")
logger.debug(f"[Delete App]: Path: {app_dir_path}")
response = delete_directory(app_dir_path, app_name)
return response
except Exception as ex:
error_message = f"Error in delete application. Error: {ex}"
error_message = f"[Delete App]: Error in delete application. Error: {ex}"
logger.error(error_message)
return {
"message": error_message,
Expand All @@ -351,7 +372,7 @@ def get_latest_load_id(load_ids, app_dir):
for load_id in reversed(load_ids):
# Path to report.json
app_detail_path = f"{CacheDir.HOME_DIR.value}/{app_dir}/{load_id}/{CacheDir.REPORT_DATA_FILE_NAME.value}"
logger.debug(f"Report File path: {app_detail_path}")
logger.debug(f"[App Details]: Report File path: {app_detail_path}")
app_detail_json = read_json_file(app_detail_path)
if app_detail_json:
# If report is found, proceed with this load_id
Expand Down Expand Up @@ -403,7 +424,7 @@ def fetch_last_accessed_time(accessed_time: list) -> str:
return last_accessed_time
except Exception as ex:
logger.error(
f"Error in fetching last accessed time while returning app details response :{ex}"
f"[Dashboard]: Error in fetching last accessed time while returning app details response :{ex}"
)
return ""

Expand Down

0 comments on commit 445c7c3

Please sign in to comment.