예제 #1
0
def _SetDynamic(target, backend_entry):
    """Sets basic scaling if backend is dynamic.

  If dynamic not set on the backend, does nothing. Otherwise, sets the
  basic scaling field to use the number of instances provided via raw_input.

  Args:
    target: A appinfo.AppInfoExternal object. Contains parsed app.yaml augmented
      by current backend info.
    backend_entry: A backendinfo.BackendEntry object. Contains a parsed backend
      definition from backends.yaml.
  """
    if not backend_entry.dynamic:
        return

    prompt = DYNAMIC_PROMPT_TEXT % (backend_entry.name, )
    result = raw_input(prompt).strip()
    if result == '':
        target.basic_scaling = appinfo.BasicScaling(max_instances=1)
        return

    max_instances = -1
    try:
        max_instances = int(result)
    except (TypeError, ValueError):
        pass

    if max_instances <= 0:
        print 'Invalid max_instances value: %r' % (result, )
        return

    target.basic_scaling = appinfo.BasicScaling(max_instances=max_instances)
예제 #2
0
    def __init__(self, module_configuration, backends_configuration,
                 backend_entry):
        """Initializer for BackendConfiguration.

    Args:
      module_configuration: A ModuleConfiguration to use.
      backends_configuration: The BackendsConfiguration that tracks updates for
          this BackendConfiguration.
      backend_entry: A backendinfo.BackendEntry containing the backend
          configuration.
    """
        self._module_configuration = module_configuration
        self._backends_configuration = backends_configuration
        self._backend_entry = backend_entry

        if backend_entry.dynamic:
            self._basic_scaling = appinfo.BasicScaling(
                max_instances=backend_entry.instances or 1)
            self._manual_scaling = None
        else:
            self._basic_scaling = None
            self._manual_scaling = appinfo.ManualScaling(
                instances=backend_entry.instances or 1)
        self._minor_version_id = ''.join(
            random.choice(string.digits) for _ in range(18))
def _SetScalingType(target, backend_entry):
    """Sets the scaling type of the modules based on the backend.

  If dynamic, sets scaling type to Basic and passes the number of instances if
  set in the backends config. If not dynamic but instances set, calls to
  _SetManualScaling. If neither dynamic or instances set, does nothing.

  Args:
    target: A appinfo.AppInfoExternal object. Contains parsed app.yaml augmented
      by current backend info.
    backend_entry: A backendinfo.BackendEntry object. Contains a parsed backend
      definition from backends.yaml.
  """
    if not (backend_entry.dynamic or backend_entry.instances):
        return

    if not backend_entry.dynamic:
        _SetManualScaling(target, backend_entry)
        return

    if backend_entry.instances:
        max_instances = backend_entry.instances
    else:
        max_instances = _GetInstances(backend_entry.name)

    if max_instances:
        target.basic_scaling = appinfo.BasicScaling(
            max_instances=max_instances)
    def test_good_configuration_dynamic_scaling(self):
        automatic_scaling = appinfo.AutomaticScaling(
            min_pending_latency='1.0s',
            max_pending_latency='2.0s',
            min_idle_instances=1,
            max_idle_instances=2)
        error_handlers = [appinfo.ErrorHandlers(file='error.html')]
        handlers = [appinfo.URLMap()]
        env_variables = appinfo.EnvironmentVariables()
        info = appinfo.AppInfoExternal(
            application='app',
            module='module1',
            version='1',
            runtime='python27',
            threadsafe=False,
            automatic_scaling=automatic_scaling,
            skip_files=r'\*.gif',
            error_handlers=error_handlers,
            handlers=handlers,
            inbound_services=['warmup'],
            env_variables=env_variables,
        )
        backend_entry = backendinfo.BackendEntry(name='dynamic',
                                                 instances='3',
                                                 options='public, dynamic',
                                                 start='handler')

        application_configuration.ModuleConfiguration._parse_configuration(
            '/appdir/app.yaml').AndReturn((info, []))
        os.path.getmtime('/appdir/app.yaml').AndReturn(10)

        self.mox.ReplayAll()
        module_config = application_configuration.ModuleConfiguration(
            '/appdir/app.yaml')
        config = application_configuration.BackendConfiguration(
            module_config, None, backend_entry)
        self.mox.VerifyAll()

        self.assertEqual(os.path.realpath('/appdir'), config.application_root)
        self.assertEqual('app', config.application)
        self.assertEqual('dynamic', config.module_name)
        self.assertEqual('1', config.major_version)
        self.assertRegexpMatches(config.version_id, r'dynamic:1\.\d+')
        self.assertEqual('python27', config.runtime)
        self.assertFalse(config.threadsafe)
        self.assertEqual(None, config.automatic_scaling)
        self.assertEqual(None, config.manual_scaling)
        self.assertEqual(appinfo.BasicScaling(max_instances='3'),
                         config.basic_scaling)
        self.assertEqual(info.GetNormalizedLibraries(),
                         config.normalized_libraries)
        self.assertEqual(r'\*.gif', config.skip_files)
        self.assertEqual(error_handlers, config.error_handlers)
        start_handler = appinfo.URLMap(url='/_ah/start',
                                       script=backend_entry.start,
                                       login='******')
        self.assertEqual([start_handler] + handlers, config.handlers)
        self.assertEqual(['warmup'], config.inbound_services)
        self.assertEqual(env_variables, config.env_variables)