1 package org
.argeo
.slc
.jcr
.execution
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.slc
.SlcException
;
13 import org
.argeo
.slc
.core
.execution
.DefaultExecutionSpec
;
14 import org
.argeo
.slc
.core
.execution
.PrimitiveSpecAttribute
;
15 import org
.argeo
.slc
.core
.execution
.PrimitiveUtils
;
16 import org
.argeo
.slc
.core
.execution
.ProcessThread
;
17 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
18 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
19 import org
.argeo
.slc
.execution
.ExecutionProcess
;
20 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
21 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
22 import org
.argeo
.slc
.jcr
.SlcNames
;
23 import org
.argeo
.slc
.jcr
.SlcTypes
;
24 import org
.argeo
.slc
.process
.RealizedFlow
;
26 /** Where the actual execution takes place */
27 public class JcrProcessThread
extends ProcessThread
implements SlcNames
{
29 public JcrProcessThread(ThreadGroup processesThreadGroup
,
30 ExecutionModulesManager executionModulesManager
,
31 JcrExecutionProcess process
) {
32 super(processesThreadGroup
, executionModulesManager
, process
);
36 protected void process() throws InterruptedException
{
38 Node rootRealizedFlowNode
= getNode().getNode(SLC_FLOW
);
39 // we just manage one level for the time being
40 NodeIterator nit
= rootRealizedFlowNode
.getNodes(SLC_FLOW
);
41 while (nit
.hasNext()) {
42 Node realizedFlowNode
= nit
.nextNode();
44 // set status on realized flow
45 realizedFlowNode
.setProperty(SLC_STATUS
,
46 ExecutionProcess
.RUNNING
);
47 realizedFlowNode
.getSession().save();
49 execute(realizedFlowNode
);
51 // set status on realized flow
52 realizedFlowNode
.setProperty(SLC_STATUS
,
53 ExecutionProcess
.COMPLETED
);
54 realizedFlowNode
.getSession().save();
55 } catch (RepositoryException e
) {
57 } catch (InterruptedException e
) {
58 // set status on realized flow
59 realizedFlowNode
.setProperty(SLC_STATUS
,
60 ExecutionProcess
.KILLED
);
61 realizedFlowNode
.getSession().save();
63 } catch (RuntimeException e
) {
64 // set status on realized flow
65 realizedFlowNode
.setProperty(SLC_STATUS
,
66 ExecutionProcess
.ERROR
);
67 realizedFlowNode
.getSession().save();
71 } catch (RepositoryException e
) {
72 throw new ArgeoException("Cannot process " + getNode(), e
);
76 /** Configure the realized flows */
77 protected void execute(Node realizedFlowNode
) throws RepositoryException
,
78 InterruptedException
{
79 if (realizedFlowNode
.hasNode(SLC_ADDRESS
)) {
80 String flowPath
= realizedFlowNode
.getNode(SLC_ADDRESS
)
81 .getProperty(Property
.JCR_PATH
).getString();
82 // TODO: convert to local path if remote
84 Node flowNode
= realizedFlowNode
.getSession().getNode(flowPath
);
85 String flowName
= flowNode
.getProperty(SLC_NAME
).getString();
87 String executionModuleName
= SlcJcrUtils
88 .flowExecutionModuleName(flowPath
);
89 String executionModuleVersion
= SlcJcrUtils
90 .flowExecutionModuleVersion(flowPath
);
92 RealizedFlow realizedFlow
= new RealizedFlow();
93 realizedFlow
.setModuleName(executionModuleName
);
94 realizedFlow
.setModuleVersion(executionModuleVersion
);
96 // retrieve execution spec
97 DefaultExecutionSpec executionSpec
= null;
98 if (flowNode
.hasProperty(SlcNames
.SLC_SPEC
)) {
99 Node executionSpecNode
= flowNode
.getProperty(SLC_SPEC
)
101 executionSpec
= new DefaultExecutionSpec();
102 executionSpec
.setBeanName(executionSpecNode
.getProperty(
103 SLC_NAME
).getString());
105 .setAttributes(readExecutionSpecAttributes(executionSpecNode
));
107 // TODO: will with original attr
108 Map
<String
, ExecutionSpecAttribute
> attrs
= readExecutionSpecAttributes(realizedFlowNode
);
109 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
110 for (String attrName
: attrs
.keySet()) {
111 // if (flowNode.hasNode(attrName)) {
112 // // we assume this is a primitive
113 // // since ref are not yet implemented
114 // Node valueNode = flowNode.getNode(attrName);
115 // String type = valueNode.getProperty(SLC_TYPE).getString();
116 // String valueStr = valueNode.getProperty(SLC_VALUE)
118 // Object value = PrimitiveUtils.convert(type, valueStr);
119 // values.put(attrName, value);
121 ExecutionSpecAttribute attr
= attrs
.get(attrName
);
122 Object value
= attr
.getValue();
123 values
.put(attrName
, value
);
127 // if(executionSpec!=null)
128 // executionSpec.setAttributes(attrs);
129 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(flowName
,
130 values
, executionSpec
);
131 realizedFlow
.setFlowDescriptor(efd
);
136 execute(realizedFlow
, true);
141 protected Map
<String
, ExecutionSpecAttribute
> readExecutionSpecAttributes(
144 Map
<String
, ExecutionSpecAttribute
> attrs
= new HashMap
<String
, ExecutionSpecAttribute
>();
145 for (NodeIterator nit
= node
.getNodes(); nit
.hasNext();) {
146 Node specAttrNode
= nit
.nextNode();
148 .isNodeType(SlcTypes
.SLC_PRIMITIVE_SPEC_ATTRIBUTE
)) {
149 String type
= specAttrNode
.getProperty(SLC_TYPE
)
152 if (specAttrNode
.hasProperty(SLC_VALUE
)) {
153 String valueStr
= specAttrNode
.getProperty(SLC_VALUE
)
155 value
= PrimitiveUtils
.convert(type
, valueStr
);
157 PrimitiveSpecAttribute specAttr
= new PrimitiveSpecAttribute(
159 attrs
.put(specAttrNode
.getName(), specAttr
);
164 } catch (RepositoryException e
) {
165 throw new SlcException("Cannot read spec attributes from " + node
,
170 protected Node
getNode() {
171 return ((JcrExecutionProcess
) getProcess()).getNode();