]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java
@update:79; First end-to-end integration test
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / server / client / impl / SlcServerHttpClientImpl.java
index 75e4e8ea0d1e7b2679e280b0d8a818772bcd91dd..e640c5c697d11f08059ceb07c8233ece408e3360 100644 (file)
@@ -1,20 +1,55 @@
 package org.argeo.slc.server.client.impl;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
 import org.apache.commons.logging.Log;
 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.msg.ExecutionAnswer;
+import org.argeo.slc.msg.MsgConstants;
 import org.argeo.slc.msg.ObjectList;
+import org.argeo.slc.process.RealizedFlow;
+import org.argeo.slc.process.SlcExecution;
 import org.argeo.slc.runtime.SlcAgentDescriptor;
 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";
 
        private final static Log log = LogFactory
                        .getLog(SlcServerHttpClientImpl.class);
 
        private Long retryTimeout = 60 * 1000l;
+       private Long serverReadyTimeout = 120 * 1000l;
+
+       public ExecutionAnswer startFlow(String agentId, String moduleName,
+                       String version, String flowName) {
+               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<String, String> parameters = new HashMap<String, String>();
+               parameters.put(MsgConstants.PROPERTY_SLC_AGENT_ID, agentId);
+               ExecutionAnswer answer = callService(NEW_SLC_EXECUTION, parameters,
+                               slcExecution);
+               return answer;
+       }
 
        public SlcAgentDescriptor waitForOneAgent() {
                ObjectList objectList = callServiceSafe(LIST_AGENTS, null,
@@ -29,9 +64,27 @@ public class SlcServerHttpClientImpl extends AbstractHttpServicesClient
                return (SlcAgentDescriptor) objectList.getObjects().get(0);
        }
 
-       /** Timeout in ms after which a safe call will throw an exception. */
+       public void waitForServerToBeReady() {
+               ExecutionAnswer answer = callServiceSafe(IS_SERVER_READY, null, null,
+                               serverReadyTimeout);
+               if (!answer.isOk())
+                       throw new SlcException("Server is not ready: " + answer);
+       }
+
+       /**
+        * Timeout in ms after which a safe call will throw an exception. Default is
+        * 60s.
+        */
        public void setRetryTimeout(Long retryTimeout) {
                this.retryTimeout = retryTimeout;
        }
 
+       /**
+        * Timeout in ms after which the client will stop waiting for the server to
+        * be ready and throw an exception. Default is 120s.
+        */
+       public void setServerReadyTimeout(Long serverReadyTimeout) {
+               this.serverReadyTimeout = serverReadyTimeout;
+       }
+
 }