コード例 #1
0
ファイル: main.py プロジェクト: Alattack/catapult
def create_handlers_map():
  """Create new handlers map.

  Returns:
    list of (regexp, handler) pairs for WSGIApplication constructor.
  """
  pipeline_handlers_map = []

  if pipeline:
    pipeline_handlers_map = pipeline.create_handlers_map(prefix=".*/pipeline")

  return pipeline_handlers_map + [
      # Task queue handlers.
      # Always suffix by mapreduce_id or shard_id for log analysis purposes.
      # mapreduce_id or shard_id also presents in headers or payload.
      (r".*/worker_callback.*", handlers.MapperWorkerCallbackHandler),
      (r".*/controller_callback.*", handlers.ControllerCallbackHandler),
      (r".*/kickoffjob_callback.*", handlers.KickOffJobHandler),
      (r".*/finalizejob_callback.*", handlers.FinalizeJobHandler),

      # RPC requests with JSON responses
      # All JSON handlers should have /command/ prefix.
      (r".*/command/start_job", handlers.StartJobHandler),
      (r".*/command/cleanup_job", handlers.CleanUpJobHandler),
      (r".*/command/abort_job", handlers.AbortJobHandler),
      (r".*/command/list_configs", status.ListConfigsHandler),
      (r".*/command/list_jobs", status.ListJobsHandler),
      (r".*/command/get_job_detail", status.GetJobDetailHandler),

      # UI static files
      (STATIC_RE, status.ResourceHandler),

      # Redirect non-file URLs that do not end in status/detail to status page.
      (r".*", RedirectHandler),
      ]
コード例 #2
0
  def run_task(self, task):
    """Runs the given task against the pipeline handlers."""
    name = task['name']
    method = task['method']
    url = task['url']
    headers = dict(task['headers'])

    environ = {
        'wsgi.input': StringIO.StringIO(base64.b64decode(task['body'])),
        'wsgi.errors': sys.stderr,
        'REQUEST_METHOD': method,
        'SCRIPT_NAME': '',
        'PATH_INFO': url,
        'CONTENT_TYPE': headers.get('content-type', ''),
        'CONTENT_LENGTH': headers.get('content-length', ''),
        'HTTP_X_APPENGINE_TASKNAME': name,
        'HTTP_X_APPENGINE_QUEUENAME': self.queue_name,
    }
    match_url = url
    if method == 'GET':
      environ['PATH_INFO'], environ['QUERY_STRING'] = (
          (url.split('?', 1) + [''])[:2])
      match_url = environ['PATH_INFO']

    logging.debug('Executing "%s %s" name="%s"', method, url, name)
    for pattern, handler_class in pipeline.create_handlers_map():
      the_match = re.match('^%s$' % pattern, match_url)
      if the_match:
        break
    else:
      self.fail('No matching handler for "%s %s"' % (method, url))

    handler = handler_class()
    request = webapp.Request(environ)
    response = webapp.Response()
    handler.initialize(request, response)
    getattr(handler, method.lower())(*the_match.groups())
コード例 #3
0
    def run_task(self, task):
        """Runs the given task against the pipeline handlers."""
        name = task['name']
        method = task['method']
        url = task['url']
        headers = dict(task['headers'])

        environ = {
            'wsgi.input': StringIO.StringIO(base64.b64decode(task['body'])),
            'wsgi.errors': sys.stderr,
            'REQUEST_METHOD': method,
            'SCRIPT_NAME': '',
            'PATH_INFO': url,
            'CONTENT_TYPE': headers.get('content-type', ''),
            'CONTENT_LENGTH': headers.get('content-length', ''),
            'HTTP_X_APPENGINE_TASKNAME': name,
            'HTTP_X_APPENGINE_QUEUENAME': self.queue_name,
        }
        match_url = url
        if method == 'GET':
            environ['PATH_INFO'], environ['QUERY_STRING'] = ((
                url.split('?', 1) + [''])[:2])
            match_url = environ['PATH_INFO']

        logging.debug('Executing "%s %s" name="%s"', method, url, name)
        for pattern, handler_class in pipeline.create_handlers_map():
            the_match = re.match('^%s$' % pattern, match_url)
            if the_match:
                break
        else:
            self.fail('No matching handler for "%s %s"' % (method, url))

        handler = handler_class()
        request = webapp.Request(environ)
        response = webapp.Response()
        handler.initialize(request, response)
        getattr(handler, method.lower())(*the_match.groups())
コード例 #4
0
    def run_task(self, task):
        """Runs the given task against the pipeline handlers."""
        name = task["name"]
        method = task["method"]
        url = task["url"]
        headers = dict(task["headers"])

        environ = {
            "wsgi.input": StringIO.StringIO(base64.b64decode(task["body"])),
            "wsgi.errors": sys.stderr,
            "REQUEST_METHOD": method,
            "SCRIPT_NAME": "",
            "PATH_INFO": url,
            "CONTENT_TYPE": headers.get("content-type", ""),
            "CONTENT_LENGTH": headers.get("content-length", ""),
            "HTTP_X_APPENGINE_TASKNAME": name,
            "HTTP_X_APPENGINE_QUEUENAME": self.queue_name,
        }
        match_url = url
        if method == "GET":
            environ["PATH_INFO"], environ["QUERY_STRING"] = (url.split("?", 1) + [""])[:2]
            match_url = environ["PATH_INFO"]

        logging.debug('Executing "%s %s" name="%s"', method, url, name)
        for pattern, handler_class in pipeline.create_handlers_map():
            the_match = re.match("^%s$" % pattern, match_url)
            if the_match:
                break
        else:
            self.fail('No matching handler for "%s %s"' % (method, url))

        handler = handler_class()
        request = webapp.Request(environ)
        response = webapp.Response()
        handler.initialize(request, response)
        getattr(handler, method.lower())(*the_match.groups())
コード例 #5
0
def create_handlers_map():
    """Create new handlers map.

  Returns:
    list of (regexp, handler) pairs for WSGIApplication constructor.
  """
    pipeline_handlers_map = []

    if pipeline:
        pipeline_handlers_map = pipeline.create_handlers_map(
            prefix=".*/pipeline")

    return pipeline_handlers_map + [
        # Task queue handlers.
        # Always suffix by mapreduce_id or shard_id for log analysis purposes.
        # mapreduce_id or shard_id also presents in headers or payload.
        (r".*/worker_callback.*", handlers.MapperWorkerCallbackHandler),
        (r".*/controller_callback.*", handlers.ControllerCallbackHandler),
        (r".*/kickoffjob_callback.*", handlers.KickOffJobHandler),
        (r".*/finalizejob_callback.*", handlers.FinalizeJobHandler),

        # RPC requests with JSON responses
        # All JSON handlers should have /command/ prefix.
        (r".*/command/start_job", handlers.StartJobHandler),
        (r".*/command/cleanup_job", handlers.CleanUpJobHandler),
        (r".*/command/abort_job", handlers.AbortJobHandler),
        (r".*/command/list_configs", status.ListConfigsHandler),
        (r".*/command/list_jobs", status.ListJobsHandler),
        (r".*/command/get_job_detail", status.GetJobDetailHandler),

        # UI static files
        (STATIC_RE, status.ResourceHandler),

        # Redirect non-file URLs that do not end in status/detail to status page.
        (r".*", RedirectHandler),
    ]
コード例 #6
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Web request dispatcher for the Google App Engine Pipeline API.

In a separate file from the core pipeline module to break circular dependencies.
"""

import logging

#from google.appengine.ext import webapp
from google.appengine.ext.webapp import util as webapp_util

import webapp2 as webapp

import pipeline


_APP = webapp.WSGIApplication(pipeline.create_handlers_map(), debug=True)


def _main():
  webapp_util.run_wsgi_app(_APP)


if __name__ == '__main__':
  _main()
コード例 #7
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Web request dispatcher for the Google App Engine Pipeline API.

In a separate file from the core pipeline module to break circular dependencies.
"""

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util as webapp_util

import pipeline

_APP = webapp.WSGIApplication(pipeline.create_handlers_map(), debug=True)


def _main():
    webapp_util.run_wsgi_app(_APP)


if __name__ == '__main__':
    _main()