Skip to content

Commit f87b505

Browse files
haiqi96junhaoliao
andauthored
feat(package): Add verbose logging option to archive_manager and improve error handling. (#1173)
Co-authored-by: Junhao Liao <[email protected]>
1 parent 135c6bb commit f87b505

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

components/clp-package-utils/clp_package_utils/scripts/archive_manager.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def main(argv: typing.List[str]) -> int:
6464
default=str(default_config_file_path),
6565
help="CLP package configuration file.",
6666
)
67+
args_parser.add_argument(
68+
"--verbose",
69+
"-v",
70+
action="store_true",
71+
help="Enable debug logging.",
72+
)
6773
args_parser.add_argument(
6874
"--dataset",
6975
type=str,
@@ -148,6 +154,10 @@ def main(argv: typing.List[str]) -> int:
148154
)
149155

150156
parsed_args: argparse.Namespace = args_parser.parse_args(argv[1:])
157+
if parsed_args.verbose:
158+
logger.setLevel(logging.DEBUG)
159+
else:
160+
logger.setLevel(logging.INFO)
151161

152162
begin_timestamp: typing.Optional[int]
153163
end_timestamp: typing.Optional[int]
@@ -169,7 +179,7 @@ def main(argv: typing.List[str]) -> int:
169179

170180
storage_type: StorageType = clp_config.archive_output.storage.type
171181
if StorageType.FS != storage_type:
172-
logger.error(f"Archive deletion is not supported for storage type: {storage_type}.")
182+
logger.error(f"Archive manager is not supported for storage type: {storage_type}.")
173183
return -1
174184

175185
storage_engine: StorageEngine = clp_config.package.storage_engine
@@ -224,6 +234,9 @@ def main(argv: typing.List[str]) -> int:
224234
if dataset is not None:
225235
archive_manager_cmd.append("--dataset")
226236
archive_manager_cmd.append(dataset)
237+
if parsed_args.verbose:
238+
archive_manager_cmd.append("--verbose")
239+
227240
archive_manager_cmd.append(subcommand)
228241

229242
# Add subcommand-specific arguments
@@ -249,15 +262,20 @@ def main(argv: typing.List[str]) -> int:
249262
archive_manager_cmd.extend([END_TS_ARG, str(end_timestamp)])
250263
else:
251264
logger.error(f"Unsupported subcommand: `{subcommand}`.")
265+
return -1
252266

253267
cmd: typing.List[str] = container_start_cmd + archive_manager_cmd
254268

255-
subprocess.run(cmd, check=True)
269+
proc = subprocess.run(cmd)
270+
ret_code = proc.returncode
271+
if 0 != ret_code:
272+
logger.error("Archive manager failed.")
273+
logger.debug(f"Docker command failed: {' '.join(cmd)}")
256274

257275
# Remove generated files
258276
generated_config_path_on_host.unlink()
259277

260-
return 0
278+
return ret_code
261279

262280

263281
if "__main__" == __name__:

components/clp-package-utils/clp_package_utils/scripts/native/archive_manager.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def main(argv: typing.List[str]) -> int:
9595
default=str(default_config_file_path),
9696
help="CLP configuration file.",
9797
)
98+
args_parser.add_argument(
99+
"--verbose",
100+
"-v",
101+
action="store_true",
102+
help="Enable debug logging.",
103+
)
98104
args_parser.add_argument(
99105
"--dataset",
100106
type=str,
@@ -176,6 +182,10 @@ def main(argv: typing.List[str]) -> int:
176182
)
177183

178184
parsed_args: argparse.Namespace = args_parser.parse_args(argv[1:])
185+
if parsed_args.verbose:
186+
logger.setLevel(logging.DEBUG)
187+
else:
188+
logger.setLevel(logging.INFO)
179189

180190
# Validate and load config file
181191
config_file_path: Path = Path(parsed_args.config)
@@ -258,7 +268,8 @@ def _find_archives(
258268
:return: 0 on success, 1 on failure.
259269
"""
260270
archive_ids: typing.List[str]
261-
logger.info("Starting to find archives from the database.")
271+
dataset_specific_message = f" of dataset `{dataset}`" if dataset is not None else ""
272+
logger.info(f"Starting to find archives{dataset_specific_message} from the database.")
262273
try:
263274
sql_adapter: SQL_Adapter = SQL_Adapter(database_config)
264275
clp_db_connection_params: dict[str, any] = (
@@ -323,7 +334,8 @@ def _delete_archives(
323334
"""
324335

325336
archive_ids: typing.List[str]
326-
logger.info("Starting to delete archives from the database.")
337+
dataset_specific_message = f" of dataset `{dataset}`" if dataset is not None else ""
338+
logger.info(f"Starting to delete archives{dataset_specific_message} from the database.")
327339
sql_adapter: SQL_Adapter = SQL_Adapter(database_config)
328340
clp_db_connection_params: dict[str, any] = database_config.get_clp_connection_params_and_type(
329341
True

0 commit comments

Comments
 (0)