Search in sources :

Example 6 with GridClient

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

the class ClientAbstractSelfTest method testShutdown.

/**
 * @throws Exception If failed.
 */
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)

Example 7 with GridClient

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

the class ClientAbstractSelfTest method testConnectable.

/**
 * @throws Exception If failed.
 */
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)

Example 8 with GridClient

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

the class ClientPreferDirectSelfTest method executeTest.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("TypeMayBeWeakened")
private void executeTest(GridClientLoadBalancer b) throws Exception {
    try (GridClient c = client(b)) {
        Set<String> executions = new HashSet<>();
        for (int i = 0; i < NODES_CNT * 10; i++) executions.add(c.compute().<String>execute(TestTask.class.getName(), null));
        assertEquals(NODES_CNT / 2, executions.size());
        for (int i = 0; i < NODES_CNT / 2; i++) executions.contains(grid(i).localNode().id().toString());
    }
}
Also used : GridClient(org.apache.ignite.internal.client.GridClient) HashSet(java.util.HashSet)

Example 9 with GridClient

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

the class MapReduceClient method client.

/**
 * Gets the client.
 *
 * @return The client.
 */
public GridClient client() throws IOException {
    GridClient cli0 = cli;
    if (cli0 == null) {
        synchronized (mux) {
            cli0 = cli;
            if (cli0 == null) {
                GridClientConfiguration cliCfg = new GridClientConfiguration();
                cliCfg.setProtocol(TCP);
                cliCfg.setServers(addrs);
                cliCfg.setMarshaller(new GridClientJdkMarshaller());
                // 1 day.
                cliCfg.setMaxConnectionIdleTime(24 * 60 * 60 * 1000L);
                cliCfg.setDaemon(true);
                try {
                    cli0 = GridClientFactory.start(cliCfg);
                    cli = cli0;
                } catch (GridClientException e) {
                    throw new IOException("Failed to establish connection with Ignite: " + addrs, e);
                }
            }
        }
    }
    return cli0;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientJdkMarshaller(org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller) GridClient(org.apache.ignite.internal.client.GridClient) IOException(java.io.IOException) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 10 with GridClient

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

the class CommandHandler method execute.

/**
 * Parse and execute command.
 *
 * @param rawArgs Arguments to parse and execute.
 * @return Exit code.
 */
public int execute(List<String> rawArgs) {
    log("Control utility [ver. " + ACK_VER_STR + "]");
    log(COPYRIGHT);
    log("User: " + System.getProperty("user.name"));
    log(DELIM);
    try {
        if (F.isEmpty(rawArgs) || (rawArgs.size() == 1 && CMD_HELP.equalsIgnoreCase(rawArgs.get(0)))) {
            log("This utility can do the following commands:");
            usage("  Activate cluster:", ACTIVATE);
            usage("  Deactivate cluster:", DEACTIVATE, " [--force]");
            usage("  Print current cluster state:", STATE);
            usage("  Print cluster baseline topology:", BASELINE);
            usage("  Add nodes into baseline topology:", BASELINE, " add consistentId1[,consistentId2,....,consistentIdN] [--force]");
            usage("  Remove nodes from baseline topology:", BASELINE, " remove consistentId1[,consistentId2,....,consistentIdN] [--force]");
            usage("  Set baseline topology:", BASELINE, " set consistentId1[,consistentId2,....,consistentIdN] [--force]");
            usage("  Set baseline topology based on version:", BASELINE, " version topologyVersion [--force]");
            log("By default cluster deactivation and changes in baseline topology commands request interactive confirmation. ");
            log("  --force option can be used to execute commands without prompting for confirmation.");
            nl();
            log("Default values:");
            log("    HOST_OR_IP=" + DFLT_HOST);
            log("    PORT=" + DFLT_PORT);
            nl();
            log("Exit codes:");
            log("    " + EXIT_CODE_OK + " - successful execution.");
            log("    " + EXIT_CODE_INVALID_ARGUMENTS + " - invalid arguments.");
            log("    " + EXIT_CODE_CONNECTION_FAILED + " - connection failed.");
            log("    " + ERR_AUTHENTICATION_FAILED + " - authentication failed.");
            log("    " + EXIT_CODE_UNEXPECTED_ERROR + " - unexpected error.");
            return EXIT_CODE_OK;
        }
        Arguments args = parseAndValidate(rawArgs);
        if (!confirm(args)) {
            log("Operation canceled.");
            return EXIT_CODE_OK;
        }
        GridClientConfiguration cfg = new GridClientConfiguration();
        cfg.setServers(Collections.singletonList(args.host() + ":" + args.port()));
        if (!F.isEmpty(args.user())) {
            cfg.setSecurityCredentialsProvider(new SecurityCredentialsBasicProvider(new SecurityCredentials(args.user(), args.password())));
        }
        try (GridClient client = GridClientFactory.start(cfg)) {
            switch(args.command()) {
                case ACTIVATE:
                    activate(client);
                    break;
                case DEACTIVATE:
                    deactivate(client);
                    break;
                case STATE:
                    state(client);
                    break;
                case BASELINE:
                    baseline(client, args.baselineAction(), args.baselineArguments());
                    break;
            }
        }
        return 0;
    } catch (IllegalArgumentException e) {
        return error(EXIT_CODE_INVALID_ARGUMENTS, "Check arguments.", e);
    } catch (Throwable e) {
        if (isAuthError(e))
            return error(ERR_AUTHENTICATION_FAILED, "Authentication error.", e);
        if (isConnectionError(e))
            return error(EXIT_CODE_CONNECTION_FAILED, "Connection to cluster failed.", e);
        return error(EXIT_CODE_UNEXPECTED_ERROR, "", e);
    }
}
Also used : 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)

Aggregations

GridClient (org.apache.ignite.internal.client.GridClient)15 GridClientNode (org.apache.ignite.internal.client.GridClientNode)7 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)4 GridClientException (org.apache.ignite.internal.client.GridClientException)4 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)1 GridClientClusterState (org.apache.ignite.internal.client.GridClientClusterState)1 GridClientData (org.apache.ignite.internal.client.GridClientData)1