Search in sources :

Example 1 with VisorTaskArgument

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;
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) SCHEDULE(org.apache.ignite.internal.commandline.defragmentation.DefragmentationSubcommands.SCHEDULE) GridClient(org.apache.ignite.internal.client.GridClient) VisorDefragmentationTask(org.apache.ignite.internal.visor.defragmentation.VisorDefragmentationTask) VisorDefragmentationOperation(org.apache.ignite.internal.visor.defragmentation.VisorDefragmentationOperation) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) DefragmentationSubcommands(org.apache.ignite.internal.commandline.defragmentation.DefragmentationSubcommands) Set(java.util.Set) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CANCEL(org.apache.ignite.internal.commandline.defragmentation.DefragmentationSubcommands.CANCEL) List(java.util.List) VisorDefragmentationTaskArg(org.apache.ignite.internal.visor.defragmentation.VisorDefragmentationTaskArg) Locale(java.util.Locale) DEFRAGMENTATION(org.apache.ignite.internal.commandline.CommandList.DEFRAGMENTATION) Optional(java.util.Optional) VisorDefragmentationTaskResult(org.apache.ignite.internal.visor.defragmentation.VisorDefragmentationTaskResult) DefragmentationArguments(org.apache.ignite.internal.commandline.defragmentation.DefragmentationArguments) GridClientNode(org.apache.ignite.internal.client.GridClientNode) VisorDefragmentationTaskResult(org.apache.ignite.internal.visor.defragmentation.VisorDefragmentationTaskResult) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) GridClient(org.apache.ignite.internal.client.GridClient)

Example 2 with VisorTaskArgument

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);
}
Also used : VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with VisorTaskArgument

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);
}
Also used : VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with VisorTaskArgument

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);
}
Also used : VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with VisorTaskArgument

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));
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) F(org.apache.ignite.internal.util.typedef.F) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) Collection(java.util.Collection) IOException(java.io.IOException) UUID(java.util.UUID) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) Collectors(java.util.stream.Collectors) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) InetAddress(java.net.InetAddress) List(java.util.List) Stream(java.util.stream.Stream) GridClientException(org.apache.ignite.internal.client.GridClientException) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ComputeTask(org.apache.ignite.compute.ComputeTask) GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) IOException(java.io.IOException) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Aggregations

VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)13 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 Test (org.junit.Test)7 UUID (java.util.UUID)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 TaskEvent (org.apache.ignite.events.TaskEvent)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 Collection (java.util.Collection)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)2 ComputeTask (org.apache.ignite.compute.ComputeTask)2 Event (org.apache.ignite.events.Event)2 GridClient (org.apache.ignite.internal.client.GridClient)2 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)2 GridClientNode (org.apache.ignite.internal.client.GridClientNode)2 VisorValidateIndexesJobResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult)2