Skip to content

Commit eebaace

Browse files
author
Mathieu Gabelle
committed
refactor: move Kinesis and eventbridge to dynamic properties
1 parent de13b2e commit eebaace

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/main/java/io/kestra/plugin/aws/eventbridge/PutEvents.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.kestra.core.models.executions.metrics.Counter;
1111
import io.kestra.core.models.executions.metrics.Timer;
1212
import io.kestra.core.models.flows.State;
13+
import io.kestra.core.models.property.Property;
1314
import io.kestra.core.models.tasks.RunnableTask;
1415
import io.kestra.core.runners.RunContext;
1516
import io.kestra.core.serializers.FileSerde;
@@ -96,14 +97,13 @@ public class PutEvents extends AbstractConnection implements RunnableTask<PutEve
9697
private static final ObjectMapper MAPPER = JacksonMapper.ofIon()
9798
.setSerializationInclusion(JsonInclude.Include.ALWAYS);
9899

99-
@PluginProperty(dynamic = false)
100100
@NotNull
101101
@Schema(
102102
title = "Mark the task as failed when sending an event is unsuccessful.",
103103
description = "If true, the task will fail when any event fails to be sent."
104104
)
105105
@Builder.Default
106-
private boolean failOnUnsuccessfulEvents = true;
106+
private Property<Boolean> failOnUnsuccessfulEvents = Property.of(true);
107107

108108
@PluginProperty(dynamic = true)
109109
@NotNull
@@ -129,7 +129,7 @@ public PutEvents.Output run(RunContext runContext) throws Exception {
129129
runContext.metric(Counter.of("entryCount", entryList.size()));
130130

131131
// Fail if failOnUnsuccessfulEvents
132-
if (failOnUnsuccessfulEvents && putEventsResponse.failedEntryCount() > 0) {
132+
if (runContext.render(failOnUnsuccessfulEvents).as(Boolean.class).orElseThrow() && putEventsResponse.failedEntryCount() > 0) {
133133
var logger = runContext.logger();
134134
logger.error("Response show {} event failed: {}", putEventsResponse.failedEntryCount(), putEventsResponse);
135135
throw new RuntimeException(String.format("Response show %d event failed: %s", putEventsResponse.failedEntryCount(), putEventsResponse));

src/main/java/io/kestra/plugin/aws/kinesis/PutRecords.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.kestra.core.models.executions.metrics.Counter;
1212
import io.kestra.core.models.executions.metrics.Timer;
1313
import io.kestra.core.models.flows.State;
14+
import io.kestra.core.models.property.Property;
1415
import io.kestra.core.models.tasks.RunnableTask;
1516
import io.kestra.core.runners.RunContext;
1617
import io.kestra.core.serializers.FileSerde;
@@ -82,7 +83,7 @@
8283
secretKeyId: "<secret-key>"
8384
region: "eu-central-1"
8485
streamName: "mystream"
85-
records: kestra:///myfile.ion
86+
records: kestra:///myfile.ion
8687
"""
8788
)
8889
}
@@ -94,28 +95,25 @@ public class PutRecords extends AbstractConnection implements RunnableTask<PutRe
9495
private static final ObjectMapper MAPPER = JacksonMapper.ofIon()
9596
.setSerializationInclusion(JsonInclude.Include.ALWAYS);
9697

97-
@PluginProperty
9898
@NotNull
9999
@Schema(
100100
title = "Mark the task as failed when sending a record is unsuccessful.",
101101
description = "If true, the task will fail when any record fails to be sent."
102102
)
103103
@Builder.Default
104-
private boolean failOnUnsuccessfulRecords = true;
104+
private Property<Boolean> failOnUnsuccessfulRecords = Property.of(true);
105105

106-
@PluginProperty(dynamic = true)
107106
@Schema(
108107
title = "The name of the stream to push the records.",
109108
description = "Make sure to set either `streamName` or `streamArn`. One of those must be provided."
110109
)
111-
private String streamName;
110+
private Property<String> streamName;
112111

113-
@PluginProperty(dynamic = true)
114112
@Schema(
115113
title = "The ARN of the stream to push the records.",
116114
description = "Make sure to set either `streamName` or `streamArn`. One of those must be provided."
117115
)
118-
private String streamArn;
116+
private Property<String> streamArn;
119117

120118
@PluginProperty(dynamic = true)
121119
@Schema(
@@ -135,7 +133,7 @@ public Output run(RunContext runContext) throws Exception {
135133
PutRecordsResponse putRecordsResponse = putRecords(runContext, records);
136134

137135
// Fail if failOnUnsuccessfulRecords
138-
if (failOnUnsuccessfulRecords && putRecordsResponse.failedRecordCount() > 0) {
136+
if (runContext.render(failOnUnsuccessfulRecords).as(Boolean.class).orElseThrow() && putRecordsResponse.failedRecordCount() > 0) {
139137
var logger = runContext.logger();
140138
logger.error("Response show {} record failed: {}", putRecordsResponse.failedRecordCount(), putRecordsResponse);
141139
throw new RuntimeException(String.format("Response show %d record failed: %s", putRecordsResponse.failedRecordCount(), putRecordsResponse));
@@ -159,10 +157,12 @@ private PutRecordsResponse putRecords(RunContext runContext, List<Record> record
159157
try (KinesisClient client = client(runContext)) {
160158
PutRecordsRequest.Builder builder = PutRecordsRequest.builder();
161159

162-
if (!Strings.isNullOrEmpty(streamArn)) {
163-
builder.streamARN(streamArn);
164-
} else if (!Strings.isNullOrEmpty(streamName)) {
165-
builder.streamName(streamName);
160+
var renderedStreamArn = runContext.render(streamArn).as(String.class).orElse(null);
161+
var renderedStreamName = runContext.render(streamName).as(String.class).orElse(null);
162+
if (!Strings.isNullOrEmpty(renderedStreamArn)) {
163+
builder.streamARN(renderedStreamArn);
164+
} else if (!Strings.isNullOrEmpty(renderedStreamName)) {
165+
builder.streamName(renderedStreamName);
166166
} else {
167167
throw new IllegalArgumentException("Either streamName or streamArn has to be set.");
168168
}

src/test/java/io/kestra/plugin/aws/kinesis/PutRecordsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void runMap() throws Exception {
121121
.region(Property.of(localstack.getRegion()))
122122
.accessKeyId(Property.of(localstack.getAccessKey()))
123123
.secretKeyId(Property.of(localstack.getSecretKey()))
124-
.streamName("streamName")
124+
.streamName(Property.of("streamName"))
125125
.records(List.of(record, record2, record3))
126126
.build();
127127

@@ -174,7 +174,7 @@ void runStorage() throws Exception {
174174
.accessKeyId(Property.of(localstack.getAccessKey()))
175175
.secretKeyId(Property.of(localstack.getSecretKey()))
176176
.records(runContext.storage().putFile(tempFile).toString())
177-
.streamName("streamName")
177+
.streamName(Property.of("streamName"))
178178
.build();
179179

180180

@@ -227,7 +227,7 @@ void runStorageUpperCase() throws Exception {
227227
.accessKeyId(Property.of(localstack.getAccessKey()))
228228
.secretKeyId(Property.of(localstack.getSecretKey()))
229229
.records(runContext.storage().putFile(tempFile).toString())
230-
.streamName("streamName")
230+
.streamName(Property.of("streamName"))
231231
.build();
232232

233233

0 commit comments

Comments
 (0)