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