Skip to content
Merged
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
5 changes: 5 additions & 0 deletions impl/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
import io.serverlessworkflow.impl.resources.ExternalResourceHandler;
import java.util.function.Function;

public interface FunctionReader extends Function<ExternalResourceHandler, Task> {}
public interface FunctionReader extends Function<ExternalResourceHandler, Task>, ServicePriority {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.impl;

import static io.serverlessworkflow.impl.WorkflowUtils.loadFirst;
import static io.serverlessworkflow.impl.WorkflowUtils.safeClose;

import io.serverlessworkflow.api.types.SchemaInline;
Expand Down Expand Up @@ -305,8 +306,7 @@ public Builder withDefaultCatalogURI(URI defaultCatalogURI) {
public WorkflowApplication build() {
if (modelFactory == null) {
modelFactory =
ServiceLoader.load(WorkflowModelFactory.class)
.findFirst()
loadFirst(WorkflowModelFactory.class)
.orElseThrow(
() ->
new IllegalStateException(
Expand All @@ -318,21 +318,17 @@ public WorkflowApplication build() {
ServiceLoader.load(ExpressionFactory.class).forEach(exprFactories::add);
if (schemaValidatorFactory == null) {
schemaValidatorFactory =
ServiceLoader.load(SchemaValidatorFactory.class)
.findFirst()
loadFirst(SchemaValidatorFactory.class)
.orElseGet(() -> EmptySchemaValidatorHolder.instance);
}
if (taskFactory == null) {
taskFactory =
ServiceLoader.load(TaskExecutorFactory.class)
.findFirst()
.orElseGet(() -> DefaultTaskExecutorFactory.get());
loadFirst(TaskExecutorFactory.class).orElseGet(() -> DefaultTaskExecutorFactory.get());
}
ServiceLoader.load(EventPublisher.class).forEach(e -> eventPublishers.add(e));
if (eventConsumer == null) {
eventConsumer =
ServiceLoader.load(EventConsumer.class)
.findFirst()
loadFirst(EventConsumer.class)
.orElseGet(
() -> {
InMemoryEvents inMemory = new InMemoryEvents(executorFactory);
Expand All @@ -353,18 +349,14 @@ public WorkflowApplication build() {

if (configManager == null) {
configManager =
ServiceLoader.load(ConfigManager.class)
.findFirst()
.orElseGet(() -> new SystemPropertyConfigManager());
loadFirst(ConfigManager.class).orElseGet(() -> new SystemPropertyConfigManager());
}
if (secretManager == null) {
secretManager =
ServiceLoader.load(SecretManager.class)
.findFirst()
.orElseGet(() -> new ConfigSecretManager(configManager));
loadFirst(SecretManager.class).orElseGet(() -> new ConfigSecretManager(configManager));
}
templateResolver = ServiceLoader.load(URITemplateResolver.class).findFirst();
functionReader = ServiceLoader.load(FunctionReader.class).findFirst();
templateResolver = loadFirst(URITemplateResolver.class);
functionReader = loadFirst(FunctionReader.class);
if (defaultCatalogURI == null) {
defaultCatalogURI = URI.create("https://github.com/serverlessworkflow/catalog");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -304,4 +305,11 @@ public static WorkflowValueResolver<URI> getURISupplier(
}
throw new IllegalArgumentException("Invalid uritemplate definition " + template);
}

public static <T extends ServicePriority> Optional<T> loadFirst(Class<T> serviceClass) {
return ServiceLoader.load(serviceClass).stream()
.map(ServiceLoader.Provider::get)
.sorted()
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package io.serverlessworkflow.impl.auth;

import io.serverlessworkflow.impl.ServicePriority;
import java.util.List;

public interface AccessTokenProviderFactory {
public interface AccessTokenProviderFactory extends ServicePriority {

AccessTokenProvider build(
HttpRequestInfo requestInfo, List<String> issuers, JWTConverter converter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.serverlessworkflow.impl.auth;

import static io.serverlessworkflow.impl.WorkflowUtils.checkSecret;
import static io.serverlessworkflow.impl.WorkflowUtils.loadFirst;
import static io.serverlessworkflow.impl.WorkflowUtils.secret;

import io.serverlessworkflow.api.types.OAuth2AuthenticationData;
Expand All @@ -28,20 +29,17 @@
import java.net.URI;
import java.util.Arrays;
import java.util.Map;
import java.util.ServiceLoader;

abstract class CommonOAuthProvider implements AuthProvider {

private final WorkflowValueResolver<AccessTokenProvider> tokenProvider;

private static JWTConverter jwtConverter =
ServiceLoader.load(JWTConverter.class)
.findFirst()
loadFirst(JWTConverter.class)
.orElseThrow(() -> new IllegalStateException("No JWTConverter implementation found"));

private static AccessTokenProviderFactory accessTokenProviderFactory =
ServiceLoader.load(AccessTokenProviderFactory.class)
.findFirst()
loadFirst(AccessTokenProviderFactory.class)
.orElseThrow(() -> new IllegalStateException("No JWTConverter implementation found"));

protected CommonOAuthProvider(WorkflowValueResolver<AccessTokenProvider> tokenProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package io.serverlessworkflow.impl.auth;

public interface JWTConverter {
import io.serverlessworkflow.impl.ServicePriority;

public interface JWTConverter extends ServicePriority {

/**
* Converts a JWT token string into a JWT object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

import io.cloudevents.CloudEvent;
import io.serverlessworkflow.api.types.EventFilter;
import io.serverlessworkflow.impl.ServicePriority;
import io.serverlessworkflow.impl.WorkflowApplication;
import java.util.Collection;
import java.util.function.Consumer;

public interface EventConsumer<T extends EventRegistration, V extends EventRegistrationBuilder>
extends AutoCloseable {
extends AutoCloseable, ServicePriority {

V listen(EventFilter filter, WorkflowApplication workflowApplication);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public CallableTask build(RunScript taskConfiguration, WorkflowDefinition defini
ServiceLoader.load(ScriptRunner.class).stream()
.map(ServiceLoader.Provider::get)
.filter(s -> s.identifier().equals(language))
.sorted()
.findFirst()
.orElseThrow(
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected RunTaskExecutorBuilder(
runnables.stream()
.map(Provider::get)
.filter(r -> r.accept(config.getClass()))
.sorted()
.findFirst()
.map(r -> r.build(config, definition))
.orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package io.serverlessworkflow.impl.executors;

import io.serverlessworkflow.api.types.RunTaskConfiguration;
import io.serverlessworkflow.impl.ServicePriority;
import io.serverlessworkflow.impl.WorkflowDefinition;

public interface RunnableTaskBuilder<T extends RunTaskConfiguration> {
public interface RunnableTaskBuilder<T extends RunTaskConfiguration> extends ServicePriority {
boolean accept(Class<? extends RunTaskConfiguration> clazz);

CallableTask build(T taskConfiguration, WorkflowDefinition definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package io.serverlessworkflow.impl.resources;

import io.serverlessworkflow.impl.ServicePriority;
import io.serverlessworkflow.impl.TaskContext;
import io.serverlessworkflow.impl.WorkflowContext;
import io.serverlessworkflow.impl.WorkflowModel;
import java.net.URI;

public interface URITemplateResolver {
public interface URITemplateResolver extends ServicePriority {
URI resolveTemplates(
String uri, WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel model);
}
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.impl;

public class LowestPriority implements ServicePriority {
public int priority() {
return DEFAULT_PRIORITY + 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.impl;

public class MediumPriority implements ServicePriority {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.impl;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class ServicePriorityTest {

@Test
void testRightOrder() {
assertThat(WorkflowUtils.loadFirst(ServicePriority.class).orElseThrow())
.isInstanceOf(TopPriority.class);
}
}
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.impl;

public class TopPriority implements ServicePriority {
public int priority() {
return DEFAULT_PRIORITY - 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
io.serverlessworkflow.impl.LowestPriority
io.serverlessworkflow.impl.TopPriority
io.serverlessworkflow.impl.MediumPriority
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.impl.expressions.jq;

import static io.serverlessworkflow.impl.WorkflowUtils.loadFirst;
import static org.assertj.core.api.Assertions.assertThat;

import io.serverlessworkflow.impl.WorkflowContext;
Expand All @@ -26,7 +27,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -41,7 +41,7 @@ class JQExpressionFactoryTest {
void setup() {
workflowContext = Mockito.mock(WorkflowContext.class);
factory = new JQExpressionFactory();
modelFactory = ServiceLoader.load(WorkflowModelFactory.class).findFirst().orElseThrow();
modelFactory = loadFirst(WorkflowModelFactory.class).orElseThrow();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.serverlessworkflow.impl.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.serverlessworkflow.impl.ServicePriority;
import java.util.function.Supplier;

public interface ObjectMapperFactory extends Supplier<ObjectMapper> {}
public interface ObjectMapperFactory extends Supplier<ObjectMapper>, ServicePriority {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package io.serverlessworkflow.impl.jackson;

import static io.serverlessworkflow.impl.WorkflowUtils.loadFirst;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.function.Supplier;

public class ObjectMapperFactoryProvider implements Supplier<ObjectMapperFactory> {
Expand All @@ -40,8 +41,7 @@ public void setFactory(ObjectMapperFactory objectMapperFactory) {
public ObjectMapperFactory get() {
return objectMapperFactory != null
? objectMapperFactory
: ServiceLoader.load(ObjectMapperFactory.class)
.findFirst()
: loadFirst(ObjectMapperFactory.class)
.orElseGet(() -> () -> new ObjectMapper().findAndRegisterModules());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package io.serverlessworkflow.impl.marshaller;

public interface CustomObjectMarshaller<T> {
import io.serverlessworkflow.impl.ServicePriority;

public interface CustomObjectMarshaller<T> extends ServicePriority {
void write(WorkflowOutputBuffer buffer, T object);

T read(WorkflowInputBuffer buffer);
Expand Down