feature emr: set_termination_protection call implementation

feature emr: support for instance_groups param in run_jobflow
This commit is contained in:
Shulman Evgeny 2015-07-08 10:26:58 +03:00
commit e498c95807
3 changed files with 76 additions and 0 deletions

View file

@ -124,6 +124,10 @@ class FakeJobFlow(object):
else:
self.visible_to_all_users = False
def set_termination_protection(self, value):
self.termination_protected = value
def add_steps(self, steps):
for index, step in enumerate(steps):
if self.steps:
@ -236,6 +240,11 @@ class ElasticMapReduceBackend(BaseBackend):
job = self.job_flows[job_id]
job.set_visibility(visible_to_all_users)
def set_termination_protection(self, job_ids, value):
for job_id in job_ids:
job = self.job_flows[job_id]
job.set_termination_protection(value)
def add_tags(self, cluster_id, tags):
cluster = self.get_cluster(cluster_id)
cluster.add_tags(tags)

View file

@ -27,6 +27,10 @@ class ElasticMapReduceResponse(BaseResponse):
flow_name, log_uri, job_flow_role,
visible_to_all_users, steps, instance_attrs
)
instance_groups = self._get_list_prefix('Instances.InstanceGroups.member')
if instance_groups:
emr_backend.add_instance_groups(job_flow.id, instance_groups)
template = self.response_template(RUN_JOB_FLOW_TEMPLATE)
return template.render(job_flow=job_flow)
@ -62,6 +66,13 @@ class ElasticMapReduceResponse(BaseResponse):
template = self.response_template(SET_VISIBLE_TO_ALL_USERS_TEMPLATE)
return template.render()
def set_termination_protection(self):
termination_protection = self._get_param('TerminationProtected')
job_ids = self._get_multi_param('JobFlowIds.member')
emr_backend.set_termination_protection(job_ids, termination_protection)
template = self.response_template(SET_TERMINATION_PROTECTION_TEMPLATE)
return template.render()
def list_clusters(self):
clusters = emr_backend.list_clusters()
template = self.response_template(LIST_CLUSTERS_TEMPLATE)
@ -149,6 +160,7 @@ DESCRIBE_JOB_FLOWS_TEMPLATE = """<DescribeJobFlowsResponse xmlns="http://elastic
<InstanceCount>{{ job_flow.instance_count }}</InstanceCount>
<KeepJobFlowAliveWhenNoSteps>{{ job_flow.keep_job_flow_alive_when_no_steps }}</KeepJobFlowAliveWhenNoSteps>
<TerminationProtected>{{ job_flow.termination_protected }}</TerminationProtected>
<MasterPublicDnsName>ec2-184-0-0-1.us-west-1.compute.amazonaws.com</MasterPublicDnsName>
<InstanceGroups>
{% for instance_group in job_flow.instance_groups %}
<member>
@ -290,6 +302,14 @@ SET_VISIBLE_TO_ALL_USERS_TEMPLATE = """<SetVisibleToAllUsersResponse xmlns="http
</SetVisibleToAllUsersResponse>"""
SET_TERMINATION_PROTECTION_TEMPLATE = """<SetTerminationProtection xmlns="http://elasticmapreduce.amazonaws.com/doc/2009-03-31">
<ResponseMetadata>
<RequestId>
2690d7eb-ed86-11dd-9877-6fad448a8419
</RequestId>
</ResponseMetadata>
</SetTerminationProtection>"""
ADD_TAGS_TEMPLATE = """<AddTagsResponse xmlns="http://elasticmapreduce.amazonaws.com/doc/2009-03-31">
<ResponseMetadata>
<RequestId>