Exemple #1
0
    def __init__(self, options):
        """Initializes a Dataflow API client object."""
        self.standard_options = options.view_as(StandardOptions)
        self.google_cloud_options = options.view_as(GoogleCloudOptions)

        if _use_fnapi(options):
            self.environment_version = _FNAPI_ENVIRONMENT_MAJOR_VERSION
        else:
            self.environment_version = _LEGACY_ENVIRONMENT_MAJOR_VERSION

        if self.google_cloud_options.no_auth:
            credentials = None
        else:
            credentials = get_service_credentials()

        # Use 60 second socket timeout avoid hangs during network flakiness.
        http_client = httplib2.Http(timeout=60)
        self._client = dataflow.DataflowV1b3(
            url=self.google_cloud_options.dataflow_endpoint,
            credentials=credentials,
            get_credentials=(not self.google_cloud_options.no_auth),
            http=http_client)
        self._storage_client = storage.StorageV1(
            url='https://www.googleapis.com/storage/v1',
            credentials=credentials,
            get_credentials=(not self.google_cloud_options.no_auth),
            http=http_client)
Exemple #2
0
    def __init__(self, options):
        """Initializes a Dataflow API client object."""
        self.standard_options = options.view_as(StandardOptions)
        self.google_cloud_options = options.view_as(GoogleCloudOptions)

        if _use_fnapi(options):
            self.environment_version = _FNAPI_ENVIRONMENT_MAJOR_VERSION
        else:
            self.environment_version = _LEGACY_ENVIRONMENT_MAJOR_VERSION

        if self.google_cloud_options.no_auth:
            credentials = None
        else:
            credentials = get_service_credentials()

        http_client = get_new_http()
        self._client = dataflow.DataflowV1b3(
            url=self.google_cloud_options.dataflow_endpoint,
            credentials=credentials,
            get_credentials=(not self.google_cloud_options.no_auth),
            http=http_client,
            response_encoding=get_response_encoding())
        self._storage_client = storage.StorageV1(
            url='https://www.googleapis.com/storage/v1',
            credentials=credentials,
            get_credentials=(not self.google_cloud_options.no_auth),
            http=http_client,
            response_encoding=get_response_encoding())
Exemple #3
0
def assert_bucket_exists(bucket_name):
    # type: (str) -> None
    """Asserts whether the specified GCS bucket with the name
  bucket_name exists.

    Logs an error and raises a ValueError if the bucket does not exist.

    Logs a warning if the bucket cannot be verified to exist.
  """
    try:
        from apitools.base.py.exceptions import HttpError
        storage_client = storage.StorageV1(
            credentials=auth.get_service_credentials(),
            get_credentials=False,
            http=get_new_http(),
            response_encoding='utf8')
        request = storage.StorageBucketsGetRequest(bucket=bucket_name)
        storage_client.buckets.Get(request)
    except HttpError as e:
        if e.status_code == 404:
            _LOGGER.error('%s bucket does not exist!', bucket_name)
            raise ValueError('Invalid GCS bucket provided!')
        else:
            _LOGGER.warning(
                'HttpError - unable to verify whether bucket %s exists',
                bucket_name)
    except ImportError:
        _LOGGER.warning(
            'ImportError - unable to verify whether bucket %s exists',
            bucket_name)
Exemple #4
0
 def __init__(self, storage_client=None):
     if storage_client is None:
         storage_client = storage.StorageV1(
             credentials=auth.get_service_credentials(),
             get_credentials=False,
             http=get_new_http(),
             response_encoding='utf8')
     self.client = storage_client
     self._rewrite_cb = None
Exemple #5
0
 def __init__(self, storage_client=None, pipeline_options=None):
     if storage_client is None:
         storage_client = storage.StorageV1(
             credentials=auth.get_service_credentials(pipeline_options),
             get_credentials=False,
             http=get_new_http(),
             response_encoding='utf8',
             additional_http_headers={
                 "User-Agent": "apache-beam-%s" % apache_beam.__version__
             })
     self.client = storage_client
     self._rewrite_cb = None
     self.bucket_to_project_number = {}
Exemple #6
0
 def __new__(cls, storage_client=None):
     if storage_client:
         return super(GcsIO, cls).__new__(cls, storage_client)
     else:
         # Create a single storage client for each thread.  We would like to avoid
         # creating more than one storage client for each thread, since each
         # initialization requires the relatively expensive step of initializing
         # credentaials.
         local_state = threading.local()
         if getattr(local_state, 'gcsio_instance', None) is None:
             credentials = auth.get_service_credentials()
             storage_client = storage.StorageV1(credentials=credentials)
             local_state.gcsio_instance = (super(GcsIO, cls).__new__(
                 cls, storage_client))
             local_state.gcsio_instance.client = storage_client
         return local_state.gcsio_instance
Exemple #7
0
 def __init__(self, options):
     super().__init__(options)
     self._google_cloud_options = options.view_as(GoogleCloudOptions)
     if self._google_cloud_options.no_auth:
         credentials = None
     else:
         credentials = get_service_credentials()
     self._storage_client = storage.StorageV1(
         url='https://www.googleapis.com/storage/v1',
         credentials=credentials,
         get_credentials=(not self._google_cloud_options.no_auth),
         http=get_new_http(),
         response_encoding='utf8')
     if not self._docker_registry_push_url:
         self._docker_registry_push_url = (
             'gcr.io/%s' % self._google_cloud_options.project)
Exemple #8
0
 def __init__(self, options, environment_version):
     """Initializes a Dataflow API client object."""
     self.standard_options = options.view_as(StandardOptions)
     self.google_cloud_options = options.view_as(GoogleCloudOptions)
     self.environment_version = environment_version
     if self.google_cloud_options.no_auth:
         credentials = None
     else:
         credentials = get_service_credentials()
     self._client = dataflow.DataflowV1b3(
         url=self.google_cloud_options.dataflow_endpoint,
         credentials=credentials,
         get_credentials=(not self.google_cloud_options.no_auth))
     self._storage_client = storage.StorageV1(
         url='https://www.googleapis.com/storage/v1',
         credentials=credentials,
         get_credentials=(not self.google_cloud_options.no_auth))
Exemple #9
0
 def __new__(cls, storage_client=None):
     if storage_client:
         # This path is only used for testing.
         return super(GcsIO, cls).__new__(cls)
     else:
         # Create a single storage client for each thread.  We would like to avoid
         # creating more than one storage client for each thread, since each
         # initialization requires the relatively expensive step of initializing
         # credentaials.
         local_state = threading.local()
         if getattr(local_state, 'gcsio_instance', None) is None:
             credentials = auth.get_service_credentials()
             storage_client = storage.StorageV1(
                 credentials=credentials,
                 http=httplib2.Http(timeout=DEFAULT_HTTP_TIMEOUT_SECONDS))
             local_state.gcsio_instance = (super(GcsIO, cls).__new__(
                 cls, storage_client))
             local_state.gcsio_instance.client = storage_client
         return local_state.gcsio_instance
Exemple #10
0
 def __new__(cls, storage_client=None):
   if storage_client:
     # This path is only used for testing.
     return super(GcsIO, cls).__new__(cls)
   else:
     # Create a single storage client for each thread.  We would like to avoid
     # creating more than one storage client for each thread, since each
     # initialization requires the relatively expensive step of initializing
     # credentaials.
     local_state = threading.local()
     if getattr(local_state, 'gcsio_instance', None) is None:
       credentials = auth.get_service_credentials()
       storage_client = storage.StorageV1(
           credentials=credentials,
           get_credentials=False,
           http=get_new_http(),
           response_encoding=None if sys.version_info[0] < 3 else 'utf8')
       local_state.gcsio_instance = super(GcsIO, cls).__new__(cls)
       local_state.gcsio_instance.client = storage_client
     return local_state.gcsio_instance
Exemple #11
0
 def __init__(self, options):
   super().__init__(options)
   self._google_cloud_options = options.view_as(GoogleCloudOptions)
   self._cloud_build_machine_type = self._get_cloud_build_machine_type_enum(
       options.view_as(SetupOptions).cloud_build_machine_type)
   if self._google_cloud_options.no_auth:
     credentials = None
   else:
     credentials = get_service_credentials(options)
   self._storage_client = storage.StorageV1(
       url='https://www.googleapis.com/storage/v1',
       credentials=credentials,
       get_credentials=(not self._google_cloud_options.no_auth),
       http=get_new_http(),
       response_encoding='utf8')
   self._cloudbuild_client = cloudbuild.CloudbuildV1(
       credentials=credentials,
       get_credentials=(not self._google_cloud_options.no_auth),
       http=get_new_http(),
       response_encoding='utf8')
   if not self._docker_registry_push_url:
     self._docker_registry_push_url = (
         'gcr.io/%s/prebuilt_beam_sdk' % self._google_cloud_options.project)