Skip to content

Commit 6838a60

Browse files
treblereelfjtiradoricardozanini
authored
Add initial RunContainer Task support (#942)
* [Fix #933] Adding timeout support (#963) Signed-off-by: fjtirado <ftirados@redhat.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * [Fix #932] Workflow scheduler (#966) Signed-off-by: fjtirado <ftirados@redhat.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * Add initial RunContainer Task support Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * image pull before run Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * refactoring + tests Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * Review comments Signed-off-by: fjtirado <ftirados@redhat.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * Disable test if docker is not Signed-off-by: fjtirado <ftirados@redhat.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * Update impl/container/pom.xml Co-authored-by: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * post review Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> * name docker check method Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> --------- Signed-off-by: fjtirado <ftirados@redhat.com> Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com> Co-authored-by: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Co-authored-by: fjtirado <ftirados@redhat.com> Co-authored-by: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com>
1 parent 9b0b0a2 commit 6838a60

File tree

21 files changed

+1112
-0
lines changed

21 files changed

+1112
-0
lines changed

impl/container/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.serverlessworkflow</groupId>
8+
<artifactId>serverlessworkflow-impl</artifactId>
9+
<version>8.0.0-SNAPSHOT</version>
10+
</parent>
11+
<artifactId>serverlessworkflow-impl-container</artifactId>
12+
<name>Serverless Workflow :: Impl :: Container</name>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.serverlessworkflow</groupId>
17+
<artifactId>serverlessworkflow-impl-core</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.serverlessworkflow</groupId>
21+
<artifactId>serverlessworkflow-types</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.github.docker-java</groupId>
25+
<artifactId>docker-java-core</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.github.docker-java</groupId>
29+
<artifactId>docker-java-transport-httpclient5</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.container.executors;
17+
18+
import static io.serverlessworkflow.impl.WorkflowUtils.isValid;
19+
20+
import com.github.dockerjava.api.command.CreateContainerCmd;
21+
import io.serverlessworkflow.api.types.Container;
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 {
31+
32+
private Optional<WorkflowValueResolver<String>> command;
33+
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();
40+
}
41+
42+
@Override
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));
51+
}
52+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.container.executors;
17+
18+
import com.github.dockerjava.api.command.CreateContainerCmd;
19+
import io.serverlessworkflow.api.types.Container;
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;
26+
import java.util.Map;
27+
import java.util.Optional;
28+
29+
class ContainerEnvironmentPropertySetter implements ContainerPropertySetter {
30+
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();
44+
}
45+
46+
@Override
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()));
58+
}
59+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.container.executors;
17+
18+
import com.github.dockerjava.api.command.CreateContainerCmd;
19+
import io.serverlessworkflow.impl.TaskContext;
20+
import io.serverlessworkflow.impl.WorkflowContext;
21+
import io.serverlessworkflow.impl.WorkflowModel;
22+
23+
interface ContainerPropertySetter {
24+
abstract void accept(
25+
CreateContainerCmd command,
26+
WorkflowContext workflowContext,
27+
TaskContext taskContext,
28+
WorkflowModel model);
29+
}

0 commit comments

Comments
 (0)