X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fserver%2Fclient%2Fimpl%2FSlcServerHttpClientImpl.java;h=20c938301dd0de2f3d1605a58553f144305eb0e2;hb=b0c2c01573db47690afdf723e49fb7fa39561e8e;hp=e640c5c697d11f08059ceb07c8233ece408e3360;hpb=986352111d5b552eeb478547df58928b9351025f;p=gpl%2Fargeo-slc.git 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() {