Search in sources :

Example 1 with GridClientCompute

use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.

the class ClientAbstractSelfTest method testExecute.

/**
 * @throws Exception If failed.
 */
@Test
public void testExecute() throws Exception {
    String taskName = getTaskName();
    Object taskArg = getTaskArgument();
    GridClientCompute compute = client.compute();
    assertEquals(Integer.valueOf(17), compute.execute(taskName, taskArg));
    assertEquals(Integer.valueOf(17), compute.executeAsync(taskName, taskArg).get());
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with GridClientCompute

use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.

the class ClientAbstractSelfTest method testShutdown.

/**
 * @throws Exception If failed.
 */
@Test
public void testShutdown() throws Exception {
    GridClient c = client();
    GridClientCompute compute = c.compute();
    String taskName = getTaskName();
    Object taskArg = getTaskArgument();
    Collection<GridClientFuture<Object>> futs = new ArrayList<>();
    // Validate connection works.
    compute.execute(taskName, taskArg);
    info(">>> First task executed successfully, running batch.");
    for (int i = 0; i < 10; i++) futs.add(compute.executeAsync(taskName, taskArg));
    // Stop client.
    GridClientFactory.stop(c.id(), true);
    info(">>> Completed stop request.");
    int failed = 0;
    for (GridClientFuture<Object> fut : futs) {
        try {
            assertEquals(17, fut.get());
        } catch (GridClientException e) {
            failed++;
            log.warning("Task execution failed.", e);
        }
    }
    assertEquals(0, failed);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) ArrayList(java.util.ArrayList) GridClient(org.apache.ignite.internal.client.GridClient) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with GridClientCompute

use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.

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 4 with GridClientCompute

use of org.apache.ignite.internal.client.GridClientCompute 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)

Example 5 with GridClientCompute

use of org.apache.ignite.internal.client.GridClientCompute 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)

Aggregations

GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)15 Test (org.junit.Test)10 GridClientNode (org.apache.ignite.internal.client.GridClientNode)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 GridClient (org.apache.ignite.internal.client.GridClient)6 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)4 GridClientException (org.apache.ignite.internal.client.GridClientException)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)2 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1