mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-25 15:41:06 +00:00
Make DeepCheckResultsRenderer a MultiFormatResource
This commit is contained in:
parent
9dcaa104c5
commit
c33c0a884d
@ -410,14 +410,17 @@ class CheckAndRepairResultsRendererElement(Element, CheckerBase, ResultsBase):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class DeepCheckResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
class DeepCheckResultsRenderer(MultiFormatResource):
|
||||||
docFactory = getxmlfile("deep-check-results.xhtml")
|
|
||||||
|
formatArgument = "output"
|
||||||
|
|
||||||
def __init__(self, client, monitor):
|
def __init__(self, client, monitor):
|
||||||
|
# TODO: document params
|
||||||
|
super(DeepCheckResultsRenderer, self).__init__()
|
||||||
self.client = client
|
self.client = client
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
|
|
||||||
def childFactory(self, ctx, name):
|
def getChild(self, name, req):
|
||||||
if not name:
|
if not name:
|
||||||
return self
|
return self
|
||||||
# /operation/$OPHANDLE/$STORAGEINDEX provides detailed information
|
# /operation/$OPHANDLE/$STORAGEINDEX provides detailed information
|
||||||
@ -431,13 +434,18 @@ class DeepCheckResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
|||||||
raise WebError("No detailed results for SI %s" % html.escape(name),
|
raise WebError("No detailed results for SI %s" % html.escape(name),
|
||||||
http.NOT_FOUND)
|
http.NOT_FOUND)
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def render_HTML(self, req):
|
||||||
if self.want_json(ctx):
|
elem = DeepCheckResultsRendererElement(self.monitor)
|
||||||
return self.json(ctx)
|
return renderElement(req, elem)
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
|
||||||
|
|
||||||
def json(self, ctx):
|
# def renderHTTP(self, ctx):
|
||||||
inevow.IRequest(ctx).setHeader("content-type", "text/plain")
|
# if self.want_json(ctx):
|
||||||
|
# return self.json(ctx)
|
||||||
|
# return rend.Page.renderHTTP(self, ctx)
|
||||||
|
|
||||||
|
def render_JSON(self, req):
|
||||||
|
# inevow.IRequest(ctx).setHeader("content-type", "text/plain")
|
||||||
|
req.setHeader("content-type", "text/plain")
|
||||||
data = {}
|
data = {}
|
||||||
data["finished"] = self.monitor.is_finished()
|
data["finished"] = self.monitor.is_finished()
|
||||||
res = self.monitor.get_status()
|
res = self.monitor.get_status()
|
||||||
@ -459,28 +467,49 @@ class DeepCheckResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
|||||||
data["stats"] = res.get_stats()
|
data["stats"] = res.get_stats()
|
||||||
return json.dumps(data, indent=1) + "\n"
|
return json.dumps(data, indent=1) + "\n"
|
||||||
|
|
||||||
def render_root_storage_index(self, ctx, data):
|
|
||||||
|
class DeepCheckResultsRendererElement(Element, ResultsBase, ReloadMixin):
|
||||||
|
|
||||||
|
loader = XMLFile(FilePath(__file__).sibling("deep-check-results.xhtml"))
|
||||||
|
|
||||||
|
def __init__(self, monitor):
|
||||||
|
super(DeepCheckResultsRendererElement, self).__init__()
|
||||||
|
self.monitor = monitor
|
||||||
|
|
||||||
|
@renderer
|
||||||
|
def root_storage_index(self, req, tag):
|
||||||
return self.monitor.get_status().get_root_storage_index_string()
|
return self.monitor.get_status().get_root_storage_index_string()
|
||||||
|
|
||||||
def data_objects_checked(self, ctx, data):
|
@renderer
|
||||||
|
def objects_checked(self, req, tag):
|
||||||
return self.monitor.get_status().get_counters()["count-objects-checked"]
|
return self.monitor.get_status().get_counters()["count-objects-checked"]
|
||||||
def data_objects_healthy(self, ctx, data):
|
|
||||||
|
@renderer
|
||||||
|
def objects_healthy(self, req, tag):
|
||||||
return self.monitor.get_status().get_counters()["count-objects-healthy"]
|
return self.monitor.get_status().get_counters()["count-objects-healthy"]
|
||||||
def data_objects_unhealthy(self, ctx, data):
|
|
||||||
|
@renderer
|
||||||
|
def objects_unhealthy(self, req, tag):
|
||||||
return self.monitor.get_status().get_counters()["count-objects-unhealthy"]
|
return self.monitor.get_status().get_counters()["count-objects-unhealthy"]
|
||||||
def data_objects_unrecoverable(self, ctx, data):
|
|
||||||
|
@renderer
|
||||||
|
def objects_unrecoverable(self, req, tag):
|
||||||
return self.monitor.get_status().get_counters()["count-objects-unrecoverable"]
|
return self.monitor.get_status().get_counters()["count-objects-unrecoverable"]
|
||||||
|
|
||||||
def data_count_corrupt_shares(self, ctx, data):
|
@renderer
|
||||||
|
def count_corrupt_shares(self, req, tag):
|
||||||
return self.monitor.get_status().get_counters()["count-corrupt-shares"]
|
return self.monitor.get_status().get_counters()["count-corrupt-shares"]
|
||||||
|
|
||||||
def render_problems_p(self, ctx, data):
|
@renderer
|
||||||
|
def problems_p(self, req, tag):
|
||||||
c = self.monitor.get_status().get_counters()
|
c = self.monitor.get_status().get_counters()
|
||||||
if c["count-objects-unhealthy"]:
|
if c["count-objects-unhealthy"]:
|
||||||
return ctx.tag
|
return tag
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def data_problems(self, ctx, data):
|
# TODO: use SlotsSequenceElement to render this.
|
||||||
|
@renderer
|
||||||
|
def problems(self, req, tag):
|
||||||
all_objects = self.monitor.get_status().get_all_results()
|
all_objects = self.monitor.get_status().get_all_results()
|
||||||
for path in sorted(all_objects.keys()):
|
for path in sorted(all_objects.keys()):
|
||||||
cr = all_objects[path]
|
cr = all_objects[path]
|
||||||
@ -488,78 +517,99 @@ class DeepCheckResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
|||||||
if not cr.is_healthy():
|
if not cr.is_healthy():
|
||||||
yield path, cr
|
yield path, cr
|
||||||
|
|
||||||
def render_problem(self, ctx, data):
|
@renderer
|
||||||
|
def render_problem(self, req, tag):
|
||||||
|
# TODO: deal with this.
|
||||||
path, cr = data
|
path, cr = data
|
||||||
summary_text = ""
|
summary_text = ""
|
||||||
summary = cr.get_summary()
|
summary = cr.get_summary()
|
||||||
if summary:
|
if summary:
|
||||||
summary_text = ": " + summary
|
summary_text = ": " + summary
|
||||||
summary_text += " [SI: %s]" % cr.get_storage_index_string()
|
summary_text += " [SI: %s]" % cr.get_storage_index_string()
|
||||||
return ctx.tag[self._join_pathstring(path), self._html(summary_text)]
|
return tag(self._join_pathstring(path), self._html(summary_text))
|
||||||
|
|
||||||
|
@renderer
|
||||||
def render_servers_with_corrupt_shares_p(self, ctx, data):
|
def servers_with_corrupt_shares_p(self, req, tag):
|
||||||
if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
|
if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
|
||||||
return ctx.tag
|
return tag
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def data_servers_with_corrupt_shares(self, ctx, data):
|
# TODO: use SlotsSequenceElement to render this.
|
||||||
|
@renderer
|
||||||
|
def servers_with_corrupt_shares(self, ctx, data):
|
||||||
servers = [s
|
servers = [s
|
||||||
for (s, storage_index, sharenum)
|
for (s, storage_index, sharenum)
|
||||||
in self.monitor.get_status().get_corrupt_shares()]
|
in self.monitor.get_status().get_corrupt_shares()]
|
||||||
servers.sort(key=lambda s: s.get_longname())
|
servers.sort(key=lambda s: s.get_longname())
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
def render_server_problem(self, ctx, server):
|
@renderer
|
||||||
|
def server_problem(self, req, tag):
|
||||||
|
# def server_problem(self, ctx, server):
|
||||||
|
# TODO: where do `server` come from now?
|
||||||
data = [server.get_name()]
|
data = [server.get_name()]
|
||||||
nickname = server.get_nickname()
|
nickname = server.get_nickname()
|
||||||
if nickname:
|
if nickname:
|
||||||
data.append(" (%s)" % self._html(nickname))
|
data.append(" (%s)" % self._html(nickname))
|
||||||
return ctx.tag[data]
|
return tag(data)
|
||||||
|
|
||||||
|
@renderer
|
||||||
def render_corrupt_shares_p(self, ctx, data):
|
def corrupt_shares_p(self, req, tag):
|
||||||
if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
|
if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
|
||||||
return ctx.tag
|
return tag
|
||||||
return ""
|
return ""
|
||||||
def data_corrupt_shares(self, ctx, data):
|
|
||||||
|
# TODO: Probably should use SlotsSequenceElement to render this.
|
||||||
|
@renderer
|
||||||
|
def corrupt_shares(self, req, tag):
|
||||||
return self.monitor.get_status().get_corrupt_shares()
|
return self.monitor.get_status().get_corrupt_shares()
|
||||||
def render_share_problem(self, ctx, data):
|
|
||||||
|
@renderer
|
||||||
|
def share_problem(self, req, tag):
|
||||||
|
# def render_share_problem(self, req, tag):
|
||||||
server, storage_index, sharenum = data
|
server, storage_index, sharenum = data
|
||||||
nickname = server.get_nickname()
|
nickname = server.get_nickname()
|
||||||
ctx.fillSlots("serverid", server.get_name())
|
tag.fillSlots("serverid", server.get_name())
|
||||||
if nickname:
|
if nickname:
|
||||||
ctx.fillSlots("nickname", self._html(nickname))
|
tag.fillSlots("nickname", self._html(nickname))
|
||||||
ctx.fillSlots("si", self._render_si_link(ctx, storage_index))
|
tag.fillSlots("si", self._render_si_link(ctx, storage_index))
|
||||||
ctx.fillSlots("shnum", str(sharenum))
|
tag.fillSlots("shnum", str(sharenum))
|
||||||
return ctx.tag
|
return tag
|
||||||
|
|
||||||
def render_return(self, ctx, data):
|
@renderer
|
||||||
req = inevow.IRequest(ctx)
|
def return_to(self, req, tag):
|
||||||
|
# req = inevow.IRequest(ctx)
|
||||||
return_to = get_arg(req, "return_to", None)
|
return_to = get_arg(req, "return_to", None)
|
||||||
if return_to:
|
if return_to:
|
||||||
return T.div[T.a(href=return_to)["Return to file/directory."]]
|
return tags.div(tags.a("Return to file/directory.", href=return_to))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
# TODO: use SlotsSequenceElement to render this.
|
||||||
|
@renderer
|
||||||
def data_all_objects(self, ctx, data):
|
def data_all_objects(self, ctx, data):
|
||||||
r = self.monitor.get_status().get_all_results()
|
r = self.monitor.get_status().get_all_results()
|
||||||
for path in sorted(r.keys()):
|
for path in sorted(r.keys()):
|
||||||
yield (path, r[path])
|
yield (path, r[path])
|
||||||
|
|
||||||
def render_object(self, ctx, data):
|
@renderer
|
||||||
|
def object(self, ctx, data):
|
||||||
|
# def render_object(self, ctx, data):
|
||||||
|
# TODO: figure `data` out
|
||||||
path, r = data
|
path, r = data
|
||||||
ctx.fillSlots("path", self._join_pathstring(path))
|
tag.fillSlots("path", self._join_pathstring(path))
|
||||||
ctx.fillSlots("healthy", str(r.is_healthy()))
|
tag.fillSlots("healthy", str(r.is_healthy()))
|
||||||
ctx.fillSlots("recoverable", str(r.is_recoverable()))
|
tag.fillSlots("recoverable", str(r.is_recoverable()))
|
||||||
storage_index = r.get_storage_index()
|
storage_index = r.get_storage_index()
|
||||||
ctx.fillSlots("storage_index", self._render_si_link(ctx, storage_index))
|
tag.fillSlots("storage_index", self._render_si_link(req, storage_index))
|
||||||
ctx.fillSlots("summary", self._html(r.get_summary()))
|
tag.fillSlots("summary", self._html(r.get_summary()))
|
||||||
return ctx.tag
|
return tag
|
||||||
|
|
||||||
def render_runtime(self, ctx, data):
|
@renderer
|
||||||
req = inevow.IRequest(ctx)
|
def runtime(self, req, tag):
|
||||||
|
# req = inevow.IRequest(ctx)
|
||||||
runtime = time.time() - req.processing_started_timestamp
|
runtime = time.time() - req.processing_started_timestamp
|
||||||
return ctx.tag["runtime: %s seconds" % runtime]
|
return tag("runtime: %s seconds" % runtime)
|
||||||
|
|
||||||
|
|
||||||
class DeepCheckAndRepairResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
class DeepCheckAndRepairResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
|
||||||
docFactory = getxmlfile("deep-check-and-repair-results.xhtml")
|
docFactory = getxmlfile("deep-check-and-repair-results.xhtml")
|
||||||
|
Loading…
Reference in New Issue
Block a user