-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add google.api.core.operations_v1 #4081
Merged
theacodes
merged 2 commits into
googleapis:master
from
theacodes:api-core-operations-client
Oct 6, 2017
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2017 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Package for interacting with the google.longrunning.operations meta-API.""" | ||
|
||
from google.api.core.operations_v1.operations_client import OperationsClient | ||
|
||
__all__ = [ | ||
'OperationsClient' | ||
] |
274 changes: 274 additions & 0 deletions
274
core/google/api/core/operations_v1/operations_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
# Copyright 2017 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A client for the google.longrunning.operations meta-API. | ||
|
||
This is a client that deals with long-running operations that follow the | ||
pattern outlined by the `Google API Style Guide`_. | ||
|
||
When an API method normally takes long time to complete, it can be designed to | ||
return ``Operation`` to the client, and the client can use this interface to | ||
receive the real response asynchronously by polling the operation resource to | ||
receive the response. | ||
|
||
It is not a separate service, but rather an interface implemented by a larger | ||
service. The protocol-level definition is available at | ||
`google/longrunning/operations.proto`_. Typically, this will be constructed | ||
automatically by another client class to deal with operations. | ||
|
||
.. _Google API Style Guide: | ||
https://cloud.google.com/apis/design/design_pattern | ||
s#long_running_operations | ||
.. _google/longrunning/operations.proto: | ||
https://github.com/googleapis/googleapis/blob/master/google/longrunning | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
/operations.proto | ||
""" | ||
|
||
from google.api.core import gapic_v1 | ||
from google.api.core.operations_v1 import operations_client_config | ||
from google.longrunning import operations_pb2 | ||
|
||
|
||
class OperationsClient(object): | ||
"""Client for interacting with long-running operations within a service. | ||
|
||
Args: | ||
channel (grpc.Channel): The gRPC channel associated with the service | ||
that implements the ``google.longrunning.operations`` interface. | ||
client_config (dict): | ||
A dictionary of call options for each method. If not specified | ||
the default configuration is used. | ||
""" | ||
|
||
def __init__(self, channel, client_config=operations_client_config.config): | ||
# Create the gRPC client stub. | ||
self.operations_stub = operations_pb2.OperationsStub(channel) | ||
|
||
# Create all wrapped methods using the interface configuration. | ||
# The interface config contains all of the default settings for retry | ||
# and timeout for each RPC method. | ||
interface_config = ( | ||
client_config | ||
['interfaces'] | ||
['google.longrunning.Operations'] | ||
) | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
method_configs = gapic_v1.config.parse_method_configs(interface_config) | ||
|
||
self._get_operation = gapic_v1.method.wrap_method( | ||
self.operations_stub.GetOperation, | ||
default_retry=method_configs['GetOperation'].retry, | ||
default_timeout=method_configs['GetOperation'].timeout) | ||
|
||
self._list_operations = gapic_v1.method.wrap_method( | ||
self.operations_stub.ListOperations, | ||
default_retry=method_configs['ListOperations'].retry, | ||
default_timeout=method_configs['ListOperations'].timeout) | ||
|
||
self._list_operations = gapic_v1.method.wrap_with_paging( | ||
self._list_operations, | ||
'operations', | ||
'page_token', | ||
'next_page_token') | ||
|
||
self._cancel_operation = gapic_v1.method.wrap_method( | ||
self.operations_stub.CancelOperation, | ||
default_retry=method_configs['CancelOperation'].retry, | ||
default_timeout=method_configs['CancelOperation'].timeout) | ||
|
||
self._delete_operation = gapic_v1.method.wrap_method( | ||
self.operations_stub.DeleteOperation, | ||
default_retry=method_configs['DeleteOperation'].retry, | ||
default_timeout=method_configs['DeleteOperation'].timeout) | ||
|
||
# Service calls | ||
def get_operation( | ||
self, name, | ||
retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT): | ||
"""Gets the latest state of a long-running operation. | ||
|
||
Clients can use this method to poll the operation result at intervals | ||
as recommended by the API service. | ||
|
||
Example: | ||
>>> from google.api.core import operations_v1 | ||
>>> api = operations_v1.OperationsClient() | ||
>>> name = '' | ||
>>> response = api.get_operation(name) | ||
|
||
Args: | ||
name (str): The name of the operation resource. | ||
retry (google.api.core.retry.Retry): The retry strategy to use | ||
when invoking the RPC. If unspecified, the default retry from | ||
the client configuration will be used. If ``None``, then this | ||
method will not retry the RPC at all. | ||
timeout (float): The amount of time in seconds to wait for the RPC | ||
to complete. Note that if ``retry`` is used, this timeout | ||
applies to each individual attempt and the overall time it | ||
takes for this method to complete may be longer. If | ||
unspecified, the the default timeout in the client | ||
configuration is used. If ``None``, then the RPC method will | ||
not time out. | ||
|
||
Returns: | ||
google.longrunning.operations_pb2.Operation: The state of the | ||
operation. | ||
|
||
Raises: | ||
google.api.core.exceptions.GoogleAPICallError: If an error occurred | ||
while invoking the RPC, the appropriate ``GoogleAPICallError`` | ||
subclass will be raised. | ||
""" | ||
request = operations_pb2.GetOperationRequest(name=name) | ||
return self._get_operation(request, retry=retry, timeout=timeout) | ||
|
||
def list_operations( | ||
self, name, filter_, | ||
retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT): | ||
""" | ||
Lists operations that match the specified filter in the request. | ||
|
||
Example: | ||
>>> from google.api.core import operations_v1 | ||
>>> api = operations_v1.OperationsClient() | ||
>>> name = '' | ||
>>> | ||
>>> # Iterate over all results | ||
>>> for operation in api.list_operations(name): | ||
>>> # process operation | ||
>>> pass | ||
>>> | ||
>>> # Or iterate over results one page at a time | ||
>>> iter = api.list_operations(name) | ||
>>> for page in iter.pages: | ||
>>> for operation in page: | ||
>>> # process operation | ||
>>> pass | ||
|
||
Args: | ||
name (str): The name of the operation collection. | ||
filter_ (str): The standard list filter. | ||
retry (google.api.core.retry.Retry): The retry strategy to use | ||
when invoking the RPC. If unspecified, the default retry from | ||
the client configuration will be used. If ``None``, then this | ||
method will not retry the RPC at all. | ||
timeout (float): The amount of time in seconds to wait for the RPC | ||
to complete. Note that if ``retry`` is used, this timeout | ||
applies to each individual attempt and the overall time it | ||
takes for this method to complete may be longer. If | ||
unspecified, the the default timeout in the client | ||
configuration is used. If ``None``, then the RPC method will | ||
not time out. | ||
|
||
Returns: | ||
google.api.core.page_iterator.Iterator: An iterator that yields | ||
:class:`google.longrunning.operations_pb2.Operation` instances. | ||
|
||
Raises: | ||
google.api.core.exceptions.MethodNotImplemented: If the server | ||
does not support this method. Services are not required to | ||
implement this method. | ||
google.api.core.exceptions.GoogleAPICallError: If an error occurred | ||
while invoking the RPC, the appropriate ``GoogleAPICallError`` | ||
subclass will be raised. | ||
""" | ||
# Create the request object. | ||
request = operations_pb2.ListOperationsRequest( | ||
name=name, filter=filter_) | ||
return self._list_operations(request, retry=retry, timeout=timeout) | ||
|
||
def cancel_operation( | ||
self, name, | ||
retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT): | ||
"""Starts asynchronous cancellation on a long-running operation. | ||
|
||
The server makes a best effort to cancel the operation, but success is | ||
not guaranteed. Clients can use :meth:`get_operation` or service- | ||
specific methods to check whether the cancellation succeeded or whether | ||
the operation completed despite cancellation. On successful | ||
cancellation, the operation is not deleted; instead, it becomes an | ||
operation with an ``Operation.error`` value with a | ||
``google.rpc.Status.code`` of ``1``, corresponding to | ||
``Code.CANCELLED``. | ||
|
||
Example: | ||
>>> from google.api.core import operations_v1 | ||
>>> api = operations_v1.OperationsClient() | ||
>>> name = '' | ||
>>> api.cancel_operation(name) | ||
|
||
Args: | ||
name (str): The name of the operation resource to be cancelled. | ||
retry (google.api.core.retry.Retry): The retry strategy to use | ||
when invoking the RPC. If unspecified, the default retry from | ||
the client configuration will be used. If ``None``, then this | ||
method will not retry the RPC at all. | ||
timeout (float): The amount of time in seconds to wait for the RPC | ||
to complete. Note that if ``retry`` is used, this timeout | ||
applies to each individual attempt and the overall time it | ||
takes for this method to complete may be longer. If | ||
unspecified, the the default timeout in the client | ||
configuration is used. If ``None``, then the RPC method will | ||
not time out. | ||
|
||
Raises: | ||
google.api.core.exceptions.MethodNotImplemented: If the server | ||
does not support this method. Services are not required to | ||
implement this method. | ||
google.api.core.exceptions.GoogleAPICallError: If an error occurred | ||
while invoking the RPC, the appropriate ``GoogleAPICallError`` | ||
subclass will be raised. | ||
""" | ||
# Create the request object. | ||
request = operations_pb2.CancelOperationRequest(name=name) | ||
self._cancel_operation(request, retry=retry, timeout=timeout) | ||
|
||
def delete_operation( | ||
self, name, | ||
retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT): | ||
"""Deletes a long-running operation. | ||
|
||
This method indicates that the client is no longer interested in the | ||
operation result. It does not cancel the operation. | ||
|
||
Example: | ||
>>> from google.api.core import operations_v1 | ||
>>> api = operations_v1.OperationsClient() | ||
>>> name = '' | ||
>>> api.delete_operation(name) | ||
|
||
Args: | ||
name (str): The name of the operation resource to be deleted. | ||
retry (google.api.core.retry.Retry): The retry strategy to use | ||
when invoking the RPC. If unspecified, the default retry from | ||
the client configuration will be used. If ``None``, then this | ||
method will not retry the RPC at all. | ||
timeout (float): The amount of time in seconds to wait for the RPC | ||
to complete. Note that if ``retry`` is used, this timeout | ||
applies to each individual attempt and the overall time it | ||
takes for this method to complete may be longer. If | ||
unspecified, the the default timeout in the client | ||
configuration is used. If ``None``, then the RPC method will | ||
not time out. | ||
|
||
Raises: | ||
google.api.core.exceptions.MethodNotImplemented: If the server | ||
does not support this method. Services are not required to | ||
implement this method. | ||
google.api.core.exceptions.GoogleAPICallError: If an error occurred | ||
while invoking the RPC, the appropriate ``GoogleAPICallError`` | ||
subclass will be raised. | ||
""" | ||
# Create the request object. | ||
request = operations_pb2.DeleteOperationRequest(name=name) | ||
self._delete_operation(request, retry=retry, timeout=timeout) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.