use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ClientAbstractMultiNodeSelfTest method testEmptyProjections.
/**
* @throws Exception If failed.
*/
@Test
public void testEmptyProjections() throws Exception {
final GridClientCompute dflt = client.compute();
Collection<? extends GridClientNode> nodes = dflt.nodes();
assertEquals(NODES_CNT, nodes.size());
Iterator<? extends GridClientNode> iter = nodes.iterator();
final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));
final GridClientNode second = iter.next();
final GridClientPredicate<GridClientNode> targetFilter = new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
return node.nodeId().equals(second.nodeId());
}
};
GridTestUtils.assertThrows(log(), new Callable<Object>() {
@Override
public Object call() throws Exception {
return singleNodePrj.projection(second);
}
}, GridClientException.class, null);
GridTestUtils.assertThrows(log(), new Callable<Object>() {
@Override
public Object call() throws Exception {
return singleNodePrj.projection(targetFilter);
}
}, GridClientException.class, null);
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ClientAbstractMultiNodeSelfTest method testProjectionRun.
/**
* @throws Exception If failed.
*/
@Test
public void testProjectionRun() throws Exception {
GridClientCompute dflt = client.compute();
Collection<? extends GridClientNode> nodes = dflt.nodes();
assertEquals(NODES_CNT, nodes.size());
for (int i = 0; i < NODES_CNT; i++) {
Ignite g = grid(i);
assert g != null;
GridClientNode clientNode = dflt.node(g.cluster().localNode().id());
assertNotNull("Client node for " + g.cluster().localNode().id() + " was not found", clientNode);
GridClientCompute prj = dflt.projection(clientNode);
String res = prj.execute(TestTask.class.getName(), null);
assertNotNull(res);
assertEquals(g.cluster().localNode().id().toString(), res);
}
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ComputeTaskRemoteSecurityContextTest method testGridClient.
/**
* Tests task execution security context in case task was initiated from the {@link GridClient}.
*/
@Test
public void testGridClient() throws Exception {
Assume.assumeFalse(failWithTimeout);
String login = "grid_client";
GridClientConfiguration cfg = new GridClientConfiguration().setServers(singletonList("127.0.0.1:11211")).setSecurityCredentialsProvider(new SecurityCredentialsBasicProvider(new SecurityCredentials(login, "")));
try (GridClient cli = GridClientFactory.start(cfg)) {
GridClientNode taskReqRecipient = cli.compute().nodes().stream().filter(n -> "crd".equals(n.attribute(ATTR_IGNITE_INSTANCE_NAME))).findFirst().orElseThrow(NoSuchElementException::new);
GridClientCompute comp = cli.compute().projection(taskReqRecipient);
String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
if (async)
comp.executeAsync(taskName, login).get();
else
comp.execute(taskName, login);
checkTaskEvents("crd", login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
}
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class CheckIndexInlineSizes method execute.
/**
* {@inheritDoc}
*/
@Override
public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
try (GridClient client = Command.startClient(clientCfg)) {
Set<GridClientNode> serverNodes = client.compute().nodes().stream().filter(SRV_NODES).collect(toSet());
Collection<UUID> serverNodeIds = F.transform(serverNodes, GridClientNode::nodeId);
CheckIndexInlineSizesResult res = client.compute().projection(serverNodes).execute(CheckIndexInlineSizesTask.class.getName(), new VisorTaskArgument<>(serverNodeIds, false));
analyzeResults(log, res);
}
return null;
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class MetadataAbstractSubCommand 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