Search in sources :

Example 46 with GridClientConfiguration

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

the class ClientTcpDirectMultiNodeSelfTest method clientConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected GridClientConfiguration clientConfiguration() throws GridClientException {
    assert NODES_CNT > 3 : "Too few nodes to execute direct multinode test";
    GridClientConfiguration cfg = super.clientConfiguration();
    cfg.setServers(Collections.<String>emptySet());
    Collection<String> srvs = new ArrayList<>(3);
    for (int i = 0; i < NODES_CNT / 2; i++) srvs.add(HOST + ':' + (REST_TCP_PORT_BASE + i));
    cfg.setRouters(srvs);
    return cfg;
}
Also used : ArrayList(java.util.ArrayList) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 47 with GridClientConfiguration

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

the class ClientTcpDirectSelfTest method clientConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected GridClientConfiguration clientConfiguration() throws GridClientException {
    GridClientConfiguration cfg = super.clientConfiguration();
    cfg.setServers(Collections.<String>emptySet());
    cfg.setRouters(Collections.singleton(HOST + ":" + BINARY_PORT));
    return cfg;
}
Also used : GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 48 with GridClientConfiguration

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

the class TaskCommandHandlerSelfTest method clientConfiguration.

/**
 * @return Client configuration.
 */
private GridClientConfiguration clientConfiguration() {
    GridClientConfiguration cfg = new GridClientConfiguration();
    GridClientDataConfiguration nullCache = new GridClientDataConfiguration();
    GridClientDataConfiguration cache = new GridClientDataConfiguration();
    cache.setName(CACHE_NAME);
    cfg.setDataConfigurations(Arrays.asList(nullCache, cache));
    cfg.setProtocol(TCP);
    cfg.setServers(Arrays.asList("localhost:" + BINARY_PORT));
    return cfg;
}
Also used : GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Example 49 with GridClientConfiguration

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

the class TaskExecutor method executeTaskByNameOnNode.

/**
 * @param client Client
 * @param taskClsName Task class name.
 * @param taskArgs Task args.
 * @param nodeId Node ID to execute task at (if null, random node will be chosen by balancer).
 * @param clientCfg
 * @return Task result.
 * @throws GridClientException If failed to execute task.
 */
public static <R> R executeTaskByNameOnNode(GridClient client, String taskClsName, Object taskArgs, UUID nodeId, GridClientConfiguration clientCfg) throws GridClientException {
    GridClientCompute compute = client.compute();
    if (nodeId == BROADCAST_UUID) {
        Collection<GridClientNode> nodes = compute.nodes(GridClientNode::connectable);
        if (F.isEmpty(nodes))
            throw new GridClientDisconnectedException("Connectable nodes not found", null);
        List<UUID> nodeIds = nodes.stream().map(GridClientNode::nodeId).collect(Collectors.toList());
        return client.compute().execute(taskClsName, new VisorTaskArgument<>(nodeIds, taskArgs, false));
    }
    GridClientNode node = null;
    if (nodeId == null) {
        // Prefer node from connect string.
        final String cfgAddr = clientCfg.getServers().iterator().next();
        String[] parts = cfgAddr.split(":");
        if (DFLT_HOST.equals(parts[0])) {
            InetAddress addr;
            try {
                addr = IgniteUtils.getLocalHost();
            } catch (IOException e) {
                throw new GridClientException("Can't get localhost name.", e);
            }
            if (addr.isLoopbackAddress())
                throw new GridClientException("Can't find localhost name.");
            String origAddr = addr.getHostName() + ":" + parts[1];
            node = listHosts(client).filter(tuple -> origAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
            if (node == null)
                node = listHostsByClientNode(client).filter(tuple -> tuple.get2().size() == 1 && cfgAddr.equals(tuple.get2().get(0))).findFirst().map(IgniteBiTuple::get1).orElse(null);
        } else
            node = listHosts(client).filter(tuple -> cfgAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
        // Otherwise choose random node.
        if (node == null)
            node = getBalancedNode(compute);
    } else {
        for (GridClientNode n : compute.nodes()) {
            if (n.connectable() && nodeId.equals(n.nodeId())) {
                node = n;
                break;
            }
        }
        if (node == null)
            throw new IllegalArgumentException("Node with id=" + nodeId + " not found");
    }
    return compute.projection(node).execute(taskClsName, new VisorTaskArgument<>(node.nodeId(), taskArgs, false));
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) F(org.apache.ignite.internal.util.typedef.F) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) Collection(java.util.Collection) IOException(java.io.IOException) UUID(java.util.UUID) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) Collectors(java.util.stream.Collectors) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) InetAddress(java.net.InetAddress) List(java.util.List) Stream(java.util.stream.Stream) GridClientException(org.apache.ignite.internal.client.GridClientException) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ComputeTask(org.apache.ignite.compute.ComputeTask) GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) IOException(java.io.IOException) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 50 with GridClientConfiguration

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

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) Command.usage(org.apache.ignite.internal.commandline.Command.usage) 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)

Aggregations

GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)64 GridClient (org.apache.ignite.internal.client.GridClient)18 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 GridClientDataConfiguration (org.apache.ignite.internal.client.GridClientDataConfiguration)11 UUID (java.util.UUID)10 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)10 List (java.util.List)9 Logger (java.util.logging.Logger)9 Collectors (java.util.stream.Collectors)9 GridClientNode (org.apache.ignite.internal.client.GridClientNode)9 GridClientException (org.apache.ignite.internal.client.GridClientException)8 F (org.apache.ignite.internal.util.typedef.F)7 Map (java.util.Map)6 VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)6 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)5 CommandLogger.optional (org.apache.ignite.internal.commandline.CommandLogger.optional)5 SecurityCredentials (org.apache.ignite.plugin.security.SecurityCredentials)5 SecurityCredentialsBasicProvider (org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider)5 File (java.io.File)4