use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
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;
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class VisorManagementEventSelfTest method testManagementOneNodeVisorTask.
/**
* Current test case start valid one node visor task that has GridVisorManagementTask annotation.
* No exceptions are expected.
*
* @throws Exception If failed.
*/
@Test
public void testManagementOneNodeVisorTask() throws Exception {
IgniteEx ignite = startGrid(0);
doTestVisorTask(TestManagementVisorOneNodeTask.class, new VisorTaskArgument(), ignite);
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class VisorManagementEventSelfTest method testManagementMultiNodeVisorTask.
/**
* Current test case start valid multi node visor task that has GridVisorManagementTask annotation.
* No exceptions are expected.
*
* @throws Exception If failed.
*/
@Test
public void testManagementMultiNodeVisorTask() throws Exception {
IgniteEx ignite = startGrid(0);
doTestVisorTask(TestManagementVisorMultiNodeTask.class, new VisorTaskArgument(), ignite);
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class VisorManagementEventSelfTest method testNotManagementMultiNodeVisorTask.
/**
* Current test case start multi node visor task that has not GridVisorManagementTask annotation.
* No exceptions are expected.
*
* @throws Exception If failed.
*/
@Test
public void testNotManagementMultiNodeVisorTask() throws Exception {
IgniteEx ignite = startGrid(0);
doTestNotManagementVisorTask(TestNotManagementVisorMultiNodeTask.class, new VisorTaskArgument(), ignite);
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
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));
}
Aggregations