コード例 #1
0
def _ConvertBackendToModules(backend_config, app_config):
    """Creates Modules configuration using app and backend config.

  Parses the app.yaml and backend.yaml contents into native AppInfoExternal
  and BackendInfoExternal objects and then creates an AppInfoExternal
  for each backend defined in backend_config.

  Args:
    backend_config: String, the contents of backend.yaml.
    app_config: String, the contents of app.yaml.

  Returns:
    A list of AppInfoExternal objects for each module.
  """
    backend_info = backendinfo.LoadBackendInfo(backend_config)
    app_yaml_config = appinfo.LoadSingleAppInfo(app_config)
    return [
        _ConvertBackendToModule(backend, app_yaml_config)
        for backend in backend_info.backends
    ]
コード例 #2
0
 def _parse_configuration(configuration_path):
     # TODO: It probably makes sense to catch the exception raised
     # by Parse() and re-raise it using a module-specific exception.
     with open(configuration_path) as f:
         return backendinfo.LoadBackendInfo(f)
コード例 #3
0
def Init(argv, options, root_path, appinfo):
    """Enter multiprocess mode, if required.

  The dev_appserver runs in multiprocess mode if any Backends are configured.
  The initial process becomes a "master" which acts as a router for the app, and
  centralized memcache/datastore API server for sharing persistent state.

  This method works by configuring the global DevProcess object, which is
  referenced by other files in the dev_appserver when necessary.  The DevProcess
  contains state indicating which role the current process plays in the
  multiprocess architecture.

  The master process creates and shuts down subprocesses.  A separate process is
  created to represent an instance of the application, and a separate process is
  created for each backend (to act as a load balancer) and for each backend
  instance.

  On shutdown, the master process kills all subprocesses before exiting.

  Args:
    argv:  The command line arguments used when starting the main application.
    options: Parsed dictionary of the command line arguments.
    root_path:  Root directory of the application.
    appinfo: An AppInfoExternal object representing a parsed app.yaml file.
  """
    if ARG_BACKENDS not in options:
        return

    backends_path = os.path.join(root_path, 'backends.yaml')
    if not os.path.exists(backends_path):
        backends = []
    else:
        backends_fh = open(backends_path)
        try:
            backend_info = backendinfo.LoadBackendInfo(backends_fh.read())
        finally:
            backends_fh.close()
        backends = backend_info.backends

    backend_set = set()
    for backend in backends:
        if backend.name in backend_set:
            raise Error('Duplicate backend: %s' % backend.name)
        if backend.instances is None:
            backend.instances = 1
        elif backend.instances > BACKEND_MAX_INSTANCES:
            raise Error('Maximum number of instances is %d',
                        BACKEND_MAX_INSTANCES)
        backend_set.add(backend.name)

    process = _dev_process
    process.Init(appinfo, backends, options)

    if process.IsDefault():
        logging.info('Default process')
        return

    SetLogPrefix(process)
    if process.IsMaster():
        process.StartChildren(argv, options)

    process.InitBalanceSet()

    if process.IsMaster():
        options['require_indexes'] = False
    else:
        options['require_indexes'] = True

    options['clear_datastore'] = False
    options['clear_prospective_search'] = False
コード例 #4
0
 def testLoadBackendInfo_EmptyBackendClause(self):
     info = backendinfo.LoadBackendInfo('backends:')
     self.assertEqual([], info.backends)