镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions google/cloud/logging/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from google.gax import CallOptions
from google.gax import INITIAL_PAGE
from google.gax.errors import GaxError
from google.gax.grpc import exc_to_code
from google.logging.type.log_severity_pb2 import LogSeverity
from google.logging.v2.logging_config_pb2 import LogSink
from google.logging.v2.logging_metrics_pb2 import LogMetric
Expand All @@ -29,7 +31,6 @@
from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud._helpers import _pb_timestamp_to_rfc3339
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import NotFound
# pylint: enable=ungrouped-imports

Expand Down Expand Up @@ -122,8 +123,8 @@ def logger_delete(self, project, logger_name):
path = 'projects/%s/logs/%s' % (project, logger_name)
try:
self._gax_api.delete_log(path, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise

Expand Down Expand Up @@ -194,8 +195,8 @@ def sink_create(self, project, sink_name, filter_, destination):
destination=destination)
try:
self._gax_api.create_sink(parent, sink_pb, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION:
path = 'projects/%s/sinks/%s' % (project, sink_name)
raise Conflict(path)
raise
Expand All @@ -217,8 +218,8 @@ def sink_get(self, project, sink_name):
path = 'projects/%s/sinks/%s' % (project, sink_name)
try:
sink_pb = self._gax_api.get_sink(path, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
return _log_sink_pb_to_mapping(sink_pb)
Expand Down Expand Up @@ -249,8 +250,8 @@ def sink_update(self, project, sink_name, filter_, destination):
sink_pb = LogSink(name=path, filter=filter_, destination=destination)
try:
self._gax_api.update_sink(path, sink_pb, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
return _log_sink_pb_to_mapping(sink_pb)
Expand All @@ -268,8 +269,8 @@ def sink_delete(self, project, sink_name):
path = 'projects/%s/sinks/%s' % (project, sink_name)
try:
self._gax_api.delete_sink(path, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise

Expand Down Expand Up @@ -339,8 +340,8 @@ def metric_create(self, project, metric_name, filter_, description):
description=description)
try:
self._gax_api.create_log_metric(parent, metric_pb, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION:
path = 'projects/%s/metrics/%s' % (project, metric_name)
raise Conflict(path)
raise
Expand All @@ -362,8 +363,8 @@ def metric_get(self, project, metric_name):
path = 'projects/%s/metrics/%s' % (project, metric_name)
try:
metric_pb = self._gax_api.get_log_metric(path, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
return _log_metric_pb_to_mapping(metric_pb)
Expand Down Expand Up @@ -394,8 +395,8 @@ def metric_update(self, project, metric_name, filter_, description):
description=description)
try:
self._gax_api.update_log_metric(path, metric_pb, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise
return _log_metric_pb_to_mapping(metric_pb)
Expand All @@ -413,8 +414,8 @@ def metric_delete(self, project, metric_name):
path = 'projects/%s/metrics/%s' % (project, metric_name)
try:
self._gax_api.delete_log_metric(path, options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(path)
raise

Expand Down
51 changes: 26 additions & 25 deletions google/cloud/pubsub/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from google.cloud.gapic.pubsub.v1.subscriber_api import SubscriberApi
from google.gax import CallOptions
from google.gax import INITIAL_PAGE
from google.gax.errors import GaxError
from google.gax.grpc import exc_to_code
from google.pubsub.v1.pubsub_pb2 import PubsubMessage
from google.pubsub.v1.pubsub_pb2 import PushConfig
from grpc import insecure_channel
Expand All @@ -27,7 +29,6 @@
from google.cloud._helpers import _to_bytes
from google.cloud._helpers import _pb_timestamp_to_rfc3339
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.exceptions import NotFound
# pylint: enable=ungrouped-imports

Expand Down Expand Up @@ -92,8 +93,8 @@ def topic_create(self, topic_path):
"""
try:
topic_pb = self._gax_api.create_topic(topic_path)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION:
raise Conflict(topic_path)
raise
return {'name': topic_pb.name}
Expand All @@ -115,8 +116,8 @@ def topic_get(self, topic_path):
"""
try:
topic_pb = self._gax_api.get_topic(topic_path)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
return {'name': topic_pb.name}
Expand All @@ -133,8 +134,8 @@ def topic_delete(self, topic_path):
"""
try:
self._gax_api.delete_topic(topic_path)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise

Expand Down Expand Up @@ -162,8 +163,8 @@ def topic_publish(self, topic_path, messages):
try:
result = self._gax_api.publish(topic_path, message_pbs,
options=options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
return result.message_ids
Expand Down Expand Up @@ -200,8 +201,8 @@ def topic_list_subscriptions(self, topic_path, page_size=0,
try:
page_iter = self._gax_api.list_topic_subscriptions(
topic_path, page_size=page_size, options=options)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(topic_path)
raise
subs = page_iter.next()
Expand Down Expand Up @@ -293,8 +294,8 @@ def subscription_create(self, subscription_path, topic_path,
try:
sub_pb = self._gax_api.create_subscription(
subscription_path, topic_path, push_config, ack_deadline)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.FAILED_PRECONDITION:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION:
raise Conflict(topic_path)
raise
return _subscription_pb_to_mapping(sub_pb)
Expand All @@ -315,8 +316,8 @@ def subscription_get(self, subscription_path):
"""
try:
sub_pb = self._gax_api.get_subscription(subscription_path)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
return _subscription_pb_to_mapping(sub_pb)
Expand All @@ -334,8 +335,8 @@ def subscription_delete(self, subscription_path):
"""
try:
self._gax_api.delete_subscription(subscription_path)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise

Expand All @@ -359,8 +360,8 @@ def subscription_modify_push_config(self, subscription_path,
push_config = PushConfig(push_endpoint=push_endpoint)
try:
self._gax_api.modify_push_config(subscription_path, push_config)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise

Expand Down Expand Up @@ -391,8 +392,8 @@ def subscription_pull(self, subscription_path, return_immediately=False,
try:
response_pb = self._gax_api.pull(
subscription_path, max_messages, return_immediately)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise
return [_received_message_pb_to_mapping(rmpb)
Expand All @@ -414,8 +415,8 @@ def subscription_acknowledge(self, subscription_path, ack_ids):
"""
try:
self._gax_api.acknowledge(subscription_path, ack_ids)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise

Expand All @@ -441,8 +442,8 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids,
try:
self._gax_api.modify_ack_deadline(
subscription_path, ack_ids, ack_deadline)
except GrpcRendezvous as exc:
if exc.code() == StatusCode.NOT_FOUND:
except GaxError as exc:
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
raise NotFound(subscription_path)
raise

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

GRPC_PACKAGES = [
'grpcio >= 1.0.0',
'google-gax >= 0.13.0, < 0.14dev',
'google-gax >= 0.14.1, < 0.15dev',
'gapic-google-pubsub-v1 >= 0.9.0, < 0.10dev',
'grpc-google-pubsub-v1 >= 0.9.0, < 0.10dev',
'gapic-google-logging-v2 >= 0.9.0, < 0.10dev',
Expand Down
5 changes: 3 additions & 2 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def _logger_name():
return 'system-tests-logger' + unique_resource_id('-')

def _list_entries(self, logger):
from google.cloud.exceptions import GrpcRendezvous
from google.gax.errors import GaxError

inner = RetryResult(_has_entries)(logger.list_entries)
outer = RetryErrors(GrpcRendezvous, _retry_on_unavailable)(inner)
outer = RetryErrors(GaxError, _retry_on_unavailable)(inner)
return outer()

def test_log_text(self):
Expand Down
7 changes: 4 additions & 3 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import os
import unittest

from google.gax.errors import GaxError
from google.gax.grpc import exc_to_code
from grpc import StatusCode
import httplib2

# pylint: disable=ungrouped-imports
from google.cloud.environment_vars import PUBSUB_EMULATOR
from google.cloud.exceptions import GrpcRendezvous
from google.cloud.pubsub import client
# pylint: enable=ungrouped-imports

Expand All @@ -32,10 +33,10 @@


def _unavailable(exc):
return exc.code() == StatusCode.UNAVAILABLE
return exc_to_code(exc) == StatusCode.UNAVAILABLE


retry_unavailable = RetryErrors(GrpcRendezvous, _unavailable)
retry_unavailable = RetryErrors(GaxError, _unavailable)


class Config(object):
Expand Down
6 changes: 1 addition & 5 deletions unit_tests/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ class _GAXBaseAPI(object):
def __init__(self, **kw):
self.__dict__.update(kw)

def _make_grpc_error(self, status_code=None):
def _make_grpc_error(self, status_code):
from grpc._channel import _RPCState
from grpc import StatusCode
from google.cloud.exceptions import GrpcRendezvous

if status_code is None:
status_code = StatusCode.UNKNOWN

details = 'Some error details.'
exc_state = _RPCState((), None, None, status_code, details)
return GrpcRendezvous(exc_state, None, None, None)
Expand Down
Loading