Skip to content

Commit 38b472d

Browse files
fjtiradotreblereel
authored andcommitted
Review comments
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent 24b213a commit 38b472d

File tree

17 files changed

+326
-293
lines changed

17 files changed

+326
-293
lines changed

impl/container/src/main/java/io/serverlessworkflow/impl/container/executors/CommandPropertySetter.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,38 @@
1515
*/
1616
package io.serverlessworkflow.impl.container.executors;
1717

18+
import static io.serverlessworkflow.impl.WorkflowUtils.isValid;
19+
1820
import com.github.dockerjava.api.command.CreateContainerCmd;
1921
import io.serverlessworkflow.api.types.Container;
20-
import java.util.function.Function;
22+
import io.serverlessworkflow.impl.TaskContext;
23+
import io.serverlessworkflow.impl.WorkflowContext;
24+
import io.serverlessworkflow.impl.WorkflowDefinition;
25+
import io.serverlessworkflow.impl.WorkflowModel;
26+
import io.serverlessworkflow.impl.WorkflowUtils;
27+
import io.serverlessworkflow.impl.WorkflowValueResolver;
28+
import java.util.Optional;
29+
30+
class CommandPropertySetter implements ContainerPropertySetter {
2131

22-
class CommandPropertySetter extends ContainerPropertySetter {
32+
private Optional<WorkflowValueResolver<String>> command;
2333

24-
CommandPropertySetter(CreateContainerCmd createContainerCmd, Container configuration) {
25-
super(createContainerCmd, configuration);
34+
CommandPropertySetter(WorkflowDefinition definition, Container configuration) {
35+
String commandName = configuration.getCommand();
36+
command =
37+
isValid(commandName)
38+
? Optional.of(WorkflowUtils.buildStringFilter(definition.application(), commandName))
39+
: Optional.empty();
2640
}
2741

2842
@Override
29-
public void accept(Function<String, String> resolver) {
30-
if (configuration.getCommand() != null && !configuration.getCommand().isEmpty()) {
31-
createContainerCmd.withCmd("sh", "-c", configuration.getCommand());
32-
}
43+
public void accept(
44+
CreateContainerCmd containerCmd,
45+
WorkflowContext workflowContext,
46+
TaskContext taskContext,
47+
WorkflowModel model) {
48+
command
49+
.map(c -> c.apply(workflowContext, taskContext, model))
50+
.ifPresent(c -> containerCmd.withCmd("sh", "-c", c));
3351
}
3452
}

impl/container/src/main/java/io/serverlessworkflow/impl/container/executors/ContainerEnvironmentPropertySetter.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,43 @@
1717

1818
import com.github.dockerjava.api.command.CreateContainerCmd;
1919
import io.serverlessworkflow.api.types.Container;
20-
import java.util.ArrayList;
21-
import java.util.List;
20+
import io.serverlessworkflow.impl.TaskContext;
21+
import io.serverlessworkflow.impl.WorkflowContext;
22+
import io.serverlessworkflow.impl.WorkflowDefinition;
23+
import io.serverlessworkflow.impl.WorkflowModel;
24+
import io.serverlessworkflow.impl.WorkflowUtils;
25+
import io.serverlessworkflow.impl.WorkflowValueResolver;
2226
import java.util.Map;
23-
import java.util.function.Function;
27+
import java.util.Optional;
2428

25-
class ContainerEnvironmentPropertySetter extends ContainerPropertySetter {
29+
class ContainerEnvironmentPropertySetter implements ContainerPropertySetter {
2630

27-
ContainerEnvironmentPropertySetter(
28-
CreateContainerCmd createContainerCmd, Container configuration) {
29-
super(createContainerCmd, configuration);
31+
private final Optional<WorkflowValueResolver<Map<String, Object>>> envResolver;
32+
33+
ContainerEnvironmentPropertySetter(WorkflowDefinition definition, Container configuration) {
34+
35+
this.envResolver =
36+
configuration.getEnvironment() != null
37+
&& configuration.getEnvironment().getAdditionalProperties() != null
38+
? Optional.of(
39+
WorkflowUtils.buildMapResolver(
40+
definition.application(),
41+
null,
42+
configuration.getEnvironment().getAdditionalProperties()))
43+
: Optional.empty();
3044
}
3145

3246
@Override
33-
public void accept(Function<String, String> resolver) {
34-
if (!(configuration.getEnvironment() == null
35-
|| configuration.getEnvironment().getAdditionalProperties() == null)) {
36-
List<String> envs = new ArrayList<>();
37-
for (Map.Entry<String, Object> entry :
38-
configuration.getEnvironment().getAdditionalProperties().entrySet()) {
39-
String key = entry.getKey();
40-
if (entry.getValue() instanceof String value) {
41-
String resolvedValue = resolver.apply(value);
42-
envs.add(key + "=" + resolvedValue);
43-
} else {
44-
throw new IllegalArgumentException("Environment variable values must be strings");
45-
}
46-
}
47-
createContainerCmd.withEnv(envs.toArray(new String[0]));
48-
}
47+
public void accept(
48+
CreateContainerCmd command,
49+
WorkflowContext workflowContext,
50+
TaskContext taskContext,
51+
WorkflowModel model) {
52+
envResolver
53+
.map(env -> env.apply(workflowContext, taskContext, model))
54+
.ifPresent(
55+
envs ->
56+
command.withEnv(
57+
envs.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).toList()));
4958
}
5059
}

impl/container/src/main/java/io/serverlessworkflow/impl/container/executors/ContainerPropertySetter.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
package io.serverlessworkflow.impl.container.executors;
1717

1818
import com.github.dockerjava.api.command.CreateContainerCmd;
19-
import io.serverlessworkflow.api.types.Container;
20-
import java.util.function.Consumer;
21-
import java.util.function.Function;
19+
import io.serverlessworkflow.impl.TaskContext;
20+
import io.serverlessworkflow.impl.WorkflowContext;
21+
import io.serverlessworkflow.impl.WorkflowModel;
2222

23-
abstract class ContainerPropertySetter implements Consumer<Function<String, String>> {
24-
25-
protected final CreateContainerCmd createContainerCmd;
26-
protected final Container configuration;
27-
28-
ContainerPropertySetter(CreateContainerCmd createContainerCmd, Container configuration) {
29-
this.createContainerCmd = createContainerCmd;
30-
this.configuration = configuration;
31-
}
23+
interface ContainerPropertySetter {
24+
abstract void accept(
25+
CreateContainerCmd command,
26+
WorkflowContext workflowContext,
27+
TaskContext taskContext,
28+
WorkflowModel model);
3229
}

0 commit comments

Comments
 (0)