Search in sources :

Example 26 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project gridgain by gridgain.

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 27 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project gridgain by gridgain.

the class ClientAbstractSelfTest method testConnectable.

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectable() throws Exception {
    GridClient client = client();
    List<GridClientNode> nodes = client.compute().refreshTopology(false, false);
    assertTrue(F.first(nodes).connectable());
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 28 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project gridgain by gridgain.

the class ClientAbstractSelfTest method testTopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testTopology() throws Exception {
    GridClientCompute compute = client.compute();
    List<GridClientNode> top = compute.refreshTopology(true, true);
    assertNotNull(top);
    assertEquals(1, top.size());
    GridClientNode node = F.first(top);
    assertNotNull(node);
    assertFalse(node.attributes().isEmpty());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    assertNotNull(node.metrics());
    top = compute.refreshTopology(false, false);
    node = F.first(top);
    assertNotNull(top);
    assertEquals(1, top.size());
    assertNull(node.metrics());
    assertTrue(node.attributes().isEmpty());
    node = F.first(top);
    assertNotNull(node);
    assertTrue(node.attributes().isEmpty());
    assertNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    top = compute.refreshTopologyAsync(true, true).get();
    assertNotNull(top);
    assertEquals(1, top.size());
    node = F.first(top);
    assertNotNull(node);
    assertFalse(node.attributes().isEmpty());
    assertNotNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    top = compute.refreshTopologyAsync(false, false).get();
    assertNotNull(top);
    assertEquals(1, top.size());
    node = F.first(top);
    assertNotNull(node);
    assertTrue(node.attributes().isEmpty());
    assertNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 29 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project gridgain by gridgain.

the class GridRouterClientImpl method forwardMessage.

/**
 * Send a raw packet "as is" directly to the given node.
 * The exact types of acceptable arguments and return values depends on underlying connections.
 *
 * @param msg Raw message to send.
 * @param destId Id of node to send message to. If {@code null} than node will be chosen
 *     from the topology randomly.
 * @return Future, representing forwarded message.
 * @throws GridServerUnreachableException If destination node can't be reached.
 * @throws GridClientClosedException If client is closed.
 * @throws GridClientException If any other client-related error occurs.
 * @throws InterruptedException If router was interrupted while trying.
 *     to establish connection with destination node.
 */
GridClientFutureAdapter<?> forwardMessage(Object msg, @Nullable UUID destId, byte marshId) throws GridClientException, InterruptedException {
    GridClientTopology top = clientImpl.topology();
    GridClientNode dest = destId != null ? top.node(destId) : cliCfg.getBalancer().balancedNode(applyFilter(top.nodes(), new GridClientPredicate<GridClientNodeImpl>() {

        @Override
        public boolean apply(GridClientNodeImpl e) {
            return restAvailable(e, cliCfg.getProtocol());
        }
    }));
    if (dest == null)
        throw new GridServerUnreachableException("Failed to resolve node for specified destination ID: " + destId);
    GridClientConnectionManager connMgr = connectionManager(marshId);
    GridClientConnection conn = null;
    // No reconnection handling there. Let client to do it if needed.
    GridClientException cause;
    try {
        conn = connMgr.connection(dest);
        return conn.forwardMessage(msg);
    } catch (GridClientConnectionResetException e) {
        if (destId != null)
            connMgr.terminateConnection(conn, top.node(destId), e);
        else
            connMgr.terminateConnection(conn, null, e);
        cause = e;
    } catch (GridClientException e) {
        cause = e;
    }
    GridClientFutureAdapter<Object> fail = new GridClientFutureAdapter<>();
    fail.onDone(cause);
    return fail;
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientTopology(org.apache.ignite.internal.client.impl.connection.GridClientTopology) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientConnectionManager(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridClientFutureAdapter(org.apache.ignite.internal.client.impl.GridClientFutureAdapter) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl)

Example 30 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project gridgain by gridgain.

the class GridClientTopology method fail.

/**
 * Marks topology as failed. After this method called all accessors will throw exception
 * until a next successful update.
 *
 * @param cause Exception caused the failure.
 */
public void fail(GridClientException cause) {
    lock.writeLock().lock();
    try {
        lastError = cause;
        for (GridClientNode n : nodes.values()) notifyEvents(Collections.singletonList(new TopologyEvent(false, n)));
        nodes = Collections.emptyMap();
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode)

Aggregations

GridClientNode (org.apache.ignite.internal.client.GridClientNode)62 GridClient (org.apache.ignite.internal.client.GridClient)32 Test (org.junit.Test)21 GridClientException (org.apache.ignite.internal.client.GridClientException)20 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)19 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)18 UUID (java.util.UUID)17 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)12 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)9 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)9 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Logger (java.util.logging.Logger)6 Collectors (java.util.stream.Collectors)6 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)6 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)6 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)6 VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)6 Map (java.util.Map)5