def testGetDefaultVersion_CurrentModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_module(None).AndReturn('default') self.dispatcher.get_default_version('default').AndReturn('1') self.mox.ReplayAll() self.assertEqual('1', modules.get_default_version()) self.mox.VerifyAll()
def get_app_hostname(): """Return hostname of a running Endpoints service. Returns hostname of an running Endpoints API. It can be 1) "localhost:PORT" if running on development server, or 2) "app_id.appspot.com" if running on external app engine prod, or "app_id.googleplex.com" if running as Google first-party Endpoints API, or 4) None if not running on App Engine (e.g. Tornado Endpoints API). Returns: A string representing the hostname of the service. """ if not is_running_on_app_engine() or is_running_on_localhost(): return None version = modules.get_current_version_name() app_id = app_identity.get_application_id() suffix = 'appspot.com' if ':' in app_id: tokens = app_id.split(':') api_name = tokens[1] if tokens[0] == 'google.com': suffix = 'googleplex.com' else: api_name = app_id # Check if this is the default version default_version = modules.get_default_version() if version == default_version: return '{0}.{1}'.format(app_id, suffix) else: return '{0}-dot-{1}.{2}'.format(version, api_name, suffix)
def get_app_hostname(): """Return hostname of a running Endpoints service. Returns hostname of an running Endpoints API. It can be 1) "localhost:PORT" if running on development server, or 2) "app_id.appspot.com" if running on external app engine prod, or "app_id.googleplex.com" if running as Google first-party Endpoints API, or 4) None if not running on App Engine (e.g. Tornado Endpoints API). Returns: A string representing the hostname of the service. """ if not is_running_on_app_engine() or is_running_on_localhost(): return None version = modules.get_current_version_name() app_id = app_identity.get_application_id() suffix = 'appspot.com' if ':' in app_id: tokens = app_id.split(':') api_name = tokens[1] if tokens[0] == 'google.com': suffix = 'googleplex.com' else: api_name = app_id # Check if this is the default version default_version = modules.get_default_version() if version == default_version: return '{0}.{1}'.format(app_id, suffix) else: return '{0}-dot-{1}.{2}'.format(version, api_name, suffix)
def get_hostname_prefix(): """Returns the hostname prefix of a running Endpoints service. The prefix is the portion of the hostname that comes before the API name. For example, if a non-default version and a non-default service are in use, the returned result would be '{VERSION}-dot-{SERVICE}-'. Returns: str, the hostname prefix. """ parts = [] # Check if this is the default version version = modules.get_current_version_name() default_version = modules.get_default_version() if version != default_version: parts.append(version) # Check if this is the default module module = modules.get_current_module_name() if module != 'default': parts.append(module) # If there is anything to prepend, add an extra blank entry for the trailing # -dot- if parts: parts.append('') return '-dot-'.join(parts)
def get_hostname_prefix(): """Returns the hostname prefix of a running Endpoints service. The prefix is the portion of the hostname that comes before the API name. For example, if a non-default version and a non-default service are in use, the returned result would be '{VERSION}-dot-{SERVICE}-'. Returns: str, the hostname prefix. """ parts = [] # Check if this is the default version version = modules.get_current_version_name() default_version = modules.get_default_version() if version != default_version: parts.append(version) # Check if this is the default module module = modules.get_current_module_name() if module != 'default': parts.append(module) # If there is anything to prepend, add an extra blank entry for the trailing # -dot- if parts: parts.append('') return '-dot-'.join(parts)
def cron_stop_non_default_instances(): # core logic (inside a cron or other handler) for m in modules.get_modules(): dv = modules.get_default_version(m) for v in modules.get_versions(m): if v != dv: modules.stop_version(m, v) return "Success!"
def cron_stop_non_default_instances(): # core logic (inside a cron or other handler) for m in modules.get_modules(): dv = modules.get_default_version(m) for v in modules.get_versions(m): if v != dv: modules.stop_version(m, v) return "Success!"
def testGetDefaultVersion_NoModule(self): """Test we return the expected results when no module is passed.""" expected_request = modules_service_pb2.GetDefaultVersionRequest() service_response = modules_service_pb2.GetDefaultVersionResponse() service_response.version = 'v1' self.SetSuccessExpectations('GetDefaultVersion', expected_request, service_response) self.assertEqual('v1', modules.get_default_version())