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"));
}
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations