-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate definition scanning from definition service, some tests stil…
…l failing
- Loading branch information
Edvard Fonsell
committed
Jun 2, 2019
1 parent
f7c3161
commit 437fd28
Showing
12 changed files
with
194 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
nflow-engine/src/main/java/io/nflow/engine/service/WorkflowDefinitionClassNameScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.nflow.engine.service; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.io.AbstractResource; | ||
import org.springframework.stereotype.Component; | ||
|
||
import io.nflow.engine.config.NFlow; | ||
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition; | ||
import io.nflow.engine.workflow.definition.WorkflowState; | ||
|
||
/** | ||
* Service for managing workflow definitions. | ||
*/ | ||
@Component | ||
public class WorkflowDefinitionClassNameScanner { | ||
|
||
private static final Logger logger = getLogger(WorkflowDefinitionClassNameScanner.class); | ||
|
||
private final WorkflowDefinitionService workflowDefinitionService; | ||
|
||
@Inject | ||
public WorkflowDefinitionClassNameScanner(WorkflowDefinitionService workflowDefinitionService) { | ||
this.workflowDefinitionService = workflowDefinitionService; | ||
} | ||
|
||
@Autowired(required = false) | ||
public void setWorkflowDefinitions(@NFlow AbstractResource classNameListing) throws IOException, ReflectiveOperationException { | ||
if (classNameListing == null) { | ||
logger.info("No non-Spring workflow definitions"); | ||
} else { | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(classNameListing.getInputStream(), UTF_8))) { | ||
String row; | ||
while ((row = br.readLine()) != null) { | ||
logger.info("Preparing workflow {}", row); | ||
@SuppressWarnings("unchecked") | ||
Class<AbstractWorkflowDefinition<? extends WorkflowState>> clazz = (Class<AbstractWorkflowDefinition<? extends WorkflowState>>) Class | ||
.forName(row); | ||
workflowDefinitionService.addWorkflowDefinition(clazz.getDeclaredConstructor().newInstance()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
nflow-engine/src/main/java/io/nflow/engine/service/WorkflowDefinitionSpringBeanScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.nflow.engine.service; | ||
|
||
import java.util.Collection; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition; | ||
import io.nflow.engine.workflow.definition.WorkflowState; | ||
|
||
/** | ||
* Service for managing workflow definitions. | ||
*/ | ||
@Component | ||
public class WorkflowDefinitionSpringBeanScanner { | ||
|
||
private final WorkflowDefinitionService workflowDefinitionService; | ||
|
||
@Inject | ||
public WorkflowDefinitionSpringBeanScanner(WorkflowDefinitionService workflowDefinitionService) { | ||
this.workflowDefinitionService = workflowDefinitionService; | ||
} | ||
|
||
/** | ||
* Add given workflow definitions to the managed definitions. | ||
* @param workflowDefinitions The workflow definitions to be added. | ||
*/ | ||
@Autowired(required = false) | ||
public void setWorkflowDefinitions(Collection<AbstractWorkflowDefinition<? extends WorkflowState>> workflowDefinitions) { | ||
workflowDefinitions.forEach(workflowDefinitionService::addWorkflowDefinition); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...-engine/src/test/java/io/nflow/engine/service/WorkflowDefinitionClassNameScannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.nflow.engine.service; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import io.nflow.engine.internal.executor.BaseNflowTest; | ||
|
||
public class WorkflowDefinitionClassNameScannerTest extends BaseNflowTest { | ||
|
||
@Mock | ||
private ClassPathResource nonSpringWorkflowListing; | ||
@Mock | ||
private WorkflowDefinitionService workflowDefinitionService; | ||
private WorkflowDefinitionClassNameScanner scanner; | ||
|
||
@Test | ||
public void definitionIsAdded() throws Exception { | ||
String dummyTestClassname = DummyTestWorkflow.class.getName(); | ||
ByteArrayInputStream bis = new ByteArrayInputStream(dummyTestClassname.getBytes(UTF_8)); | ||
when(nonSpringWorkflowListing.getInputStream()).thenReturn(bis); | ||
scanner = new WorkflowDefinitionClassNameScanner(workflowDefinitionService); | ||
scanner.setWorkflowDefinitions(nonSpringWorkflowListing); | ||
verify(workflowDefinitionService).addWorkflowDefinition(any(DummyTestWorkflow.class)); | ||
} | ||
|
||
} |
Oops, something went wrong.