mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(firehose): add TagDeliveryStream, UntagDeliveryStream, and ListTagsForDeliveryStream (#1061)
* feat(firehose): add tag, untag, and list tags endpoints to delivery stream * test(lambda): resolve flaky port bind error in RuntimeApiServerTest * test(ec2): isolate Ec2NetworkInterfacePaginationTest by filtering by subnet-id * fix: resolve flaky integration tests and robustify runtime binding & codebuild diagnostics * fix: unregister websocket connection immediately on close to prevent postToConnection race conditions * fix(lambda): fix RuntimeApiServer retry race condition when stopping during retries
This commit is contained in:
1 parent
5606fcd286
commit
aceeeca0af
4 files changed
+184
-2
No files matched your search
+55
-1
@@ -36,7 +36,13 @@ public class FirehoseJsonHandler {
|
||||
} else if (request.has("ExtendedS3DestinationConfiguration")) {
|
||||
s3 = mapper.treeToValue(request.get("ExtendedS3DestinationConfiguration"), S3Destination.class);
|
||||
}
|
||||
String arn = firehoseService.createDeliveryStream(name, s3);
|
||||
List<io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag> tags = new ArrayList<>();
|
||||
if (request.has("Tags")) {
|
||||
for (JsonNode tNode : request.get("Tags")) {
|
||||
tags.add(mapper.treeToValue(tNode, io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag.class));
|
||||
}
|
||||
}
|
||||
String arn = firehoseService.createDeliveryStream(name, s3, tags);
|
||||
yield Response.ok(Map.of("DeliveryStreamARN", arn)).build();
|
||||
}
|
||||
case "DescribeDeliveryStream" -> {
|
||||
@@ -72,6 +78,54 @@ public class FirehoseJsonHandler {
|
||||
.toList();
|
||||
yield Response.ok(Map.of("FailedPutCount", 0, "RequestResponses", responses)).build();
|
||||
}
|
||||
case "TagDeliveryStream" -> {
|
||||
String name = request.get("DeliveryStreamName").asText();
|
||||
List<io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag> tags = new ArrayList<>();
|
||||
if (request.has("Tags")) {
|
||||
for (JsonNode tNode : request.get("Tags")) {
|
||||
tags.add(mapper.treeToValue(tNode, io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag.class));
|
||||
}
|
||||
}
|
||||
firehoseService.tagDeliveryStream(name, tags);
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "UntagDeliveryStream" -> {
|
||||
String name = request.get("DeliveryStreamName").asText();
|
||||
List<String> keys = new ArrayList<>();
|
||||
if (request.has("TagKeys")) {
|
||||
for (JsonNode kNode : request.get("TagKeys")) {
|
||||
keys.add(kNode.asText());
|
||||
}
|
||||
}
|
||||
firehoseService.untagDeliveryStream(name, keys);
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListTagsForDeliveryStream" -> {
|
||||
String name = request.get("DeliveryStreamName").asText();
|
||||
String exclusiveStartTagKey = request.has("ExclusiveStartTagKey") ? request.get("ExclusiveStartTagKey").asText() : null;
|
||||
Integer limit = request.has("Limit") ? request.get("Limit").asInt() : null;
|
||||
|
||||
List<io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag> tags = firehoseService.listTagsForDeliveryStream(name, exclusiveStartTagKey, limit);
|
||||
boolean hasMore = false;
|
||||
var allTags = firehoseService.describeDeliveryStream(name).getTags();
|
||||
if (!tags.isEmpty() && !allTags.isEmpty()) {
|
||||
String lastKey = tags.get(tags.size() - 1).getKey();
|
||||
int idx = -1;
|
||||
for (int i = 0; i < allTags.size(); i++) {
|
||||
if (allTags.get(i).getKey().equals(lastKey)) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idx >= 0 && idx < allTags.size() - 1) {
|
||||
hasMore = true;
|
||||
}
|
||||
}
|
||||
yield Response.ok(Map.of(
|
||||
"Tags", tags,
|
||||
"HasMoreTags", hasMore
|
||||
)).build();
|
||||
}
|
||||
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,15 +41,69 @@ public class FirehoseService {
|
||||
}
|
||||
|
||||
public String createDeliveryStream(String name, S3Destination s3Config) {
|
||||
return createDeliveryStream(name, s3Config, List.of());
|
||||
}
|
||||
|
||||
public String createDeliveryStream(String name, S3Destination s3Config, List<DeliveryStreamDescription.Tag> tags) {
|
||||
String arn = AwsArnUtils.Arn.of("firehose", regionResolver.getDefaultRegion(), regionResolver.getAccountId(), "deliverystream/" + name).toString();
|
||||
DeliveryStreamDescription description = new DeliveryStreamDescription(name, arn, s3Config);
|
||||
description.setAccountId(regionResolver.getAccountId());
|
||||
description.setTags(tags);
|
||||
streamStore.put(name, description);
|
||||
buffers.put(name, Collections.synchronizedList(new ArrayList<>()));
|
||||
LOG.infov("Created Firehose delivery stream: {0}", name);
|
||||
return arn;
|
||||
}
|
||||
|
||||
public void tagDeliveryStream(String name, List<DeliveryStreamDescription.Tag> tagsToTag) {
|
||||
DeliveryStreamDescription stream = describeDeliveryStream(name);
|
||||
Map<String, String> tagMap = new LinkedHashMap<>();
|
||||
for (DeliveryStreamDescription.Tag t : stream.getTags()) {
|
||||
tagMap.put(t.getKey(), t.getValue());
|
||||
}
|
||||
for (DeliveryStreamDescription.Tag t : tagsToTag) {
|
||||
tagMap.put(t.getKey(), t.getValue());
|
||||
}
|
||||
List<DeliveryStreamDescription.Tag> newTags = new ArrayList<>();
|
||||
tagMap.forEach((k, v) -> newTags.add(new DeliveryStreamDescription.Tag(k, v)));
|
||||
stream.setTags(newTags);
|
||||
streamStore.put(name, stream);
|
||||
LOG.infov("Tagged Firehose delivery stream {0}: {1}", name, tagsToTag);
|
||||
}
|
||||
|
||||
public void untagDeliveryStream(String name, List<String> tagKeys) {
|
||||
DeliveryStreamDescription stream = describeDeliveryStream(name);
|
||||
List<DeliveryStreamDescription.Tag> newTags = new ArrayList<>();
|
||||
for (DeliveryStreamDescription.Tag t : stream.getTags()) {
|
||||
if (!tagKeys.contains(t.getKey())) {
|
||||
newTags.add(t);
|
||||
}
|
||||
}
|
||||
stream.setTags(newTags);
|
||||
streamStore.put(name, stream);
|
||||
LOG.infov("Untagged Firehose delivery stream {0}: {1}", name, tagKeys);
|
||||
}
|
||||
|
||||
public List<DeliveryStreamDescription.Tag> listTagsForDeliveryStream(String name, String exclusiveStartTagKey, Integer limit) {
|
||||
DeliveryStreamDescription stream = describeDeliveryStream(name);
|
||||
List<DeliveryStreamDescription.Tag> tags = stream.getTags();
|
||||
int startIndex = 0;
|
||||
if (exclusiveStartTagKey != null && !exclusiveStartTagKey.isEmpty()) {
|
||||
for (int i = 0; i < tags.size(); i++) {
|
||||
if (tags.get(i).getKey().equals(exclusiveStartTagKey)) {
|
||||
startIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int size = tags.size() - startIndex;
|
||||
int end = tags.size();
|
||||
if (limit != null && limit > 0 && limit < size) {
|
||||
end = startIndex + limit;
|
||||
}
|
||||
return new ArrayList<>(tags.subList(startIndex, end));
|
||||
}
|
||||
|
||||
public DeliveryStreamDescription describeDeliveryStream(String name) {
|
||||
return streamStore.get(name)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
|
||||
+27
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RegisterForReflection
|
||||
public class DeliveryStreamDescription {
|
||||
@@ -20,6 +21,8 @@ public class DeliveryStreamDescription {
|
||||
private Instant createTimestamp;
|
||||
@JsonProperty("Destinations")
|
||||
private List<Destination> destinations;
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public DeliveryStreamDescription() {}
|
||||
public DeliveryStreamDescription(String name, String arn, S3Destination s3) {
|
||||
@@ -99,4 +102,28 @@ public class DeliveryStreamDescription {
|
||||
public int getIntervalInSeconds() { return intervalInSeconds; }
|
||||
public void setIntervalInSeconds(int intervalInSeconds) { this.intervalInSeconds = intervalInSeconds; }
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
if (tags == null) tags = new ArrayList<>();
|
||||
return tags;
|
||||
}
|
||||
public void setTags(List<Tag> tags) { this.tags = tags; }
|
||||
|
||||
@RegisterForReflection
|
||||
public static class Tag {
|
||||
@JsonProperty("Key")
|
||||
private String key;
|
||||
@JsonProperty("Value")
|
||||
private String value;
|
||||
|
||||
public Tag() {}
|
||||
public Tag(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
public String getKey() { return key; }
|
||||
public void setKey(String key) { this.key = key; }
|
||||
public String getValue() { return value; }
|
||||
public void setValue(String value) { this.value = value; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user