// Example of starting an algorithm, a stored pipeline, and a raw pipeline
@Override
public Object Start(Map args, IHKubeAPI hkubeAPI) throws Exception {
Collection<Object> input = (Collection<Object>)args.get("input");
Map action = (Map) input.iterator().next();
String act = (String)action.get("action");
if(act.equals("startAlg")) {
List<String> list = new ArrayList<>();
list.add("4");
// Asynchronous call
APIExecutionFuture futureResult = hkubeAPI.startAlgorithmAsynch("green-alg", list, true);
return returnWhenExecDone(futureResult);
}
if(act.equals("startStored")) {
APIExecutionFuture futureResult = hkubeAPI.startStoredPipeLineAsynch("simple", new HashMap());
return returnWhenExecDone(futureResult);
}
if(act.equals("startRaw")) {
// Define nodes for the raw pipeline
INode jnkNode = createNode("one", "green-alg", "42");
INode[] nodes = {jnkNode};
APIExecutionFuture futureResult = hkubeAPI.startRawSubPipeLineAsynch("raw-pipe", nodes, new HashMap(), new HashMap(), new HashMap());
return returnWhenExecDone(futureResult);
}
return 42;
}
// Helper to block until the asynchronous execution is complete
private Map returnWhenExecDone(APIExecutionFuture future) {
while (!future.isDone()) {
try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); }
}
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}