diff --git a/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java index 194ad6cf6..4306d20f4 100644 --- a/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java +++ b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java @@ -16,10 +16,14 @@ import java.util.List; import java.util.Map; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; import org.springframework.core.env.Environment; import com.netflix.conductor.client.automator.TaskRunnerConfigurer; @@ -32,13 +36,15 @@ import lombok.extern.slf4j.Slf4j; -@Configuration(proxyBeanMethods = false) +@AutoConfiguration +@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) @EnableConfigurationProperties(ClientProperties.class) @Slf4j public class ConductorClientAutoConfiguration { - @ConditionalOnMissingBean @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "conductor.client", name = "rootUri") public ConductorClient conductorClient(ClientProperties clientProperties) { // TODO allow configuration of other properties via application.properties return ConductorClient.builder() @@ -46,20 +52,23 @@ public ConductorClient conductorClient(ClientProperties clientProperties) { .build(); } - @ConditionalOnMissingBean @Bean + @ConditionalOnBean(ConductorClient.class) + @ConditionalOnMissingBean public TaskClient taskClient(ConductorClient client) { return new TaskClient(client); } - @ConditionalOnMissingBean @Bean + @ConditionalOnBean(ConductorClient.class) + @ConditionalOnMissingBean public AnnotatedWorkerExecutor annotatedWorkerExecutor(TaskClient taskClient) { return new AnnotatedWorkerExecutor(taskClient); } - @ConditionalOnMissingBean @Bean(initMethod = "init", destroyMethod = "shutdown") + @ConditionalOnMissingBean + @ConditionalOnBean(ConductorClient.class) public TaskRunnerConfigurer taskRunnerConfigurer(Environment env, TaskClient taskClient, ClientProperties clientProperties, @@ -90,12 +99,15 @@ public TaskRunnerConfigurer taskRunnerConfigurer(Environment env, } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ConductorClient.class) public WorkflowExecutor workflowExecutor(ConductorClient client, AnnotatedWorkerExecutor annotatedWorkerExecutor) { return new WorkflowExecutor(client, annotatedWorkerExecutor); } - @ConditionalOnMissingBean @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ConductorClient.class) public WorkflowClient workflowClient(ConductorClient client) { return new WorkflowClient(client); } diff --git a/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorWorkerAutoConfiguration.java b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorWorkerAutoConfiguration.java index cdc212c5e..f40b1017d 100644 --- a/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorWorkerAutoConfiguration.java +++ b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/java/com/netflix/conductor/client/spring/ConductorWorkerAutoConfiguration.java @@ -14,9 +14,13 @@ import java.util.Map; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.Ordered; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @@ -24,8 +28,10 @@ import com.netflix.conductor.sdk.workflow.executor.task.AnnotatedWorkerExecutor; import com.netflix.conductor.sdk.workflow.executor.task.WorkerConfiguration; -@Component -public class ConductorWorkerAutoConfiguration implements ApplicationListener { +@AutoConfiguration +@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) +@ConditionalOnBean(TaskClient.class) +public class ConductorWorkerAutoConfiguration { private final TaskClient taskClient; @@ -33,7 +39,7 @@ public ConductorWorkerAutoConfiguration(TaskClient taskClient) { this.taskClient = taskClient; } - @Override + @EventListener(ContextRefreshedEvent.class) public void onApplicationEvent(ContextRefreshedEvent refreshedEvent) { ApplicationContext applicationContext = refreshedEvent.getApplicationContext(); Environment environment = applicationContext.getEnvironment(); diff --git a/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..2e489d842 --- /dev/null +++ b/conductor-clients/java/conductor-java-sdk/conductor-client-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +com.netflix.conductor.client.spring.ConductorClientAutoConfiguration +com.netflix.conductor.client.spring.ConductorWorkerAutoConfiguration diff --git a/conductor-clients/java/conductor-java-sdk/gradle.properties b/conductor-clients/java/conductor-java-sdk/gradle.properties index 19a01881d..4b7e759ba 100644 --- a/conductor-clients/java/conductor-java-sdk/gradle.properties +++ b/conductor-clients/java/conductor-java-sdk/gradle.properties @@ -1 +1 @@ -version=4.0.0 +version=4.0.1-alpha5 diff --git a/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/java/io/orkes/conductor/client/spring/OrkesConductorClientAutoConfiguration.java b/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/java/io/orkes/conductor/client/spring/OrkesConductorClientAutoConfiguration.java index acc602df6..1971ff5e2 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/java/io/orkes/conductor/client/spring/OrkesConductorClientAutoConfiguration.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/java/io/orkes/conductor/client/spring/OrkesConductorClientAutoConfiguration.java @@ -13,9 +13,10 @@ package io.orkes.conductor.client.spring; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import io.orkes.conductor.client.ApiClient; @@ -30,7 +31,7 @@ import lombok.extern.slf4j.Slf4j; -@Configuration(proxyBeanMethods = false) +@AutoConfiguration @Slf4j public class OrkesConductorClientAutoConfiguration { @@ -95,41 +96,56 @@ public ApiClient orkesConductorClient(Environment env) { } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public OrkesClients orkesClients(ApiClient client) { return new OrkesClients(client); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public OrkesTaskClient orkesTaskClient(OrkesClients clients) { return clients.getTaskClient(); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public OrkesMetadataClient orkesMetadataClient(OrkesClients clients) { return clients.getMetadataClient(); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public OrkesWorkflowClient orkesWorkflowClient(OrkesClients clients) { return clients.getWorkflowClient(); } @Bean + @ConditionalOnMissingBean public AuthorizationClient orkesAuthorizationClient(OrkesClients clients) { return clients.getAuthorizationClient(); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public OrkesEventClient orkesEventClient(OrkesClients clients) { return clients.getEventClient(); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public SchedulerClient orkesSchedulerClient(OrkesClients clients) { return clients.getSchedulerClient(); } @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ApiClient.class) public SecretClient orkesSecretClient(OrkesClients clients) { return clients.getSecretClient(); } diff --git a/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..6dcfe1446 --- /dev/null +++ b/conductor-clients/java/conductor-java-sdk/orkes-spring/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.orkes.conductor.client.spring.OrkesConductorClientAutoConfiguration