Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification 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 io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallGRPC;
import io.serverlessworkflow.api.types.GRPCArguments;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import io.serverlessworkflow.fluent.spec.spi.CallGrpcTaskFluent;

public class FuncCallGrpcTaskBuilder extends TaskBaseBuilder<FuncCallGrpcTaskBuilder>
implements CallGrpcTaskFluent<FuncCallGrpcTaskBuilder>,
FuncTaskTransformations<FuncCallGrpcTaskBuilder>,
ConditionalTaskBuilder<FuncCallGrpcTaskBuilder> {

FuncCallGrpcTaskBuilder() {
final CallGRPC callGRPC = new CallGRPC();
callGRPC.setWith(new GRPCArguments());
super.setTask(callGRPC);
}

@Override
public FuncCallGrpcTaskBuilder self() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public FuncDoTaskBuilder openapi(
return this;
}

@Override
public FuncDoTaskBuilder grpc(String name, Consumer<FuncCallGrpcTaskBuilder> itemsConfigurer) {
this.listBuilder().grpc(name, itemsConfigurer);
return this;
}

@Override
public FuncDoTaskBuilder workflow(String name, Consumer<WorkflowTaskBuilder> itemsConfigurer) {
this.listBuilder().workflow(name, itemsConfigurer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallGRPC;
import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.CallOpenAPI;
import io.serverlessworkflow.api.types.CallTask;
Expand Down Expand Up @@ -168,6 +169,23 @@ public FuncTaskItemListBuilder openapi(
return this.addTaskItem(new TaskItem(name, task));
}

@Override
public FuncTaskItemListBuilder grpc(
String name, Consumer<FuncCallGrpcTaskBuilder> itemsConfigurer) {
name = this.defaultNameAndRequireConfig(name, itemsConfigurer, TYPE_GRPC);

final FuncCallGrpcTaskBuilder grpcTaskBuilder = new FuncCallGrpcTaskBuilder();
itemsConfigurer.accept(grpcTaskBuilder);

final CallGRPC callGRPC = grpcTaskBuilder.build();
final CallTask callTask = new CallTask();
callTask.setCallGRPC(callGRPC);
final Task task = new Task();
task.setCallTask(callTask);

return this.addTaskItem(new TaskItem(name, task));
}

@Override
public FuncTaskItemListBuilder workflow(
String name, Consumer<WorkflowTaskBuilder> itemsConfigurer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification 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 io.serverlessworkflow.fluent.func.configurers;

import io.serverlessworkflow.fluent.func.FuncCallGrpcTaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface FuncCallGrpcConfigurer extends Consumer<FuncCallGrpcTaskBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification 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 io.serverlessworkflow.fluent.func.dsl;

import io.serverlessworkflow.fluent.func.FuncCallGrpcTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;
import io.serverlessworkflow.fluent.spec.configurers.AuthenticationConfigurer;
import io.serverlessworkflow.fluent.spec.spi.CallGrpcTaskFluent;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class FuncCallGrpcStep extends Step<FuncCallGrpcStep, FuncCallGrpcTaskBuilder> {

private final List<Consumer<CallGrpcTaskFluent<?>>> steps = new ArrayList<>();

private String name;

public FuncCallGrpcStep(String name) {
this.name = name;
}

public FuncCallGrpcStep() {}

public void setName(String name) {
this.name = name;
}

public FuncCallGrpcStep proto(String uri) {
steps.add(b -> b.proto(uri));
return this;
}

public FuncCallGrpcStep proto(String uri, AuthenticationConfigurer authenticationConfigurer) {
steps.add(b -> b.proto(uri, authenticationConfigurer));
return this;
}

public FuncCallGrpcStep service(String name, String host) {
steps.add(b -> b.service(name, host));
return this;
}

public FuncCallGrpcStep service(String name, String host, int port) {
steps.add(b -> b.service(name, host, port));
return this;
}

public FuncCallGrpcStep method(String method) {
steps.add(b -> b.method(method));
return this;
}

public FuncCallGrpcStep argument(String name, Object value) {
steps.add(b -> b.argument(name, value));
return this;
}

public FuncCallGrpcStep arguments(java.util.Map<String, Object> arguments) {
steps.add(b -> b.arguments(arguments));
return this;
}

public FuncCallGrpcStep authentication(AuthenticationConfigurer authenticationConfigurer) {
steps.add(b -> b.authentication(authenticationConfigurer));
return this;
}

@Override
protected void configure(FuncTaskItemListBuilder list, Consumer<FuncCallGrpcTaskBuilder> post) {
list.grpc(
name,
builder -> {
for (Consumer<CallGrpcTaskFluent<?>> c : steps) {
c.accept(builder);
}
post.accept(builder);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;
import io.serverlessworkflow.fluent.func.FuncTryTaskBuilder;
import io.serverlessworkflow.fluent.func.configurers.FuncCallGrpcConfigurer;
import io.serverlessworkflow.fluent.func.configurers.FuncCallHttpConfigurer;
import io.serverlessworkflow.fluent.func.configurers.FuncCallOpenAPIConfigurer;
import io.serverlessworkflow.fluent.func.configurers.FuncTaskConfigurer;
Expand Down Expand Up @@ -1946,19 +1947,90 @@ public static FuncTaskConfigurer call(String name, FuncCallOpenAPIConfigurer con
return list -> list.openapi(name, configurer);
}

/**
* gRPC call using a fluent {@link FuncCallGrpcStep}.
*
* <p>This overload creates an unnamed gRPC call task.
*
* <pre>{@code
* tasks(FuncDSL.call(FuncDSL.grpc()
* .proto("proto/greeter.proto")
* .service("Greeter", "localhost")
* .method("SayHello")
* .argument("name", "World")));
* }</pre>
*
* @param spec fluent gRPC spec built via {@link #grpc()}
* @return a {@link FuncTaskConfigurer} that adds a gRPC call task
*/
public static FuncTaskConfigurer call(FuncCallGrpcStep spec) {
return call(null, spec);
}
Comment thread
matheusandre1 marked this conversation as resolved.

/**
* gRPC call using a fluent {@link FuncCallGrpcStep} with an explicit task name.
*
* <pre>{@code
* tasks(
* FuncDSL.call(
* "greet",
* FuncDSL.grpc()
* .proto("proto/greeter.proto")
* .service("Greeter", "localhost")
* .method("SayHello")
* .argument("name", "World"))
* );
* }</pre>
*
* @param name task name, or {@code null} for an anonymous task
* @param spec fluent gRPC spec built via {@link #grpc()}
* @return a {@link FuncTaskConfigurer} that adds a named gRPC call task
*/
public static FuncTaskConfigurer call(String name, FuncCallGrpcStep spec) {
Objects.requireNonNull(spec, "spec");
spec.setName(name);
return spec;
}

/**
* Low-level gRPC call entrypoint using a {@link FuncCallGrpcConfigurer}.
*
* <p>This overload creates an unnamed gRPC call task.
*
* @param configurer configurer that mutates the underlying gRPC call builder
* @return a {@link FuncTaskConfigurer} that adds a gRPC call task
*/
public static FuncTaskConfigurer call(FuncCallGrpcConfigurer configurer) {
return call(null, configurer);
}

/**
* Low-level gRPC call entrypoint using a {@link FuncCallGrpcConfigurer}.
*
* <p>This overload allows assigning an explicit task name.
*
* @param name task name, or {@code null} for an anonymous task
* @param configurer configurer that mutates the underlying gRPC call builder
* @return a {@link FuncTaskConfigurer} that adds a gRPC call task
*/
public static FuncTaskConfigurer call(String name, FuncCallGrpcConfigurer configurer) {
Objects.requireNonNull(configurer, "configurer");
return list -> list.grpc(name, configurer);
}

/**
* Create a new OpenAPI specification to be used with {@link #call(FuncCallOpenAPIStep)}.
*
* <p>Typical usage:
*
* <pre>{@code
* FuncDSL.call(openapi().document("https://petstore.swagger.io/v2/swagger.json", DSL.auth("openapi-auth")).operation("getPetById").parameter("id", 123));
* FuncDSL.call(
* openapi()
* .document("https://petstore.swagger.io/v2/swagger.json")
* .operation("getPetById"))
* );
* }</pre>
*
* <p>The returned spec is a fluent builder that records operations (document, operation,
* parameters, authentication, etc.) and applies them to the underlying OpenAPI call task at build
* time.
*
* @return a new {@link FuncCallOpenAPIStep}
*/
public static FuncCallOpenAPIStep openapi() {
Expand All @@ -1977,7 +2049,37 @@ public static FuncCallOpenAPIStep openapi(String name) {
}

/**
* Create a new, empty HTTP specification to be used with {@link #call(FuncCallHttpStep)}.
* Create a new gRPC specification to be used with {@link #call(FuncCallGrpcStep)}.
*
* <p>Typical usage:
*
Comment thread
matheusandre1 marked this conversation as resolved.
* <pre>{@code
* FuncDSL.call(
* grpc()
* .proto("proto/greeter.proto")
* .service("Greeter", "localhost")
* .method("SayHello")
* .argument("name", "World"));
* }</pre>
*
* @return a new {@link FuncCallGrpcStep}
*/
public static FuncCallGrpcStep grpc() {
return new FuncCallGrpcStep();
}

/**
* Named variant of {@link #grpc()}.
*
* @param name task name to be used when the spec is attached via {@link #call(FuncCallGrpcStep)}
* @return a new named {@link FuncCallGrpcStep}
*/
public static FuncCallGrpcStep grpc(String name) {
return new FuncCallGrpcStep(name);
}

/**
* Create a new HTTP specification to be used with {@link #call(FuncCallHttpStep)}.
*
* <p>Typical usage:
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification 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 io.serverlessworkflow.fluent.func.spi;

import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import java.util.function.Consumer;

public interface CallGrpcFluent<SELF extends TaskBaseBuilder<SELF>, LIST> {

LIST grpc(String name, Consumer<SELF> itemsConfigurer);

default LIST grpc(Consumer<SELF> itemsConfigurer) {
return this.grpc(null, itemsConfigurer);
}
Comment on lines +21 to +27

@matheusandre1 matheusandre1 Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this would require changing the hierarchy of the FuncDoFluent types and would break the structure of the other module.

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.fluent.func.spi;

import io.serverlessworkflow.fluent.func.FuncCallGrpcTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncCallHttpTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
Expand Down Expand Up @@ -52,6 +53,7 @@ public interface FuncDoFluent<SELF extends FuncDoFluent<SELF>>
CallFnFluent<FuncCallTaskBuilder, SELF>,
CallHttpFluent<FuncCallHttpTaskBuilder, SELF>,
CallOpenAPIFluent<FuncCallOpenAPITaskBuilder, SELF>,
CallGrpcFluent<FuncCallGrpcTaskBuilder, SELF>,
WorkflowFluent<WorkflowTaskBuilder, SELF> {

default SELF subflow(String name, Consumer<WorkflowTaskBuilder> itemsConfigurer) {
Expand Down
Loading
Loading