X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2Fexecution%2FJcrProcessThread.java;h=8755829e7bba6e213b896c1d142ca82d65c22c45;hb=805e3301575e708491482a2a00dd37bc2b41b851;hp=e28c727501a95a91ad74c66c92105e1589a93f34;hpb=f86db0937b395c7fa96fa4bf4a29cc2c676fe3f5;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java index e28c72750..8755829e7 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java @@ -16,31 +16,19 @@ */ package org.argeo.slc.jcr.execution; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; -import org.argeo.slc.SlcException; -import org.argeo.slc.core.execution.DefaultExecutionSpec; -import org.argeo.slc.core.execution.PrimitiveSpecAttribute; -import org.argeo.slc.core.execution.PrimitiveUtils; import org.argeo.slc.core.execution.ProcessThread; -import org.argeo.slc.core.execution.RefSpecAttribute; -import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.execution.ExecutionSpecAttribute; import org.argeo.slc.execution.RealizedFlow; -import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; -import org.argeo.slc.jcr.SlcTypes; /** Where the actual execution takes place */ public class JcrProcessThread extends ProcessThread implements SlcNames { @@ -51,155 +39,54 @@ public class JcrProcessThread extends ProcessThread implements SlcNames { super(processesThreadGroup, executionModulesManager, process); } + /** Overridden in order to set progress status on realized flow nodes. */ @Override protected void process() throws InterruptedException { Session session = null; - try { - session = getJcrExecutionProcess().getRepository().login(); - Node rootRealizedFlowNode = session.getNode( - getJcrExecutionProcess().getNodePath()).getNode(SLC_FLOW); - // we just manage one level for the time being - NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW); - while (nit.hasNext()) { - Node realizedFlowNode = nit.nextNode(); - - // set status on realized flow - realizedFlowNode.setProperty(SLC_STATUS, - ExecutionProcess.RUNNING); - realizedFlowNode.getSession().save(); - try { - execute(realizedFlowNode); - - // set status on realized flow - realizedFlowNode.setProperty(SLC_STATUS, - ExecutionProcess.COMPLETED); - realizedFlowNode.getSession().save(); - } catch (RepositoryException e) { - throw e; - } catch (InterruptedException e) { - // set status on realized flow - realizedFlowNode.setProperty(SLC_STATUS, - ExecutionProcess.KILLED); - realizedFlowNode.getSession().save(); - throw e; - } catch (RuntimeException e) { - // set status on realized flow - realizedFlowNode.setProperty(SLC_STATUS, - ExecutionProcess.ERROR); - realizedFlowNode.getSession().save(); - throw e; + if (getProcess() instanceof JcrExecutionProcess) + try { + session = ((JcrExecutionProcess) getProcess()).getRepository() + .login(); + + List realizedFlows = getProcess() + .getRealizedFlows(); + for (RealizedFlow realizedFlow : realizedFlows) { + Node realizedFlowNode = session + .getNode(((JcrRealizedFlow) realizedFlow).getPath()); + setFlowStatus(realizedFlowNode, ExecutionProcess.RUNNING); + + try { + // + // EXECUTE THE FLOW + // + execute(realizedFlow, true); + + setFlowStatus(realizedFlowNode, + ExecutionProcess.COMPLETED); + } catch (RepositoryException e) { + throw e; + } catch (InterruptedException e) { + setFlowStatus(realizedFlowNode, ExecutionProcess.KILLED); + throw e; + } catch (RuntimeException e) { + setFlowStatus(realizedFlowNode, ExecutionProcess.ERROR); + throw e; + } } + } catch (RepositoryException e) { + throw new ArgeoException("Cannot process " + + getJcrExecutionProcess().getNodePath(), e); + } finally { + JcrUtils.logoutQuietly(session); } - } catch (RepositoryException e) { - throw new ArgeoException("Cannot process " - + getJcrExecutionProcess().getNodePath(), e); - } finally { - JcrUtils.logoutQuietly(session); - } - } - - /** Configure the realized flows */ - protected void execute(Node realizedFlowNode) throws RepositoryException, - InterruptedException { - if (realizedFlowNode.hasNode(SLC_ADDRESS)) { - String flowPath = realizedFlowNode.getNode(SLC_ADDRESS) - .getProperty(Property.JCR_PATH).getString(); - // TODO: convert to local path if remote - - Node flowNode = realizedFlowNode.getSession().getNode(flowPath); - String flowName = flowNode.getProperty(SLC_NAME).getString(); - - Node executionModuleNode = flowNode.getSession().getNode( - SlcJcrUtils.modulePath(flowPath)); - String executionModuleName = executionModuleNode.getProperty( - SLC_NAME).getString(); - String executionModuleVersion = executionModuleNode.getProperty( - SLC_VERSION).getString(); - - RealizedFlow realizedFlow = new RealizedFlow(); - realizedFlow.setModuleName(executionModuleName); - realizedFlow.setModuleVersion(executionModuleVersion); - - // retrieve execution spec - DefaultExecutionSpec executionSpec = new DefaultExecutionSpec(); - Map attrs = readExecutionSpecAttributes(realizedFlowNode); - executionSpec.setAttributes(attrs); - - // set execution spec name - if (flowNode.hasProperty(SlcNames.SLC_SPEC)) { - Node executionSpecNode = flowNode.getProperty(SLC_SPEC) - .getNode(); - executionSpec.setBeanName(executionSpecNode.getProperty( - SLC_NAME).getString()); - } - - // explicitly retrieve values - Map values = new HashMap(); - for (String attrName : attrs.keySet()) { - ExecutionSpecAttribute attr = attrs.get(attrName); - Object value = attr.getValue(); - values.put(attrName, value); - } - - ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(flowName, - values, executionSpec); - realizedFlow.setFlowDescriptor(efd); - - // - // EXECUTE THE FLOW - // - execute(realizedFlow, true); - // - } + else + super.process(); } - protected Map readExecutionSpecAttributes( - Node node) { - try { - Map attrs = new HashMap(); - for (NodeIterator nit = node.getNodes(); nit.hasNext();) { - Node specAttrNode = nit.nextNode(); - if (specAttrNode - .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) { - String type = specAttrNode.getProperty(SLC_TYPE) - .getString(); - Object value = null; - if (specAttrNode.hasProperty(SLC_VALUE)) { - String valueStr = specAttrNode.getProperty(SLC_VALUE) - .getString(); - value = PrimitiveUtils.convert(type, valueStr); - } - PrimitiveSpecAttribute specAttr = new PrimitiveSpecAttribute( - type, value); - attrs.put(specAttrNode.getName(), specAttr); - } else if (specAttrNode - .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) { - if (!specAttrNode.hasProperty(SLC_VALUE)) { - continue; - } - Integer value = (int) specAttrNode.getProperty(SLC_VALUE) - .getLong(); - RefSpecAttribute specAttr = new RefSpecAttribute(); - NodeIterator children = specAttrNode.getNodes(); - int index = 0; - String id = null; - while (children.hasNext()) { - Node child = children.nextNode(); - if (index == value) - id = child.getName(); - index++; - } - specAttr.setValue(id); - attrs.put(specAttrNode.getName(), specAttr); - } - // throw new SlcException("Unsupported spec attribute " - // + specAttrNode); - } - return attrs; - } catch (RepositoryException e) { - throw new SlcException("Cannot read spec attributes from " + node, - e); - } + protected void setFlowStatus(Node realizedFlowNode, String status) + throws RepositoryException { + realizedFlowNode.setProperty(SLC_STATUS, status); + realizedFlowNode.getSession().save(); } protected JcrExecutionProcess getJcrExecutionProcess() {