Skip to content

Commit

Permalink
Improve Spring modules with auto-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigueprieto committed Oct 14, 2024
1 parent 76ed504 commit 9b8a6ca
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,34 +36,39 @@

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()
.basePath(clientProperties.getRootUri())
.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,
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@

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;

import com.netflix.conductor.client.http.TaskClient;
import com.netflix.conductor.sdk.workflow.executor.task.AnnotatedWorkerExecutor;
import com.netflix.conductor.sdk.workflow.executor.task.WorkerConfiguration;

@Component
public class ConductorWorkerAutoConfiguration implements ApplicationListener<ContextRefreshedEvent> {
@AutoConfiguration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@ConditionalOnBean(TaskClient.class)
public class ConductorWorkerAutoConfiguration {

private final TaskClient taskClient;

public ConductorWorkerAutoConfiguration(TaskClient taskClient) {
this.taskClient = taskClient;
}

@Override
@EventListener(ContextRefreshedEvent.class)
public void onApplicationEvent(ContextRefreshedEvent refreshedEvent) {
ApplicationContext applicationContext = refreshedEvent.getApplicationContext();
Environment environment = applicationContext.getEnvironment();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
com.netflix.conductor.client.spring.ConductorClientAutoConfiguration
com.netflix.conductor.client.spring.ConductorWorkerAutoConfiguration
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.0.0
version=4.0.1-alpha5
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,7 @@

import lombok.extern.slf4j.Slf4j;

@Configuration(proxyBeanMethods = false)
@AutoConfiguration
@Slf4j
public class OrkesConductorClientAutoConfiguration {

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.orkes.conductor.client.spring.OrkesConductorClientAutoConfiguration

0 comments on commit 9b8a6ca

Please sign in to comment.