Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Commit 35b2a5d

Browse files
committed
Remove unused BackendService
1 parent 6acdf1e commit 35b2a5d

4 files changed

Lines changed: 0 additions & 298 deletions

File tree

endpoints/api_backend.py

Lines changed: 0 additions & 102 deletions
This file was deleted.

endpoints/api_backend_service.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,19 @@
1313
# limitations under the License.
1414

1515
"""API serving config collection service implementation.
16-
17-
Contains the implementation for BackendService as defined in api_backend.py.
1816
"""
1917

2018
# pylint: disable=g-statement-before-imports,g-import-not-at-top
2119
from __future__ import absolute_import
2220

23-
try:
24-
import json
25-
except ImportError:
26-
import simplejson as json
27-
2821
import logging
2922

30-
from . import api_backend
3123
from . import api_exceptions
3224

3325
from protorpc import message_types
3426

3527
__all__ = [
3628
'ApiConfigRegistry',
37-
'BackendServiceImpl',
3829
]
3930

4031

@@ -120,66 +111,3 @@ def lookup_api_method(self, api_method_name):
120111
def all_api_configs(self):
121112
"""Return a list of all API configration specs as registered above."""
122113
return self.__api_configs
123-
124-
125-
class BackendServiceImpl(api_backend.BackendService):
126-
"""Implementation of BackendService."""
127-
128-
def __init__(self, api_config_registry, app_revision):
129-
"""Create a new BackendService implementation.
130-
131-
Args:
132-
api_config_registry: ApiConfigRegistry to register and look up configs.
133-
app_revision: string containing the current app revision.
134-
"""
135-
self.__api_config_registry = api_config_registry
136-
self.__app_revision = app_revision
137-
138-
# pylint: disable=g-bad-name
139-
# pylint: disable=g-doc-return-or-yield
140-
# pylint: disable=g-doc-args
141-
@staticmethod
142-
def definition_name():
143-
"""Override definition_name so that it is not BackendServiceImpl."""
144-
return api_backend.BackendService.definition_name()
145-
146-
def getApiConfigs(self, request=None):
147-
"""Return a list of active APIs and their configuration files.
148-
149-
Args:
150-
request: A request which may contain an app revision
151-
152-
Returns:
153-
ApiConfigList: A list of API config strings
154-
"""
155-
if (request and request.appRevision and
156-
request.appRevision != self.__app_revision):
157-
raise api_exceptions.BadRequestException(
158-
message='API backend app revision %s not the same as expected %s' % (
159-
self.__app_revision, request.appRevision))
160-
161-
configs = [json.dumps(d) for d in self.__api_config_registry.all_api_configs()]
162-
return api_backend.ApiConfigList(items=configs)
163-
164-
def logMessages(self, request):
165-
"""Write a log message from the Swarm FE to the log.
166-
167-
Args:
168-
request: A log message request.
169-
170-
Returns:
171-
Void message.
172-
"""
173-
Level = api_backend.LogMessagesRequest.LogMessage.Level
174-
log = logging.getLogger(__name__)
175-
for message in request.messages:
176-
level = message.level if message.level is not None else Level.info
177-
# Create a log record and override the pathname and lineno. These
178-
# messages come from the front end, so it's misleading to say that they
179-
# come from api_backend_service.
180-
record = logging.LogRecord(name=__name__, level=level.number, pathname='',
181-
lineno='', msg=message.message, args=None,
182-
exc_info=None)
183-
log.handle(record)
184-
185-
return message_types.VoidMessage()

endpoints/test/api_backend_service_test.py

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -94,99 +94,5 @@ def testRegisterSpiDifferentClasses(self):
9494
self.assertEqual([config1], self.registry.all_api_configs())
9595

9696

97-
class BackedServiceImplTest(unittest.TestCase):
98-
99-
def setUp(self):
100-
self.service = api_backend_service.BackendServiceImpl(
101-
api_backend_service.ApiConfigRegistry(), '1')
102-
103-
def testGetApiConfigsWithEmptyRequest(self):
104-
request = api_backend.GetApiConfigsRequest()
105-
self.assertEqual([], self.service.getApiConfigs(request).items)
106-
107-
def testGetApiConfigsWithCorrectRevision(self):
108-
# TODO: there currently exists a bug in protorpc where non-unicode strings
109-
# aren't validated correctly and so their values aren't set correctly.
110-
# Remove 'u' this once that's fixed. This shouldn't affect production.
111-
request = api_backend.GetApiConfigsRequest(appRevision=u'1')
112-
self.assertEqual([], self.service.getApiConfigs(request).items)
113-
114-
def testGetApiConfigsWithIncorrectRevision(self):
115-
# TODO: there currently exists a bug in protorpc where non-unicode strings
116-
# aren't validated correctly and so their values aren't set correctly.
117-
# Remove 'u' this once that's fixed. This shouldn't affect production.
118-
request = api_backend.GetApiConfigsRequest(appRevision=u'2')
119-
self.assertRaises(
120-
api_exceptions.BadRequestException, self.service.getApiConfigs, request)
121-
122-
# pylint: disable=g-bad-name
123-
def verifyLogLevels(self, levels):
124-
Level = api_backend.LogMessagesRequest.LogMessage.Level
125-
message = u'Test message.'
126-
logger_name = api_backend_service.__name__
127-
128-
with mock.patch('logging.getLogger') as mock_getLogger:
129-
log = mock_getLogger.return_value
130-
131-
requestMessages = []
132-
for level in levels:
133-
if level:
134-
requestMessage = api_backend.LogMessagesRequest.LogMessage(
135-
level=getattr(Level, level), message=message)
136-
else:
137-
requestMessage = api_backend.LogMessagesRequest.LogMessage(
138-
message=message)
139-
requestMessages.append(requestMessage)
140-
141-
request = api_backend.LogMessagesRequest(messages=requestMessages)
142-
self.service.logMessages(request)
143-
144-
mock_getLogger.assert_called_once_with(logger_name)
145-
mock_calls = []
146-
for i, level in enumerate(levels):
147-
if level is None:
148-
level = 'info'
149-
levelno = getattr(logging, level.upper())
150-
# We can't assert equality of LogRecords because that's not
151-
# supported. So instead we pull out the actual LogRecord
152-
# objects and check values.
153-
mock_call = log.handle.call_args_list[i]
154-
actual_record = mock_call[0][0] # first object in positional args
155-
assert actual_record.name == logger_name
156-
assert actual_record.levelno == levelno
157-
assert actual_record.pathname == ''
158-
assert actual_record.lineno == ''
159-
assert actual_record.msg == message
160-
assert actual_record.args is None
161-
assert actual_record.exc_info is None
162-
163-
def testLogMessagesUnspecifiedLevel(self):
164-
self.verifyLogLevels([None])
165-
166-
def testLogMessagesDebug(self):
167-
self.verifyLogLevels(['debug'])
168-
169-
def testLogMessagesInfo(self):
170-
self.verifyLogLevels(['info'])
171-
172-
def testLogMessagesWarning(self):
173-
self.verifyLogLevels(['warning'])
174-
175-
def testLogMessagesError(self):
176-
self.verifyLogLevels(['error'])
177-
178-
def testLogMessagesCritical(self):
179-
self.verifyLogLevels(['critical'])
180-
181-
def testLogMessagesAll(self):
182-
self.verifyLogLevels([None, 'debug', 'info', 'warning', 'error',
183-
'critical'])
184-
185-
def testLogMessagesRandom(self):
186-
self.verifyLogLevels(['info', 'debug', 'info', 'info', 'warning', 'info',
187-
'error', 'error', None, 'info', None, None,
188-
'critical', 'critical', 'info', 'info', None])
189-
190-
19197
if __name__ == '__main__':
19298
unittest.main()

endpoints/test/api_backend_test.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)