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