OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 from google.appengine.api import users | 6 from google.appengine.api import users |
7 from google.appengine.ext import db | 7 from google.appengine.ext import db |
8 from google.appengine.ext import webapp | 8 from google.appengine.ext import webapp |
9 from google.appengine.ext.webapp import template | 9 from google.appengine.ext.webapp import template |
10 from google.appengine.ext.webapp.util import run_wsgi_app | 10 from google.appengine.ext.webapp.util import run_wsgi_app |
(...skipping 10 matching lines...) Expand all Loading... |
21 stdout = db.StringProperty(multiline=True) | 21 stdout = db.StringProperty(multiline=True) |
22 stderr = db.StringProperty(multiline=True) | 22 stderr = db.StringProperty(multiline=True) |
23 runtime = db.FloatProperty() | 23 runtime = db.FloatProperty() |
24 timestamp = db.DateTimeProperty(auto_now_add=True) | 24 timestamp = db.DateTimeProperty(auto_now_add=True) |
25 uname_sysname = db.StringProperty() | 25 uname_sysname = db.StringProperty() |
26 uname_nodename = db.StringProperty() | 26 uname_nodename = db.StringProperty() |
27 uname_release = db.StringProperty() | 27 uname_release = db.StringProperty() |
28 uname_version = db.StringProperty() | 28 uname_version = db.StringProperty() |
29 uname_machine = db.StringProperty() | 29 uname_machine = db.StringProperty() |
30 uname_processor = db.StringProperty() | 30 uname_processor = db.StringProperty() |
| 31 response = db.StringProperty() |
31 | 32 |
32 | 33 |
33 class LogHandler(webapp.RequestHandler): | 34 class LogHandler(webapp.RequestHandler): |
34 """Handle requests to log events.""" | 35 """Handle requests to log events.""" |
35 | 36 |
36 def post(self): | 37 def post(self): |
37 ci = CommandInvocation() | 38 ci = CommandInvocation() |
38 ci.remote_addr = self.request.remote_addr | 39 ci.remote_addr = self.request.remote_addr |
39 ci.command_id = str(self.request.get('command_id')) | 40 ci.command_id = str(self.request.get('command_id')) |
40 ci.attempt = int(self.request.get('attempt')) | 41 ci.attempt = int(self.request.get('attempt')) |
41 ci.retries = int(self.request.get('retries')) | 42 ci.retries = int(self.request.get('retries')) |
42 ci.cwd = str(self.request.get('cwd')) | 43 ci.cwd = str(self.request.get('cwd')) |
43 ci.command = str(self.request.get('command')) | 44 ci.command = str(self.request.get('command')) |
44 ci.returncode = int(self.request.get('returncode')) | 45 ci.returncode = int(self.request.get('returncode')) |
45 ci.stdout = str(self.request.get('stdout')) | 46 ci.stdout = str(self.request.get('stdout')) |
46 ci.stderr = str(self.request.get('stderr')) | 47 ci.stderr = str(self.request.get('stderr')) |
47 ci.runtime = float(self.request.get('runtime')) | 48 ci.runtime = float(self.request.get('runtime')) |
48 ci.uname_sysname = str(self.request.get('uname_sysname')) | 49 ci.uname_sysname = str(self.request.get('uname_sysname')) |
49 ci.uname_nodename = str(self.request.get('uname_nodename')) | 50 ci.uname_nodename = str(self.request.get('uname_nodename')) |
50 ci.uname_release = str(self.request.get('uname_release')) | 51 ci.uname_release = str(self.request.get('uname_release')) |
51 ci.uname_version = str(self.request.get('uname_version')) | 52 ci.uname_version = str(self.request.get('uname_version')) |
52 ci.uname_machine = str(self.request.get('uname_machine')) | 53 ci.uname_machine = str(self.request.get('uname_machine')) |
53 ci.uname_processor = str(self.request.get('uname_processor')) | 54 ci.uname_processor = str(self.request.get('uname_processor')) |
| 55 ci.response = '0' |
| 56 # Don't retry cat for _index.html |
| 57 if (ci.command.find('_index.html') >= 0 and |
| 58 ci.command.find('gsutil cat gs://') >= 0 and |
| 59 ci.returncode == 1): |
| 60 ci.response = '1' |
| 61 # Store it. |
54 ci.put() | 62 ci.put() |
| 63 # Emit response. |
| 64 self.response.out.write(ci.response) |
55 | 65 |
56 | 66 |
57 class ViewerHandler(webapp.RequestHandler): | 67 class ViewerHandler(webapp.RequestHandler): |
58 """View log info.""" | 68 """View log info.""" |
59 | 69 |
60 def get(self): | 70 def get(self): |
61 user = users.get_current_user() | 71 user = users.get_current_user() |
62 if not user: | 72 if not user: |
63 uri = self.request.uri | 73 uri = self.request.uri |
64 if uri.startswith('http:'): | 74 if uri.startswith('http:'): |
65 uri = 'https:' + uri[5:] | 75 uri = 'https:' + uri[5:] |
66 self.redirect(users.create_login_url(uri)) | 76 self.redirect(users.create_login_url(uri)) |
67 return | 77 return |
68 # Only allow @google.com folks to look. | 78 # Only allow @google.com folks to look. |
69 if not user.email().endswith('@google.com'): | 79 if not user.email().endswith('@google.com'): |
70 return | 80 return |
71 items = db.GqlQuery('SELECT * FROM CommandInvocation ' | 81 uname_nodename = self.request.get('uname_nodename') |
72 'ORDER BY timestamp DESC LIMIT 100') | 82 if uname_nodename: |
| 83 items = db.GqlQuery('SELECT * FROM CommandInvocation ' |
| 84 'WHERE uname_nodename = :1 ' |
| 85 'ORDER BY timestamp DESC LIMIT 100', uname_nodename) |
| 86 else: |
| 87 items = db.GqlQuery('SELECT * FROM CommandInvocation ' |
| 88 'ORDER BY timestamp DESC LIMIT 100') |
73 template_values = { | 89 template_values = { |
74 'items': items, | 90 'items': items, |
75 } | 91 } |
76 path = os.path.join(os.path.dirname(__file__), 'viewer.html') | 92 path = os.path.join(os.path.dirname(__file__), 'viewer.html') |
77 self.response.out.write(template.render(path, template_values)) | 93 self.response.out.write(template.render(path, template_values)) |
78 | 94 |
79 | 95 |
80 APPLICATION = webapp.WSGIApplication([ | 96 APPLICATION = webapp.WSGIApplication([ |
81 ('/log', LogHandler), | 97 ('/log', LogHandler), |
82 ('/', ViewerHandler), | 98 ('/', ViewerHandler), |
83 ], debug=False) | 99 ], debug=False) |
84 | 100 |
85 | 101 |
86 def main(): | 102 def main(): |
87 run_wsgi_app(APPLICATION) | 103 run_wsgi_app(APPLICATION) |
88 | 104 |
89 | 105 |
90 if __name__ == '__main__': | 106 if __name__ == '__main__': |
91 main() | 107 main() |
OLD | NEW |