<!-- Manager -->\r
<bean id="modulesManager" class="org.argeo.slc.osgi.OsgiExecutionModulesManager"\r
init-method="init" destroy-method="destroy">\r
- <property name="slcExecutionNotifiers" ref="slcExecutionListeners" />\r
<property name="bundlesManager" ref="bundlesManager" />\r
</bean>\r
\r
<listener ref="modulesManager" />\r
</list>\r
\r
- <list id="slcExecutionListeners" interface="org.argeo.slc.process.SlcExecutionNotifier"\r
- cardinality="0..N" />\r
-\r
<list id="agents" interface="org.argeo.slc.execution.SlcAgent"\r
cardinality="0..N">\r
<listener ref="vmAgentFactory" bind-method="register"\r
import org.argeo.slc.execution.ExecutionProcessNotifier;
import org.argeo.slc.execution.ExecutionStep;
import org.argeo.slc.execution.RealizedFlow;
-import org.argeo.slc.process.SlcExecutionNotifier;
/** Provides the base feature of an execution module manager. */
-@SuppressWarnings("deprecation")
public abstract class AbstractExecutionModulesManager implements
ExecutionModulesManager {
private final static Log log = LogFactory
.getLog(AbstractExecutionModulesManager.class);
- private List<SlcExecutionNotifier> slcExecutionNotifiers = new ArrayList<SlcExecutionNotifier>();
-
private List<FilteredNotifier> filteredNotifiers = Collections
.synchronizedList(new ArrayList<FilteredNotifier>());
public void dispatchUpdateStatus(ExecutionProcess process,
String oldStatus, String newStatus) {
- // generic notifiers (notified of everything)
- for (Iterator<SlcExecutionNotifier> it = getSlcExecutionNotifiers()
- .iterator(); it.hasNext();) {
- it.next().updateStatus(process, oldStatus, newStatus);
- }
-
// filtered notifiers
for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
.hasNext();) {
public void dispatchAddSteps(ExecutionProcess process,
List<ExecutionStep> steps) {
process.addSteps(steps);
-
- for (Iterator<SlcExecutionNotifier> it = getSlcExecutionNotifiers()
- .iterator(); it.hasNext();) {
- it.next().addSteps(process, steps);
- }
-
for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
.hasNext();) {
FilteredNotifier filteredNotifier = it.next();
filteredNotifiers.remove(notifier);
}
- public void setSlcExecutionNotifiers(
- List<SlcExecutionNotifier> slcExecutionNotifiers) {
- this.slcExecutionNotifiers = slcExecutionNotifiers;
- }
-
- private List<SlcExecutionNotifier> getSlcExecutionNotifiers() {
- return slcExecutionNotifiers;
- }
-
protected class FilteredNotifier {
private final ExecutionProcessNotifier notifier;
private final String processId;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
import org.argeo.slc.execution.ExecutionModuleDescriptor;
import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.execution.ExecutionStep;
import org.argeo.slc.execution.SlcAgent;
import org.argeo.slc.execution.SlcAgentDescriptor;
-import org.argeo.slc.process.SlcExecution;
/** Implements the base methods of an SLC agent. */
-@SuppressWarnings("deprecation")
public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
private final static Log log = LogFactory.getLog(DefaultAgent.class);
protected ProcessThread createProcessThread(
ThreadGroup processesThreadGroup,
ExecutionModulesManager modulesManager, ExecutionProcess process) {
- if (!(process instanceof SlcExecution))
- throw new SlcException("Unsupported process type "
- + process.getClass());
ProcessThread processThread = new ProcessThread(processesThreadGroup,
- modulesManager, (SlcExecution) process);
+ modulesManager, process);
return processThread;
}
--- /dev/null
+package org.argeo.slc.core.execution;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.argeo.slc.execution.ExecutionProcess;
+import org.argeo.slc.execution.ExecutionStep;
+import org.argeo.slc.execution.RealizedFlow;
+
+public class DefaultProcess implements ExecutionProcess {
+ private String uuid = UUID.randomUUID().toString();
+ private String status;
+
+ private List<ExecutionStep> steps = new ArrayList<ExecutionStep>();
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public void addSteps(List<ExecutionStep> steps) {
+ steps.addAll(steps);
+ }
+
+ public List<RealizedFlow> getRealizedFlows() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.execution.ExecutionStep;
import org.argeo.slc.execution.RealizedFlow;
-import org.argeo.slc.process.SlcExecution;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder;
-/** Thread of the SLC Process, starting the sub executions. */
-@SuppressWarnings("deprecation")
public class ProcessThread extends Thread {
private final static Log log = LogFactory.getLog(ProcessThread.class);
public final void run() {
// authenticate thread
- Authentication authentication = getProcessThreadGroup()
- .getAuthentication();
- if (authentication == null)
- throw new SlcException("Can only execute authenticated threads");
- SecurityContextHolder.getContext().setAuthentication(authentication);
+ Authentication authentication = getProcessThreadGroup()
+ .getAuthentication();
+ if (authentication == null)
+ throw new SlcException("Can only execute authenticated threads");
+ SecurityContextHolder.getContext().setAuthentication(authentication);
// log.info("\n##\n## SLC Process #" + process.getUuid() +
// " STARTED by "
* custom process types. Default expects an {@link SlcExecution}.
*/
protected void process() throws InterruptedException {
- if (!(process instanceof SlcExecution))
- throw new SlcException("Unsupported process type "
- + process.getClass());
- SlcExecution slcExecution = (SlcExecution) process;
List<RealizedFlow> flowsToProcess = new ArrayList<RealizedFlow>();
- flowsToProcess.addAll(slcExecution.getRealizedFlows());
-
+ flowsToProcess.addAll(process.getRealizedFlows());
while (flowsToProcess.size() > 0) {
RealizedFlow realizedFlow = flowsToProcess.remove(0);
execute(realizedFlow, true);
import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.execution.ExecutionStep;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.process.SlcExecutionStep;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder;
/** The thread group attached to a given {@link SlcExecution}. */
-@SuppressWarnings("deprecation")
public class ProcessThreadGroup extends ThreadGroup {
private final ExecutionModulesManager executionModulesManager;
private final ProcessThread processThread;
}
public void dispatchAddStep(ExecutionStep step) {
- // legacy
ExecutionProcess slcProcess = processThread.getProcess();
- if (slcProcess instanceof SlcExecution)
- ((SlcExecution) slcProcess).getSteps().add((SlcExecutionStep) step);
-
List<ExecutionStep> steps = new ArrayList<ExecutionStep>();
steps.add(step);
+ // TODO clarify why we don't dispatch steps, must be a reason
// dispatchAddSteps(steps);
+ slcProcess.addSteps(steps);
this.steps.add(step);
}
public void setStatus(String status);
public void addSteps(List<ExecutionStep> steps);
+
+ public List<RealizedFlow> getRealizedFlows();
}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.process;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.TreeMap;\r
-\r
-import org.argeo.slc.execution.ExecutionProcess;\r
-import org.argeo.slc.execution.ExecutionStep;\r
-import org.argeo.slc.execution.RealizedFlow;\r
-\r
-/** @deprecated use other implementations of {@link ExecutionProcess} */\r
-public class SlcExecution implements ExecutionProcess, Serializable {\r
- private static final long serialVersionUID = -7607457971382118466L;\r
-\r
- public final static String UNKOWN_HOST = "UNKOWN_HOST";\r
-\r
- private String uuid;\r
- private String host;\r
- private String user;\r
- private String type;\r
- private String status = NEW;\r
- private Map<String, String> attributes = new TreeMap<String, String>();\r
-\r
- /** TODO: Synchronize */\r
- private List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();\r
- private List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();\r
-\r
- /** Attachment uuid. */\r
- private String realizedFlowsXml = null;\r
-\r
- public List<RealizedFlow> getRealizedFlows() {\r
- return realizedFlows;\r
- }\r
-\r
- public void setRealizedFlows(List<RealizedFlow> realizedFlows) {\r
- this.realizedFlows = realizedFlows;\r
- }\r
-\r
- public List<SlcExecutionStep> getSteps() {\r
- return steps;\r
- }\r
-\r
- public void setSteps(List<SlcExecutionStep> steps) {\r
- this.steps = steps;\r
- }\r
-\r
- public void addSteps(List<ExecutionStep> steps) {\r
- // not implemented on deprecated\r
- }\r
-\r
- public String getUuid() {\r
- return uuid;\r
- }\r
-\r
- public void setUuid(String uuid) {\r
- this.uuid = uuid;\r
- }\r
-\r
- public String getHost() {\r
- return host;\r
- }\r
-\r
- public void setHost(String host) {\r
- this.host = host;\r
- }\r
-\r
- public String getUser() {\r
- return user;\r
- }\r
-\r
- public void setUser(String user) {\r
- this.user = user;\r
- }\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public String getStatus() {\r
- return status;\r
- }\r
-\r
- public void setStatus(String status) {\r
- this.status = status;\r
- }\r
-\r
- public SlcExecutionStep currentStep() {\r
- synchronized (steps) {\r
- if (steps.size() > 0)\r
- return steps.get(steps.size() - 1);\r
- else\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj instanceof SlcExecution) {\r
- return getUuid().equals(((SlcExecution) obj).getUuid());\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return getUuid().hashCode();\r
- }\r
-\r
- public Map<String, String> getAttributes() {\r
- return attributes;\r
- }\r
-\r
- public void setAttributes(Map<String, String> attributes) {\r
- this.attributes = attributes;\r
- }\r
-\r
- public String toString() {\r
- StringBuffer buf = new StringBuffer(getClass().getSimpleName());\r
- buf.append('#').append(uuid);\r
- buf.append(" status=").append(status);\r
- buf.append(" attributes=").append(attributes);\r
- return buf.toString();\r
- }\r
-\r
- public Date getStartDate() {\r
- synchronized (steps) {\r
- if (steps.size() == 0)\r
- return null;\r
- else\r
- return steps.get(0).getTimestamp();\r
- }\r
- }\r
-\r
- public Date getEndDate() {\r
- if (!status.equals(COMPLETED) && !status.equals(ERROR))\r
- return null;\r
-\r
- synchronized (steps) {\r
- if (steps.size() == 0)\r
- return null;\r
- else\r
- return steps.get(steps.size() - 1).getTimestamp();\r
- }\r
- }\r
-\r
- /**\r
- * Not (yet) a stable API, should not be relied upon!\r
- * \r
- * @return an id or an url allowing to retrieve the XML, not the XML itself!\r
- */\r
- public String getRealizedFlowsXml() {\r
- return realizedFlowsXml;\r
- }\r
-\r
- /** Not (yet) a stable API, should not be relied upon! */\r
- public void setRealizedFlowsXml(String realizedFlowsXml) {\r
- this.realizedFlowsXml = realizedFlowsXml;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.process;\r
-\r
-@Deprecated\r
-public interface SlcExecutionAware {\r
- public void notifySlcExecution(SlcExecution slcExecution);\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.process;\r
-\r
-import org.argeo.slc.execution.ExecutionProcessNotifier;\r
-\r
-/**\r
- * Notifies of changes in the current process\r
- * \r
- * @deprecated use {@link ExecutionProcessNotifier} instead.\r
- */\r
-public interface SlcExecutionNotifier extends ExecutionProcessNotifier {\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.process;
-
-@Deprecated
-public interface SlcExecutionRelated {
- public String getSlcExecutionUuid();
-
- public String getSlcExecutionStepUuid();
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.process;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-import java.util.UUID;\r
-\r
-import org.argeo.slc.execution.ExecutionStep;\r
-\r
-/**\r
- * An atomic step to be notified in during an {@link SlcExecution}. Can be a log\r
- * or the start/end of a phase, etc.\r
- * \r
- * @deprecated use {@link ExecutionStep} instead\r
- */\r
-public class SlcExecutionStep extends ExecutionStep {\r
- private static final long serialVersionUID = -7308643628104726471L;\r
-\r
- private String uuid = UUID.randomUUID().toString();\r
- private List<String> logLines = new ArrayList<String>();\r
-\r
- /** Empty constructor */\r
- public SlcExecutionStep() {\r
- }\r
-\r
- /** Creates a step at the current date of type INFO */\r
- public SlcExecutionStep(String log) {\r
- this(new Date(), INFO, log);\r
- }\r
-\r
- /** Creates a step at the current date */\r
- public SlcExecutionStep(String type, String log) {\r
- this(new Date(), type, log);\r
- }\r
-\r
- /** Creates a step of the given type. */\r
- public SlcExecutionStep(Date timestamp, String type, String log) {\r
- this(timestamp, type, log, Thread.currentThread().getName());\r
- }\r
-\r
- public SlcExecutionStep(Date timestamp, String type, String log,\r
- String thread) {\r
- super("UNKOWN_LOCATION", timestamp, type, log, thread);\r
- }\r
-\r
- public String getUuid() {\r
- return uuid;\r
- }\r
-\r
- public void setUuid(String uuid) {\r
- this.uuid = uuid;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public void setTimestamp(Date begin) {\r
- this.timestamp = begin;\r
- }\r
-\r
- public void setThread(String thread) {\r
- this.thread = thread;\r
- }\r
-\r
- public List<String> getLogLines() {\r
- return logLines;\r
- }\r
-\r
- public void setLogLines(List<String> logLines) {\r
- this.logLines = logLines;\r
- }\r
-\r
- /** public for legacy reasons */\r
- public String addLog(String log) {\r
- if (logLines == null)\r
- logLines = new ArrayList<String>();\r
-\r
- if (log == null)\r
- return null;\r
-\r
- StringTokenizer st = new StringTokenizer(log, "\n");\r
- while (st.hasMoreTokens())\r
- logLines.add(removeNonXmlChars(st.nextToken()));\r
- return null;\r
- }\r
-\r
- /**\r
- * Removes non XML compliant characters (from\r
- * http://stackoverflow.com/questions\r
- * /20762/how-do-you-remove-invalid-hexadecimal\r
- * -characters-from-an-xml-based-data-source-pr)\r
- */\r
- private static String removeNonXmlChars(String inString) {\r
- if (inString == null)\r
- return null;\r
-\r
- StringBuilder newString = new StringBuilder();\r
- char ch;\r
-\r
- for (int i = 0; i < inString.length(); i++) {\r
-\r
- ch = inString.charAt(i);\r
- // remove any characters outside the valid UTF-8 range as well as\r
- // all control characters\r
- // except tabs and new lines\r
- if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n'\r
- || ch == '\r') {\r
- newString.append(ch);\r
- }\r
- }\r
- return newString.toString();\r
-\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "#" + uuid;\r
- }\r
-\r
-}\r
*/
package org.argeo.slc.jcr.execution;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import org.argeo.slc.SlcException;
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.execution.ExecutionStep;
+import org.argeo.slc.execution.RealizedFlow;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
// return node;
// }
+ public List<RealizedFlow> getRealizedFlows() {
+ try {
+ List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
+ Node rootRealizedFlowNode = node.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();
+ RealizedFlow realizedFlow = new JcrRealizedFlow(
+ realizedFlowNode);
+ if (realizedFlow != null)
+ realizedFlows.add(realizedFlow);
+ }
+ return realizedFlows;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot get realized flows", e);
+ }
+ }
+
public String getNodePath() {
try {
return node.getPath();
*/
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 {
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();
+
+ List<RealizedFlow> realizedFlows = getProcess().getRealizedFlows();
+ for (RealizedFlow realizedFlow : realizedFlows) {
+ Node realizedFlowNode = session
+ .getNode(((JcrRealizedFlow) realizedFlow).getPath());
// set status on realized flow
realizedFlowNode.setProperty(SLC_STATUS,
ExecutionProcess.RUNNING);
realizedFlowNode.getSession().save();
try {
- execute(realizedFlowNode);
+ //
+ // EXECUTE THE FLOW
+ //
+ execute(realizedFlow, true);
// set status on realized flow
realizedFlowNode.setProperty(SLC_STATUS,
}
}
- /** 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<String, ExecutionSpecAttribute> 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<String, Object> values = new HashMap<String, Object>();
- 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);
- //
- }
- }
-
- protected Map<String, ExecutionSpecAttribute> readExecutionSpecAttributes(
- Node node) {
- try {
- Map<String, ExecutionSpecAttribute> attrs = new HashMap<String, ExecutionSpecAttribute>();
- 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);
- }
- }
+ //
+ // /** 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<STRING, EXECUTIONSPECATTRIBUTE> 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<STRING, OBJECT> VALUES = NEW HASHMAP<STRING, OBJECT>();
+ // 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);
+ // //
+ // }
+ // }
+ //
+ // PROTECTED MAP<STRING, EXECUTIONSPECATTRIBUTE>
+ // READEXECUTIONSPECATTRIBUTES(
+ // NODE NODE) {
+ // TRY {
+ // MAP<STRING, EXECUTIONSPECATTRIBUTE> ATTRS = NEW HASHMAP<STRING,
+ // EXECUTIONSPECATTRIBUTE>();
+ // 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 JcrExecutionProcess getJcrExecutionProcess() {
return (JcrExecutionProcess) getProcess();
--- /dev/null
+package org.argeo.slc.jcr.execution;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+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.RefSpecAttribute;
+import org.argeo.slc.execution.ExecutionFlowDescriptor;
+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;
+
+public class JcrRealizedFlow extends RealizedFlow implements SlcNames {
+ private static final long serialVersionUID = -3709453850260712001L;
+ private String path;
+
+ public JcrRealizedFlow(Node node) {
+ try {
+ this.path = node.getPath();
+ loadFromNode(node);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot initialize from " + node, e);
+ }
+ }
+
+ protected void loadFromNode(Node realizedFlowNode)
+ throws RepositoryException {
+ 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 = this;
+ realizedFlow.setModuleName(executionModuleName);
+ realizedFlow.setModuleVersion(executionModuleVersion);
+
+ // retrieve execution spec
+ DefaultExecutionSpec executionSpec = new DefaultExecutionSpec();
+ Map<String, ExecutionSpecAttribute> 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<String, Object> values = new HashMap<String, Object>();
+ 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);
+ } else {
+ throw new SlcException("Unsupported realized flow "
+ + realizedFlowNode);
+ }
+ }
+
+ protected Map<String, ExecutionSpecAttribute> readExecutionSpecAttributes(
+ Node node) {
+ try {
+ Map<String, ExecutionSpecAttribute> attrs = new HashMap<String, ExecutionSpecAttribute>();
+ 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);
+ }
+ }
+
+ public String getPath() {
+ return path;
+ }
+}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.process;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNotNull;\r
-import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.UUID;\r
-\r
-import org.argeo.slc.execution.ExecutionFlowDescriptor;\r
-import org.argeo.slc.execution.ExecutionStep;\r
-import org.argeo.slc.execution.RealizedFlow;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.unit.execution.ExecutionFlowDescriptorTestUtils;\r
-\r
-public abstract class SlcExecutionTestUtils {\r
-\r
- public static SlcExecution createSimpleSlcExecution() {\r
- SlcExecution slcExec = new SlcExecution();\r
- slcExec.setUuid(UUID.randomUUID().toString());\r
- slcExec.setHost("localhost");\r
- slcExec.setUser("user");\r
- slcExec.setType("slcAnt");\r
- slcExec.setStatus("STARTED");\r
- slcExec.getAttributes().put("ant.file", "/test");\r
- return slcExec;\r
- }\r
-\r
- public static SlcExecution createSlcExecutionWithRealizedFlows() {\r
- SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();\r
- List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();\r
- RealizedFlow realizedFlow = new RealizedFlow();\r
- ExecutionFlowDescriptor flowDescriptor = ExecutionFlowDescriptorTestUtils\r
- .createSimpleExecutionFlowDescriptor();\r
- realizedFlow.setModuleName("test.module");\r
- realizedFlow.setModuleVersion("1.0.0");\r
- realizedFlow.setFlowDescriptor(flowDescriptor);\r
- //realizedFlow.setExecutionSpec(flowDescriptor.getExecutionSpec());\r
- realizedFlows.add(realizedFlow);\r
- slcExec.setRealizedFlows(realizedFlows);\r
- return slcExec;\r
- }\r
-\r
- public static void assertSlcExecution(SlcExecution expected,\r
- SlcExecution reached) {\r
- assertNotNull(reached);\r
- assertEquals(expected.getHost(), reached.getHost());\r
- assertEquals(expected.getUser(), reached.getUser());\r
- assertEquals(expected.getType(), reached.getType());\r
- assertEquals(expected.getStatus(), reached.getStatus());\r
-\r
- // Attributes\r
- assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
- .size());\r
- for (String key : expected.getAttributes().keySet()) {\r
- String expectedValue = expected.getAttributes().get(key);\r
- String reachedValue = reached.getAttributes().get(key);\r
- assertNotNull(reachedValue);\r
- assertEquals(expectedValue, reachedValue);\r
- }\r
-\r
- assertEquals(expected.getSteps().size(), reached.getSteps().size());\r
- for (int i = 0; i < expected.getSteps().size(); i++) {\r
- SlcExecutionStep stepExpected = expected.getSteps().get(i);\r
- SlcExecutionStep stepReached = reached.getSteps().get(i);\r
- assertSlcExecutionStep(stepExpected, stepReached);\r
- }\r
-\r
- // FIXME: compare realized flows\r
- // assertEquals(expected.getRealizedFlows().size(), reached\r
- // .getRealizedFlows().size());\r
-\r
- }\r
-\r
- public static void assertSlcExecutionStep(ExecutionStep expected,\r
- ExecutionStep reached) {\r
- assertNotNull(reached);\r
- assertEquals(expected.getType(), reached.getType());\r
- assertDateSec(expected.getTimestamp(), reached.getTimestamp());\r
- if (expected instanceof SlcExecutionStep) {\r
- SlcExecutionStep slcExpected = (SlcExecutionStep)expected;\r
- SlcExecutionStep slcReached = (SlcExecutionStep)reached;\r
- assertEquals(slcExpected.getUuid(), slcReached.getUuid());\r
- assertEquals(slcExpected.getLogLines().size(), slcReached.getLogLines()\r
- .size());\r
- for (int i = 0; i < slcExpected.getLogLines().size(); i++) {\r
- assertEquals(slcExpected.getLogLines().get(i), slcReached\r
- .getLogLines().get(i));\r
- }\r
- }\r
- }\r
-\r
- private SlcExecutionTestUtils() {\r
-\r
- }\r
-}\r