Search in sources :

Example 1 with GridClientNode

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);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientPredicate(org.apache.ignite.internal.client.GridClientPredicate) IgniteException(org.apache.ignite.IgniteException) GridClientException(org.apache.ignite.internal.client.GridClientException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with GridClientNode

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

Example 3 with GridClientNode

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);
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) GridClient(org.apache.ignite.internal.client.GridClient) SecurityCredentialsBasicProvider(org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 4 with GridClientNode

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;
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) CheckIndexInlineSizesTask(org.apache.ignite.internal.commandline.cache.check_indexes_inline_size.CheckIndexInlineSizesTask) CheckIndexInlineSizesResult(org.apache.ignite.internal.commandline.cache.check_indexes_inline_size.CheckIndexInlineSizesResult) GridClient(org.apache.ignite.internal.client.GridClient) UUID(java.util.UUID)

Example 5 with GridClientNode

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;
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) GridClient(org.apache.ignite.internal.client.GridClient)

Aggregations

GridClientNode (org.apache.ignite.internal.client.GridClientNode)30 GridClient (org.apache.ignite.internal.client.GridClient)15 Test (org.junit.Test)11 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)9 GridClientException (org.apache.ignite.internal.client.GridClientException)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 UUID (java.util.UUID)7 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)5 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)5 ArrayList (java.util.ArrayList)3 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)3 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)3 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)3 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Ignite (org.apache.ignite.Ignite)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2