
                             d Z ddlmZ ddlmZ ddlmZ ddl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 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 dZej6                  j8                  dej6                  j:                  diZ ej>                  ej6                  j8                  ej6                  j:                        ej@                   G d dejB                                      Z"d Z#d Z$d Z%y)z/`gcloud dataproc-gdc instances create` command.    )absolute_import)division)unicode_literalsN)util)apis)waiter)arg_parsers)base)concepts)	yaml_data)labels_util)concept_parsers)presentation_specs)log)	resourcesdataprocgdcv1alpha1v1c                   &    e Zd ZdZed        Zd Zy)BaseGDCSparkApplicationCommandzrCreate a Dataproc GDC spark application.

  A Saprk application that run locally on the Dataproc
  GDC cluster.
  c                 R   t        j                  t               t               t	               gdgdgdgdgd      j                  |        | j                  dd       | j                  dd	       | j                  d
d       | j                  dd       | j                  dt        j                         dd       | j                  ddt        j                         t        j                  d       t        j                  |        t        j                  j                  |        y )Nz#--service-instance.service-instancez--service-instance.location)z*--application-environment.service-instancez"--application-environment.locationz--application.service-instancez--application.location)command_level_fallthroughsz--request-ida  An optional request ID to identify requests. If the service receives two identical
        instance create requests with the same request_id, the second request is
        ignored and the operation that corresponds to the first request is returned for both.

        The request ID must be a valid UUID with the exception that zero UUID is
        not supported (00000000-0000-0000-0000-000000000000).)helpz--display-namezLHuman-readable name for this service instance to be used in user interfaces.z--namespacez#namespace to run the application inz	--versionzversion of the applicationz--propertieszPROPERTY=VALUEzList of key value pairs to configure Spark. For a list of available properties, see: https://spark.apache.org/docs/latest/configuration.html#available-properties.)typemetavarr   z--annotationsz	KEY=VALUEzBList of annotation KEY=VALUE pairs to add to the service instance.)r   r   actionr   )r   ConceptParser+GetSparkApplicationResourcePresentationSpec1GetApplicationEnvironmentResourcePresentationSpec#GetInstanceResourcePresentationSpecAddToParseradd_argumentr	   ArgDictUpdateActionr   AddCreateLabelsFlagsr
   
ASYNC_FLAG)parsers    Llib/googlecloudsdk/command_lib/dataproc_gdc/spark_applications/basecreate.pyArgsz#BaseGDCSparkApplicationCommand.Args5   sO   !!79=?/1	
 6; .3 6/ (E&E$
( k&
A      2   )     " 7  
   "''P   $$V,OO'    c                    t         j                  | j                               }t        j                  t
        |      }|j                  xs t        j                         j                  }||j                         nt        j                         j                  }||_        ||_        t        j                  t
        t         j                  | j                                     }|j                  j                  |      }	|j                   sht"        j$                  j'                  |	j(                  d      }
t+        j,                  |j                  |j.                        }t+        j0                  ||
dj3                  |
j5                                      t6        j8                  j;                  dj3                  ||	j(                               t7        j<                  |dj3                  |j>                               tA        jB                  | ||j>                  dz   |z   ||jD                  jF                  jH                  |		      }t6        j8                  j;                  d
|jJ                  z         yy)a5  Submits spark application on the GDC Kubernetes cluster.

    Args:
      args: arguments required for the command.
      application_ref: application reference which contains relative name.
      create_req: create spark application request object.

    Returns:
      Job: The final value of spark job.
    Nz)dataprocgdc.projects.locations.operations)
collectionz4Waiting for Spark application create operation [{0}]zBCreate request issued for: [{0}]
Check operation [{1}] for status.z-- Spark application in service instance [{0}])detailsz/sparkApplications/)	spark_appzSpark Application status: %s)&VERSION_MAPgetReleaseTrackr   GetMessagesModuleDATAPROCGDC_API_NAME
request_iduuiduuid4hexName	requestIdsparkApplicationIdGetClientInstance5projects_locations_serviceInstances_sparkApplicationsCreateasync_r   REGISTRYParsenamer   CloudOperationPollerprojects_locations_operationsWaitForformatRelativeNamer   statusPrintCreatedResourceparentr   WaitForSparkAppTerminationSparkApplicationStateValueValuesEnum	SUCCEEDEDstate)selfargsapplication_ref
create_reqapi_versionmessagesr4   application_iddataprocgdc_client	create_opoperation_refpollerjobs                r(   Submitz%BaseGDCSparkApplicationCommand.Submit{   s    //$"3"3"56K%%&:KHH4DJJL$4$4J & 	ZZ\  &J$2J!//kood.?.?.AB #XX__I ;;((..
..%P / m **

R
R

:
:f nn


@
G
G((* 
jj
O6.)..1 

=DD## ++




3
3n
D


#
#
8
8
B
Bc 
jj5		ABK r*   N)__name__
__module____qualname____doc__staticmethodr)   r\    r*   r(   r   r   ,   s$     C( C(JEr*   r   c            
          t         j                  j                  d      } t        j                  j                  | j                               }t        j                  d|dddddd      S )Nzdataproc_gdc.spark_applicationz--applicationzSpark application to create.F zservice-instancelocationrA   concept_spec
group_helprequiredprefixesflag_name_overrides	r   ResourceYAMLDataFromPathr   ResourceSpecFromYamlGetDatar   ResourcePresentationSpec)application_dataresource_specs     r(   r   r      sh    //88& ''001A1I1I1KL-		4	4 //1rB
 r*   c            
          t         j                  j                  d      } t        j                  j                  | j                               }t        j                  d|dddddd      S )	Nz$dataproc_gdc.application_environmentz--application-environmentzLName of the application environment to reference for this Spark Application.FTrd   re   rg   rm   instance_dataru   s     r(   r   r      sj    ,,55,- ''001F1F1HI-		4	4&  /1rB

 
r*   c                      t         j                  j                  d      } t        j                  j                  | j                               }t        j                  d|ddd      S )Nzdataproc_gdc.service_instancez--service-instancezFName of the service instance on which this Spark Application will run.TF)rA   rh   ri   rj   rk   rm   rw   s     r(   r    r       sb    ,,55%- ''001F1F1HI-		4	4  	
 	r*   )&r`   
__future__r   r   r   r5   #googlecloudsdk.api_lib.dataproc_gdcr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper	   r
    googlecloudsdk.calliope.conceptsr   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   r3   r1   ALPHAGAr/   ReleaseTracksDefaultUniverseOnlyCreateCommandr   r   r   r    rb   r*   r(   <module>r      s    6 &  '  4 , . / ( 5 : < D G # ) % Z$ D%%++T->->-A-ABRT%7%7 R  CRj $r*   