Skip to content

Commit 3193c98

Browse files
committed
Refactor error handling to help identify cause of AIP createion failures.
1 parent e3e00d0 commit 3193c98

File tree

2 files changed

+52
-37
lines changed

2 files changed

+52
-37
lines changed

rootfs/var/www/leaf-isle-bagger/leaf-bagger.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def main():
118118
args = parse_args()
119119

120120
logging.basicConfig(level=args.logging_level)
121+
logging.getLogger('swiftclient').setLevel(logging.CRITICAL)
121122

122123
username, password = drupalUtilities.get_drupal_credentials()
123124

rootfs/var/www/leaf-isle-bagger/swift/utilities.py

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def generate_aip_path(aip_dir, id):
2727
return f"{aip_dir}/{generate_aip_id(id)}"
2828

2929

30+
def aip_exists(aip_path):
31+
return os.path.exists(aip_path)
32+
33+
3034
#
3135
def upload_aip(node_list, aip_dir, swift_options, container_dst, database_csv):
3236

@@ -37,20 +41,26 @@ def upload_aip(node_list, aip_dir, swift_options, container_dst, database_csv):
3741
for key, item_values in node_list.items():
3842
aip_path = generate_aip_path(aip_dir, key)
3943
aip_id = generate_aip_id(key)
40-
logging.info(f" adding to upload: {aip_path}")
41-
checksums = file_checksum(aip_path)
42-
item_options = {
43-
"header": {
44-
"x-object-meta-sha256sum": checksums["sha256sum"],
45-
"x-object-meta-last-mod-timestamp": item_values["changed"],
46-
"content-type": item_values["content_type"],
44+
if aip_exists(aip_path):
45+
logging.info(f" adding to upload: {aip_path}")
46+
checksums = file_checksum(aip_path)
47+
item_options = {
48+
"header": {
49+
"x-object-meta-sha256sum": checksums["sha256sum"],
50+
"x-object-meta-last-mod-timestamp": item_values["changed"],
51+
"content-type": item_values["content_type"],
52+
}
4753
}
48-
}
49-
dst_objs.append(
50-
build_swift_upload_object(
51-
aip_id, aip_path, swift_options, item_options
54+
dst_objs.append(
55+
build_swift_upload_object(
56+
aip_id, aip_path, swift_options, item_options
57+
)
5258
)
53-
)
59+
else:
60+
logging.error(f" Failed to find: {aip_path}")
61+
# delete from the nodelist so not used in subsequent steps
62+
node_list[key] = None
63+
5464
# May need to be split into batches of "x" if memory usage is too high
5565
upload(swift_conn_dst, dst_objs, container_dst, db_writer)
5666
os.fsync(db_file)
@@ -63,31 +73,35 @@ def validate(node_list, swift_container):
6373
for key, src_value in node_list.items():
6474
aip_id = generate_aip_id(key)
6575
logging.info(f" Validating: {aip_id}")
66-
swift_stat = swift_conn_dst.stat(swift_container, [aip_id])
67-
if swift_stat:
68-
for dst in swift_stat:
69-
logging.debug(f"{dst}")
70-
if dst["success"] is False:
71-
logging.error(
72-
f"id:[{aip_id}] - preservation error [{dst['error']}]"
73-
)
74-
logging.error(f"id:[{aip_id}] - swift stat - [{dst}]")
75-
break
76-
elif (
77-
src_value["changed"]
78-
!= dst["headers"]["x-object-meta-last-mod-timestamp"]
79-
):
80-
logging.error(
81-
(
82-
f"id:[{aip_id}] - mismatched modification timestamp [{src_value['changed']}]"
83-
f" : {dst['headers']['x-object-meta-last-mod-timestamp']}"
76+
try:
77+
swift_stat = swift_conn_dst.stat(swift_container, [aip_id])
78+
except Exception as e:
79+
logging.error(f"swift stat - [{aip_id}]")
80+
logging.error(f"{e}")
81+
finally:
82+
if swift_stat:
83+
for dst in swift_stat:
84+
logging.debug(f"{dst}")
85+
if dst["success"] is False:
86+
logging.error(
87+
f"id:[{aip_id}] - preservation error [{dst['error']}]"
8488
)
85-
)
86-
break
87-
else:
88-
logging.error(
89-
f"key:[{aip_id}] - not present in destination: {swift_stat}"
90-
)
89+
break
90+
elif (
91+
src_value["changed"]
92+
!= dst["headers"]["x-object-meta-last-mod-timestamp"]
93+
):
94+
logging.error(
95+
(
96+
f"id:[{aip_id}] - mismatched modification timestamp [{src_value['changed']}]"
97+
f" : {dst['headers']['x-object-meta-last-mod-timestamp']}"
98+
)
99+
)
100+
break
101+
else:
102+
logging.error(
103+
f"key:[{aip_id}] - not present in destination: {swift_stat}"
104+
)
91105

92106

93107
def log_init(fd):
@@ -200,7 +214,7 @@ def upload(swift_conn_dst, dst_objs, container_dst, db_writer=None):
200214
os.getenv("OS_USERNAME"),
201215
)
202216
except Exception as e:
203-
logging.error(f"swift stat - [{dst_item}]")
217+
logging.error(f"swift upload - [{dst_item}]")
204218
logging.error(f"{e}")
205219

206220

0 commit comments

Comments
 (0)