当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.AlreadyExists方法代码示例

本文整理汇总了Python中google.api_core.exceptions.AlreadyExists方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.AlreadyExists方法的具体用法?Python exceptions.AlreadyExists怎么用?Python exceptions.AlreadyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.api_core.exceptions的用法示例。


在下文中一共展示了exceptions.AlreadyExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_already_exists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_already_exists(self, mock_hook):
        # Exception AlreadyExists not raised, caught in the operator's execute() - idempotence
        op = CloudVisionCreateReferenceImageOperator(
            location=LOCATION_TEST,
            product_id=PRODUCT_ID_TEST,
            reference_image=REFERENCE_IMAGE_TEST,
            task_id='id',
        )
        op.execute(context=None)
        mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
        mock_hook.return_value.create_reference_image.assert_called_once_with(
            location=LOCATION_TEST,
            product_id=PRODUCT_ID_TEST,
            reference_image=REFERENCE_IMAGE_TEST,
            reference_image_id=None,
            project_id=None,
            retry=None,
            timeout=None,
            metadata=None,
        ) 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:test_vision.py

示例2: execute

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def execute(self, context):
        hook = CloudDLPHook(gcp_conn_id=self.gcp_conn_id)
        try:
            template = hook.create_deidentify_template(
                organization_id=self.organization_id,
                project_id=self.project_id,
                deidentify_template=self.deidentify_template,
                template_id=self.template_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
        except AlreadyExists:
            template = hook.get_deidentify_template(
                organization_id=self.organization_id,
                project_id=self.project_id,
                template_id=self.template_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )

        return MessageToDict(template) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:dlp.py

示例3: execute

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def execute(self, context):
        hook = CloudTasksHook(gcp_conn_id=self.gcp_conn_id)
        try:
            queue = hook.create_queue(
                location=self.location,
                task_queue=self.task_queue,
                project_id=self.project_id,
                queue_name=self.queue_name,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
        except AlreadyExists:
            queue = hook.get_queue(
                location=self.location,
                project_id=self.project_id,
                queue_name=self.queue_name,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )

        return MessageToDict(queue) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:tasks.py

示例4: execute

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def execute(self, context):
        hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
        try:
            return hook.create_product_set(
                location=self.location,
                project_id=self.project_id,
                product_set=self.product_set,
                product_set_id=self.product_set_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
        except AlreadyExists:
            self.log.info(
                "Product set with id %s already exists. Exiting from the create operation.",
                self.product_set_id,
            )
            return self.product_set_id 
开发者ID:apache,项目名称:airflow,代码行数:20,代码来源:vision.py

示例5: create_subscription

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def create_subscription(self, subscription, topic):
        """Handles creating the subscription when it does not exists.

        This makes it easier to deploy a worker and forget about the
        subscription side of things. The subscription must
        have a topic to subscribe to. Which means that the topic must be
        created manually before the worker is started.

        :param subscription: str Subscription name
        :param topic: str Topic name to subscribe
        """
        subscription_path = self._client.subscription_path(
            self._gc_project_id, subscription
        )
        topic_path = self._client.topic_path(self._gc_project_id, topic)

        with suppress(exceptions.AlreadyExists):
            try:
                self._client.create_subscription(
                    name=subscription_path,
                    topic=topic_path,
                    ack_deadline_seconds=self._ack_deadline,
                )
            except exceptions.NotFound:
                logger.error("Cannot subscribe to a topic that does not exist.") 
开发者ID:mercadona,项目名称:rele,代码行数:27,代码来源:client.py

示例6: test_topic

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_topic():
    pubsub_client = pubsub.PublisherClient()
    try:
        topic = manager.create_iot_topic(project_id, topic_id)
    except AlreadyExists as e:
        print("The topic already exists, detail: {}".format(str(e)))
        # Ignore the error, fetch the topic
        topic = pubsub_client.get_topic(
            pubsub_client.topic_path(project_id, topic_id))

    yield topic

    topic_path = pubsub_client.topic_path(project_id, topic_id)
    try:
        pubsub_client.delete_topic(topic_path)
    except NotFound as e:
        # We ignore this case.
        print("The topic doesn't exist: detail: {}".format(str(e))) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20,代码来源:fixtures.py

示例7: test_subscription

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_subscription(test_topic):
    subscriber = pubsub.SubscriberClient()
    subscription_path = subscriber.subscription_path(
        project_id, subscription_name)

    try:
        subscription = subscriber.create_subscription(
            subscription_path, test_topic.name)
    except AlreadyExists as e:
        print("The topic already exists, detail: {}".format(str(e)))
        # Ignore the error, fetch the subscription
        subscription = subscriber.get_subscription(subscription_path)

    yield subscription

    try:
        subscriber.delete_subscription(subscription_path)
    except NotFound as e:
        # We ignore this case.
        print("The subscription doesn't exist: detail: {}".format(str(e))) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:22,代码来源:fixtures.py

示例8: open_registry

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def open_registry(
        service_account_json, project_id, cloud_region, pubsub_topic,
        registry_id):
    """Gets or creates a device registry."""
    # project_id = 'YOUR_PROJECT_ID'
    # cloud_region = 'us-central1'
    # pubsub_topic = 'your-pubsub-topic'
    # registry_id = 'your-registry-id'
    print('Creating registry')

    try:
        response = create_registry(
            service_account_json, project_id, cloud_region,
            pubsub_topic, registry_id)
    except AlreadyExists:
        # Device registry already exists. We just re-use the existing one.
        print(
            'Registry {} already exists - looking it up instead.'.format(
                registry_id))
        response = get_registry(
            service_account_json, project_id, cloud_region,
            registry_id)

    print('Registry {} opened: '.format(response.name))
    print(response) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:27,代码来源:manager.py

示例9: test_create_document

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_create_document(client, cleanup):
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)
    collection_id = "doc-create" + UNIQUE_RESOURCE_ID
    document_id = "doc" + UNIQUE_RESOURCE_ID
    document = client.document(collection_id, document_id)
    # Add to clean-up before API request (in case ``create()`` fails).
    cleanup(document.delete)

    data = {
        "now": firestore.SERVER_TIMESTAMP,
        "eenta-ger": 11,
        "bites": b"\xe2\x98\x83 \xe2\x9b\xb5",
        "also": {"nestednow": firestore.SERVER_TIMESTAMP, "quarter": 0.25},
    }
    write_result = document.create(data)
    updated = _pb_timestamp_to_datetime(write_result.update_time)
    delta = updated - now
    # Allow a bit of clock skew, but make sure timestamps are close.
    assert -300.0 < delta.total_seconds() < 300.0

    with pytest.raises(AlreadyExists):
        document.create(data)

    # Verify the server times.
    snapshot = document.get()
    stored_data = snapshot.to_dict()
    server_now = stored_data["now"]

    delta = updated - server_now
    # NOTE: We could check the ``transform_results`` from the write result
    #       for the document transform, but this value gets dropped. Instead
    #       we make sure the timestamps are close.
    assert 0.0 <= delta.total_seconds() < 5.0
    expected_data = {
        "now": server_now,
        "eenta-ger": data["eenta-ger"],
        "bites": data["bites"],
        "also": {"nestednow": server_now, "quarter": data["also"]["quarter"]},
    }
    assert stored_data == expected_data 
开发者ID:googleapis,项目名称:python-firestore,代码行数:42,代码来源:test_system.py

示例10: test_execute_if_cluster_exists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_execute_if_cluster_exists(self, mock_hook):
        mock_hook.return_value.create_cluster.side_effect = [AlreadyExists("test")]
        op = DataprocCreateClusterOperator(
            task_id=TASK_ID,
            region=GCP_LOCATION,
            project_id=GCP_PROJECT,
            cluster=CLUSTER,
            gcp_conn_id=GCP_CONN_ID,
            retry=RETRY,
            timeout=TIMEOUT,
            metadata=METADATA,
            request_id=REQUEST_ID,
        )
        op.execute(context={})
        mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
        mock_hook.return_value.create_cluster.assert_called_once_with(
            region=GCP_LOCATION,
            project_id=GCP_PROJECT,
            cluster=CLUSTER,
            request_id=REQUEST_ID,
            retry=RETRY,
            timeout=TIMEOUT,
            metadata=METADATA,
        )
        mock_hook.return_value.get_cluster.assert_called_once_with(
            region=GCP_LOCATION,
            project_id=GCP_PROJECT,
            cluster_name=CLUSTER_NAME,
            retry=RETRY,
            timeout=TIMEOUT,
            metadata=METADATA,
        ) 
开发者ID:apache,项目名称:airflow,代码行数:34,代码来源:test_dataproc.py

示例11: test_create_preexisting_topic_failifexists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_create_preexisting_topic_failifexists(self, mock_service):
        mock_service.return_value.create_topic.side_effect = AlreadyExists(
            'Topic already exists: %s' % TEST_TOPIC
        )
        with self.assertRaises(PubSubException) as e:
            self.pubsub_hook.create_topic(project_id=TEST_PROJECT, topic=TEST_TOPIC, fail_if_exists=True)
        self.assertEqual(str(e.exception), 'Topic already exists: %s' % TEST_TOPIC) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:test_pubsub.py

示例12: test_create_subscription_failifexists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_create_subscription_failifexists(self, mock_service):
        mock_service.create_subscription.side_effect = AlreadyExists(
            'Subscription already exists: %s' % EXPANDED_SUBSCRIPTION
        )
        with self.assertRaises(PubSubException) as e:
            self.pubsub_hook.create_subscription(
                project_id=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION, fail_if_exists=True
            )
        self.assertEqual(str(e.exception), 'Subscription already exists: %s' % EXPANDED_SUBSCRIPTION) 
开发者ID:apache,项目名称:airflow,代码行数:11,代码来源:test_pubsub.py

示例13: test_create_subscription_nofailifexists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_create_subscription_nofailifexists(self, mock_service):
        mock_service.create_subscription.side_effect = AlreadyExists(
            'Subscription already exists: %s' % EXPANDED_SUBSCRIPTION
        )
        response = self.pubsub_hook.create_subscription(
            project_id=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION
        )
        self.assertEqual(TEST_SUBSCRIPTION, response) 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_pubsub.py

示例14: test_create_cluster_already_exists

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def test_create_cluster_already_exists(self, wait_mock, convert_mock, log_mock, mock_get_credentials):
        from google.api_core.exceptions import AlreadyExists
        # To force an error
        message = 'Already Exists'
        self.gke_hook._client.create_cluster.side_effect = AlreadyExists(message=message)

        self.gke_hook.create_cluster(cluster={}, project_id=TEST_GCP_PROJECT_ID)
        wait_mock.assert_not_called()
        self.assertEqual(convert_mock.call_count, 1)
        log_mock.info.assert_any_call("Assuming Success: %s", message) 
开发者ID:apache,项目名称:airflow,代码行数:12,代码来源:test_kubernetes_engine.py

示例15: execute

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import AlreadyExists [as 别名]
def execute(self, context):
        self.log.info('Creating cluster: %s', self.cluster_name)
        hook = DataprocHook(gcp_conn_id=self.gcp_conn_id)
        try:
            operation = hook.create_cluster(
                project_id=self.project_id,
                region=self.region,
                cluster=self.cluster,
                request_id=self.request_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
            cluster = operation.result()
            self.log.info("Cluster created.")
        except AlreadyExists:
            cluster = hook.get_cluster(
                project_id=self.project_id,
                region=self.region,
                cluster_name=self.cluster_name,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
            self.log.info("Cluster already exists.")
        return MessageToDict(cluster) 
开发者ID:apache,项目名称:airflow,代码行数:28,代码来源:dataproc.py


注:本文中的google.api_core.exceptions.AlreadyExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。