Search in sources :

Example 1 with GridClientConfiguration

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

the class CommandHandler method main.

/**
     * @param args Args.
     */
public static void main(String[] args) throws GridClientException {
    String host = "127.0.0.1";
    String port = "11212";
    Boolean activate = null;
    if (args.length == 1 && "help".equals(args[0])) {
        System.out.println("Example: --host {ip} --port {port} --{activate/deactivate} " + "or without command --host {ip} --port {port} then will print status.");
        return;
    }
    if (args.length > 5)
        throw new IllegalArgumentException("incorrect number of arguments");
    for (int i = 0; i < args.length; i++) {
        String str = args[i];
        if ("--host".equals(str))
            host = args[i + 1];
        else if ("--port".equals(str))
            port = args[i + 1];
        else if ("--activate".equals(str))
            activate = true;
        else if ("--deactivate".equals(str))
            activate = false;
    }
    if (host == null)
        throw new IllegalArgumentException("host can not be empty");
    if (port == null)
        throw new IllegalArgumentException("port can not be empty");
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setServers(Collections.singletonList(host + ":" + port));
    try (GridClient client = GridClientFactory.start(cfg)) {
        GridClientClusterState state = client.state();
        if (activate != null)
            try {
                state.active(activate);
                System.out.println(host + ":" + port + " - was " + (activate ? "activate" : "deactivate"));
            } catch (Exception e) {
                System.out.println("Something fail during " + (activate ? "activation" : "deactivation") + ", exception message: " + e.getMessage());
            }
        else
            System.out.println(host + ":" + port + " - " + (state.active() ? "active" : "inactive"));
    }
}
Also used : GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientException(org.apache.ignite.internal.client.GridClientException)

Example 2 with GridClientConfiguration

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

the class TaskEventSubjectIdSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    Ignite g = startGrid();
    g.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assert evt instanceof TaskEvent;
            evts.add((TaskEvent) evt);
            latch.countDown();
            return true;
        }
    }, EVTS_TASK_EXECUTION);
    nodeId = g.cluster().localNode().id();
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setServers(Collections.singleton("127.0.0.1:11211"));
    client = GridClientFactory.start(cfg);
}
Also used : TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 3 with GridClientConfiguration

use of org.apache.ignite.internal.client.GridClientConfiguration 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 4 with GridClientConfiguration

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

the class BinaryConfigurationCustomSerializerSelfTest method testThinClientConnected.

/**
 * Test that thin client will be able to connect to node with custom binary serializer and custom consistent ID.
 *
 * @throws Exception If failed.
 */
@Test
public void testThinClientConnected() throws Exception {
    UUID nid = ignite(0).cluster().localNode().id();
    GridClientConfiguration clnCfg = new GridClientConfiguration();
    clnCfg.setProtocol(GridClientProtocol.TCP);
    clnCfg.setServers(Collections.singleton("127.0.0.1:11211"));
    clnCfg.setBalancer(new GridClientRoundRobinBalancer());
    // Start client.
    GridClient client = GridClientFactory.start(clnCfg);
    // Execute some task.
    client.compute().execute(VisorNodePingTask.class.getName(), new VisorTaskArgument<>(nid, new VisorNodePingTaskArg(nid), false));
    GridClientFactory.stop(client.id(), false);
}
Also used : GridClientRoundRobinBalancer(org.apache.ignite.internal.client.balancer.GridClientRoundRobinBalancer) VisorNodePingTaskArg(org.apache.ignite.internal.visor.node.VisorNodePingTaskArg) GridClient(org.apache.ignite.internal.client.GridClient) VisorNodePingTask(org.apache.ignite.internal.visor.node.VisorNodePingTask) UUID(java.util.UUID) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with GridClientConfiguration

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

the class CacheEventSecurityContextTest method testGridClient.

/**
 * Tests cache event security context in case operation is initiated from the {@link GridClient}.
 */
@Test
public void testGridClient() throws Exception {
    Assume.assumeTrue(txIsolation == null && txConcurrency == null);
    operationInitiatorLogin = "grid_client";
    GridClientConfiguration cfg = new GridClientConfiguration().setServers(singletonList("127.0.0.1:11211")).setDataConfigurations(singletonList(new GridClientDataConfiguration().setName(cacheName))).setSecurityCredentialsProvider(new SecurityCredentialsBasicProvider(new SecurityCredentials(operationInitiatorLogin, "")));
    try (GridClient cli = GridClientFactory.start(cfg)) {
        GridClientData cache = cli.data(cacheName);
        checkEvents(k -> cache.put(k, "val"), false, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.putAsync(k, "val").get(), false, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.putAll(singletonMap(k, "val")), false, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.putAllAsync(singletonMap(k, "val")).get(), false, EVT_CACHE_OBJECT_PUT);
        checkEvents(cache::remove, true, EVT_CACHE_OBJECT_REMOVED);
        checkEvents(k -> cache.removeAsync(k).get(), true, EVT_CACHE_OBJECT_REMOVED);
        checkEvents(k -> cache.removeAll(of(k)), true, EVT_CACHE_OBJECT_REMOVED);
        checkEvents(k -> cache.removeAllAsync(of(k)).get(), true, EVT_CACHE_OBJECT_REMOVED);
        checkEvents(cache::get, true, EVT_CACHE_OBJECT_READ);
        checkEvents(k -> cache.getAsync(k).get(), true, EVT_CACHE_OBJECT_READ);
        checkEvents(k -> cache.getAll(of(k)), true, EVT_CACHE_OBJECT_READ);
        checkEvents(k -> cache.getAllAsync(of(k)).get(), true, EVT_CACHE_OBJECT_READ);
        checkEvents(k -> cache.replace(k, "val"), true, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.replaceAsync(k, "val").get(), true, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.append(k, "val"), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.appendAsync(k, "val").get(), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.prepend(k, "val"), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.prependAsync(k, "val").get(), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.cas(k, "new_val", "val"), true, EVT_CACHE_OBJECT_PUT);
        checkEvents(k -> cache.casAsync(k, "new_val", "val").get(), true, EVT_CACHE_OBJECT_PUT);
    }
}
Also used : SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) GridClientData(org.apache.ignite.internal.client.GridClientData) GridClient(org.apache.ignite.internal.client.GridClient) SecurityCredentialsBasicProvider(org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration) Test(org.junit.Test)

Aggregations

GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)33 GridClient (org.apache.ignite.internal.client.GridClient)10 Test (org.junit.Test)8 GridClientDataConfiguration (org.apache.ignite.internal.client.GridClientDataConfiguration)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 GridClientException (org.apache.ignite.internal.client.GridClientException)4 SecurityCredentials (org.apache.ignite.plugin.security.SecurityCredentials)4 SecurityCredentialsBasicProvider (org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Logger (java.util.logging.Logger)3 GridClientNode (org.apache.ignite.internal.client.GridClientNode)3 File (java.io.File)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Map (java.util.Map)2 GridClientClusterState (org.apache.ignite.internal.client.GridClientClusterState)2 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2