From b0c2c01573db47690afdf723e49fb7fa39561e8e Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 8 Jun 2009 13:12:28 +0000 Subject: [PATCH] @update:79; Simplify the execution of flows git-svn-id: https://svn.argeo.org/slc/trunk@2513 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/it/webapp/SimpleScenarioTest.java | 15 +-- .../server/client/SlcServerHttpClient.java | 27 +++++- .../impl/AbstractHttpServicesClient.java | 2 +- .../client/impl/SlcServerHttpClientImpl.java | 96 ++++++++++++++++--- .../mvc/execution/ListModulesDescriptors.java | 2 + .../execution/ExecutionModuleDescriptor.java | 2 + .../java/org/argeo/slc/msg/ObjectList.java | 7 ++ 7 files changed, 125 insertions(+), 26 deletions(-) diff --git a/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/SimpleScenarioTest.java b/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/SimpleScenarioTest.java index 1d751f3cb..9ab5d7584 100644 --- a/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/SimpleScenarioTest.java +++ b/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/SimpleScenarioTest.java @@ -2,21 +2,16 @@ package org.argeo.slc.it.webapp; import org.argeo.slc.Condition; import org.argeo.slc.core.test.tree.TreeTestResultList; -import org.argeo.slc.runtime.SlcAgentDescriptor; +import org.argeo.slc.server.client.SlcServerHttpClient; import org.argeo.slc.server.unit.AbstractHttpClientTestCase; public class SimpleScenarioTest extends AbstractHttpClientTestCase { public void testSimpleScenario() throws Exception { - // Get agent - SlcAgentDescriptor agentDescriptor = getHttpClient().waitForOneAgent(); - assertNotNull(agentDescriptor); + String moduleName = "org.argeo.slc.demo.basic"; + assertAnswerOk(getHttpClient().startFlowDefault(moduleName, "main", + null)); - // Launch SLC Execution - // TODO: don't hardcode tested version - assertAnswerOk(getHttpClient().startFlow(agentDescriptor.getUuid(), - "org.argeo.slc.demo.basic", "0.11.4.SNAPSHOT", "main")); - - getHttpClient().callServiceSafe("listResults.service", null, + getHttpClient().callServiceSafe(SlcServerHttpClient.LIST_RESULTS, null, new Condition() { public Boolean check(TreeTestResultList obj) { diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/SlcServerHttpClient.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/SlcServerHttpClient.java index 3bd51e910..6087d2a1b 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/SlcServerHttpClient.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/SlcServerHttpClient.java @@ -1,10 +1,22 @@ package org.argeo.slc.server.client; +import java.util.List; +import java.util.Map; + +import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.runtime.SlcAgentDescriptor; /** Abstraction of the access to HTTP services of an SLC Server. */ public interface SlcServerHttpClient extends HttpServicesClient { + public final static String LIST_AGENTS = "listAgents.service"; + public final static String IS_SERVER_READY = "isServerReady.service"; + public final static String NEW_SLC_EXECUTION = "newSlcExecution.service"; + public final static String GET_MODULE_DESCRIPTOR = "getExecutionDescriptor.service"; + public final static String LIST_MODULE_DESCRIPTORS = "listModulesDescriptors.service"; + public final static String LIST_RESULTS = "listResults.service"; + /** Wait for one agent to be available. */ public SlcAgentDescriptor waitForOneAgent(); @@ -12,6 +24,17 @@ public interface SlcServerHttpClient extends HttpServicesClient { public void waitForServerToBeReady(); /** Start an execution flow on the given agent. */ - public ExecutionAnswer startFlow(String agentId, String moduleName, - String version, String flowName); + public ExecutionAnswer startFlow(String agentId, RealizedFlow realizedFlow); + + /** Assume one agent and one version per module. */ + public ExecutionAnswer startFlowDefault(String moduleName, String flowName, + Map args); + + /** List execution modules descriptors. */ + public List listModuleDescriptors(String agentId); + + /** Retrieve a single execution module descriptot. */ + public ExecutionModuleDescriptor getModuleDescriptor(String agentId, + String moduleName, String version); + } diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java index 410e8d9af..44444f6f1 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java @@ -34,7 +34,7 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { private String encoding = "UTF-8"; private Long retryPeriod = 1000l; - private Long defaultTimeout = 30 * 1000l; + private Long defaultTimeout = 10 * 1000l; public T callService(String path, Map parameters) { return callService(path, parameters, null); diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java index e640c5c69..20c938301 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java @@ -1,6 +1,8 @@ package org.argeo.slc.server.client.impl; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -9,6 +11,7 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.Condition; import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.msg.ExecutionAnswer; import org.argeo.slc.msg.MsgConstants; import org.argeo.slc.msg.ObjectList; @@ -19,9 +22,8 @@ import org.argeo.slc.server.client.SlcServerHttpClient; public class SlcServerHttpClientImpl extends AbstractHttpServicesClient implements SlcServerHttpClient { - public final static String LIST_AGENTS = "listAgents.service"; - public final static String IS_SERVER_READY = "isServerReady.service"; - public final static String NEW_SLC_EXECUTION = "newSlcExecution.service"; + + protected final static String PARAM_AGENT_ID = "agentId"; private final static Log log = LogFactory .getLog(SlcServerHttpClientImpl.class); @@ -29,19 +31,10 @@ public class SlcServerHttpClientImpl extends AbstractHttpServicesClient private Long retryTimeout = 60 * 1000l; private Long serverReadyTimeout = 120 * 1000l; - public ExecutionAnswer startFlow(String agentId, String moduleName, - String version, String flowName) { + public ExecutionAnswer startFlow(String agentId, RealizedFlow realizedFlow) { SlcExecution slcExecution = new SlcExecution(); slcExecution.setUuid(UUID.randomUUID().toString()); - RealizedFlow realizedFlow = new RealizedFlow(); - realizedFlow.setModuleName(moduleName); - realizedFlow.setModuleVersion(version); - - ExecutionFlowDescriptor flowDescriptor = new ExecutionFlowDescriptor(); - flowDescriptor.setName(flowName); - - realizedFlow.setFlowDescriptor(flowDescriptor); slcExecution.getRealizedFlows().add(realizedFlow); Map parameters = new HashMap(); @@ -51,6 +44,83 @@ public class SlcServerHttpClientImpl extends AbstractHttpServicesClient return answer; } + public ExecutionAnswer startFlowDefault(String moduleName, String flowName, + Map args) { + SlcAgentDescriptor agentDescriptor = waitForOneAgent(); + List lst = listModuleDescriptors(agentDescriptor + .getUuid()); + ExecutionModuleDescriptor moduleDescMinimal = findModule(lst, + moduleName); + String moduleVersion = moduleDescMinimal.getVersion(); + + ExecutionModuleDescriptor moduleDesc = getModuleDescriptor( + agentDescriptor.getUuid(), moduleName, moduleVersion); + + RealizedFlow realizedFlow = new RealizedFlow(); + realizedFlow.setModuleName(moduleName); + realizedFlow.setModuleVersion(moduleDesc.getVersion()); + + ExecutionFlowDescriptor flowDescriptor = findFlow(moduleDesc, flowName); + if (args != null) { + for (String key : args.keySet()) { + if (flowDescriptor.getValues().containsKey(key)) { + flowDescriptor.getValues().put(key, args.get(key)); + } + } + } + realizedFlow.setFlowDescriptor(flowDescriptor); + + return startFlow(agentDescriptor.getUuid(), realizedFlow); + } + + public static ExecutionModuleDescriptor findModule( + List lst, String moduleName) { + ExecutionModuleDescriptor moduleDesc = null; + for (ExecutionModuleDescriptor desc : lst) { + if (desc.getName().equals(moduleName)) { + if (moduleDesc != null) + throw new SlcException( + "There is more than one module named " + moduleName + + " (versions: " + moduleDesc + " and " + + desc.getVersion() + ")"); + moduleDesc = desc; + } + } + return moduleDesc; + } + + public static ExecutionFlowDescriptor findFlow( + ExecutionModuleDescriptor moduleDesc, String flowName) { + ExecutionFlowDescriptor flowDesc = null; + for (ExecutionFlowDescriptor desc : moduleDesc.getExecutionFlows()) { + if (desc.getName().equals(flowName)) { + flowDesc = desc; + } + } + return flowDesc; + } + + public List listModuleDescriptors(String agentId) { + Map parameters = new HashMap(); + parameters.put(PARAM_AGENT_ID, agentId); + + List moduleDescriptors = new ArrayList(); + ObjectList ol = callService(LIST_MODULE_DESCRIPTORS, parameters); + ol.fill(moduleDescriptors); + return moduleDescriptors; + } + + public ExecutionModuleDescriptor getModuleDescriptor(String agentId, + String moduleName, String version) { + Map parameters = new HashMap(); + parameters.put(PARAM_AGENT_ID, agentId); + parameters.put("moduleName", moduleName); + parameters.put("version", version); + ExecutionModuleDescriptor moduleDescriptor = callService( + GET_MODULE_DESCRIPTOR, parameters); + return moduleDescriptor; + } + public SlcAgentDescriptor waitForOneAgent() { ObjectList objectList = callServiceSafe(LIST_AGENTS, null, new Condition() { diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/execution/ListModulesDescriptors.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/execution/ListModulesDescriptors.java index b9b210b56..392e46ebc 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/execution/ListModulesDescriptors.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/execution/ListModulesDescriptors.java @@ -21,7 +21,9 @@ public class ListModulesDescriptors extends AbstractServiceController { HttpServletResponse response, ModelAndView modelAndView) throws Exception { + // TODO: use centralized agentId property (from MsgConstants)? String agentId = request.getParameter("agentId"); + SlcAgent slcAgent = agentFactory.getAgent(agentId); List descriptors = slcAgent.listExecutionModuleDescriptors(); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java index 62f6682b1..555ef40d7 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java @@ -4,6 +4,8 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import org.argeo.slc.SlcException; + public class ExecutionModuleDescriptor implements Serializable { private static final long serialVersionUID = 1L; private String name; diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/msg/ObjectList.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/msg/ObjectList.java index 886f47a32..720729ac0 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/msg/ObjectList.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/msg/ObjectList.java @@ -14,6 +14,13 @@ public class ObjectList { this.objects.addAll(objects); } + @SuppressWarnings(value = { "unchecked" }) + public void fill(List objects) { + for (Serializable o : this.objects){ + objects.add((T) o); + } + } + public List getObjects() { return objects; } -- 2.39.2