Esempio n. 1
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.

"""Long running operation representation for Google Speech API"""

from google.cloud.proto.speech.v1 import cloud_speech_pb2

from google.cloud import operation
from google.cloud.speech.result import Result


operation.register_type(cloud_speech_pb2.LongRunningRecognizeMetadata)
operation.register_type(cloud_speech_pb2.LongRunningRecognizeResponse)


class Operation(operation.Operation):
    """Custom Long-Running Operation for Google Speech API.

    :type name: str
    :param name: The fully-qualified path naming the operation.

    :type client: :class:`~google.cloud.speech.client.Client`
    :param client: Client that created the current operation.

    :type caller_metadata: dict
    :param caller_metadata: caller-assigned metadata about the operation
    """
Esempio n. 2
0
    def _call_fut(self, klass, type_url=None):
        from google.cloud.operation import register_type

        register_type(klass, type_url=type_url)
Esempio n. 3
0
    def _call_fut(self, klass, type_url=None):
        from google.cloud.operation import register_type

        register_type(klass, type_url=type_url)
#
#     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.
"""Long running operation representation for Google Speech API"""

from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2

from google.cloud import operation
from google.cloud.speech.alternative import Alternative

operation.register_type(cloud_speech_pb2.AsyncRecognizeMetadata)
operation.register_type(cloud_speech_pb2.AsyncRecognizeResponse)


class Operation(operation.Operation):
    """Custom Long-Running Operation for Google Speech API.

    :type name: str
    :param name: The fully-qualified path naming the operation.

    :type client: :class:`~google.cloud.speech.client.Client`
    :param client: Client that created the current operation.

    :type caller_metadata: dict
    :param caller_metadata: caller-assigned metadata about the operation
    """
Esempio n. 5
0
    bigtable_instance_admin_pb2 as messages_v2_pb2)
from google.cloud.bigtable._generated import (
    bigtable_table_admin_pb2 as table_messages_v2_pb2)
from google.cloud.bigtable.cluster import Cluster
from google.cloud.bigtable.cluster import DEFAULT_SERVE_NODES
from google.cloud.bigtable.table import Table
from google.cloud.operation import Operation
from google.cloud.operation import register_type


_EXISTING_INSTANCE_LOCATION_ID = 'see-existing-cluster'
_INSTANCE_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
                               r'instances/(?P<instance_id>[a-z][-a-z0-9]*)$')


register_type(messages_v2_pb2.CreateInstanceMetadata)
register_type(data_v2_pb2.Instance)


def _prepare_create_request(instance):
    """Creates a protobuf request for a CreateInstance request.

    :type instance: :class:`Instance`
    :param instance: The instance to be created.

    :rtype: :class:`.messages_v2_pb2.CreateInstanceRequest`
    :returns: The CreateInstance request object containing the instance info.
    """
    parent_name = ('projects/' + instance._client.project)
    message = messages_v2_pb2.CreateInstanceRequest(
        parent=parent_name,
Esempio n. 6
0
# pylint: disable=ungrouped-imports
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import NotFound
from google.cloud.iterator import GAXIterator
from google.cloud.operation import register_type
from google.cloud.spanner._helpers import _options_with_prefix
from google.cloud.spanner.database import Database
from google.cloud.spanner.pool import BurstyPool
# pylint: enable=ungrouped-imports

_INSTANCE_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
                               r'instances/(?P<instance_id>[a-z][-a-z0-9]*)$')

DEFAULT_NODE_COUNT = 1

register_type(admin_v1_pb2.Instance)
register_type(admin_v1_pb2.CreateInstanceMetadata)
register_type(admin_v1_pb2.UpdateInstanceMetadata)


class Instance(object):
    """Representation of a Cloud Spanner Instance.

    We can use a :class:`Instance` to:

    * :meth:`reload` itself
    * :meth:`create` itself
    * :meth:`update` itself
    * :meth:`delete` itself

    :type instance_id: str
Esempio n. 7
0
from google.cloud.operation import register_type
from google.cloud.spanner import __version__
from google.cloud.spanner._helpers import _options_with_prefix
from google.cloud.spanner.batch import Batch
from google.cloud.spanner.session import Session
from google.cloud.spanner.pool import BurstyPool
from google.cloud.spanner.snapshot import Snapshot
from google.cloud.spanner.pool import SessionCheckout
# pylint: enable=ungrouped-imports

_DATABASE_NAME_RE = re.compile(
    r'^projects/(?P<project>[^/]+)/'
    r'instances/(?P<instance_id>[a-z][-a-z0-9]*)/'
    r'databases/(?P<database_id>[a-z][a-z0-9_\-]*[a-z0-9])$')

register_type(admin_v1_pb2.Database)
register_type(admin_v1_pb2.CreateDatabaseMetadata)
register_type(admin_v1_pb2.UpdateDatabaseDdlMetadata)


class Database(object):
    """Representation of a Cloud Spanner Database.

    We can use a :class:`Database` to:

    * :meth:`create` the database
    * :meth:`reload` the database
    * :meth:`update` the database
    * :meth:`drop` the database

    :type database_id: str
Esempio n. 8
0
    instance_pb2 as data_v2_pb2)
from google.cloud.bigtable._generated import (
    bigtable_instance_admin_pb2 as messages_v2_pb2)
from google.cloud.operation import Operation
from google.cloud.operation import register_type


_CLUSTER_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
                              r'instances/(?P<instance>[^/]+)/clusters/'
                              r'(?P<cluster_id>[a-z][-a-z0-9]*)$')

DEFAULT_SERVE_NODES = 3
"""Default number of nodes to use when creating a cluster."""


register_type(messages_v2_pb2.UpdateClusterMetadata)


def _prepare_create_request(cluster):
    """Creates a protobuf request for a CreateCluster request.

    :type cluster: :class:`Cluster`
    :param cluster: The cluster to be created.

    :rtype: :class:`.messages_v2_pb2.CreateClusterRequest`
    :returns: The CreateCluster request object containing the cluster info.
    """
    return messages_v2_pb2.CreateClusterRequest(
        parent=cluster._instance.name,
        cluster_id=cluster.cluster_id,
        cluster=data_v2_pb2.Cluster(
Esempio n. 9
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.

"""Long running operation representation for Google Speech API"""

from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2

from google.cloud import operation
from google.cloud.speech.alternative import Alternative


operation.register_type(cloud_speech_pb2.AsyncRecognizeMetadata)
operation.register_type(cloud_speech_pb2.AsyncRecognizeResponse)


class Operation(operation.Operation):
    """Custom Long-Running Operation for Google Speech API.

    :type name: str
    :param name: The fully-qualified path naming the operation.

    :type client: :class:`~google.cloud.speech.client.Client`
    :param client: Client that created the current operation.

    :type caller_metadata: dict
    :param caller_metadata: caller-assigned metadata about the operation
    """
Esempio n. 10
0
import re

from google.cloud.bigtable._generated import (instance_pb2 as data_v2_pb2)
from google.cloud.bigtable._generated import (bigtable_instance_admin_pb2 as
                                              messages_v2_pb2)
from google.cloud.operation import Operation
from google.cloud.operation import register_type

_CLUSTER_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
                              r'instances/(?P<instance>[^/]+)/clusters/'
                              r'(?P<cluster_id>[a-z][-a-z0-9]*)$')

DEFAULT_SERVE_NODES = 3
"""Default number of nodes to use when creating a cluster."""

register_type(messages_v2_pb2.UpdateClusterMetadata)


def _prepare_create_request(cluster):
    """Creates a protobuf request for a CreateCluster request.

    :type cluster: :class:`Cluster`
    :param cluster: The cluster to be created.

    :rtype: :class:`.messages_v2_pb2.CreateClusterRequest`
    :returns: The CreateCluster request object containing the cluster info.
    """
    return messages_v2_pb2.CreateClusterRequest(
        parent=cluster._instance.name,
        cluster_id=cluster.cluster_id,
        cluster=data_v2_pb2.Cluster(serve_nodes=cluster.serve_nodes, ),