
                         f    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
  G d d	e      Zy
)z7Common stateful utilities for the gcloud dataproc tool.    )absolute_import)division)unicode_literals)apis)base)	resourcesc                        e Zd ZdZej
                  j                  f fd	Zed        Z	ed        Z
ed        Zed        Z	 d	dZd	dZ xZS )
DataproczStateful utility for calling Dataproc APIs.

  While this currently could all be static. It is encapsulated in a class to
  support API version switching in future.
  c                 b    t         t        |           || _        d| _        d | _        d | _        y )Nv1)superr
   __init__release_trackapi_version_client
_resources)selfr   	__class__s     /lib/googlecloudsdk/api_lib/dataproc/dataproc.pyr   zDataproc.__init__"   s.    	(D"$&DDDLDO    c                 |    | j                   %t        j                  d| j                        | _         | j                   S Ndataproc)r   r   GetClientInstancer   r   s    r   clientzDataproc.client)   s0    ||++J8H8HIdl<<r   c                 B    t        j                  d| j                        S r   )r   GetMessagesModuler   r   s    r   messageszDataproc.messages/   s    !!*d.>.>??r   c                     | j                   It        j                  j                         | _         | j                   j	                  d| j
                         | j                   S r   )r   r   REGISTRYCloneRegisterApiByNamer   r   s    r   r   zDataproc.resources3   sF    !**002do
oo''
D4D4DE??r   c                     | j                   j                  j                  j                  | j                   j                  j                  j                  | j                   j                  j                  j
                  gS N)r   	JobStatusStateValueValuesEnum	CANCELLEDDONEERRORr   s    r   terminal_job_stateszDataproc.terminal_job_states:   sY     	44>>449944:: r   c                     || j                   j                  ||||      S | j                  dk(  rt        d      | j                   j                  |||||      S )aU  Gets the CreateClusterRequest for the appropriate api version.

    Args :
      cluster : Dataproc cluster to be created.
      project_id: The ID of the Google Cloud Platform project that the cluster
      belongs to.
      region : The Dataproc region in which to handle the request.
      request_id : A unique ID used to identify the request.
      action_on_failed_primary_workers : Supported only for v1 api.

    Raises :
      ValueError : if non-None action_on_failed_primary_workers is passed for
      v1beta2 api.

    Returns :
      DataprocProjectsRegionsClustersCreateRequest
    )cluster	projectIdregion	requestIdv1beta2zAaction_on_failed_primary_workers is not supported for v1beta2 api)r-   r.   r/   r0   actionOnFailedPrimaryWorkers)r   ,DataprocProjectsRegionsClustersCreateRequestr   
ValueError)r   r-   
project_idr/   
request_id action_on_failed_primary_workerss         r   GetCreateClusterRequestz Dataproc.GetCreateClusterRequestB   s    . (/]]GG	 H     9$
MO O ==EE%E F G Gr   c                     | j                   }|j                  |j                               }|rt        |      |_        | j
                  j                  j                  |      S )ad  Gets workflow template from dataproc.

    Args:
      template: workflow template resource that contains template name and id.
      version: version of the workflow template to get.

    Returns:
      WorkflowTemplate object that contains the workflow template info.

    Raises:
      ValueError: if version cannot be converted to a valid integer.
    )name)r   2DataprocProjectsRegionsWorkflowTemplatesGetRequestRelativeNameintversionr   "projects_regions_workflowTemplatesGet)r   templater>   r   get_requests        r   GetRegionsWorkflowTemplatez#Dataproc.GetRegionsWorkflowTemplatek   sY     }}HMM""$ N &KLk;;99==kJJr   r%   )__name__
__module____qualname____doc__r   ReleaseTrackGAr   propertyr   r   r   r+   r8   rC   __classcell__)r   s   @r   r
   r
      s     $(#4#4#7#7   
 @ @     @D'GRKr   r
   N)rG   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   objectr
    r   r   <module>rR      s,     > &  ' , ( )bKv bKr   