o ckF[q@sdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZddlmZddlmZGd d d eZdS) z, Represents a connection to the EMR service N) RegionInfo) AddInstanceGroupsResponseBootstrapActionListClusterClusterSummaryList HadoopStepInstanceGroupList InstanceListJobFlowJobFlowStepListModifyInstanceGroupsResponseRunJobFlowResponseStepSummaryList)JarStep)AWSQueryConnection)EmrResponseError)sixcseZdZejdddZejdddZejdddZe Z dZ d Z dPfdd Z ddZddZddZ dQddZddZdRddZ dQddZdRddZ dSd d!ZdTd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd d d d2d2d3d4d5d5d d gd d d d d d d fd6d7Zd8d9Z d:d;Z!dd?Z#d@dAZ$dBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+Z,S)U EmrConnectionBoto emr_versionz 2009-03-31emr_region_namez us-east-1emr_region_endpointz(elasticmapreduce.us-east-1.amazonaws.comzHs3://{region_name}.elasticmapreduce/libs/script-runner/script-runner.jarz?s3://{region_name}.elasticmapreduce/libs/state-pusher/0.1/fetchNTr/cs`| s t||j|j} | |_tt|j|||||||||jj| | | | ||d|jj|_ d|_ dS)N)validate_certs profile_nameelasticmapreduce) rDefaultRegionNameDefaultRegionEndpointregionsuperr__init__endpointnameauth_region_nameauth_service_name)selfaws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryrpathsecurity_tokenrr __class__5/usr/lib/python3/dist-packages/boto/emr/connection.pyr 9s"   zEmrConnection.__init__cCsdgS)Nzhmac-v4r4r%r4r4r5_required_auth_capabilityTsz'EmrConnection._required_auth_capabilitycCsd|i}|d|tS)z Describes an Elastic MapReduce cluster :type cluster_id: str :param cluster_id: The cluster id of interest ClusterIdDescribeCluster) get_objectr)r% cluster_idparamsr4r4r5describe_clusterWszEmrConnection.describe_clustercCs|j|gd}|r |dSdS)aD This method is deprecated. We recommend you use list_clusters, describe_cluster, list_steps, list_instance_groups and list_bootstrap_actions instead. Describes a single Elastic MapReduce job flow :type jobflow_id: str :param jobflow_id: The job flow id of interest ) jobflow_idsrN)describe_jobflows)r% jobflow_idjobflowsr4r4r5describe_jobflowcs zEmrConnection.describe_jobflowcCshi}|r |||d|r|||d|r|tjj|d<|r*|tjj|d<|d|dtfgS)a} This method is deprecated. We recommend you use list_clusters, describe_cluster, list_steps, list_instance_groups and list_bootstrap_actions instead. Retrieve all the Elastic MapReduce job flows on your account :type states: list :param states: A list of strings with job flow states wanted :type jobflow_ids: list :param jobflow_ids: A list of job flow IDs :type created_after: datetime :param created_after: Bound on job flow creation time :type created_before: datetime :param created_before: Bound on job flow creation time zJobFlowStates.memberJobFlowIds.member CreatedAfter CreatedBeforeDescribeJobFlowsmember)build_list_paramsstrftimebotoutilsISO8601get_listr )r%statesr> created_aftercreated_beforer<r4r4r5r?rszEmrConnection.describe_jobflowscCs||d}|d|tS)z Describe an Elastic MapReduce step :type cluster_id: str :param cluster_id: The cluster id of interest :type step_id: str :param step_id: The step id of interest )r8StepId DescribeStep)r:r)r%r;step_idr<r4r4r5 describe_steps zEmrConnection.describe_stepcC"d|i}|r ||d<|d|tS)z Get a list of bootstrap actions for an Elastic MapReduce cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type marker: str :param marker: Pagination marker r8MarkerListBootstrapActions)r:rr%r;markerr<r4r4r5list_bootstrap_actions  z$EmrConnection.list_bootstrap_actionscCs\i}|r |tjj|d<|r|tjj|d<|r||d<|r'|||d|d|tS)a List Elastic MapReduce clusters with optional filtering :type created_after: datetime :param created_after: Bound on cluster creation time :type created_before: datetime :param created_before: Bound on cluster creation time :type cluster_states: list :param cluster_states: Bound on cluster states :type marker: str :param marker: Pagination marker rDrErVzClusterStates.member ListClusters)rIrJrKrLrHr:r)r%rOrPcluster_statesrYr<r4r4r5 list_clustersszEmrConnection.list_clusterscCrU)z List EC2 instance groups in a cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type marker: str :param marker: Pagination marker r8rVListInstanceGroups)r:rrXr4r4r5list_instance_groupsr[z"EmrConnection.list_instance_groupscCs@d|i}|r ||d<|r||d<|r|||d|d|tS)a List EC2 instances in a cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type instance_group_id: str :param instance_group_id: The EC2 instance group id of interest :type instance_group_types: list :param instance_group_types: Filter by EC2 instance group type :type marker: str :param marker: Pagination marker r8InstanceGroupIdrVzInstanceGroupTypes.member ListInstances)rHr:r )r%r;instance_group_idinstance_group_typesrYr<r4r4r5list_instancesszEmrConnection.list_instancescCs4d|i}|r ||d<|r|||d|d|tS)a List cluster steps :type cluster_id: str :param cluster_id: The cluster id of interest :type step_states: list :param step_states: Filter by step states :type marker: str :param marker: Pagination marker r8rVzStepStates.member ListSteps)rHr:r)r%r; step_statesrYr<r4r4r5 list_stepss zEmrConnection.list_stepscCs8t|tjsJd|i}||||jd|ddS)a Create new metadata tags for the specified resource id. :type resource_id: str :param resource_id: The cluster id :type tags: dict :param tags: A dictionary containing the name/value pairs. If you want to create only a tag name, the value for that tag should be the empty string (e.g. '') or None. ResourceIdAddTagsPOSTverb) isinstancer string_typesupdate_build_tag_list get_statusr% resource_idtagsr<r4r4r5add_tagss  zEmrConnection.add_tagscCs*d|i}||d||jd|ddS)z Remove metadata tags for the specified resource id. :type resource_id: str :param resource_id: The cluster id :type tags: list :param tags: A list of tag names to remove. riTagKeys RemoveTagsrkrl)rp_build_string_listrrrsr4r4r5 remove_tags.s zEmrConnection.remove_tagscCs||gdS)z Terminate an Elastic MapReduce job flow :type jobflow_id: str :param jobflow_id: A jobflow id N)terminate_jobflows)r%r@r4r4r5terminate_jobflow>szEmrConnection.terminate_jobflowcCs"i}|||d|jd|ddS)z Terminate an Elastic MapReduce job flow :type jobflow_ids: list :param jobflow_ids: A list of job flow IDs rCTerminateJobFlowsrkrlrHrr)r%r>r<r4r4r5r{Gsz EmrConnection.terminate_jobflowscsPt|ts|g}i}||d<fdd|D}||jd|tddS)z Adds steps to a jobflow :type jobflow_id: str :param jobflow_id: The job flow id :type steps: list(boto.emr.Step) :param steps: A list of steps to add to the job JobFlowIdcg|]}|qSr4_build_step_args.0stepr6r4r5 az3EmrConnection.add_jobflow_steps..AddJobFlowStepsrkrl)rnlistrp_build_step_listr:r )r%r@stepsr< step_argsr4r6r5add_jobflow_stepsRs zEmrConnection.add_jobflow_stepscCs>t|ts|g}i}||d<||||jd|tddS)aI Adds instance groups to a running cluster. :type jobflow_id: str :param jobflow_id: The id of the jobflow which will take the new instance groups :type instance_groups: list(boto.emr.InstanceGroup) :param instance_groups: A list of instance groups to add to the job rAddInstanceGroupsrkrl)rnrrp_build_instance_group_list_argsr:r)r%r@instance_groupsr<r4r4r5add_instance_groupsgs z!EmrConnection.add_instance_groupscCszt|ts|g}t|ts|g}t||}i}t|D]\}}|d|d|d<|d|d|d<q|jd|tddS)ah Modify the number of nodes and configuration settings in an instance group. :type instance_group_ids: list(str) :param instance_group_ids: A list of the ID's of the instance groups to be modified :type new_sizes: list(int) :param new_sizes: A list of the new sizes for each instance group rz(InstanceGroups.member.%d.InstanceGroupIdz&InstanceGroups.member.%d.InstanceCountModifyInstanceGroupsrkrl)rnrzip enumerater:r )r%instance_group_ids new_sizesrr<kigr4r4r5modify_instance_groups{s   z$EmrConnection.modify_instance_groupszm1.smallrTERMINATE_JOB_FLOWFcs| pg} i}|r ||d<|r||d<||d<||| | }|||s2|||}||n|}tddt|D}||| rgtdddjj j j d j j j j d d }| d || rzfd d | D}||| rfdd | D}|||r||d<|dur||d<|rt|D]\}}|dur||dq|||<q|dur|rd|d<nd|d<|dur||d<|dur||d<jd|tdd}|jS)a Runs a job flow :type name: str :param name: Name of the job flow :type log_uri: str :param log_uri: URI of the S3 bucket to place logs :type ec2_keyname: str :param ec2_keyname: EC2 key used for the instances :type availability_zone: str :param availability_zone: EC2 availability zone of the cluster :type master_instance_type: str :param master_instance_type: EC2 instance type of the master :type slave_instance_type: str :param slave_instance_type: EC2 instance type of the slave nodes :type num_instances: int :param num_instances: Number of instances in the Hadoop cluster :type action_on_failure: str :param action_on_failure: Action to take if a step terminates :type keep_alive: bool :param keep_alive: Denotes whether the cluster should stay alive upon completion :type enable_debugging: bool :param enable_debugging: Denotes whether AWS console debugging should be enabled. :type hadoop_version: str :param hadoop_version: Version of Hadoop to use. This no longer defaults to '0.20' and now uses the AMI default. :type steps: list(boto.emr.Step) :param steps: List of steps to add with the job :type bootstrap_actions: list(boto.emr.BootstrapAction) :param bootstrap_actions: List of bootstrap actions that run before Hadoop starts. :type instance_groups: list(boto.emr.InstanceGroup) :param instance_groups: Optional list of instance groups to use when creating this job. NB: When provided, this argument supersedes num_instances and master/slave_instance_type. :type ami_version: str :param ami_version: Amazon Machine Image (AMI) version to use for instances. Values accepted by EMR are '1.0', '2.0', and 'latest'; EMR currently defaults to '1.0' if you don't set 'ami_version'. :type additional_info: JSON str :param additional_info: A JSON string for selecting additional features :type api_params: dict :param api_params: a dictionary of additional parameters to pass directly to the EMR API (so you don't have to upgrade boto to use new EMR features). You can also delete an API parameter by setting it to None. :type visible_to_all_users: bool :param visible_to_all_users: Whether the job flow is visible to all IAM users of the AWS account associated with the job flow. If this value is set to ``True``, all IAM users of that AWS account can view and (if they have the proper policy permissions set) manage the job flow. If it is set to ``False``, only the IAM user that created the job flow can view and manage it. :type job_flow_role: str :param job_flow_role: An IAM role for the job flow. The EC2 instances of the job flow assume this role. The default role is ``EMRJobflowDefault``. In order to use the default role, you must have already created it using the CLI. :type service_role: str :param service_role: The IAM role that will be assumed by the Amazon EMR service to access AWS resources on your behalf. :rtype: str :return: The jobflow id ActionOnFailureLogUriNamecss |] \}}d||fVqdS)z Instances.%sNr4)rrvr4r4r5 s z,EmrConnection.run_jobflow..zSetup Hadoop DebuggingrN) region_name)r"action_on_failure main_classjarrrcrr4rrr6r4r5r/rz-EmrConnection.run_jobflow..crr4)_build_bootstrap_action_args)rbootstrap_actionr6r4r5r3r AmiVersionAdditionalInfotrueVisibleToAllUsersfalse JobFlowRole ServiceRole RunJobFlowrkrl)_build_instance_common_argsrp#_build_instance_count_and_type_argsrdictr iteritemsr DebuggingJarformatrr" DebuggingArgsinsertr_build_bootstrap_action_listpopr:r jobflowid)r%r"log_uri ec2_keynameavailability_zonemaster_instance_typeslave_instance_type num_instancesr keep_aliveenable_debugginghadoop_versionrbootstrap_actionsradditional_info ami_version api_paramsvisible_to_all_users job_flow_role service_roler< common_paramsinstance_params list_argsdebugging_steprbootstrap_action_argskeyvalueresponser4r6r5 run_jobflowsxh       zEmrConnection.run_jobflowcC@|dvsJi}|r dp d|d<|||gd|jd|ddS) a/ Set termination protection on specified Elastic MapReduce job flows :type jobflow_ids: list or str :param jobflow_ids: A list of job flow IDs :type termination_protection_status: bool :param termination_protection_status: Termination protection status TFrrTerminationProtectedrCSetTerminationProtectionrkrlr~)r%r@termination_protection_statusr<r4r4r5set_termination_protectionSs z(EmrConnection.set_termination_protectioncCr) a Set whether specified Elastic Map Reduce job flows are visible to all IAM users :type jobflow_ids: list or str :param jobflow_ids: A list of job flow IDs :type visibility: bool :param visibility: Visibility rrrrrCSetVisibleToAllUsersrkrlr~)r%r@ visibilityr<r4r4r5set_visible_to_all_usersfs z&EmrConnection.set_visible_to_all_userscCsNi}|j|d<z|j|d<Wn tyYnw|}|r%|||d|S)NzScriptBootstrapAction.Pathrz!ScriptBootstrapAction.Args.member)r0r"AttributeErrorargsrH)r%rbootstrap_action_paramsrr4r4r5rxs  z*EmrConnection._build_bootstrap_action_argscCsVi}|j|d<||d<|}|r||d<|}|r$|||d|j|d<|S)NrzHadoopJarStep.JarzHadoopJarStep.MainClasszHadoopJarStep.Args.memberr)rrrrrHr")r%r step_paramsrrr4r4r5rs   zEmrConnection._build_step_argscCRt|ts|g}i}t|D]\}}t|D]\}}||d|d|f<qq|S)NzBootstrapActions.member.%s.%srrnrrrr)r%rr<irrrr4r4r5r z*EmrConnection._build_bootstrap_action_listcCr)NzSteps.member.%s.%srr)r%rr<rrrrr4r4r5rrzEmrConnection._build_step_listcCs>t|ts|g}i}t|D]\}}||d||df<q|S)Nz %s.member.%sr)rnrr)r%fielditemsr<ritemr4r4r5rys z EmrConnection._build_string_listcCsbt|tsJi}ttt|ddD]\}}|\}}d|}||d|<|r.||d|<q|S)Nr)startzTags.member.%sz%s.Keyz%s.Value)rnrrsortedrr)r%rur<r key_valuerrcurrent_prefixr4r4r5rqs  zEmrConnection._build_tag_listcCs8dt|i}|r||d<|r||d<|r||d<|S)z Takes a number of parameters used when starting a jobflow (as specified in run_jobflow() above). Returns a comparable dict for use in making a RunJobFlow request. z%Instances.KeepJobFlowAliveWhenNoStepszInstances.HadoopVersionzInstances.Ec2KeyNamez$Instances.Placement.AvailabilityZone)strlower)r%rrrrr<r4r4r5rs z)EmrConnection._build_instance_common_argscCs|||d}|S)z Takes a master instance type (string), a slave instance type (string), and a number of instances. Returns a comparable dict for use in making a RunJobFlow request. )zInstances.MasterInstanceTypezInstances.SlaveInstanceTypezInstances.InstanceCountr4)r%rrrr<r4r4r5rs z1EmrConnection._build_instance_count_and_type_argscCs2|j|j|j|j|jd}|jdkr|j|d<|S)z Takes an InstanceGroup; returns a dict that, when its keys are properly prefixed, can be used for describing InstanceGroups in RunJobFlow or AddInstanceGroups requests. ) InstanceCount InstanceRole InstanceTyperMarketSPOTBidPrice)rroletyper"marketbidprice)r%instance_groupr<r4r4r5_build_instance_group_argss  z(EmrConnection._build_instance_group_argscCs\t|ts|g}i}t|D]\}}||}t|D]\}}||d|d|f<qq|S)z Takes a list of InstanceGroups, or a single InstanceGroup. Returns a comparable dict for use in making a RunJobFlow or AddInstanceGroups request. zInstanceGroups.member.%d.%sr)rnrrrrr)r%rr<rrig_dictrrr4r4r5rs  z-EmrConnection._build_instance_group_list_args)NNTNNNNNrNNrNTN)NNNN)N)NNN)NN)-__name__ __module__ __qualname__rJconfigget APIVersionrrr ResponseErrorrrr r7r=rBr?rTrZr^r`rerhrvrzr|r{rrrrrrrrrrryrqrrrr __classcell__r4r4r2r5r+s   #      ;     r)__doc__typesrJ boto.utilsboto.ec2.regioninforboto.emr.emrobjectrrrrrrr r r r r r boto.emr.steprboto.connectionrboto.exceptionr boto.compatrrr4r4r4r5s 8