Ticket #386: 386_status_page_nicknames.dpatch

File 386_status_page_nicknames.dpatch, 19.5 KB (added by akp, at 2010-09-19T07:23:30Z)

patch to add nicknames to status pages (fixed to pass unit tests)

Line 
1Sun Sep 19 02:56:59 EDT 2010  tahoe@alistairphipps.com
2  * 386_status_page_nicknames
3
4New patches:
5
6[386_status_page_nicknames
7tahoe@alistairphipps.com**20100919065659
8 Ignore-this: 31c58a74489839b51e534372a98a839f
9] {
10hunk ./src/allmydata/client.py 294
11         self.history = History(self.stats_provider)
12         self.terminator = Terminator()
13         self.terminator.setServiceParent(self)
14-        self.add_service(Uploader(helper_furl, self.stats_provider))
15+        self.add_service(Uploader(helper_furl, self.stats_provider, self.history))
16         self.init_stub_client()
17         self.init_nodemaker()
18 
19hunk ./src/allmydata/client.py 499
20 
21     def upload(self, uploadable):
22         uploader = self.getServiceNamed("uploader")
23-        return uploader.upload(uploadable, history=self.get_history())
24+        return uploader.upload(uploadable)
25hunk ./src/allmydata/immutable/upload.py 1401
26     name = "uploader"
27     URI_LIT_SIZE_THRESHOLD = 55
28 
29-    def __init__(self, helper_furl=None, stats_provider=None):
30+    def __init__(self, helper_furl=None, stats_provider=None, history=None):
31         self._helper_furl = helper_furl
32         self.stats_provider = stats_provider
33         self._helper = None
34hunk ./src/allmydata/immutable/upload.py 1406
35         self._all_uploads = weakref.WeakKeyDictionary() # for debugging
36+        self.history = history
37         log.PrefixingLogMixin.__init__(self, facility="tahoe.immutable.upload")
38         service.MultiService.__init__(self)
39 
40hunk ./src/allmydata/immutable/upload.py 1440
41         return (self._helper_furl, bool(self._helper))
42 
43 
44-    def upload(self, uploadable, history=None):
45+    def upload(self, uploadable):
46         """
47         Returns a Deferred that will fire with the UploadResults instance.
48         """
49hunk ./src/allmydata/immutable/upload.py 1446
50         assert self.parent
51         assert self.running
52-
53         uploadable = IUploadable(uploadable)
54         d = uploadable.get_size()
55         def _got_size(size):
56hunk ./src/allmydata/immutable/upload.py 1457
57             if self.stats_provider:
58                 self.stats_provider.count('uploader.files_uploaded', 1)
59                 self.stats_provider.count('uploader.bytes_uploaded', size)
60-
61             if size <= self.URI_LIT_SIZE_THRESHOLD:
62                 uploader = LiteralUploader()
63                 return uploader.start(uploadable)
64hunk ./src/allmydata/immutable/upload.py 1474
65                     d2.addCallback(lambda x: uploader.start(eu))
66 
67                 self._all_uploads[uploader] = None
68-                if history:
69-                    history.add_upload(uploader.get_upload_status())
70+                if self.history:
71+                    self.history.add_upload(uploader.get_upload_status())
72                 def turn_verifycap_into_read_cap(uploadresults):
73                     # Generate the uri from the verifycap plus the key.
74                     d3 = uploadable.get_encryption_key()
75hunk ./src/allmydata/nodemaker.py 109
76             convergence = self.secret_holder.get_convergence_secret()
77         packed = pack_children(children, None, deep_immutable=True)
78         uploadable = Data(packed, convergence)
79-        d = self.uploader.upload(uploadable, history=self.history)
80+        d = self.uploader.upload(uploadable)
81         d.addCallback(lambda results: self.create_from_cap(None, results.uri))
82         d.addCallback(self._create_dirnode)
83         return d
84hunk ./src/allmydata/web/root.py 165
85 
86         self.child_file = FileHandler(client)
87         self.child_named = FileHandler(client)
88-        self.child_status = status.Status(client.get_history())
89+        self.child_status = status.Status(client)
90         self.child_statistics = status.Statistics(client.stats_provider)
91 
92     def child_helper_status(self, ctx):
93hunk ./src/allmydata/web/status.py 21
94         return abbreviate_rate(data)
95 
96 class UploadResultsRendererMixin(RateAndTimeMixin):
97-    # this requires a method named 'upload_results'
98+    # this requires a method named 'upload_results'and 'get_storage_broker'
99 
100     def render_pushed_shares(self, ctx, data):
101         d = self.upload_results()
102hunk ./src/allmydata/web/status.py 41
103                 return "None"
104             l = T.ul()
105             for shnum, peerids in sorted(sharemap.items()):
106+                nicknames = ', '.join([self.get_storage_broker().get_nickname_for_serverid(i) for i in peerids])
107                 peerids = ', '.join([idlib.shortnodeid_b2a(i) for i in peerids])
108hunk ./src/allmydata/web/status.py 43
109-                l[T.li["%d -> placed on [%s]" % (shnum, peerids)]]
110+                l[T.li["%d -> placed on %s [%s]" % (shnum, nicknames, peerids)]]
111             return l
112         d.addCallback(_render)
113         return d
114hunk ./src/allmydata/web/status.py 59
115                 peerid_s = idlib.shortnodeid_b2a(peerid)
116                 shares_s = ",".join(["#%d" % shnum
117                                      for shnum in servermap[peerid]])
118-                l[T.li["[%s] got share%s: %s" % (peerid_s,
119+                l[T.li["%s [%s] got share%s: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s,
120                                                  plural(servermap[peerid]),
121                                                  shares_s)]]
122             return l
123hunk ./src/allmydata/web/status.py 155
124 class UploadStatusPage(UploadResultsRendererMixin, rend.Page):
125     docFactory = getxmlfile("upload-status.xhtml")
126 
127-    def __init__(self, data):
128+    def __init__(self, data, storage_broker):
129         rend.Page.__init__(self, data)
130         self.upload_status = data
131hunk ./src/allmydata/web/status.py 158
132+        self.storage_broker = storage_broker
133 
134hunk ./src/allmydata/web/status.py 160
135+    def get_storage_broker(self):
136+        return self.storage_broker;
137+   
138     def upload_results(self):
139         return defer.maybeDeferred(self.upload_status.get_results)
140 
141hunk ./src/allmydata/web/status.py 216
142         return data.get_status()
143 
144 class DownloadResultsRendererMixin(RateAndTimeMixin):
145-    # this requires a method named 'download_results'
146+    # this requires a method named 'download_results' and 'get_storage_broker'
147 
148     def render_servermap(self, ctx, data):
149         d = self.download_results()
150hunk ./src/allmydata/web/status.py 229
151                 peerid_s = idlib.shortnodeid_b2a(peerid)
152                 shares_s = ",".join(["#%d" % shnum
153                                      for shnum in servermap[peerid]])
154-                l[T.li["[%s] has share%s: %s" % (peerid_s,
155+                l[T.li["%s [%s] has share%s: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s,
156                                                  plural(servermap[peerid]),
157                                                  shares_s)]]
158             return l
159hunk ./src/allmydata/web/status.py 242
160         def _got(servers_used):
161             if not servers_used:
162                 return ""
163-            peerids_s = ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
164+            peerids_s = ", ".join(["%s [%s]" % (self.get_storage_broker().get_nickname_for_serverid(peerid), idlib.shortnodeid_b2a(peerid))
165                                    for peerid in servers_used])
166             return T.li["Servers Used: ", peerids_s]
167         d.addCallback(_got)
168hunk ./src/allmydata/web/status.py 257
169             l = T.ul()
170             for peerid in sorted(server_problems.keys()):
171                 peerid_s = idlib.shortnodeid_b2a(peerid)
172-                l[T.li["[%s]: %s" % (peerid_s, server_problems[peerid])]]
173+                l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, server_problems[peerid])]]
174             return T.li["Server Problems:", l]
175         d.addCallback(_got)
176         return d
177hunk ./src/allmydata/web/status.py 334
178                 peerid_s = idlib.shortnodeid_b2a(peerid)
179                 times_s = ", ".join([self.render_time(None, t)
180                                      for t in per_server[peerid]])
181-                l[T.li["[%s]: %s" % (peerid_s, times_s)]]
182+                l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, times_s)]]
183             return T.li["Per-Server Segment Fetch Response Times: ", l]
184         d.addCallback(_render)
185         return d
186hunk ./src/allmydata/web/status.py 342
187 class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
188     docFactory = getxmlfile("download-status.xhtml")
189 
190-    def __init__(self, data):
191+    def __init__(self, data, storage_broker):
192         rend.Page.__init__(self, data)
193         self.download_status = data
194hunk ./src/allmydata/web/status.py 345
195+        self.storage_broker = storage_broker
196 
197hunk ./src/allmydata/web/status.py 347
198+    def get_storage_broker(self):
199+        return self.storage_broker
200+   
201     def download_results(self):
202         return defer.maybeDeferred(self.download_status.get_results)
203 
204hunk ./src/allmydata/web/status.py 398
205         l = T.ul()
206 
207         t = T.table(class_="status-download-events")
208-        t[T.tr[T.td["serverid"], T.td["sent"], T.td["received"],
209+        t[T.tr[T.td["nickname"], T.td["serverid"], T.td["sent"], T.td["received"],
210                T.td["shnums"], T.td["RTT"]]]
211         dyhb_events = []
212         for serverid,requests in self.download_status.dyhb_requests.iteritems():
213hunk ./src/allmydata/web/status.py 414
214             if not shnums:
215                 shnums = []
216             t[T.tr(style="background: %s" % self.color(serverid))[
217-                [T.td[serverid_s], T.td[srt(sent)], T.td[srt(received)],
218+                [T.td[self.get_storage_broker().get_nickname_for_serverid(serverid)], T.td[serverid_s], T.td[srt(sent)], T.td[srt(received)],
219                  T.td[",".join([str(shnum) for shnum in shnums])],
220                  T.td[self.render_time(None, rtt)],
221                  ]]]
222hunk ./src/allmydata/web/status.py 468
223         l["Segment Events:", t]
224 
225         t = T.table(border="1")
226-        t[T.tr[T.td["serverid"], T.td["shnum"], T.td["range"],
227+        t[T.tr[T.td["nickname"], T.td["serverid"], T.td["shnum"], T.td["range"],
228                T.td["txtime"], T.td["rxtime"], T.td["received"], T.td["RTT"]]]
229         reqtime = (None, None)
230         request_events = []
231hunk ./src/allmydata/web/status.py 483
232                 rtt = received - sent
233             peerid_s = idlib.shortnodeid_b2a(peerid)
234             t[T.tr(style="background: %s" % self.color(peerid))[
235-                T.td[peerid_s], T.td[shnum],
236+                T.td[self.get_storage_broker().get_nickname_for_serverid(peerid)], T.td[peerid_s], T.td[shnum],
237                 T.td["[%d:+%d]" % (start, length)],
238                 T.td[srt(sent)], T.td[srt(received)], T.td[receivedlen],
239                 T.td[self.render_time(None, rtt)],
240hunk ./src/allmydata/web/status.py 539
241 class RetrieveStatusPage(rend.Page, RateAndTimeMixin):
242     docFactory = getxmlfile("retrieve-status.xhtml")
243 
244-    def __init__(self, data):
245+    def __init__(self, data, storage_broker):
246         rend.Page.__init__(self, data)
247         self.retrieve_status = data
248hunk ./src/allmydata/web/status.py 542
249+        self.storage_broker = storage_broker
250+       
251+    def get_storage_broker(self):
252+        return self.storage_broker
253 
254     def render_started(self, ctx, data):
255         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
256hunk ./src/allmydata/web/status.py 588
257         l = T.ul()
258         for peerid in sorted(problems.keys()):
259             peerid_s = idlib.shortnodeid_b2a(peerid)
260-            l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
261+            l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, problems[peerid])]]
262         return ctx.tag["Server Problems:", l]
263 
264     def _get_rate(self, data, name):
265hunk ./src/allmydata/web/status.py 632
266 class PublishStatusPage(rend.Page, RateAndTimeMixin):
267     docFactory = getxmlfile("publish-status.xhtml")
268 
269-    def __init__(self, data):
270+    def __init__(self, data, storage_broker):
271         rend.Page.__init__(self, data)
272         self.publish_status = data
273hunk ./src/allmydata/web/status.py 635
274+        self.storage_broker = storage_broker
275+       
276+    def get_storage_broker(self):
277+        return self.storage_broker
278 
279     def render_started(self, ctx, data):
280         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
281hunk ./src/allmydata/web/status.py 682
282         sharemap = servermap.make_sharemap()
283         for shnum in sorted(sharemap.keys()):
284             l[T.li["%d -> Placed on " % shnum,
285-                   ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
286+                   ", ".join(["%s [%s]" % (self.get_storage_broker().get_nickname_for_serverid(peerid), idlib.shortnodeid_b2a(peerid))
287                               for peerid in sharemap[shnum]])]]
288         return ctx.tag["Sharemap:", l]
289 
290hunk ./src/allmydata/web/status.py 693
291         l = T.ul()
292         for peerid in sorted(problems.keys()):
293             peerid_s = idlib.shortnodeid_b2a(peerid)
294-            l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
295+            l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, problems[peerid])]]
296         return ctx.tag["Server Problems:", l]
297 
298     def _get_rate(self, data, name):
299hunk ./src/allmydata/web/status.py 740
300             peerid_s = idlib.shortnodeid_b2a(peerid)
301             times_s = ", ".join([self.render_time(None, t)
302                                  for t in per_server[peerid]])
303-            l[T.li["[%s]: %s" % (peerid_s, times_s)]]
304+            l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, times_s)]]
305         return T.li["Per-Server Response Times: ", l]
306 
307 class MapupdateStatusPage(rend.Page, RateAndTimeMixin):
308hunk ./src/allmydata/web/status.py 746
309     docFactory = getxmlfile("map-update-status.xhtml")
310 
311-    def __init__(self, data):
312+    def __init__(self, data, storage_broker):
313         rend.Page.__init__(self, data)
314         self.update_status = data
315hunk ./src/allmydata/web/status.py 749
316+        self.storage_broker = storage_broker
317+       
318+    def get_storage_broker(self):
319+        return self.storage_broker
320 
321     def render_started(self, ctx, data):
322         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
323hunk ./src/allmydata/web/status.py 794
324         l = T.ul()
325         for peerid in sorted(problems.keys()):
326             peerid_s = idlib.shortnodeid_b2a(peerid)
327-            l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
328+            l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, problems[peerid])]]
329         return ctx.tag["Server Problems:", l]
330 
331     def render_privkey_from(self, ctx, data):
332hunk ./src/allmydata/web/status.py 800
333         peerid = data.get_privkey_from()
334         if peerid:
335-            return ctx.tag["Got privkey from: [%s]"
336-                           % idlib.shortnodeid_b2a(peerid)]
337+            return ctx.tag["Got privkey from: %s [%s]"
338+                           % (self.get_storage_broker().get_nickname_for_serverid(peerid), idlib.shortnodeid_b2a(peerid))]
339         else:
340             return ""
341 
342hunk ./src/allmydata/web/status.py 834
343                 else:
344                     times.append( "privkey(" + self.render_time(None, t) + ")" )
345             times_s = ", ".join(times)
346-            l[T.li["[%s]: %s" % (peerid_s, times_s)]]
347+            l[T.li["%s [%s]: %s" % (self.get_storage_broker().get_nickname_for_serverid(peerid), peerid_s, times_s)]]
348         return T.li["Per-Server Response Times: ", l]
349 
350     def render_timing_chart(self, ctx, data):
351hunk ./src/allmydata/web/status.py 862
352         for peerid in peerids:
353             times = per_server[peerid]
354             peerid_s = idlib.shortnodeid_b2a(peerid)
355-            peerids_s.append(peerid_s)
356+            peerids_s.append(self.get_storage_broker().get_nickname_for_serverid(peerid) + "[" + peerid_s + "]")
357             # for servermap updates, there are either one or two queries per
358             # peer. The second (if present) is to get the privkey.
359             op,q_started,q_elapsed = times[0]
360hunk ./src/allmydata/web/status.py 905
361     docFactory = getxmlfile("status.xhtml")
362     addSlash = True
363 
364-    def __init__(self, history):
365-        rend.Page.__init__(self, history)
366-        self.history = history
367+    def __init__(self, client):
368+        rend.Page.__init__(self, client.get_history())
369+        self.client = client
370+        self.history = client.get_history()
371 
372     def renderHTTP(self, ctx):
373         req = inevow.IRequest(ctx)
374hunk ./src/allmydata/web/status.py 946
375         return simplejson.dumps(data, indent=1) + "\n"
376 
377     def _get_all_statuses(self):
378-        h = self.history
379+        h = self.client.get_history()
380         return itertools.chain(h.list_all_upload_statuses(),
381                                h.list_all_download_statuses(),
382                                h.list_all_mapupdate_statuses(),
383hunk ./src/allmydata/web/status.py 1029
384         return ctx.tag
385 
386     def childFactory(self, ctx, name):
387-        h = self.history
388+        h = self.client.get_history()
389         stype,count_s = name.split("-")
390         count = int(count_s)
391         if stype == "up":
392hunk ./src/allmydata/web/status.py 1038
393                 # immutable-upload helpers use the same status object as a
394                 # regular immutable-upload
395                 if s.get_counter() == count:
396-                    return UploadStatusPage(s)
397+                    return UploadStatusPage(s, self.client.get_storage_broker())
398         if stype == "down":
399             for s in h.list_all_download_statuses():
400                 if s.get_counter() == count:
401hunk ./src/allmydata/web/status.py 1042
402-                    return DownloadStatusPage(s)
403+                    return DownloadStatusPage(s, self.client.get_storage_broker())
404         if stype == "mapupdate":
405             for s in h.list_all_mapupdate_statuses():
406                 if s.get_counter() == count:
407hunk ./src/allmydata/web/status.py 1046
408-                    return MapupdateStatusPage(s)
409+                    return MapupdateStatusPage(s, self.client.get_storage_broker())
410         if stype == "publish":
411             for s in h.list_all_publish_statuses():
412                 if s.get_counter() == count:
413hunk ./src/allmydata/web/status.py 1050
414-                    return PublishStatusPage(s)
415+                    return PublishStatusPage(s, self.client.get_storage_broker())
416         if stype == "retrieve":
417             for s in h.list_all_retrieve_statuses():
418                 if s.get_counter() == count:
419hunk ./src/allmydata/web/status.py 1054
420-                    return RetrieveStatusPage(s)
421+                    return RetrieveStatusPage(s, self.client.get_storage_broker())
422 
423 
424 class HelperStatus(rend.Page):
425hunk ./src/allmydata/web/unlinked.py 62
426     def __init__(self, upload_results):
427         rend.Page.__init__(self)
428         self.results = upload_results
429+        self.storage_broker = UnlinkedStorageBroker()
430 
431     def upload_results(self):
432         return defer.succeed(self.results)
433hunk ./src/allmydata/web/unlinked.py 66
434+   
435+    def get_storage_broker(self):
436+        return self.storage_broker
437 
438     def data_done(self, ctx, data):
439         d = self.upload_results()
440hunk ./src/allmydata/web/unlinked.py 163
441         d.addCallback(lambda dirnode: dirnode.get_uri())
442     return d
443 
444+class UnlinkedStorageBroker:
445+    def get_nickname_for_serverid(self, server_id):
446+        return 'NICKNAME' + server_id
447+   
448}
449
450Context:
451
452[docs/quickstart.html: note dependency on python development files, e.g. on Ubuntu
453david-sarah@jacaranda.org**20100914040456
454 Ignore-this: 8f2ab59d3048de1ea0fbea5850843045
455] 
456[TAG allmydata-tahoe-1.8.0c4
457zooko@zooko.com**20100912062225
458 Ignore-this: 4c99e0eed253e2a38ed9ea4f4db5ad77
459] 
460Patch bundle hash:
461cf8c3608d165ac8266dccf5bac9648a888e82600