1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.execution
.ExecutionContext
;
12 import org
.argeo
.slc
.execution
.ExecutionFlow
;
13 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
14 import org
.argeo
.slc
.execution
.ExecutionModule
;
15 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
16 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
17 import org
.argeo
.slc
.process
.RealizedFlow
;
18 import org
.argeo
.slc
.process
.SlcExecution
;
19 import org
.springframework
.util
.Assert
;
21 public class DefaultModulesManager
implements ExecutionModulesManager
{
22 private final static Log log
= LogFactory
23 .getLog(DefaultModulesManager
.class);
25 private List
<ExecutionModule
> executionModules
= new ArrayList
<ExecutionModule
>();
27 protected ExecutionModule
getExecutionModule(String moduleName
, String version
) {
28 for (ExecutionModule moduleT
: executionModules
) {
29 if (moduleT
.getName().equals(moduleName
)) {
30 if(moduleT
.getVersion().equals(version
)) {
38 public ExecutionModuleDescriptor
getExecutionModuleDescriptor(
39 String moduleName
, String version
) {
40 ExecutionModule module
= getExecutionModule(moduleName
, version
);
42 Assert
.notNull(module
);
44 return module
.getDescriptor();
47 public List
<ExecutionModule
> listExecutionModules() {
48 return executionModules
;
51 public void setExecutionModules(List
<ExecutionModule
> executionModules
) {
52 this.executionModules
= executionModules
;
55 protected Map
<String
, Object
> convertValues(ExecutionFlowDescriptor executionFlowDescriptor
) {
56 // convert the values of flow.getFlowDescriptor()
57 Map
<String
, Object
> values
= executionFlowDescriptor
.getValues();
59 Map
<String
, Object
> convertedValues
= new HashMap
<String
, Object
>();
61 for(String key
: values
.keySet()) {
62 Object value
= values
.get(key
);
63 if(value
instanceof PrimitiveValue
) {
64 PrimitiveValue primitiveValue
= (PrimitiveValue
) value
;
66 // TODO: check that the class of the the primitiveValue.value matches
67 // the primitiveValue.type
68 convertedValues
.put(key
, primitiveValue
.getValue());
70 else if(value
instanceof RefValue
) {
71 RefValue refValue
= (RefValue
) value
;
72 convertedValues
.put(key
, refValue
.getLabel());
75 return convertedValues
;
78 public void process(SlcExecution slcExecution
) {
79 log
.info("##\n## Process SLC Execution " + slcExecution
+"\n##");
81 for(RealizedFlow flow
: slcExecution
.getRealizedFlows()) {
82 ExecutionModule module
= getExecutionModule(flow
.getModuleName(),
83 flow
.getModuleVersion());
85 ExecutionThread thread
= new ExecutionThread(flow
.getFlowDescriptor(), module
);
89 throw new SlcException("ExecutionModule " + flow
.getModuleName() + ", version "
90 + flow
.getModuleVersion() + " not found.");
95 private class ExecutionThread
extends Thread
{
96 private final ExecutionFlowDescriptor executionFlowDescriptor
;
97 private final ExecutionModule executionModule
;
99 public ExecutionThread(ExecutionFlowDescriptor executionFlowDescriptor
,
100 ExecutionModule executionModule
) {
101 super("SLC Execution #" /*+ executionContext.getUuid()*/);
102 this.executionFlowDescriptor
= executionFlowDescriptor
;
103 this.executionModule
= executionModule
;
107 ExecutionContext executionContext
= executionModule
.getExecutionContext();
108 executionContext
.addVariables(convertValues(executionFlowDescriptor
));
110 executionModule
.execute(executionFlowDescriptor
);
111 } catch (Exception e
) {
112 //TODO: re-throw exception ?
113 log
.error("Execution " + executionContext
.getUuid()