*/
package org.argeo.slc.client.ui;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.NameVersion;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.deploy.ModulesManager;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/** The activator class controls the plug-in life cycle */
-public class ClientUiPlugin extends AbstractUIPlugin {
+public class ClientUiPlugin extends AbstractUIPlugin implements SlcNames {
public static final String ID = "org.argeo.slc.client.ui";
private static ClientUiPlugin plugin;
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(ID, path);
}
+
+ /** Start execution module if it was stopped and vice-versa */
+ public static void startStopExecutionModule(
+ final ModulesManager modulesManager, Node node) {
+ try {
+ if (!node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE))
+ throw new SlcException(node + " is not an execution module");
+
+ String name = node.getProperty(SLC_NAME).getString();
+ String version = node.getProperty(SLC_VERSION).getString();
+ final NameVersion nameVersion = new BasicNameVersion(name, version);
+ Boolean started = node.getProperty(SLC_STARTED).getBoolean();
+
+ Job job;
+ if (started) {
+ job = new Job("Stop " + nameVersion) {
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Stop " + nameVersion, 1);
+ modulesManager.stop(nameVersion);
+ monitor.worked(1);
+ return Status.OK_STATUS;
+ }
+
+ protected void canceling() {
+ getThread().interrupt();
+ super.canceling();
+ }
+ };
+ } else {
+ job = new Job("Start " + nameVersion) {
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Start " + nameVersion, 1);
+ modulesManager.start(nameVersion);
+ monitor.worked(1);
+ return Status.OK_STATUS;
+ }
+
+ protected void canceling() {
+ getThread().interrupt();
+ super.canceling();
+ }
+ };
+ }
+ job.setUser(true);
+ job.schedule();
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot start " + node, e);
+ }
+
+ }
}
import javax.jcr.query.QueryManager;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.ClientUiPlugin;
import org.argeo.slc.client.ui.SlcImages;
+import org.argeo.slc.core.execution.PrimitiveAccessor;
import org.argeo.slc.core.execution.PrimitiveUtils;
+import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.jcr.SlcJcrUtils;
import org.argeo.slc.jcr.SlcNames;
/** Definition of the process. */
public class ProcessBuilderPage extends FormPage implements SlcNames {
public final static String ID = "processBuilderPage";
- // private final static Log log =
- // LogFactory.getLog(ProcessBuilderPage.class);
/** To be displayed in empty lists */
final static String NONE = "<none>";
private Node processNode;
+ private final ExecutionModulesManager modulesManager;
private TreeViewer flowsViewer;
private TableViewer valuesViewer;
private AbstractFormPart formPart;
private EventListener statusObserver;
- public ProcessBuilderPage(ProcessEditor editor, Node processNode) {
+ public ProcessBuilderPage(ProcessEditor editor, Node processNode,
+ ExecutionModulesManager modulesManager) {
super(editor, ID, "Definition");
this.processNode = processNode;
+ this.modulesManager = modulesManager;
}
@Override
/*
* UTILITIES
*/
- // protected static Object getAttributeSpecValue(Node specAttrNode) {
- // try {
- // if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
- // if (!specAttrNode.hasProperty(SLC_VALUE))
- // return null;
- // String type = specAttrNode.getProperty(SLC_TYPE).getString();
- // // TODO optimize based on data type?
- // Object value = PrimitiveUtils.convert(type, specAttrNode
- // .getProperty(SLC_VALUE).getString());
- // // log.debug(specAttrNode + ", type=" + type + ", value=" +
- // // value);
- // return value;
- // } else if (specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
- // if (specAttrNode.hasNode(SLC_VALUE)) {
- // // return the index of the sub node
- // // in the future we may manage reference as well
- // return specAttrNode.getProperty(SLC_VALUE).getLong();
- // } else
- // return null;
- // }
- // return null;
- // } catch (RepositoryException e) {
- // throw new SlcException("Cannot get value", e);
- // }
- //
- // }
-
protected static String getAttributeSpecText(Node specAttrNode) {
try {
if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
if (!specAttrNode.hasProperty(SLC_VALUE))
return "";
String type = specAttrNode.getProperty(SLC_TYPE).getString();
+ if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
+ return "****************";
Object value = PrimitiveUtils.convert(type, specAttrNode
.getProperty(SLC_VALUE).getString());
return value.toString();
/*
* FLOWS SUBCLASSES
*/
- static class FlowsContentProvider implements ITreeContentProvider {
+ class FlowsContentProvider implements ITreeContentProvider {
public Object[] getElements(Object obj) {
if (!(obj instanceof Node))
return new Object[0];
Node node = (Node) obj;
List<Node> children = new ArrayList<Node>();
for (NodeIterator nit = node.getNode(SLC_FLOW).getNodes(); nit
- .hasNext();)
- children.add(nit.nextNode());
+ .hasNext();) {
+ Node flowNode = nit.nextNode();
+ children.add(flowNode);
+ try {
+ // make sure modules are started for all nodes
+ String flowDefPath = flowNode.getNode(SLC_ADDRESS)
+ .getProperty(Property.JCR_PATH).getString();
+ Node executionModuleNode = flowNode.getSession()
+ .getNode(SlcJcrUtils.modulePath(flowDefPath));
+ if (!executionModuleNode.getProperty(SLC_STARTED)
+ .getBoolean())
+ ClientUiPlugin.startStopExecutionModule(
+ modulesManager, executionModuleNode);
+ } catch (Exception e) {
+ ErrorFeedback.show(
+ "Cannot start execution module related to "
+ + flowNode, e);
+ }
+
+ }
return children.toArray();
} catch (RepositoryException e) {
- throw new SlcException("Cannot list children of " + obj, e);
+ throw new SlcException("Cannot list flows of " + obj, e);
}
}
Node specAttrNode = (Node) element;
if (specAttrNode
.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
- return new TextCellEditor(tableViewer.getTable());
+ String type = specAttrNode.getProperty(SLC_TYPE)
+ .getString();
+ if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
+ return new TextCellEditor(tableViewer.getTable(),
+ SWT.PASSWORD);
+ } else {
+ return new TextCellEditor(tableViewer.getTable());
+ }
} else if (specAttrNode
.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
NodeIterator children = specAttrNode.getNodes();
protected Object getValue(Object element) {
Node specAttrNode = (Node) element;
try {
- // Object value = getAttributeSpecValue(specAttrNode);
- // if (value == null)
- // throw new SlcException("Unsupported attribute " + element);
if (specAttrNode
.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
if (!specAttrNode.hasProperty(SLC_VALUE))
private ProcessController processController;
private ProcessBuilderPage builderPage;
- //private ProcessLogPage logPage;
private ExecutionModulesManager modulesManager;
- //private Boolean switchToLog = false;
-
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
protected Node newProcessNode(ProcessEditorInput pei)
throws RepositoryException {
String uuid = UUID.randomUUID().toString();
- String processPath = SlcJcrUtils.createExecutionProcessPath(uuid);
+ String processPath = SlcJcrUtils.createExecutionProcessPath(session,
+ uuid);
Node processNode = JcrUtils.mkdirs(session, processPath, SLC_PROCESS);
processNode.setProperty(SLC_UUID, uuid);
processNode.setProperty(SLC_STATUS, ExecutionProcess.NEW);
}
doSave(null);
try {
- // show log
-// if (switchToLog)
-// setActivePage(logPage.getId());
-
ExecutionProcess process = processController.process(processNode);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ExecutionModulesManager.SLC_PROCESS_ID,
try {
Session session = processNode.getSession();
String uuid = UUID.randomUUID().toString();
- String destPath = SlcJcrUtils.createExecutionProcessPath(uuid);
+ String destPath = SlcJcrUtils.createExecutionProcessPath(session,
+ uuid);
Node newNode = JcrUtils.mkdirs(session, destPath,
SlcTypes.SLC_PROCESS);
@Override
protected void addPages() {
try {
- builderPage = new ProcessBuilderPage(this, processNode);
+ builderPage = new ProcessBuilderPage(this, processNode,
+ modulesManager);
addPage(builderPage);
firePropertyChange(PROP_DIRTY);
-// logPage = new ProcessLogPage(this, processNode);
-// addPage(logPage);
} catch (PartInitException e) {
throw new SlcException("Cannot add pages", e);
}
}
public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
- // logPage.addSteps(steps);
}
/** Expects one session per editor. */
import org.argeo.eclipse.ui.jcr.NodeElementComparer;
import org.argeo.eclipse.ui.jcr.SimpleNodeContentProvider;
import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils;
-import org.argeo.slc.BasicNameVersion;
-import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.ClientUiPlugin;
import org.argeo.slc.client.ui.SlcImages;
import org.argeo.slc.client.ui.editors.ProcessEditor;
import org.argeo.slc.client.ui.editors.ProcessEditorInput;
import org.argeo.slc.jcr.SlcJcrConstants;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
new String[] { SlcJcrConstants.VM_AGENT_FACTORY_PATH });
}
- // @Override
- // protected Object[] getChildren(Node node) throws RepositoryException
- // {
- // if (node.isNodeType(SlcTypes.SLC_AGENT_FACTORY)) {
- // List<AgentNodesWrapper> wrappers = new
- // ArrayList<AgentNodesWrapper>();
- // for (NodeIterator nit = node.getNodes(); nit.hasNext();) {
- // wrappers.add(new AgentNodesWrapper(nit.nextNode()));
- // }
- // return wrappers.toArray();
- // }
- // return super.getChildren(node);
- // }
-
@Override
protected Object[] sort(Object parent, Object[] children) {
Object[] sorted = new Object[children.length];
}
- // /** Wraps the execution modules of an agent. */
- // static class AgentNodesWrapper extends NodesWrapper {
- //
- // public AgentNodesWrapper(Node node) {
- // super(node);
- // }
- //
- // protected List<WrappedNode> getWrappedNodes()
- // throws RepositoryException {
- // List<WrappedNode> children = new ArrayList<WrappedNode>();
- // Node executionModules = getNode();
- // for (NodeIterator nit = executionModules.getNodes(); nit.hasNext();) {
- // for (NodeIterator nitVersions = nit.nextNode().getNodes(); nitVersions
- // .hasNext();) {
- // children.add(new WrappedNode(this, nitVersions.nextNode()));
- // }
- // }
- // return children;
- // }
- //
- // }
-
class VmAgentObserver extends AsyncUiEventListener {
public VmAgentObserver(Display display) {
}
}
- // try {
- // Node vmAgentNode = session
- // .getNode(SlcJcrConstants.VM_AGENT_FACTORY_PATH);
- // viewer.refresh(vmAgentNode);
- // } catch (RepositoryException e) {
- // log.warn("Cannot process event : " + e);
- // }
// TODO: optimize based on event
viewer.refresh();
}
if (obj instanceof Node) {
Node node = (Node) obj;
if (node.isNodeType(SLC_EXECUTION_MODULE)) {
- String name = node.getProperty(SLC_NAME).getString();
- String version = node.getProperty(SLC_VERSION)
- .getString();
- final NameVersion nameVersion = new BasicNameVersion(
- name, version);
- Boolean started = node.getProperty(SLC_STARTED)
- .getBoolean();
-
- Job job;
- if (started) {
- job = new Job("Stop " + nameVersion) {
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask("Stop " + nameVersion, 1);
- modulesManager.stop(nameVersion);
- monitor.worked(1);
- return Status.OK_STATUS;
- }
-
- protected void canceling() {
- getThread().interrupt();
- super.canceling();
- }
- };
- } else {
- job = new Job("Start " + nameVersion) {
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask("Start " + nameVersion, 1);
- modulesManager.start(nameVersion);
- monitor.worked(1);
- return Status.OK_STATUS;
- }
-
- protected void canceling() {
- getThread().interrupt();
- super.canceling();
- }
- };
- }
- job.setUser(true);
- job.schedule();
+ ClientUiPlugin.startStopExecutionModule(modulesManager,
+ node);
} else {
String path = node.getPath();
// TODO factorize with editor
paths.add(nit.nextNode().getPath());
}
- // List<String> paths = new ArrayList<String>();
- // paths.add(node.getPath());
IWorkbenchPage activePage = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
activePage.openEditor(new ProcessEditorInput(
import org.argeo.slc.client.ui.editors.ProcessEditor;
import org.argeo.slc.client.ui.editors.ProcessEditorInput;
import org.argeo.slc.execution.ExecutionProcess;
-import org.argeo.slc.jcr.SlcJcrConstants;
+import org.argeo.slc.jcr.SlcJcrUtils;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.jface.viewers.ColumnLabelProvider;
observationManager.addEventListener(processesObserver,
Event.NODE_ADDED | Event.NODE_REMOVED
| Event.PROPERTY_CHANGED,
- SlcJcrConstants.PROCESSES_BASE_PATH, true, null, null,
- false);
+ SlcJcrUtils.getSlcProcessesBasePath(session), true, null,
+ null, false);
} catch (RepositoryException e) {
throw new SlcException("Cannot register listeners", e);
}
/** Abstraction of access to primitive values */
public interface PrimitiveAccessor {
public final static String TYPE_STRING = "string";
+ /**
+ * As of Argeo 1, passwords are NOT stored encrypted, just hidden in the UI,
+ * but stored in plain text in JCR. Use keyring instead.
+ */
+ public final static String TYPE_PASSWORD = "password";
public final static String TYPE_INTEGER = "integer";
public final static String TYPE_LONG = "long";
public final static String TYPE_FLOAT = "float";
public static Class<?> typeAsClass(String type) {
if (PrimitiveAccessor.TYPE_STRING.equals(type))
return String.class;
+ else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
+ return char[].class;
else if (PrimitiveAccessor.TYPE_INTEGER.equals(type))
return Integer.class;
else if (PrimitiveAccessor.TYPE_LONG.equals(type))
public static String classAsType(Class<?> clss) {
if (String.class.isAssignableFrom(clss))
return PrimitiveAccessor.TYPE_STRING;
+ else if (char[].class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_PASSWORD;
else if (Integer.class.isAssignableFrom(clss))
return PrimitiveAccessor.TYPE_INTEGER;
else if (Long.class.isAssignableFrom(clss))
return null;
}
+ /** Parse string as an object. Passwords are returned as String.*/
public static Object convert(String type, String str) {
if (PrimitiveAccessor.TYPE_STRING.equals(type)) {
return str;
+ } else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
+ return str;
} else if (PrimitiveAccessor.TYPE_INTEGER.equals(type)) {
return (Integer.parseInt(str));
} else if (PrimitiveAccessor.TYPE_LONG.equals(type)) {
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="string" />
+ <xsd:enumeration value="password" />
<xsd:enumeration value="integer" />
<xsd:enumeration value="long" />
<xsd:enumeration value="float" />
/** JCR related constants used across SLC */
public interface SlcJcrConstants {
public final static String PROPERTY_PATH = "argeo.slc.jcr.path";
- public final static String SLC_BASE_PATH = "/slc:system";
- public final static String PROCESSES_BASE_PATH = SLC_BASE_PATH
- + "/slc:processes";
+
+ public final static String SLC_BASE_PATH = "/" + SlcNames.SLC_SYSTEM;
public final static String AGENTS_BASE_PATH = SLC_BASE_PATH + "/slc:agents";
- // public final static String RESULTS_BASE_PATH = SLC_BASE_PATH
- // + "/slc:results";
public final static String VM_AGENT_FACTORY_PATH = AGENTS_BASE_PATH
+ "/slc:vm";
-
- /*
- * SLC SPECIFIC JCR PATHS
- */
- public final static String SLC_MYRESULT_BASEPATH = "slc:myResults";
}
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
-import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.UserJcrUtils;
import org.argeo.slc.SlcException;
*/
public static String getSlcResultsBasePath(Session session) {
try {
-
- return UserJcrUtils.getUserHome(session).getPath() + "/"
+ Node userHome = UserJcrUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ SlcNames.SLC_RESULTS;
} catch (RepositoryException re) {
- throw new ArgeoException(
+ throw new SlcException(
"Unexpected error while getting Slc Results Base Path.", re);
}
}
*/
public static String getMyResultsBasePath(Session session) {
try {
- return UserJcrUtils.getUserHome(session).getPath() + "/"
- + SlcJcrConstants.SLC_MYRESULT_BASEPATH;
+ Node userHome = UserJcrUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ + SlcNames.SLC_MY_RESULTS;
} catch (RepositoryException re) {
- throw new ArgeoException(
+ throw new SlcException(
"Unexpected error while getting Slc Results Base Path.", re);
}
}
return myResParNode;
}
} catch (RepositoryException re) {
- throw new ArgeoException(
+ throw new SlcException(
"Unexpected error while creating user MyResult base node.",
re);
}
session.save();
return rfNode;
} catch (RepositoryException re) {
- throw new ArgeoException(
+ throw new SlcException(
"Unexpected error while creating Result Folder node.", re);
}
}
}
/** Create a new execution process path based on the current time */
- public static String createExecutionProcessPath(String uuid) {
+ public static String createExecutionProcessPath(Session session, String uuid) {
Calendar now = new GregorianCalendar();
- return SlcJcrConstants.PROCESSES_BASE_PATH + '/'
+ return getSlcProcessesBasePath(session) + '/'
+ JcrUtils.dateAsPath(now, true) + uuid;
}
+ /** GEt the base for the user processeses. */
+ public static String getSlcProcessesBasePath(Session session) {
+ try {
+ Node userHome = UserJcrUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ + SlcNames.SLC_PROCESSES;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while getting Slc Results Base Path.", re);
+ }
+ }
+
/**
* Create a new execution result path in the user home based on the current
* time
public static String createResultPath(Session session, String uuid)
throws RepositoryException {
Calendar now = new GregorianCalendar();
- Node userHome = UserJcrUtils.getUserHome(session);
- if (userHome == null)
- throw new SlcException("No user home available for "
- + session.getUserID());
- return userHome.getPath() + '/' + SlcNames.SLC_RESULTS + '/'
+ return SlcJcrResultUtils.getSlcResultsBasePath(session) + '/'
+ JcrUtils.dateAsPath(now, true) + uuid;
}
if (value instanceof CharSequence)
value = PrimitiveUtils.convert(type,
((CharSequence) value).toString());
+ if (value instanceof char[])
+ value = new String((char[]) value);
try {
if (type.equals(PrimitiveAccessor.TYPE_STRING))
node.setProperty(propertyName, value.toString());
+ else if (type.equals(PrimitiveAccessor.TYPE_PASSWORD))
+ node.setProperty(propertyName, value.toString());
else if (type.equals(PrimitiveAccessor.TYPE_INTEGER))
node.setProperty(propertyName, (long) ((Integer) value));
else if (type.equals(PrimitiveAccessor.TYPE_LONG))
*/
package org.argeo.slc.jcr;
-
/** JCR names used by SLC */
public interface SlcNames {
public final static String SLC_ = "slc:";
public final static String SLC_IS_CONSTANT = "slc:isConstant";
public final static String SLC_IS_HIDDEN = "slc:isHidden";
- // result
+ // base directories
+ public final static String SLC_SYSTEM = "slc:system";
public final static String SLC_RESULTS = "slc:results";
+ public final static String SLC_MY_RESULTS = "slc:myResults";
+ public final static String SLC_PROCESSES = "slc:processes";
+
+ // result
public final static String SLC_SUCCESS = "slc:success";
public final static String SLC_MESSAGE = "slc:message";
public final static String SLC_TAG = "slc:tag";
// diff result
public final static String SLC_SUMMARY = "slc:summary";
public final static String SLC_ISSUES = "slc:issues";
-
+
/*
* REPO
*/