use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class CommandHandler method executeTask.
/**
* @param client Client
* @return Task result.
* @throws GridClientException If failed to execute task.
*/
private <R> R executeTask(GridClient client, Class<?> taskCls, Object taskArgs) throws GridClientException {
GridClientCompute compute = client.compute();
List<GridClientNode> nodes = new ArrayList<>();
for (GridClientNode node : compute.nodes()) if (node.connectable())
nodes.add(node);
if (F.isEmpty(nodes))
throw new GridClientDisconnectedException("Connectable node not found", null);
GridClientNode node = compute.balancer().balancedNode(nodes);
return compute.projection(node).execute(taskCls.getName(), new VisorTaskArgument<>(node.nodeId(), taskArgs, false));
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testNoAsyncExceptions.
/**
* Check async API methods don't generate exceptions.
*
* @throws Exception If failed.
*/
@Test
public void testNoAsyncExceptions() throws Exception {
GridClient client = client();
GridClientData data = client.data(CACHE_NAME);
GridClientCompute compute = client.compute().projection(new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return false;
}
});
Map<String, GridClientFuture<?>> futs = new LinkedHashMap<>();
futs.put("exec", compute.executeAsync("taskName", "taskArg"));
futs.put("affExec", compute.affinityExecuteAsync("taskName", "cacheName", "affKey", "taskArg"));
futs.put("refreshById", compute.refreshNodeAsync(UUID.randomUUID(), true, true));
futs.put("refreshByIP", compute.refreshNodeAsync("nodeIP", true, true));
futs.put("refreshTop", compute.refreshTopologyAsync(true, true));
GridClientFactory.stop(client.id(), false);
futs.put("put", data.putAsync("key", "val"));
futs.put("putAll", data.putAllAsync(F.asMap("key", "val")));
futs.put("get", data.getAsync("key"));
futs.put("getAll", data.getAllAsync(Collections.singletonList("key")));
futs.put("remove", data.removeAsync("key"));
futs.put("removeAll", data.removeAllAsync(Collections.singletonList("key")));
futs.put("replace", data.replaceAsync("key", "val"));
futs.put("cas", data.casAsync("key", "val", "val2"));
futs.put("metrics", data.metricsAsync());
for (Map.Entry<String, GridClientFuture<?>> e : futs.entrySet()) {
try {
e.getValue().get();
info("Expects '" + e.getKey() + "' fails with grid client exception.");
} catch (GridServerUnreachableException | GridClientClosedException ignore) {
// No op: compute projection is empty.
}
}
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testForceShutdown.
/**
* @throws Exception If failed.
*/
@Test
public void testForceShutdown() throws Exception {
GridClientCompute compute = client.compute();
Object taskArg = getTaskArgument();
String taskName = getSleepTaskName();
GridClientFuture<Object> fut = compute.executeAsync(taskName, taskArg);
GridClientFactory.stop(client.id(), false);
try {
fut.get();
} catch (GridClientClosedException ignored) {
return;
}
Assert.fail("Expected GridClientClosedException.");
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testGracefulShutdown.
/**
* @throws Exception If failed.
*/
@Test
public void testGracefulShutdown() throws Exception {
GridClientCompute compute = client.compute();
Object taskArg = getTaskArgument();
String taskName = getSleepTaskName();
GridClientFuture<Object> fut = compute.executeAsync(taskName, taskArg);
GridClientFuture<Object> fut2 = compute.executeAsync(taskName, taskArg);
GridClientFactory.stop(client.id(), true);
Assert.assertEquals(17, fut.get());
Assert.assertEquals(17, fut2.get());
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class PropertyAbstractSubCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public final Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
try (GridClient client = Command.startClient(clientCfg)) {
GridClientCompute compute = client.compute();
// Try to find connectable server nodes.
Collection<GridClientNode> nodes = compute.nodes((n) -> n.connectable() && !n.isClient());
if (F.isEmpty(nodes)) {
nodes = compute.nodes(GridClientNode::connectable);
if (F.isEmpty(nodes))
throw new GridClientDisconnectedException("Connectable nodes not found", null);
}
GridClientNode node = nodes.stream().findAny().orElse(null);
if (node == null)
node = compute.balancer().balancedNode(nodes);
MetadataResultDto res = compute.projection(node).execute(taskName(), new VisorTaskArgument<>(node.nodeId(), arg(), false));
printResult(res, log);
} catch (Throwable e) {
log.severe("Failed to execute metadata command='" + name() + "'");
log.severe(CommandLogger.errorMessage(e));
throw e;
}
return null;
}
Aggregations