mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr): give resource-tag conditions the tags of the cluster a request names (#8698)
The generated request resources give EMR's cluster type the aws:ResourceTag/ and elasticmapreduce:ResourceTag/ keys, but EmrService answered no tags, so a condition on a cluster's tags saw none. EmrService.storedTags now reads the cluster stored under the ARN's id in the account it names, in place, in the ARN's Region or recorded with none, as the tag handlers find it, the ARN matched whole. AddTags and RemoveTags now put a new map in place of the held one under the service's lock instead of editing it in place, and the field is volatile.
This commit is contained in:
1 parent
1d581eb131
commit
3313a5a9f0
6 files changed
+103
-9
No files matched your search
@@ -22,10 +22,11 @@ import java.util.Optional;
|
||||
* <p>Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
|
||||
* Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment Cryptography, for
|
||||
* the key an alias names; EMR, for the clusters of its instance groups; IAM Identity Center, for the accounts its
|
||||
* permission sets are provisioned to; Resource Explorer, for its default view; OAM and RAM, for the sinks,
|
||||
* invitations and shares of other accounts they act on; Secrets Manager, for the secret a name or an ARN names,
|
||||
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group and its groups' tags;
|
||||
* the key an alias names; EMR, for the clusters of its instance groups and a tag call's resource and the tags of a
|
||||
* cluster; IAM Identity Center, for the accounts its permission sets are provisioned to; Resource Explorer, for its
|
||||
* default view; OAM and RAM, for the sinks, invitations and shares of other accounts they act on; Secrets Manager,
|
||||
* for the secret a name or an ARN names, random suffix included, and its tags; EventBridge Scheduler, for its
|
||||
* default schedule group and its groups' tags;
|
||||
* CloudFormation, for the stack or the stack set a name names, whose id it minted, and the tags of a stack, a stack set
|
||||
* or a change set; S3 Tables, for the table a request names by its table bucket, namespace and name, and the tags of a
|
||||
* table bucket or a table; Lambda, for the layer version a layer version ARN selects, the image of a MicroVM and the
|
||||
|
||||
@@ -107,6 +107,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
private static final String RUNNER_DOCKER = "docker";
|
||||
// The service a step's driver belongs to, which names it and labels it.
|
||||
private static final String SERVICE = "emr";
|
||||
// The resource of a cluster's ARN, before its id.
|
||||
private static final String CLUSTER_RESOURCE = "cluster/";
|
||||
// The reason of a cluster a failed bootstrap action ended, as Terraform reported a real one's
|
||||
// (hashicorp/terraform-provider-aws#4378) and the Management Guide's VPC errors page quotes it.
|
||||
private static final String BOOTSTRAP_ACTION_FAILED =
|
||||
@@ -1019,24 +1021,60 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
/** Puts a new map, the held tags with {@code tags} added, in place of the cluster's, so a lookup reads it whole. */
|
||||
public void addTags(String resourceId, Map<String, String> tags) {
|
||||
run(() -> {
|
||||
EmrCluster cluster = requireCluster(resourceId);
|
||||
rejectTerminatedTagging(cluster);
|
||||
cluster.getTags().putAll(tags);
|
||||
Map<String, String> updated = new LinkedHashMap<>(cluster.getTags());
|
||||
updated.putAll(tags);
|
||||
cluster.setTags(updated);
|
||||
clusterStore.put(resourceId, cluster);
|
||||
});
|
||||
}
|
||||
|
||||
/** Puts a new map, the held tags without {@code keys}, in place of the cluster's, so a lookup reads it whole. */
|
||||
public void removeTags(String resourceId, List<String> keys) {
|
||||
run(() -> {
|
||||
EmrCluster cluster = requireCluster(resourceId);
|
||||
rejectTerminatedTagging(cluster);
|
||||
keys.forEach(cluster.getTags()::remove);
|
||||
Map<String, String> updated = new LinkedHashMap<>(cluster.getTags());
|
||||
keys.forEach(updated::remove);
|
||||
cluster.setTags(updated);
|
||||
clusterStore.put(resourceId, cluster);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the cluster stored under {@code arn}, in the account it names, read in place: the cluster of
|
||||
* that id in the ARN's Region, or one recorded with no Region, as the tag handlers find it; empty for an ARN
|
||||
* naming nothing stored or naming anything but a cluster.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "elasticmapreduce")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String resource = parsed.resource();
|
||||
if (!resource.startsWith(CLUSTER_RESOURCE) || resource.indexOf('/', CLUSTER_RESOURCE.length()) >= 0
|
||||
|| !arn.equals(AwsArnUtils.Arn.of("elasticmapreduce", parsed.region(), parsed.accountId(), resource)
|
||||
.toString())) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
AccountAwareStorageBackend.readInAccount(clusterStore, parsed.accountId(),
|
||||
resource.substring(CLUSTER_RESOURCE.length()))
|
||||
.filter(cluster -> cluster.getRegion() == null || cluster.getRegion().equals(parsed.region()))
|
||||
.map(EmrCluster::getTags)
|
||||
.ifPresent(tags -> tags.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
}));
|
||||
return held;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
// ──────────────────────────── Scaling and termination policies ────────────────────────────
|
||||
|
||||
@@ -74,7 +74,7 @@ public class EmrCluster {
|
||||
private Instant terminatingDateTime;
|
||||
// Status.ErrorDetails: the errors that ended the cluster, empty unless one of those with an ErrorDetail code did.
|
||||
private List<EmrErrorDetail> errorDetails = new ArrayList<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
private List<EmrStep> steps = new ArrayList<>();
|
||||
private List<EmrInstanceGroup> instanceGroups = new ArrayList<>();
|
||||
private List<EmrInstanceFleet> instanceFleets = new ArrayList<>();
|
||||
|
||||
Reference in new issue
Block a user