Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/com.google.guava-guava-32…
Browse files Browse the repository at this point in the history
….0.0-jre
  • Loading branch information
andresgomezfrr authored Aug 11, 2023
2 parents 3f709f3 + 3264398 commit e5581a9
Show file tree
Hide file tree
Showing 34 changed files with 367 additions and 109 deletions.
2 changes: 1 addition & 1 deletion flyteidl-protos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flyte</groupId>
<artifactId>flytekit-parent</artifactId>
<version>0.4.20-SNAPSHOT</version>
<version>0.4.21-SNAPSHOT</version>
</parent>

<artifactId>flyteidl-protos</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flytekit-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flyte</groupId>
<artifactId>flytekit-parent</artifactId>
<version>0.4.20-SNAPSHOT</version>
<version>0.4.21-SNAPSHOT</version>
</parent>

<artifactId>flytekit-api</artifactId>
Expand Down
41 changes: 41 additions & 0 deletions flytekit-api/src/main/java/org/flyte/api/v1/OnFailurePolicy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2021 Flyte Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.flyte.api.v1;

import com.google.auto.value.AutoValue;

/** Failure Handling Strategy. */
@AutoValue
public abstract class OnFailurePolicy {
public enum Kind {
FAIL_IMMEDIATELY,
FAIL_AFTER_EXECUTABLE_NODES_COMPLETE
}

public abstract Kind getKind();

public static OnFailurePolicy.Builder builder() {
return new AutoValue_OnFailurePolicy.Builder();
}

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder kind(Kind kind);

public abstract OnFailurePolicy build();
}
}
9 changes: 6 additions & 3 deletions flytekit-api/src/main/java/org/flyte/api/v1/RunnableTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@

import static java.util.Collections.emptyMap;

import java.util.List;

/** Building block for tasks that execute Java code. */
public interface RunnableTask extends Task, RunnableNode {

@Override
default String getType() {
// FIXME default only for backwards-compatibility, remove in 0.3.x
return "java-task";
}

@Override
default Struct getCustom() {
// FIXME default only for backwards-compatibility, remove in 0.3.x
return Struct.of(emptyMap());
}

default Resources getResources() {
// FIXME default only for backwards-compatibility, remove in 0.3.x
return Resources.builder().build();
}

default List<String> getCustomJavaToolOptions() {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@
package org.flyte.api.v1;

import com.google.auto.value.AutoValue;
import org.flyte.api.v1.OnFailurePolicy.Kind;

/** Metadata for the entire workflow. */
@AutoValue
public class WorkflowMetadata {
public abstract class WorkflowMetadata {

public abstract OnFailurePolicy onFailure();

public static Builder builder() {
return new AutoValue_WorkflowMetadata.Builder();
return new AutoValue_WorkflowMetadata.Builder()
.onFailure(OnFailurePolicy.builder().kind(Kind.FAIL_IMMEDIATELY).build());
}

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder onFailure(OnFailurePolicy onFailure);

public abstract WorkflowMetadata build();
}
}
2 changes: 1 addition & 1 deletion flytekit-examples-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flyte</groupId>
<artifactId>flytekit-parent</artifactId>
<version>0.4.20-SNAPSHOT</version>
<version>0.4.21-SNAPSHOT</version>
</parent>

<artifactId>flytekit-examples-scala</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flytekit-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flyte</groupId>
<artifactId>flytekit-parent</artifactId>
<version>0.4.20-SNAPSHOT</version>
<version>0.4.21-SNAPSHOT</version>
</parent>

<artifactId>flytekit-examples</artifactId>
Expand Down
42 changes: 10 additions & 32 deletions flytekit-examples/src/main/java/org/flyte/examples/SubWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,28 @@
package org.flyte.examples;

import com.google.auto.service.AutoService;
import com.google.auto.value.AutoValue;
import org.flyte.flytekit.SdkBindingData;
import org.flyte.flytekit.SdkWorkflow;
import org.flyte.flytekit.SdkWorkflowBuilder;
import org.flyte.flytekit.jackson.Description;
import org.flyte.flytekit.jackson.JacksonSdkType;

@AutoService(SdkWorkflow.class)
public class SubWorkflow extends SdkWorkflow<SubWorkflow.Input, SubWorkflow.Output> {
public class SubWorkflow extends SdkWorkflow<WelcomeWorkflow.Input, WelcomeWorkflow.Output> {

public SubWorkflow() {
super(JacksonSdkType.of(SubWorkflow.Input.class), JacksonSdkType.of(SubWorkflow.Output.class));
super(
JacksonSdkType.of(WelcomeWorkflow.Input.class),
JacksonSdkType.of(WelcomeWorkflow.Output.class));
}

@Override
public Output expand(SdkWorkflowBuilder builder, Input input) {
SdkBindingData<Long> result =
public WelcomeWorkflow.Output expand(SdkWorkflowBuilder builder, WelcomeWorkflow.Input input) {
SdkBindingData<String> greeting =
builder
.apply("sum", new SumTask(), SumTask.SumInput.create(input.left(), input.right()))
.getOutputs();
return Output.create(result);
}

// Used in testing to mock this workflow
@AutoValue
public abstract static class Input {
@Description("First operand")
abstract SdkBindingData<Long> left();

@Description("Second operand")
abstract SdkBindingData<Long> right();

public static Input create(SdkBindingData<Long> left, SdkBindingData<Long> right) {
return new AutoValue_SubWorkflow_Input(left, right);
}
}

@AutoValue
public abstract static class Output {
@Description("Summed results")
abstract SdkBindingData<Long> result();
.apply("greet", new WelcomeWorkflow(), WelcomeWorkflow.Input.create(input.name()))
.getOutputs()
.greeting();

public static Output create(SdkBindingData<Long> result) {
return new AutoValue_SubWorkflow_Output(result);
}
return WelcomeWorkflow.Output.create(greeting);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2021 Flyte Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.flyte.examples;

import com.google.auto.service.AutoService;
import com.google.auto.value.AutoValue;
import org.flyte.flytekit.SdkBindingData;
import org.flyte.flytekit.SdkWorkflow;
import org.flyte.flytekit.SdkWorkflowBuilder;
import org.flyte.flytekit.jackson.Description;
import org.flyte.flytekit.jackson.JacksonSdkType;

@AutoService(SdkWorkflow.class)
public class SumWorkflow extends SdkWorkflow<SumWorkflow.Input, SumWorkflow.Output> {

public SumWorkflow() {
super(JacksonSdkType.of(SumWorkflow.Input.class), JacksonSdkType.of(SumWorkflow.Output.class));
}

@Override
public Output expand(SdkWorkflowBuilder builder, Input input) {
SdkBindingData<Long> result =
builder
.apply("sum", new SumTask(), SumTask.SumInput.create(input.left(), input.right()))
.getOutputs();
return Output.create(result);
}

// Used in testing to mock this workflow
@AutoValue
public abstract static class Input {
@Description("First operand")
abstract SdkBindingData<Long> left();

@Description("Second operand")
abstract SdkBindingData<Long> right();

public static Input create(SdkBindingData<Long> left, SdkBindingData<Long> right) {
return new AutoValue_SumWorkflow_Input(left, right);
}
}

@AutoValue
public abstract static class Output {
@Description("Summed results")
abstract SdkBindingData<Long> result();

public static Output create(SdkBindingData<Long> result) {
return new AutoValue_SumWorkflow_Output(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.flyte.flytekit.jackson.JacksonSdkType;

@AutoService(SdkWorkflow.class)
public class UberWorkflow extends SdkWorkflow<UberWorkflow.Input, SubWorkflow.Output> {
public class UberWorkflow extends SdkWorkflow<UberWorkflow.Input, SumWorkflow.Output> {

@AutoValue
public abstract static class Input {
Expand All @@ -47,27 +47,27 @@ public static UberWorkflow.Input create(
}

public UberWorkflow() {
super(JacksonSdkType.of(UberWorkflow.Input.class), JacksonSdkType.of(SubWorkflow.Output.class));
super(JacksonSdkType.of(UberWorkflow.Input.class), JacksonSdkType.of(SumWorkflow.Output.class));
}

@Override
public SubWorkflow.Output expand(SdkWorkflowBuilder builder, Input input) {
public SumWorkflow.Output expand(SdkWorkflowBuilder builder, Input input) {
SdkBindingData<Long> a = input.a();
SdkBindingData<Long> b = input.b();
SdkBindingData<Long> c = input.c();
SdkBindingData<Long> d = input.d();
SdkBindingData<Long> ab =
builder
.apply("sub-1", new SubWorkflow(), SubWorkflow.Input.create(a, b))
.apply("sub-1", new SumWorkflow(), SumWorkflow.Input.create(a, b))
.getOutputs()
.result();
SdkBindingData<Long> abc =
builder
.apply("sub-2", new SubWorkflow(), SubWorkflow.Input.create(ab, c))
.apply("sub-2", new SumWorkflow(), SumWorkflow.Input.create(ab, c))
.getOutputs()
.result();
SdkBindingData<Long> abcd =
builder.apply("post-sum", new SumTask(), SumTask.SumInput.create(abc, d)).getOutputs();
return SubWorkflow.Output.create(abcd);
return SumWorkflow.Output.create(abcd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/** Example workflow that takes a name and outputs a welcome message. */
@AutoService(SdkWorkflow.class)
public class WelcomeWorkflow extends SdkWorkflow<WelcomeWorkflow.Input, AddQuestionTask.Output> {
public class WelcomeWorkflow extends SdkWorkflow<WelcomeWorkflow.Input, WelcomeWorkflow.Output> {

@AutoValue
public abstract static class Input {
Expand All @@ -38,14 +38,23 @@ public static WelcomeWorkflow.Input create(SdkBindingData<String> name) {
}
}

@AutoValue
public abstract static class Output {
public abstract SdkBindingData<String> greeting();

public static Output create(SdkBindingData<String> greeting) {
return new AutoValue_WelcomeWorkflow_Output(greeting);
}
}

public WelcomeWorkflow() {
super(
JacksonSdkType.of(WelcomeWorkflow.Input.class),
JacksonSdkType.of(AddQuestionTask.Output.class));
JacksonSdkType.of(WelcomeWorkflow.Output.class));
}

@Override
public AddQuestionTask.Output expand(SdkWorkflowBuilder builder, Input input) {
public WelcomeWorkflow.Output expand(SdkWorkflowBuilder builder, Input input) {
// uses the workflow input as the task input of the GreetTask
SdkBindingData<String> greeting =
builder
Expand All @@ -60,6 +69,6 @@ public AddQuestionTask.Output expand(SdkWorkflowBuilder builder, Input input) {
.getOutputs()
.greeting();

return AddQuestionTask.Output.create(greetingWithQuestion);
return WelcomeWorkflow.Output.create(greetingWithQuestion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ public class WorkflowTest {
@Test
public void testSubWorkflow() {
SdkTestingExecutor.Result result =
SdkTestingExecutor.of(new UberWorkflow())
.withFixedInput("a", 1)
.withFixedInput("b", 2)
.withFixedInput("c", 3)
.withFixedInput("d", 4)
.execute();
SdkTestingExecutor.of(new SubWorkflow()).withFixedInput("name", "foo").execute();

assertEquals(10L, result.getIntegerOutput("result"));
assertEquals("Welcome, foo! How are you?", result.getStringOutput("greeting"));
}

@Test
Expand Down Expand Up @@ -75,19 +70,19 @@ public void testMockSubWorkflow() {
// Deliberately mock with absurd values to make sure that we are not picking the
// SumTask implementation
.withWorkflowOutput(
new SubWorkflow(),
JacksonSdkType.of(SubWorkflow.Input.class),
SubWorkflow.Input.create(
new SumWorkflow(),
JacksonSdkType.of(SumWorkflow.Input.class),
SumWorkflow.Input.create(
SdkBindingDataFactory.of(1L), SdkBindingDataFactory.of(2L)),
JacksonSdkType.of(SubWorkflow.Output.class),
SubWorkflow.Output.create(SdkBindingDataFactory.of(5L)))
JacksonSdkType.of(SumWorkflow.Output.class),
SumWorkflow.Output.create(SdkBindingDataFactory.of(5L)))
.withWorkflowOutput(
new SubWorkflow(),
JacksonSdkType.of(SubWorkflow.Input.class),
SubWorkflow.Input.create(
new SumWorkflow(),
JacksonSdkType.of(SumWorkflow.Input.class),
SumWorkflow.Input.create(
SdkBindingDataFactory.of(5L), SdkBindingDataFactory.of(3L)),
JacksonSdkType.of(SubWorkflow.Output.class),
SubWorkflow.Output.create(SdkBindingDataFactory.of(10L)))
JacksonSdkType.of(SumWorkflow.Output.class),
SumWorkflow.Output.create(SdkBindingDataFactory.of(10L)))
.withTaskOutput(
new SumTask(),
SumInput.create(SdkBindingDataFactory.of(10L), SdkBindingDataFactory.of(4L)),
Expand Down
Loading

0 comments on commit e5581a9

Please sign in to comment.