use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClientTcpDirectMultiNodeSelfTest method clientConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected GridClientConfiguration clientConfiguration() throws GridClientException {
assert NODES_CNT > 3 : "Too few nodes to execute direct multinode test";
GridClientConfiguration cfg = super.clientConfiguration();
cfg.setServers(Collections.<String>emptySet());
Collection<String> srvs = new ArrayList<>(3);
for (int i = 0; i < NODES_CNT / 2; i++) srvs.add(HOST + ':' + (REST_TCP_PORT_BASE + i));
cfg.setRouters(srvs);
return cfg;
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClientTcpDirectSelfTest method clientConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected GridClientConfiguration clientConfiguration() throws GridClientException {
GridClientConfiguration cfg = super.clientConfiguration();
cfg.setServers(Collections.<String>emptySet());
cfg.setRouters(Collections.singleton(HOST + ":" + BINARY_PORT));
return cfg;
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class TaskCommandHandlerSelfTest method clientConfiguration.
/**
* @return Client configuration.
*/
private GridClientConfiguration clientConfiguration() {
GridClientConfiguration cfg = new GridClientConfiguration();
GridClientDataConfiguration nullCache = new GridClientDataConfiguration();
GridClientDataConfiguration cache = new GridClientDataConfiguration();
cache.setName(CACHE_NAME);
cfg.setDataConfigurations(Arrays.asList(nullCache, cache));
cfg.setProtocol(TCP);
cfg.setServers(Arrays.asList("localhost:" + BINARY_PORT));
return cfg;
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class TaskExecutor method executeTaskByNameOnNode.
/**
* @param client Client
* @param taskClsName Task class name.
* @param taskArgs Task args.
* @param nodeId Node ID to execute task at (if null, random node will be chosen by balancer).
* @param clientCfg
* @return Task result.
* @throws GridClientException If failed to execute task.
*/
public static <R> R executeTaskByNameOnNode(GridClient client, String taskClsName, Object taskArgs, UUID nodeId, GridClientConfiguration clientCfg) throws GridClientException {
GridClientCompute compute = client.compute();
if (nodeId == BROADCAST_UUID) {
Collection<GridClientNode> nodes = compute.nodes(GridClientNode::connectable);
if (F.isEmpty(nodes))
throw new GridClientDisconnectedException("Connectable nodes not found", null);
List<UUID> nodeIds = nodes.stream().map(GridClientNode::nodeId).collect(Collectors.toList());
return client.compute().execute(taskClsName, new VisorTaskArgument<>(nodeIds, taskArgs, false));
}
GridClientNode node = null;
if (nodeId == null) {
// Prefer node from connect string.
final String cfgAddr = clientCfg.getServers().iterator().next();
String[] parts = cfgAddr.split(":");
if (DFLT_HOST.equals(parts[0])) {
InetAddress addr;
try {
addr = IgniteUtils.getLocalHost();
} catch (IOException e) {
throw new GridClientException("Can't get localhost name.", e);
}
if (addr.isLoopbackAddress())
throw new GridClientException("Can't find localhost name.");
String origAddr = addr.getHostName() + ":" + parts[1];
node = listHosts(client).filter(tuple -> origAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
if (node == null)
node = listHostsByClientNode(client).filter(tuple -> tuple.get2().size() == 1 && cfgAddr.equals(tuple.get2().get(0))).findFirst().map(IgniteBiTuple::get1).orElse(null);
} else
node = listHosts(client).filter(tuple -> cfgAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
// Otherwise choose random node.
if (node == null)
node = getBalancedNode(compute);
} else {
for (GridClientNode n : compute.nodes()) {
if (n.connectable() && nodeId.equals(n.nodeId())) {
node = n;
break;
}
}
if (node == null)
throw new IllegalArgumentException("Node with id=" + nodeId + " not found");
}
return compute.projection(node).execute(taskClsName, new VisorTaskArgument<>(node.nodeId(), taskArgs, false));
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class DefragmentationCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
try (GridClient client = Command.startClient(clientCfg)) {
Optional<GridClientNode> firstNodeOpt = client.compute().nodes().stream().filter(GridClientNode::connectable).findFirst();
if (firstNodeOpt.isPresent()) {
VisorDefragmentationTaskResult res;
if (args.nodeIds() == null) {
res = TaskExecutor.executeTaskByNameOnNode(client, VisorDefragmentationTask.class.getName(), convertArguments(), // Use node from clientCfg.
null, clientCfg);
} else {
VisorTaskArgument<?> visorArg = new VisorTaskArgument<>(client.compute().nodes().stream().filter(node -> args.nodeIds().contains(node.consistentId().toString())).map(GridClientNode::nodeId).collect(Collectors.toList()), convertArguments(), false);
res = client.compute().projection(firstNodeOpt.get()).execute(VisorDefragmentationTask.class.getName(), visorArg);
}
printResult(res, log);
} else
log.warning("No nodes found in topology, command won't be executed.");
} catch (Throwable t) {
log.severe("Failed to execute defragmentation command='" + args.subcommand().text() + "'");
log.severe(CommandLogger.errorMessage(t));
throw t;
}
return null;
}
Aggregations