From 548235484edd6b48de5ddc3bbca318e0e49cb57b Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 18 Apr 2011 08:52:50 +0000 Subject: [PATCH 1/1] Introduce JCR agent. Client agent not needed anymore. NEW - bug 17: Generalize agent management and registration beyond JMS https://bugzilla.argeo.org/show_bug.cgi?id=17 git-svn-id: https://svn.argeo.org/slc/trunk@4446 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/client.xml | 4 +- .../META-INF/spring/osgi.xml | 4 +- .../META-INF/spring/jms.xml | 7 +- .../META-INF/MANIFEST.MF | 2 + .../META-INF/spring/jcr-osgi.xml | 8 ++- .../META-INF/spring/jcr.xml | 14 +++- .../argeo/slc/core/runtime/DefaultAgent.java | 36 ++++++++--- .../argeo/slc/deploy/ModuleDescriptor.java | 23 +++++-- .../argeo/slc/execution/ExecutionSpec.java | 2 - .../slc/execution/ExecutionSpecAttribute.java | 8 +-- .../main/java/org/argeo/slc/jms/JmsAgent.java | 24 ++++--- .../main/java/org/argeo/slc/jcr/JcrAgent.java | 37 ----------- .../org/argeo/slc/jcr/SlcJcrConstants.java | 6 ++ .../main/java/org/argeo/slc/jcr/SlcNames.java | 1 + .../org/argeo/slc/jcr/execution/JcrAgent.java | 64 +++++++++++++++++++ .../JcrExecutionModulesListener.java | 31 ++++++--- 16 files changed, 178 insertions(+), 93 deletions(-) delete mode 100644 runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrAgent.java create mode 100644 runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrConstants.java create mode 100644 runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrAgent.java diff --git a/eclipse/modules/org.argeo.slc.client.agent/META-INF/spring/client.xml b/eclipse/modules/org.argeo.slc.client.agent/META-INF/spring/client.xml index ab0f40886..5d7b3c047 100644 --- a/eclipse/modules/org.argeo.slc.client.agent/META-INF/spring/client.xml +++ b/eclipse/modules/org.argeo.slc.client.agent/META-INF/spring/client.xml @@ -9,12 +9,12 @@ - + + init-method="init" destroy-method="dispose" p:modulesManager-ref="modulesManager" /> diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml index 6247a21f0..a945cdcbe 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml @@ -32,8 +32,8 @@ - + + - + @@ -16,7 +17,7 @@ - + @@ -32,7 +33,7 @@ - + diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF b/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF index e0cdde8c1..023fd63df 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF @@ -7,6 +7,7 @@ Import-Package: javax.jcr, org.argeo.jcr.mvc, org.argeo.jcr.spring, org.argeo.security, + org.argeo.security.core, org.argeo.security.jcr, org.argeo.slc.core.attachment, org.argeo.slc.core.execution, @@ -26,4 +27,5 @@ Import-Package: javax.jcr, org.argeo.slc.test, org.springframework.beans.factory.config, org.springframework.osgi.util, + org.springframework.security;specification-version="2.0.6.RELEASE", org.springframework.web.context.request diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml index d1a550c18..f682f931e 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml @@ -9,11 +9,17 @@ - + + + + + diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml index 4d9983cfd..bd435bbd1 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml @@ -12,14 +12,24 @@ + + + + + + - + - + + + + diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java index 430b6bd97..ca230856f 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java @@ -28,22 +28,39 @@ import org.argeo.slc.process.SlcExecution; import org.argeo.slc.runtime.SlcAgent; import org.argeo.slc.runtime.SlcAgentDescriptor; +/** Implements the base methods of an SLC agent. */ public class DefaultAgent implements SlcAgent { - // private final static Log log = LogFactory.getLog(AbstractAgent.class); - - private final SlcAgentDescriptor agentDescriptor; + private SlcAgentDescriptor agentDescriptor; private ExecutionModulesManager modulesManager; - public DefaultAgent() { + /* + * LIFECYCLE + */ + public void init() { try { agentDescriptor = new SlcAgentDescriptor(); - agentDescriptor.setUuid(UUID.randomUUID().toString()); + agentDescriptor.setUuid(initAgentUuid()); agentDescriptor.setHost(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { throw new SlcException("Unable to create agent descriptor.", e); } } + public void dispose() { + + } + + /** + * Called during initialization in order to determines the agent UUID. To be + * overridden. By default creates a new one per instance. + */ + protected String initAgentUuid() { + return UUID.randomUUID().toString(); + } + + /* + * SLC AGENT + */ public void runSlcExecution(final SlcExecution slcExecution) { modulesManager.process(slcExecution); } @@ -61,20 +78,19 @@ public class DefaultAgent implements SlcAgent { return true; } + /* + * BEAN + */ public void setModulesManager(ExecutionModulesManager modulesManager) { this.modulesManager = modulesManager; } - public ExecutionModulesManager getModulesManager() { - return modulesManager; - } - protected SlcAgentDescriptor getAgentDescriptor() { return agentDescriptor; } public String getAgentUuid() { - return getAgentDescriptor().getUuid(); + return agentDescriptor.getUuid(); } @Override diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModuleDescriptor.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModuleDescriptor.java index 84608a15c..0a36002fb 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModuleDescriptor.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModuleDescriptor.java @@ -18,17 +18,18 @@ package org.argeo.slc.deploy; import org.argeo.slc.BasicNameVersion; +/** The description of a versioned module. */ public class ModuleDescriptor extends BasicNameVersion { - private static final long serialVersionUID = 3703329250058821882L; - private String label; + private static final long serialVersionUID = 4310820315478645419L; + private String title; private String description; - public String getLabel() { - return label; + public String getTitle() { + return title; } - public void setLabel(String label) { - this.label = label; + public void setTitle(String title) { + this.title = title; } public String getDescription() { @@ -39,4 +40,14 @@ public class ModuleDescriptor extends BasicNameVersion { this.description = description; } + /** @deprecated use {@link #getTitle()} instead */ + public String getLabel() { + return title; + } + + /** @deprecated use {@link #setTitle(String)} instead */ + public void setLabel(String label) { + this.title = label; + } + } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java index 899b76f96..8111cc7d9 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpec.java @@ -21,8 +21,6 @@ import java.util.Map; /** * The class implementing this interface defines the map of attributes that are * necessary for the corresponding ExecutionFlow. - * - * @author bsinou */ public interface ExecutionSpec { public Map getAttributes(); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java index 22d981f44..4866f6377 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionSpecAttribute.java @@ -17,7 +17,6 @@ package org.argeo.slc.execution; /** - * * This interface stands for one attribute of a given flow. * * We mainly have two implementations : @@ -29,13 +28,10 @@ package org.argeo.slc.execution; * the application context + the display of some choices among which the end * user can choose. * - * Note : - * + * @see org.argeo.slc.core.execution.PrimitiveSpecAttribute + * @see org.argeo.slc.core.execution.RefSpecAttribute * @see org.argeo.slc.core.execution.PrimitiveUtils : this class offers some * helper, among others to cast the various type of primitive attribute. - * - * @author bsinou - * */ public interface ExecutionSpecAttribute { public Object getValue(); diff --git a/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgent.java b/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgent.java index fecb5178b..33584bb00 100644 --- a/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgent.java +++ b/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgent.java @@ -33,15 +33,12 @@ import org.argeo.slc.msg.MsgConstants; import org.argeo.slc.msg.ReferenceList; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.runtime.SlcAgentDescriptor; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.JmsException; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessagePostProcessor; -/** JMS based implementation of SLC Agent. */ -public class JmsAgent extends DefaultAgent implements InitializingBean, - DisposableBean, MessageListener { +/** JMS based implementation of an SLC Agent. */ +public class JmsAgent extends DefaultAgent implements MessageListener { public final static String PROPERTY_QUERY = "query"; public final static String QUERY_PING_ALL = "pingAll"; @@ -53,24 +50,24 @@ public class JmsAgent extends DefaultAgent implements InitializingBean, private Destination responseDestination; - public void afterPropertiesSet() throws Exception { + public void init() { + super.init(); try { jmsTemplate.convertAndSend(agentRegister, getAgentDescriptor()); log.info("Agent #" + getAgentUuid() + " registered to " + agentRegister); } catch (JmsException e) { - log - .warn("Could not register agent " - + getAgentDescriptor().getUuid() - + " to server: " - + e.getMessage() - + ". The agent will stay offline but will keep listening for a ping all sent by server."); + log.warn("Could not register agent " + + getAgentDescriptor().getUuid() + + " to server: " + + e.getMessage() + + ". The agent will stay offline but will keep listening for a ping all sent by server."); if (log.isTraceEnabled()) log.debug("Original error.", e); } } - public void destroy() throws Exception { + public void dispose() { try { jmsTemplate.convertAndSend(agentUnregister, getAgentDescriptor()); log.info("Agent #" + getAgentUuid() + " unregistered from " @@ -81,6 +78,7 @@ public class JmsAgent extends DefaultAgent implements InitializingBean, if (log.isTraceEnabled()) log.debug("Original error.", e); } + super.dispose(); } public void setAgentRegister(Destination agentRegister) { diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrAgent.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrAgent.java deleted file mode 100644 index b8e99cb3f..000000000 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrAgent.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.argeo.slc.jcr; - -import java.util.List; - -import org.argeo.slc.execution.ExecutionModuleDescriptor; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.runtime.SlcAgent; - -public class JcrAgent implements SlcAgent { - - public String getAgentUuid() { - // TODO Auto-generated method stub - return null; - } - - public ExecutionModuleDescriptor getExecutionModuleDescriptor( - String moduleName, String version) { - // TODO Auto-generated method stub - return null; - } - - public List listExecutionModuleDescriptors() { - // TODO Auto-generated method stub - return null; - } - - public void runSlcExecution(SlcExecution slcExecution) { - // TODO Auto-generated method stub - - } - - public boolean ping() { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrConstants.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrConstants.java new file mode 100644 index 000000000..eb8b13521 --- /dev/null +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrConstants.java @@ -0,0 +1,6 @@ +package org.argeo.slc.jcr; + +public interface SlcJcrConstants { + public final static String AGENTS_BASE_PATH = "/slc/agents"; + public final static String VM_AGENT_FACTORY_PATH = AGENTS_BASE_PATH + "/vm"; +} diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java index 55387b27d..728d576a5 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java @@ -6,5 +6,6 @@ public interface SlcNames { public final static String SLC_NAME = "slc:name"; public final static String SLC_VERSION = "slc:version"; public final static String SLC_FLOWS = "slc:flows"; + public final static String SLC_EXECUTION_MODULES = "slc:executionModules"; } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrAgent.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrAgent.java new file mode 100644 index 000000000..9327f8b6a --- /dev/null +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrAgent.java @@ -0,0 +1,64 @@ +package org.argeo.slc.jcr.execution; + +import java.util.List; +import java.util.UUID; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.core.runtime.DefaultAgent; +import org.argeo.slc.jcr.SlcJcrConstants; +import org.argeo.slc.runtime.SlcAgent; +import org.argeo.slc.runtime.SlcAgentFactory; + +/** SLC agent synchronizing with a JCR repository. */ +public class JcrAgent extends DefaultAgent implements SlcAgentFactory { + private Session session; + + /* + * LIFECYCLE + */ + protected String initAgentUuid() { + try { + Node vmAgentFactoryNode = JcrUtils.mkdirs(session, + SlcJcrConstants.VM_AGENT_FACTORY_PATH); + if (!vmAgentFactoryNode.hasNodes()) { + String uuid = UUID.randomUUID().toString(); + vmAgentFactoryNode.addNode(uuid); + } + session.save(); + + return vmAgentFactoryNode.getNodes().nextNode().getName(); + } catch (RepositoryException e) { + throw new SlcException("Cannot find JCR agent UUID", e); + } finally { + JcrUtils.discardQuietly(session); + } + } + + public void dispose() { + + } + + /* + * SLC AGENT FACTORY + */ + public SlcAgent getAgent(String uuid) { + return this; + } + + public void pingAll(List activeAgentIds) { + ping(); + } + + /* + * BEAN METHODS + */ + public void setSession(Session session) { + this.session = session; + } + +} diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java index dd91d5dee..c68272dc4 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -15,21 +15,24 @@ import org.argeo.slc.deploy.Module; import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionModulesListener; +import org.argeo.slc.jcr.SlcJcrConstants; +import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.runtime.SlcAgent; /** - * Synchronizes the execution runtime with JCR. For the time being the state is - * completely reset from one start to another. + * Synchronizes the local execution runtime with a JCR repository. For the time + * being the state is completely reset from one start to another. */ public class JcrExecutionModulesListener implements ExecutionModulesListener { private final static Log log = LogFactory .getLog(JcrExecutionModulesListener.class); - private String modulesPath = "/slc/modules"; - private Session session; + private SlcAgent agent; public void init() { try { + String modulesPath = getExecutionModulesPath(); // clean up previous state if (session.nodeExists(modulesPath)) session.getNode(modulesPath).remove(); @@ -45,6 +48,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { public void dispose() { try { + String modulesPath = getExecutionModulesPath(); // clean up previous state if (session.nodeExists(modulesPath)) session.getNode(modulesPath).remove(); @@ -60,7 +64,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { public void executionModuleAdded(Module module, ExecutionContext executionContext) { try { - Node base = session.getNode(modulesPath); + 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 @@ -76,7 +80,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { public void executionModuleRemoved(Module module, ExecutionContext executionContext) { try { - Node base = session.getNode(modulesPath); + Node base = session.getNode(getExecutionModulesPath()); if (base.hasNode(module.getName())) { Node moduleName = base.getNode(module.getName()); if (moduleName.hasNode(module.getVersion())) @@ -96,7 +100,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { try { Node flowNode; if (!session.nodeExists(path)) { - Node base = session.getNode(modulesPath); + Node base = session.getNode(getExecutionModulesPath()); Node moduleNode = base.getNode(module.getName() + '/' + module.getVersion()); String relativePath = getExecutionFlowRelativePath(executionFlow); @@ -143,8 +147,8 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { protected String getExecutionFlowPath(Module module, ExecutionFlow executionFlow) { String relativePath = getExecutionFlowRelativePath(executionFlow); - return modulesPath + '/' + module.getName() + '/' + module.getVersion() - + '/' + relativePath; + return getExecutionModulesPath() + '/' + module.getName() + '/' + + module.getVersion() + '/' + relativePath; } /** @return the relative path, never starts with '/' */ @@ -159,8 +163,17 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener { return relativePath; } + protected String getExecutionModulesPath() { + return SlcJcrConstants.VM_AGENT_FACTORY_PATH + '/' + + agent.getAgentUuid() + '/' + SlcNames.SLC_EXECUTION_MODULES; + } + public void setSession(Session session) { this.session = session; } + public void setAgent(SlcAgent agent) { + this.agent = agent; + } + } -- 2.39.2