Changeset c33c0a8 in trunk


Ignore:
Timestamp:
2020-06-18T01:18:14Z (5 years ago)
Author:
Sajith Sasidharan <sajith@…>
Branches:
master
Children:
27e5ce0
Parents:
9dcaa10
git-author:
Sajith Sasidharan <sajith@…> (2020-06-04 21:46:06)
git-committer:
Sajith Sasidharan <sajith@…> (2020-06-18 01:18:14)
Message:

Make DeepCheckResultsRenderer? a MultiFormatResource?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/web/check_results.py

    r9dcaa10 rc33c0a8  
    411411
    412412
    413 class DeepCheckResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
    414     docFactory = getxmlfile("deep-check-results.xhtml")
     413class DeepCheckResultsRenderer(MultiFormatResource):
     414
     415    formatArgument = "output"
    415416
    416417    def __init__(self, client, monitor):
     418        # TODO: document params
     419        super(DeepCheckResultsRenderer, self).__init__()
    417420        self.client = client
    418421        self.monitor = monitor
    419422
    420     def childFactory(self, ctx, name):
     423    def getChild(self, name, req):
    421424        if not name:
    422425            return self
     
    432435                           http.NOT_FOUND)
    433436
    434     def renderHTTP(self, ctx):
    435         if self.want_json(ctx):
    436             return self.json(ctx)
    437         return rend.Page.renderHTTP(self, ctx)
    438 
    439     def json(self, ctx):
    440         inevow.IRequest(ctx).setHeader("content-type", "text/plain")
     437    def render_HTML(self, req):
     438        elem = DeepCheckResultsRendererElement(self.monitor)
     439        return renderElement(req, elem)
     440
     441    # def renderHTTP(self, ctx):
     442    #     if self.want_json(ctx):
     443    #         return self.json(ctx)
     444    #     return rend.Page.renderHTTP(self, ctx)
     445
     446    def render_JSON(self, req):
     447        # inevow.IRequest(ctx).setHeader("content-type", "text/plain")
     448        req.setHeader("content-type", "text/plain")
    441449        data = {}
    442450        data["finished"] = self.monitor.is_finished()
     
    460468        return json.dumps(data, indent=1) + "\n"
    461469
    462     def render_root_storage_index(self, ctx, data):
     470
     471class DeepCheckResultsRendererElement(Element, ResultsBase, ReloadMixin):
     472
     473    loader = XMLFile(FilePath(__file__).sibling("deep-check-results.xhtml"))
     474
     475    def __init__(self, monitor):
     476        super(DeepCheckResultsRendererElement, self).__init__()
     477        self.monitor = monitor
     478
     479    @renderer
     480    def root_storage_index(self, req, tag):
    463481        return self.monitor.get_status().get_root_storage_index_string()
    464482
    465     def data_objects_checked(self, ctx, data):
     483    @renderer
     484    def objects_checked(self, req, tag):
    466485        return self.monitor.get_status().get_counters()["count-objects-checked"]
    467     def data_objects_healthy(self, ctx, data):
     486
     487    @renderer
     488    def objects_healthy(self, req, tag):
    468489        return self.monitor.get_status().get_counters()["count-objects-healthy"]
    469     def data_objects_unhealthy(self, ctx, data):
     490
     491    @renderer
     492    def objects_unhealthy(self, req, tag):
    470493        return self.monitor.get_status().get_counters()["count-objects-unhealthy"]
    471     def data_objects_unrecoverable(self, ctx, data):
     494
     495    @renderer
     496    def objects_unrecoverable(self, req, tag):
    472497        return self.monitor.get_status().get_counters()["count-objects-unrecoverable"]
    473498
    474     def data_count_corrupt_shares(self, ctx, data):
     499    @renderer
     500    def count_corrupt_shares(self, req, tag):
    475501        return self.monitor.get_status().get_counters()["count-corrupt-shares"]
    476502
    477     def render_problems_p(self, ctx, data):
     503    @renderer
     504    def problems_p(self, req, tag):
    478505        c = self.monitor.get_status().get_counters()
    479506        if c["count-objects-unhealthy"]:
    480             return ctx.tag
    481         return ""
    482 
    483     def data_problems(self, ctx, data):
     507            return tag
     508        return ""
     509
     510    # TODO: use SlotsSequenceElement to render this.
     511    @renderer
     512    def problems(self, req, tag):
    484513        all_objects = self.monitor.get_status().get_all_results()
    485514        for path in sorted(all_objects.keys()):
     
    489518                yield path, cr
    490519
    491     def render_problem(self, ctx, data):
     520    @renderer
     521    def render_problem(self, req, tag):
     522        # TODO: deal with this.
    492523        path, cr = data
    493524        summary_text = ""
     
    496527            summary_text = ": " + summary
    497528        summary_text += " [SI: %s]" % cr.get_storage_index_string()
    498         return ctx.tag[self._join_pathstring(path), self._html(summary_text)]
    499 
    500 
    501     def render_servers_with_corrupt_shares_p(self, ctx, data):
     529        return tag(self._join_pathstring(path), self._html(summary_text))
     530
     531    @renderer
     532    def servers_with_corrupt_shares_p(self, req, tag):
    502533        if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
    503             return ctx.tag
    504         return ""
    505 
    506     def data_servers_with_corrupt_shares(self, ctx, data):
     534            return tag
     535        return ""
     536
     537    # TODO: use SlotsSequenceElement to render this.
     538    @renderer
     539    def servers_with_corrupt_shares(self, ctx, data):
    507540        servers = [s
    508541                   for (s, storage_index, sharenum)
     
    511544        return servers
    512545
    513     def render_server_problem(self, ctx, server):
     546    @renderer
     547    def server_problem(self, req, tag):
     548    # def server_problem(self, ctx, server):
     549        # TODO: where do `server` come from now?
    514550        data = [server.get_name()]
    515551        nickname = server.get_nickname()
    516552        if nickname:
    517553            data.append(" (%s)" % self._html(nickname))
    518         return ctx.tag[data]
    519 
    520 
    521     def render_corrupt_shares_p(self, ctx, data):
     554        return tag(data)
     555
     556    @renderer
     557    def corrupt_shares_p(self, req, tag):
    522558        if self.monitor.get_status().get_counters()["count-corrupt-shares"]:
    523             return ctx.tag
    524         return ""
    525     def data_corrupt_shares(self, ctx, data):
     559            return tag
     560        return ""
     561
     562    # TODO: Probably should use SlotsSequenceElement to render this.
     563    @renderer
     564    def corrupt_shares(self, req, tag):
    526565        return self.monitor.get_status().get_corrupt_shares()
    527     def render_share_problem(self, ctx, data):
     566
     567    @renderer
     568    def share_problem(self, req, tag):
     569    # def render_share_problem(self, req, tag):
    528570        server, storage_index, sharenum = data
    529571        nickname = server.get_nickname()
    530         ctx.fillSlots("serverid", server.get_name())
     572        tag.fillSlots("serverid", server.get_name())
    531573        if nickname:
    532             ctx.fillSlots("nickname", self._html(nickname))
    533         ctx.fillSlots("si", self._render_si_link(ctx, storage_index))
    534         ctx.fillSlots("shnum", str(sharenum))
    535         return ctx.tag
    536 
    537     def render_return(self, ctx, data):
    538         req = inevow.IRequest(ctx)
     574            tag.fillSlots("nickname", self._html(nickname))
     575        tag.fillSlots("si", self._render_si_link(ctx, storage_index))
     576        tag.fillSlots("shnum", str(sharenum))
     577        return tag
     578
     579    @renderer
     580    def return_to(self, req, tag):
     581        # req = inevow.IRequest(ctx)
    539582        return_to = get_arg(req, "return_to", None)
    540583        if return_to:
    541             return T.div[T.a(href=return_to)["Return to file/directory."]]
    542         return ""
    543 
     584            return tags.div(tags.a("Return to file/directory.", href=return_to))
     585        return ""
     586
     587    # TODO: use SlotsSequenceElement to render this.
     588    @renderer
    544589    def data_all_objects(self, ctx, data):
    545590        r = self.monitor.get_status().get_all_results()
     
    547592            yield (path, r[path])
    548593
    549     def render_object(self, ctx, data):
     594    @renderer
     595    def object(self, ctx, data):
     596    # def render_object(self, ctx, data):
     597        # TODO: figure `data` out
    550598        path, r = data
    551         ctx.fillSlots("path", self._join_pathstring(path))
    552         ctx.fillSlots("healthy", str(r.is_healthy()))
    553         ctx.fillSlots("recoverable", str(r.is_recoverable()))
     599        tag.fillSlots("path", self._join_pathstring(path))
     600        tag.fillSlots("healthy", str(r.is_healthy()))
     601        tag.fillSlots("recoverable", str(r.is_recoverable()))
    554602        storage_index = r.get_storage_index()
    555         ctx.fillSlots("storage_index", self._render_si_link(ctx, storage_index))
    556         ctx.fillSlots("summary", self._html(r.get_summary()))
    557         return ctx.tag
    558 
    559     def render_runtime(self, ctx, data):
    560         req = inevow.IRequest(ctx)
     603        tag.fillSlots("storage_index", self._render_si_link(req, storage_index))
     604        tag.fillSlots("summary", self._html(r.get_summary()))
     605        return tag
     606
     607    @renderer
     608    def runtime(self, req, tag):
     609        # req = inevow.IRequest(ctx)
    561610        runtime = time.time() - req.processing_started_timestamp
    562         return ctx.tag["runtime: %s seconds" % runtime]
     611        return tag("runtime: %s seconds" % runtime)
     612
    563613
    564614class DeepCheckAndRepairResultsRenderer(rend.Page, ResultsBase, ReloadMixin):
Note: See TracChangeset for help on using the changeset viewer.