Esempio n. 1
0
    def test_delete_job(self):
        channel = ChannelStub()
        client = dataproc_v1beta2.JobControllerClient(channel=channel)

        # Setup Request
        project_id = 'projectId-1969970175'
        region = 'region-934795532'
        job_id = 'jobId-1154752291'

        client.delete_job(project_id, region, job_id)

        assert len(channel.requests) == 1
        expected_request = jobs_pb2.DeleteJobRequest(
            project_id=project_id, region=region, job_id=job_id)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_delete_job(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dataproc_v1beta2.JobControllerClient()

        # Setup Request
        project_id = "projectId-1969970175"
        region = "region-934795532"
        job_id = "jobId-1154752291"

        client.delete_job(project_id, region, job_id)

        assert len(channel.requests) == 1
        expected_request = jobs_pb2.DeleteJobRequest(
            project_id=project_id, region=region, job_id=job_id
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def delete_job(
        self,
        project_id,
        region,
        job_id,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Deletes the job from the project. If the job is active, the delete
        fails, and the response returns ``FAILED_PRECONDITION``.

        Example:
            >>> from google.cloud import dataproc_v1beta2
            >>>
            >>> client = dataproc_v1beta2.JobControllerClient()
            >>>
            >>> # TODO: Initialize `project_id`:
            >>> project_id = ''
            >>>
            >>> # TODO: Initialize `region`:
            >>> region = ''
            >>>
            >>> # TODO: Initialize `job_id`:
            >>> job_id = ''
            >>>
            >>> client.delete_job(project_id, region, job_id)

        Args:
            project_id (str): Required. The ID of the Google Cloud Platform project that the job
                belongs to.
            region (str): Required. The Cloud Dataproc region in which to handle the request.
            job_id (str): Required. The job ID.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "delete_job" not in self._inner_api_calls:
            self._inner_api_calls[
                "delete_job"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.delete_job,
                    default_retry=self._method_configs["DeleteJob"].retry,
                    default_timeout=self._method_configs["DeleteJob"].timeout,
                    client_info=self._client_info,
                )

        request = jobs_pb2.DeleteJobRequest(project_id=project_id,
                                            region=region,
                                            job_id=job_id)
        self._inner_api_calls["delete_job"](request,
                                            retry=retry,
                                            timeout=timeout,
                                            metadata=metadata)