--- /dev/null
+package org.argeo.slc.client.ui.views;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.client.oxm.OxmInterface;
+import org.argeo.slc.client.ui.ClientUiPlugin;
+import org.argeo.slc.client.ui.controllers.ProcessController;
+import org.argeo.slc.client.ui.providers.ExecutionModulesContentProvider;
+import org.argeo.slc.client.ui.providers.ExecutionModulesContentProvider.FlowNode;
+import org.argeo.slc.execution.ExecutionModuleDescriptor;
+import org.argeo.slc.process.RealizedFlow;
+import org.argeo.slc.process.SlcExecution;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+public class JcrExecutionModulesView extends ViewPart {
+ private final static Log log = LogFactory
+ .getLog(JcrExecutionModulesView.class);
+
+ public static final String ID = "org.argeo.slc.client.ui.executionModulesView";
+
+ private TreeViewer viewer;
+
+ // Ioc
+ private IContentProvider contentProvider;
+ private OxmInterface oxmBean;
+ private ProcessController processController;
+
+ public void createPartControl(Composite parent) {
+ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.setContentProvider(contentProvider);
+ viewer.setLabelProvider(new ViewLabelProvider());
+ viewer.setInput(getViewSite());
+ viewer.addDoubleClickListener(new ViewDoubleClickListener());
+ int operations = DND.DROP_COPY | DND.DROP_MOVE;
+ Transfer[] tt = new Transfer[] { TextTransfer.getInstance() };
+ viewer.addDragSupport(operations, tt, new ViewDragListener());
+ }
+
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+ public TreeViewer getViewer() {
+ return viewer;
+ }
+
+ public void refreshView() {
+ viewer.setInput(getViewSite());
+ }
+
+ class ViewLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+ public String getColumnText(Object obj, int index) {
+ if (obj instanceof ExecutionModulesContentProvider.ExecutionModuleNode) {
+ ExecutionModuleDescriptor emd = ((ExecutionModulesContentProvider.ExecutionModuleNode) obj)
+ .getDescriptor();
+ if (emd.getLabel() != null) {
+ return emd.getLabel();
+ } else {
+ return getText(emd);
+ }
+ } else
+ return getText(obj);
+ }
+
+ public Image getColumnImage(Object obj, int index) {
+ return getImage(obj);
+ }
+
+ public Image getImage(Object obj) {
+ if (obj instanceof ExecutionModulesContentProvider.AgentNode)
+ return ClientUiPlugin.getDefault().getImageRegistry()
+ .get("agent");
+ else if (obj instanceof ExecutionModulesContentProvider.ExecutionModuleNode)
+ return ClientUiPlugin.getDefault().getImageRegistry()
+ .get("executionModule");
+ else if (obj instanceof ExecutionModulesContentProvider.FolderNode)
+ return ClientUiPlugin.getDefault().getImageRegistry()
+ .get("folder");
+ else if (obj instanceof ExecutionModulesContentProvider.FlowNode)
+ return ClientUiPlugin.getDefault().getImageRegistry()
+ .get("flow");
+ else
+ return PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJ_ELEMENT);
+ }
+ }
+
+ class ViewDoubleClickListener implements IDoubleClickListener {
+ public void doubleClick(DoubleClickEvent evt) {
+ Object obj = ((IStructuredSelection) evt.getSelection())
+ .getFirstElement();
+ if (obj instanceof ExecutionModulesContentProvider.FlowNode) {
+ ExecutionModulesContentProvider.FlowNode fn = (ExecutionModulesContentProvider.FlowNode) obj;
+
+ List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
+ RealizedFlow realizedFlow = new RealizedFlow();
+ realizedFlow.setModuleName(fn.getExecutionModuleNode()
+ .getDescriptor().getName());
+ realizedFlow.setModuleVersion(fn.getExecutionModuleNode()
+ .getDescriptor().getVersion());
+ realizedFlow.setFlowDescriptor(fn.getExecutionModuleNode()
+ .getFlowDescriptors().get(fn.getFlowName()));
+ realizedFlows.add(realizedFlow);
+
+ SlcExecution slcExecution = new SlcExecution();
+ slcExecution.setUuid(UUID.randomUUID().toString());
+ slcExecution.setRealizedFlows(realizedFlows);
+ slcExecution.setHost(fn.getExecutionModuleNode().getAgentNode()
+ .getAgent().toString());
+ processController.execute(fn.getExecutionModuleNode()
+ .getAgentNode().getAgent(), slcExecution);
+ }
+ }
+
+ }
+
+ class ViewDragListener implements DragSourceListener {
+
+ public void dragStart(DragSourceEvent event) {
+ System.out.println("Start Drag");
+ }
+
+ public void dragSetData(DragSourceEvent event) {
+
+ // System.out.println("dragSetData: " + event);
+
+ IStructuredSelection selection = (IStructuredSelection) viewer
+ .getSelection();
+ if (selection.getFirstElement() instanceof ExecutionModulesContentProvider.FlowNode) {
+
+ if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
+ ExecutionModulesContentProvider.FlowNode flowNode = (ExecutionModulesContentProvider.FlowNode) selection
+ .getFirstElement();
+
+ Properties props = new Properties();
+ flowNodeAsProperties(props, flowNode);
+ props.setProperty("agentId", flowNode
+ .getExecutionModuleNode().getAgentNode().getAgent()
+ .getAgentUuid());
+ props.setProperty("host", flowNode.getExecutionModuleNode()
+ .getAgentNode().getAgent().toString());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ props.store(out, "");
+ event.data = new String(out.toByteArray());
+ } catch (IOException e) {
+ throw new SlcException(
+ "Cannot transform realized flow", e);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ }
+ }
+ }
+
+ public void dragFinished(DragSourceEvent event) {
+ System.out.println("Finished Drag");
+ }
+
+ protected void flowNodeAsProperties(Properties props, FlowNode fn) {
+
+ RealizedFlow realizedFlow = new RealizedFlow();
+ realizedFlow.setModuleName(fn.getExecutionModuleNode()
+ .getDescriptor().getName());
+ realizedFlow.setModuleVersion(fn.getExecutionModuleNode()
+ .getDescriptor().getVersion());
+ realizedFlow.setFlowDescriptor(fn.getExecutionFlowDescriptor());
+
+ // As we want to have the effective ExecutionSpec and not a
+ // reference; we store it at the RealizeFlow level : thus the
+ // marshaller will store the object and not only a reference.
+ realizedFlow.setExecutionSpec(fn.getExecutionFlowDescriptor()
+ .getExecutionSpec());
+
+ props.setProperty("RealizedFlowAsXml",
+ oxmBean.marshal(realizedFlow));
+ System.out
+ .println(oxmBean.marshal(fn.getExecutionFlowDescriptor()));
+
+ }
+
+ }
+
+ // IoC
+ public void setContentProvider(IContentProvider contentProvider) {
+ this.contentProvider = contentProvider;
+ }
+
+ public void setProcessController(ProcessController processController) {
+ this.processController = processController;
+ }
+
+ public void setOxmBean(OxmInterface oxmBean) {
+ this.oxmBean = oxmBean;
+ }
+
+}
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.slc.agent.jmx</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-Manifest-Version: 1.0
-Bundle-Version: 0.13.1.SNAPSHOT
-Bundle-Name: SLC Agent JMX
-Bundle-SymbolicName: org.argeo.slc.agent.jmx
-Import-Package: org.argeo.slc.core.execution,
- org.argeo.slc.execution
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
- default-lazy-init="false">
-<!--
- <bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="ignoreUnresolvablePlaceholders" value="true" />
- <property name="locations">
- <value>osgibundle:agent.properties
- </value>
- </property>
- </bean>
- -->
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
- default-lazy-init="false">
-
- <bean id="executionModulesListener"
- class="org.argeo.slc.core.execution.JmxExecutionModulesListeners">
- </bean>
-
-
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<beans:beans xmlns="http://www.springframework.org/schema/osgi"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"\r
- xsi:schemaLocation="http://www.springframework.org/schema/osgi \r
- http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd\r
- http://www.springframework.org/schema/beans \r
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
-\r
- <bundle id="agent" action="start" symbolic-name="org.argeo.slc.agent" />\r
-\r
- <service ref="executionModulesListener" interface="org.argeo.slc.execution.ExecutionModulesListener" />\r
-</beans:beans>
\ No newline at end of file
for (String name : executionFlows.keySet()) {
ExecutionFlow executionFlow = executionFlows.get(name);
- Assert.notNull(executionFlow.getName());
- Assert.state(name.equals(executionFlow.getName()));
-
- ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
- Assert.notNull(executionSpec);
- Assert.notNull(executionSpec.getName());
-
- Map<String, Object> values = new TreeMap<String, Object>();
- for (String key : executionSpec.getAttributes().keySet()) {
- ExecutionSpecAttribute attribute = executionSpec
- .getAttributes().get(key);
-
- if (attribute instanceof PrimitiveSpecAttribute) {
- if (executionFlow.isSetAsParameter(key)) {
- Object value = executionFlow.getParameter(key);
- PrimitiveValue primitiveValue = new PrimitiveValue();
- primitiveValue
- .setType(((PrimitiveSpecAttribute) attribute)
- .getType());
- primitiveValue.setValue(value);
- values.put(key, primitiveValue);
- } else {
- // no need to add a primitive value if it is not set,
- // all necessary information is in the spec
- }
- } else if (attribute instanceof RefSpecAttribute) {
- if (attribute.getIsFrozen()) {
- values.put(key, new RefValue(REF_VALUE_INTERNAL));
- } else
- values.put(key, buildRefValue(
- (RefSpecAttribute) attribute, executionFlow,
- key));
- } else {
- throw new SlcException("Unkown spec attribute type "
- + attribute.getClass());
- }
-
- }
-
- ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
- values, executionSpec);
- if (executionFlow.getPath() != null)
- efd.setPath(executionFlow.getPath());
- else
- efd.setPath("");
-
- // Takes description from spring
- BeanDefinition bd = getBeanFactory().getBeanDefinition(name);
- efd.setDescription(bd.getDescription());
+ ExecutionFlowDescriptor efd = getExecutionFlowDescriptor(executionFlow);
+ ExecutionSpec executionSpec = efd.getExecutionSpec();
// Add execution spec if necessary
if (!md.getExecutionSpecs().contains(executionSpec))
md.getExecutionFlows().addAll(set);
}
+ public ExecutionFlowDescriptor getExecutionFlowDescriptor(
+ ExecutionFlow executionFlow) {
+ Assert.notNull(executionFlow.getName());
+ String name = executionFlow.getName();
+
+ ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
+ Assert.notNull(executionSpec);
+ Assert.notNull(executionSpec.getName());
+
+ Map<String, Object> values = new TreeMap<String, Object>();
+ for (String key : executionSpec.getAttributes().keySet()) {
+ ExecutionSpecAttribute attribute = executionSpec.getAttributes()
+ .get(key);
+
+ if (attribute instanceof PrimitiveSpecAttribute) {
+ if (executionFlow.isSetAsParameter(key)) {
+ Object value = executionFlow.getParameter(key);
+ PrimitiveValue primitiveValue = new PrimitiveValue();
+ primitiveValue.setType(((PrimitiveSpecAttribute) attribute)
+ .getType());
+ primitiveValue.setValue(value);
+ values.put(key, primitiveValue);
+ } else {
+ // no need to add a primitive value if it is not set,
+ // all necessary information is in the spec
+ }
+ } else if (attribute instanceof RefSpecAttribute) {
+ if (attribute.getIsFrozen()) {
+ values.put(key, new RefValue(REF_VALUE_INTERNAL));
+ } else
+ values.put(
+ key,
+ buildRefValue((RefSpecAttribute) attribute,
+ executionFlow, key));
+ } else {
+ throw new SlcException("Unkown spec attribute type "
+ + attribute.getClass());
+ }
+
+ }
+
+ ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, values,
+ executionSpec);
+ if (executionFlow.getPath() != null)
+ efd.setPath(executionFlow.getPath());
+ else
+ efd.setPath("");
+
+ // Takes description from spring
+ BeanDefinition bd = getBeanFactory().getBeanDefinition(name);
+ efd.setDescription(bd.getDescription());
+ return efd;
+ }
+
@SuppressWarnings(value = { "unchecked" })
protected RefValue buildRefValue(RefSpecAttribute rsa,
ExecutionFlow executionFlow, String key) {
String ref = null;
Object value = executionFlow.getParameter(key);
if (applicationContext == null) {
- log
- .warn("No application context declared, cannot scan ref value.");
+ log.warn("No application context declared, cannot scan ref value.");
ref = value.toString();
} else {
}
}
if (ref == null) {
- log
- .warn("Cannot define reference for ref spec attribute "
- + key
- + " in "
- + executionFlow
- + " ("
- + rsa
- + ")."
- + " If it is an inner bean consider put it frozen.");
+ log.warn("Cannot define reference for ref spec attribute "
+ + key + " in " + executionFlow + " (" + rsa + ")."
+ + " If it is an inner bean consider put it frozen.");
ref = REF_VALUE_INTERNAL;
} else {
if (log.isTraceEnabled())
// Check whether name include path
int lastIndex1 = name1.lastIndexOf('/');
- //log.debug(name1+", "+lastIndex1);
+ // log.debug(name1+", "+lastIndex1);
if (!StringUtils.hasText(path1) && lastIndex1 >= 0) {
path1 = name1.substring(0, lastIndex1);
name1 = name1.substring(lastIndex1 + 1);
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * 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.core.execution;
-
-import java.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
-
-import org.argeo.slc.SlcException;
-import org.argeo.slc.deploy.Module;
-import org.argeo.slc.execution.ExecutionContext;
-import org.argeo.slc.execution.ExecutionFlow;
-import org.argeo.slc.execution.ExecutionModulesListener;
-
-public class JmxExecutionModulesListeners implements ExecutionModulesListener {
- private String executionModulesPrefix = "SLCExecutionModules";
- private MBeanServer mBeanServer = ManagementFactory
- .getPlatformMBeanServer();
-
- public void executionModuleAdded(Module module,
- ExecutionContext executionContext) {
- }
-
- public void executionModuleRemoved(Module module,
- ExecutionContext executionContext) {
- }
-
- public void executionFlowAdded(Module module, ExecutionFlow executionFlow) {
- try {
- StandardMBean mbean = new StandardMBean(executionFlow,
- ExecutionFlow.class);
- mBeanServer.registerMBean(mbean, flowName(module, executionFlow));
- } catch (Exception e) {
- String msg = "Cannot register execution flow " + executionFlow
- + " as mbean";
- throw new SlcException(msg, e);
- }
- }
-
- public void executionFlowRemoved(Module module, ExecutionFlow executionFlow) {
- try {
- mBeanServer.unregisterMBean(flowName(module, executionFlow));
- } catch (Exception e) {
- String msg = "Cannot unregister execution flow " + executionFlow
- + " as mbean";
- throw new SlcException(msg, e);
- }
- }
-
- protected ObjectName flowName(Module module, ExecutionFlow executionFlow) {
- String path = executionFlow.getPath();
- String name = executionModulesPrefix + ":" + "module="
- + module.getName() + "[" + module.getVersion() + "],"
- + (path != null ? "path=" + path + "," : "") + "name="
- + executionFlow.getName();
- try {
- return new ObjectName(name);
- } catch (Exception e) {
- throw new SlcException("Cannot generate object name based on "
- + name, e);
- }
- }
-}
import org.argeo.slc.BasicNameVersion;
+/** Describes a distribution of modules. */
public class ModularDistributionDescriptor extends BasicNameVersion implements
Serializable {
- private static final long serialVersionUID = 1L;
-
+ private static final long serialVersionUID = 6076494586594591185L;
/** key is type, value the URL */
private Map<String, String> modulesDescriptors = new HashMap<String, String>();
import org.argeo.slc.NameVersion;
+/**
+ * Represents a deployed module of a broader deployed system. A module is
+ * uniquely identifiable via a name / version.
+ */
public interface Module extends DeployedSystem, NameVersion {
+ /** A serializable stateless description of the module */
+ public ModuleDescriptor getModuleDescriptor();
}
package org.argeo.slc.deploy;
+import java.io.Serializable;
+
import org.argeo.slc.BasicNameVersion;
/** The description of a versioned module. */
-public class ModuleDescriptor extends BasicNameVersion {
+public class ModuleDescriptor extends BasicNameVersion implements Serializable {
private static final long serialVersionUID = 4310820315478645419L;
private String title;
private String description;
import org.argeo.slc.NameVersion;
-/** Provides access to modules */
+/** Provides access to deployed modules */
public interface ModulesManager {
/** @return a full fledged module descriptor. */
public ModuleDescriptor getModuleDescriptor(String moduleName,
String version);
/**
- * @return a list of minimal module descriptors
+ * @return a list of minimal module descriptors of the deployed modules
*/
public List<ModuleDescriptor> listModules();
import java.util.Map;
+/**
+ * Maps back and forth between {@link ExecutionFlowDescriptor} and
+ * {@link ExecutionFlow}
+ */
public interface ExecutionFlowDescriptorConverter {
public Map<String, Object> convertValues(
ExecutionFlowDescriptor executionFlowDescriptor);
public void addFlowsToDescriptor(ExecutionModuleDescriptor md,
Map<String, ExecutionFlow> executionFlows);
+
+ public ExecutionFlowDescriptor getExecutionFlowDescriptor(
+ ExecutionFlow executionFlow);
}
package org.argeo.slc.execution;
-import org.argeo.slc.deploy.Module;
+import org.argeo.slc.deploy.ModuleDescriptor;
/** Listen to events on execution modules. */
public interface ExecutionModulesListener {
- public void executionModuleAdded(Module module,
- ExecutionContext executionContext);
+ public void executionModuleAdded(ModuleDescriptor moduleDescriptor);
- public void executionModuleRemoved(Module module,
- ExecutionContext executionContext);
+ public void executionModuleRemoved(ModuleDescriptor moduleDescriptor);
- public void executionFlowAdded(Module module, ExecutionFlow executionFlow);
+ public void executionFlowAdded(ModuleDescriptor moduleDescriptor,
+ ExecutionFlowDescriptor executionFlowDescriptor);
- public void executionFlowRemoved(Module module, ExecutionFlow executionFlow);
+ public void executionFlowRemoved(ModuleDescriptor moduleDescriptor,
+ ExecutionFlowDescriptor executionFlowDescriptor);
}
import java.util.Iterator;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
-import org.argeo.slc.deploy.Module;
-import org.argeo.slc.execution.ExecutionContext;
-import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.deploy.ModuleDescriptor;
+import org.argeo.slc.execution.ExecutionFlowDescriptor;
import org.argeo.slc.execution.ExecutionModulesListener;
import org.argeo.slc.jcr.SlcJcrConstants;
import org.argeo.slc.jcr.SlcNames;
}
}
- public void executionModuleAdded(Module module,
- ExecutionContext executionContext) {
+ public void executionModuleAdded(ModuleDescriptor moduleDescriptor) {
try {
Node base = session.getNode(getExecutionModulesPath());
- Node moduleName = base.hasNode(module.getName()) ? base
- .getNode(module.getName()) : base.addNode(module.getName());
- Node moduleVersion = moduleName.hasNode(module.getVersion()) ? moduleName
- .getNode(module.getVersion()) : moduleName.addNode(module
+ Node moduleName = base.hasNode(moduleDescriptor.getName()) ? base
+ .getNode(moduleDescriptor.getName()) : base
+ .addNode(moduleDescriptor.getName());
+ Node moduleVersion = moduleName.hasNode(moduleDescriptor
+ .getVersion()) ? moduleName.getNode(moduleDescriptor
+ .getVersion()) : moduleName.addNode(moduleDescriptor
.getVersion());
+ moduleVersion.addMixin(NodeType.MIX_TITLE);
+ moduleVersion.setProperty(Property.JCR_TITLE,
+ moduleDescriptor.getTitle());
+ moduleVersion.setProperty(Property.JCR_DESCRIPTION,
+ moduleDescriptor.getDescription());
session.save();
} catch (RepositoryException e) {
- throw new SlcException("Cannot add module " + module, e);
+ throw new SlcException("Cannot add module " + moduleDescriptor, e);
}
}
- public void executionModuleRemoved(Module module,
- ExecutionContext executionContext) {
+ public void executionModuleRemoved(ModuleDescriptor moduleDescriptor) {
try {
Node base = session.getNode(getExecutionModulesPath());
- if (base.hasNode(module.getName())) {
- Node moduleName = base.getNode(module.getName());
- if (moduleName.hasNode(module.getVersion()))
- moduleName.getNode(module.getVersion()).remove();
+ if (base.hasNode(moduleDescriptor.getName())) {
+ Node moduleName = base.getNode(moduleDescriptor.getName());
+ if (moduleName.hasNode(moduleDescriptor.getVersion()))
+ moduleName.getNode(moduleDescriptor.getVersion()).remove();
if (!moduleName.hasNodes())
moduleName.remove();
session.save();
}
} catch (RepositoryException e) {
- throw new SlcException("Cannot remove module " + module, e);
+ throw new SlcException("Cannot remove module " + moduleDescriptor,
+ e);
}
}
- public void executionFlowAdded(Module module, ExecutionFlow executionFlow) {
+ public void executionFlowAdded(ModuleDescriptor module,
+ ExecutionFlowDescriptor executionFlow) {
String path = getExecutionFlowPath(module, executionFlow);
- log.debug("path=" + path);
try {
Node flowNode;
if (!session.nodeExists(path)) {
Node moduleNode = base.getNode(module.getName() + '/'
+ module.getVersion());
String relativePath = getExecutionFlowRelativePath(executionFlow);
- log.debug("relativePath='" + relativePath + "'");
Iterator<String> names = Arrays.asList(relativePath.split("/"))
.iterator();
Node currNode = moduleNode;
}
- public void executionFlowRemoved(Module module, ExecutionFlow executionFlow) {
+ public void executionFlowRemoved(ModuleDescriptor module,
+ ExecutionFlowDescriptor executionFlow) {
String path = getExecutionFlowPath(module, executionFlow);
try {
if (session.nodeExists(path)) {
}
}
- protected String getExecutionFlowPath(Module module,
- ExecutionFlow executionFlow) {
+ protected String getExecutionFlowPath(ModuleDescriptor module,
+ ExecutionFlowDescriptor executionFlow) {
String relativePath = getExecutionFlowRelativePath(executionFlow);
return getExecutionModulesPath() + '/' + module.getName() + '/'
+ module.getVersion() + '/' + relativePath;
/** @return the relative path, never starts with '/' */
@SuppressWarnings("deprecation")
- protected String getExecutionFlowRelativePath(ExecutionFlow executionFlow) {
+ protected String getExecutionFlowRelativePath(
+ ExecutionFlowDescriptor executionFlow) {
String relativePath = executionFlow.getPath() == null ? executionFlow
.getName() : executionFlow.getPath() + '/'
+ executionFlow.getName();
import org.argeo.slc.core.build.ResourceDistribution;
import org.argeo.slc.deploy.DeploymentData;
import org.argeo.slc.deploy.Module;
+import org.argeo.slc.deploy.ModuleDescriptor;
import org.argeo.slc.deploy.TargetData;
import org.argeo.slc.process.RealizedFlow;
import org.osgi.framework.Bundle;
/** A deployed OSGi bundle. */
public class OsgiBundle extends BasicNameVersion implements Module {
- private static final long serialVersionUID = -1970854723780452072L;
+ private static final long serialVersionUID = 35073826504550477L;
private ResourceDistribution distribution;
private Long internalBundleId;
- private String label;
+ private String title;
private String description;
public OsgiBundle() {
}
/** Value of the <code>Bundle-Name</code> directive. */
- public String getLabel() {
- return label;
+ public String getTitle() {
+ return title;
}
- public void setLabel(String label) {
- this.label = label;
+ public void setTitle(String label) {
+ this.title = label;
}
/** Value of the <code>Bundle-Description</code> directive. */
this.description = description;
}
+ public ModuleDescriptor getModuleDescriptor() {
+ ModuleDescriptor moduleDescriptor = new ModuleDescriptor();
+ moduleDescriptor.setName(getName());
+ moduleDescriptor.setVersion(getVersion());
+ moduleDescriptor.setDescription(description);
+ moduleDescriptor.setTitle(title);
+ return moduleDescriptor;
+ }
}
package org.argeo.slc.osgi;
+import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.StandardMBean;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.BasicNameVersion;
import org.argeo.slc.SlcException;
import org.argeo.slc.core.execution.AbstractExecutionModulesManager;
import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter;
+import org.argeo.slc.deploy.Module;
import org.argeo.slc.deploy.ModuleDescriptor;
import org.argeo.slc.execution.ExecutionContext;
import org.argeo.slc.execution.ExecutionFlow;
private List<ExecutionModulesListener> executionModulesListeners = new ArrayList<ExecutionModulesListener>();
+ private Boolean registerFlowsToJmx = true;
+
public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor(
String moduleName, String version) {
ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
+ nameVersion);
md.setName(osgiBundle.getName());
md.setVersion(osgiBundle.getVersion());
- md.setLabel(osgiBundle.getLabel());
+ md.setTitle(osgiBundle.getTitle());
md.setDescription(osgiBundle.getDescription());
ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = getExecutionFlowDescriptorConverter(
protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
String moduleName, String moduleVersion) {
OsgiBundle osgiBundle = new OsgiBundle(moduleName, moduleVersion);
+ return getExecutionFlowDescriptorConverter(osgiBundle);
+ }
+
+ protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
+ OsgiBundle osgiBundle) {
if (executionFlowDescriptorConverters.containsKey(osgiBundle))
return executionFlowDescriptorConverters.get(osgiBundle);
else
md.setName(bdl.getSymbolicName());
md.setVersion(getHeaderSafe(bdl, Constants.BUNDLE_VERSION));
- md.setLabel(getHeaderSafe(bdl, Constants.BUNDLE_NAME));
+ md.setTitle(getHeaderSafe(bdl, Constants.BUNDLE_NAME));
md.setDescription(getHeaderSafe(bdl, Constants.BUNDLE_DESCRIPTION));
}
Map<String, String> properties) {
OsgiBundle osgiBundle = asOsgiBundle(properties);
Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle);
- osgiBundle.setLabel(getHeaderSafe(bundle, Constants.BUNDLE_NAME));
+ osgiBundle.setTitle(getHeaderSafe(bundle, Constants.BUNDLE_NAME));
osgiBundle.setDescription(getHeaderSafe(bundle,
Constants.BUNDLE_DESCRIPTION));
executionContexts.put(osgiBundle, executionContext);
log.trace("Registered execution context from " + osgiBundle);
// Notify
for (ExecutionModulesListener listener : executionModulesListeners)
- listener.executionModuleAdded(osgiBundle, executionContext);
+ listener.executionModuleAdded(osgiBundle.getModuleDescriptor());
}
/** Unregisters an execution context. */
log.trace("Removed execution context from " + osgiBundle);
// Notify
for (ExecutionModulesListener listener : executionModulesListeners)
- listener.executionModuleRemoved(osgiBundle, executionContext);
+ listener.executionModuleRemoved(osgiBundle
+ .getModuleDescriptor());
}
}
if (log.isTraceEnabled())
log.trace("Registered " + executionFlow + " from " + osgiBundle);
+ // notifications
+ if (registerFlowsToJmx)
+ registerMBean(osgiBundle, executionFlow);
+ ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
for (ExecutionModulesListener listener : executionModulesListeners)
- listener.executionFlowAdded(osgiBundle, executionFlow);
+ listener.executionFlowAdded(osgiBundle.getModuleDescriptor(),
+ efdc.getExecutionFlowDescriptor(executionFlow));
}
/** Unregisters an execution flow. */
if (log.isTraceEnabled())
log.trace("Removed flows set from " + osgiBundle);
}
+
+ // notifications
+ if (registerFlowsToJmx)
+ unregisterMBean(osgiBundle, executionFlow);
+ ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
for (ExecutionModulesListener listener : executionModulesListeners)
- listener.executionFlowRemoved(osgiBundle, executionFlow);
+ listener.executionFlowRemoved(osgiBundle.getModuleDescriptor(),
+ efdc.getExecutionFlowDescriptor(executionFlow));
}
}
Map<String, String> properties) {
// sync with current state
for (OsgiBundle osgiBundle : executionContexts.keySet()) {
- executionModulesListener.executionModuleAdded(osgiBundle,
- executionContexts.get(osgiBundle));
+ executionModulesListener.executionModuleAdded(osgiBundle
+ .getModuleDescriptor());
}
for (OsgiBundle osgiBundle : executionFlows.keySet()) {
+ ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
for (ExecutionFlow executionFlow : executionFlows.get(osgiBundle))
- executionModulesListener.executionFlowAdded(osgiBundle,
- executionFlow);
+ executionModulesListener.executionFlowAdded(
+ osgiBundle.getModuleDescriptor(),
+ efdc.getExecutionFlowDescriptor(executionFlow));
}
executionModulesListeners.add(executionModulesListener);
}
}
}
+ /*
+ * JMX
+ */
+ protected MBeanServer getMBeanServer() {
+ return ManagementFactory.getPlatformMBeanServer();
+ }
+
+ public void registerMBean(Module module, ExecutionFlow executionFlow) {
+ try {
+ StandardMBean mbean = new StandardMBean(executionFlow,
+ ExecutionFlow.class);
+ getMBeanServer().registerMBean(mbean,
+ flowMBeanName(module, executionFlow));
+ } catch (Exception e) {
+ String msg = "Cannot register execution flow " + executionFlow
+ + " as mbean";
+ throw new SlcException(msg, e);
+ }
+ }
+
+ public void unregisterMBean(Module module, ExecutionFlow executionFlow) {
+ try {
+ getMBeanServer().unregisterMBean(
+ flowMBeanName(module, executionFlow));
+ } catch (Exception e) {
+ String msg = "Cannot unregister execution flow " + executionFlow
+ + " as mbean";
+ throw new SlcException(msg, e);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ protected ObjectName flowMBeanName(Module module,
+ ExecutionFlow executionFlow) {
+ String executionModulesPrefix = "SLCExecutionModules";
+ String path = executionFlow.getPath();
+ String name = executionFlow.getName();
+ if (path == null && name.indexOf('/') >= 0) {
+ path = name.substring(0, name.lastIndexOf('/') - 1);
+ name = name.substring(name.lastIndexOf('/'));
+ }
+
+ StringBuffer buf = new StringBuffer(executionModulesPrefix + ":"
+ + "module=" + module.getName() + " [" + module.getVersion()
+ + "],");
+
+ if (path != null && !path.equals("")) {
+ int depth = 0;
+ for (String token : path.split("/")) {
+ if (!token.equals("")) {
+ buf.append("path").append(depth).append('=');
+ // in order to have directories first
+ buf.append('/');
+ buf.append(token).append(',');
+ depth++;
+ }
+ }
+ }
+ buf.append("name=").append(name);
+ try {
+ return new ObjectName(buf.toString());
+ } catch (Exception e) {
+ throw new SlcException("Cannot generate object name based on "
+ + buf, e);
+ }
+ }
+
+ /*
+ * UTILITIES
+ */
@SuppressWarnings("rawtypes")
private OsgiBundle asOsgiBundle(Map properties) {
String bundleSymbolicName = checkAndGet(Constants.BUNDLE_SYMBOLICNAME,
this.defaultDescriptorConverter = defaultDescriptorConverter;
}
+ public void setRegisterFlowsToJmx(Boolean registerFlowsToJmx) {
+ this.registerFlowsToJmx = registerFlowsToJmx;
+ }
+
}