Check storage server status before using it

This commit is contained in:
Sajith Sasidharan 2020-02-05 22:09:16 -05:00
parent c019c7e955
commit 4e81a3a0a2

View File

@ -31,9 +31,13 @@ class StorageStatusElement(Element):
@renderer @renderer
def nodeid(self, req, tag): def nodeid(self, req, tag):
if not self.storage:
return tag("No storage server running.")
return idlib.nodeid_b2a(self.storage.my_nodeid) return idlib.nodeid_b2a(self.storage.my_nodeid)
def get_stat(self, key): def get_stat(self, key):
if not self.storage:
return None
return self.storage.get_stats().get(key) return self.storage.get_stats().get(key)
def str(self, tag, val): def str(self, tag, val):
@ -101,6 +105,8 @@ class StorageStatusElement(Element):
@renderer @renderer
def last_complete_bucket_count(self, req, tag): def last_complete_bucket_count(self, req, tag):
if not self.storage:
return tag("No storage server running.")
s = self.storage.bucket_counter.get_state() s = self.storage.bucket_counter.get_state()
count = s.get("last-complete-bucket-count") count = s.get("last-complete-bucket-count")
if count is None: if count is None:
@ -109,6 +115,8 @@ class StorageStatusElement(Element):
@renderer @renderer
def count_crawler_status(self, req, tag): def count_crawler_status(self, req, tag):
if not self.storage:
return tag("No storage server running.")
p = self.storage.bucket_counter.get_progress() p = self.storage.bucket_counter.get_progress()
return self.format_crawler_progress(p) return self.format_crawler_progress(p)
@ -145,6 +153,8 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_expiration_enabled(self, req, tag): def lease_expiration_enabled(self, req, tag):
if not self.storage:
return tag("No storage server running.")
lc = self.storage.lease_checker lc = self.storage.lease_checker
if lc.expiration_enabled: if lc.expiration_enabled:
return tag("Enabled: expired leases will be removed") return tag("Enabled: expired leases will be removed")
@ -153,6 +163,8 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_expiration_mode(self, req, tag): def lease_expiration_mode(self, req, tag):
if not self.storage:
return tag("No storage server running.")
lc = self.storage.lease_checker lc = self.storage.lease_checker
if lc.mode == "age": if lc.mode == "age":
if lc.override_lease_duration is None: if lc.override_lease_duration is None:
@ -176,12 +188,16 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_current_cycle_progress(self, req, tag): def lease_current_cycle_progress(self, req, tag):
if not self.storage:
return tag("No storage server running.")
lc = self.storage.lease_checker lc = self.storage.lease_checker
p = lc.get_progress() p = lc.get_progress()
return tag(self.format_crawler_progress(p)) return tag(self.format_crawler_progress(p))
@renderer @renderer
def lease_current_cycle_results(self, req, tag): def lease_current_cycle_results(self, req, tag):
if not self.storage:
return tag("No storage server running.")
lc = self.storage.lease_checker lc = self.storage.lease_checker
p = lc.get_progress() p = lc.get_progress()
if not p["cycle-in-progress"]: if not p["cycle-in-progress"]:
@ -239,6 +255,8 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_last_cycle_results(self, req, tag): def lease_last_cycle_results(self, req, tag):
if not self.storage:
return tag("No storage server running.")
lc = self.storage.lease_checker lc = self.storage.lease_checker
h = lc.get_state()["history"] h = lc.get_state()["history"]
if not h: if not h: