EMR and SWF - add arn to response (#3873)

* emr: add ClusterArn to describe_cluster response

* emr: add ClusterArn to list_clusters response

* emr: add ClusterArn to put_auto_scaling_policy response

* emr: add ClusterArn to run_job_flow response

* emr: rename property "cluster_arn" to simply "arn"

* emr: generalize arn for account_id and region

* swf: add arn to list_domains response

* black reformat source code

* fix double import

* swf: require region on Domain object

Co-authored-by: Kevin Neal <Kevin_Neal@intuit.com>
This commit is contained in:
khneal 2021-04-23 07:20:36 -07:00 committed by GitHub
commit 8b523c3fe1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 21 deletions

View file

@ -7,7 +7,7 @@ import warnings
import pytz
from boto3 import Session
from dateutil.parser import parse as dtparse
from moto.core import BaseBackend, BaseModel
from moto.core import ACCOUNT_ID, BaseBackend, BaseModel
from moto.emr.exceptions import EmrError, InvalidRequestException
from .utils import (
random_instance_group_id,
@ -272,6 +272,12 @@ class FakeCluster(BaseModel):
)
self.kerberos_attributes = kerberos_attributes
@property
def arn(self):
return "arn:aws:elasticmapreduce:{0}:{1}:cluster/{2}".format(
self.emr_backend.region_name, ACCOUNT_ID, self.id
)
@property
def instance_groups(self):
return self.emr_backend.get_instance_groups(self.instance_group_ids)

View file

@ -529,13 +529,16 @@ class ElasticMapReduceResponse(BaseResponse):
@generate_boto3_response("PutAutoScalingPolicy")
def put_auto_scaling_policy(self):
cluster_id = self._get_param("ClusterId")
cluster = self.backend.get_cluster(cluster_id)
instance_group_id = self._get_param("InstanceGroupId")
auto_scaling_policy = self._get_param("AutoScalingPolicy")
instance_group = self.backend.put_auto_scaling_policy(
instance_group_id, auto_scaling_policy
)
template = self.response_template(PUT_AUTO_SCALING_POLICY)
return template.render(cluster_id=cluster_id, instance_group=instance_group)
return template.render(
cluster_id=cluster_id, cluster=cluster, instance_group=instance_group
)
@generate_boto3_response("RemoveAutoScalingPolicy")
def remove_auto_scaling_policy(self):
@ -691,6 +694,7 @@ DESCRIBE_CLUSTER_TEMPLATE = """<DescribeClusterResponse xmlns="http://elasticmap
<TerminationProtected>{{ cluster.termination_protected|lower }}</TerminationProtected>
<VisibleToAllUsers>{{ cluster.visible_to_all_users|lower }}</VisibleToAllUsers>
<StepConcurrencyLevel>{{ cluster.step_concurrency_level }}</StepConcurrencyLevel>
<ClusterArn>{{ cluster.arn }}</ClusterArn>
</Cluster>
</DescribeClusterResult>
<ResponseMetadata>
@ -940,6 +944,7 @@ LIST_CLUSTERS_TEMPLATE = """<ListClustersResponse xmlns="http://elasticmapreduce
{% endif %}
</Timeline>
</Status>
<ClusterArn>{{ cluster.arn }}</ClusterArn>
</member>
{% endfor %}
</Clusters>
@ -1249,6 +1254,7 @@ REMOVE_TAGS_TEMPLATE = """<RemoveTagsResponse xmlns="http://elasticmapreduce.ama
RUN_JOB_FLOW_TEMPLATE = """<RunJobFlowResponse xmlns="http://elasticmapreduce.amazonaws.com/doc/2009-03-31">
<RunJobFlowResult>
<JobFlowId>{{ cluster.id }}</JobFlowId>
<ClusterArn>{{ cluster.arn }}</ClusterArn>
</RunJobFlowResult>
<ResponseMetadata>
<RequestId>8296d8b8-ed85-11dd-9877-6fad448a8419</RequestId>
@ -1378,6 +1384,7 @@ PUT_AUTO_SCALING_POLICY = """<PutAutoScalingPolicyResponse xmlns="http://elastic
{% endif %}
</AutoScalingPolicy>
{% endif %}
<ClusterArn>{{ cluster.arn }}</ClusterArn>
</PutAutoScalingPolicyResult>
<ResponseMetadata>
<RequestId>d47379d9-b505-49af-9335-a68950d82535</RequestId>

View file

@ -112,7 +112,12 @@ class SWFBackend(BaseBackend):
):
if self._get_domain(name, ignore_empty=True):
raise SWFDomainAlreadyExistsFault(name)
domain = Domain(name, workflow_execution_retention_period_in_days, description)
domain = Domain(
name,
workflow_execution_retention_period_in_days,
self.region_name,
description,
)
self.domains.append(domain)
def deprecate_domain(self, name):

View file

@ -1,7 +1,7 @@
from __future__ import unicode_literals
from collections import defaultdict
from moto.core import BaseModel
from moto.core import ACCOUNT_ID, BaseModel
from ..exceptions import (
SWFUnknownResourceFault,
SWFWorkflowExecutionAlreadyStartedFault,
@ -9,9 +9,10 @@ from ..exceptions import (
class Domain(BaseModel):
def __init__(self, name, retention, description=None):
def __init__(self, name, retention, region_name, description=None):
self.name = name
self.retention = retention
self.region_name = region_name
self.description = description
self.status = "REGISTERED"
self.types = {"activity": defaultdict(dict), "workflow": defaultdict(dict)}
@ -31,6 +32,9 @@ class Domain(BaseModel):
hsh = {"name": self.name, "status": self.status}
if self.description:
hsh["description"] = self.description
hsh["arn"] = "arn:aws:swf:{0}:{1}:/domain/{2}".format(
self.region_name, ACCOUNT_ID, self.name
)
return hsh
def to_full_dict(self):