use of org.apache.ignite.internal.client.GridClientConfiguration in project ignite by apache.
the class ClientFailedInitSelfTest method testRoutersAndServersAddressesProvided.
/**
*/
@Test
public void testRoutersAndServersAddressesProvided() {
try {
GridClientConfiguration c = new GridClientConfiguration();
c.setRouters(Collections.singleton("127.0.0.1:10000"));
c.setServers(Collections.singleton("127.0.0.1:10000"));
GridClientFactory.start(c);
assert false;
} catch (GridClientException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project ignite by apache.
the class ClientPreferDirectSelfTest method client.
/**
* @param b Balancer.
* @return Client.
* @throws Exception If failed.
*/
private GridClient client(GridClientLoadBalancer b) throws Exception {
GridClientConfiguration cfg = new GridClientConfiguration();
cfg.setBalancer(b);
cfg.setTopologyRefreshFrequency(TOP_REFRESH_FREQ);
Collection<String> rtrs = new ArrayList<>(3);
for (int i = 0; i < NODES_CNT / 2; i++) rtrs.add(HOST + ':' + (REST_TCP_PORT_BASE + i));
cfg.setRouters(rtrs);
return GridClientFactory.start(cfg);
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project ignite by apache.
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;
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project ignite by apache.
the class CommandHandler method getClientConfiguration.
/**
* @param userName User name for authorization.
* @param password Password for authorization.
* @param args Common arguments.
* @return Thin client configuration to connect to cluster.
* @throws IgniteCheckedException If error occur.
*/
@NotNull
private GridClientConfiguration getClientConfiguration(String userName, String password, ConnectionAndSslParameters args) throws IgniteCheckedException {
GridClientConfiguration clientCfg = new GridClientConfiguration();
clientCfg.setPingInterval(args.pingInterval());
clientCfg.setPingTimeout(args.pingTimeout());
clientCfg.setServers(Collections.singletonList(args.host() + ":" + args.port()));
if (!F.isEmpty(userName))
clientCfg.setSecurityCredentialsProvider(getSecurityCredentialsProvider(userName, password, clientCfg));
if (!F.isEmpty(args.sslKeyStorePath()))
clientCfg.setSslContextFactory(createSslSupportFactory(args));
return clientCfg;
}
use of org.apache.ignite.internal.client.GridClientConfiguration 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) {
LocalDateTime startTime = LocalDateTime.now();
Thread.currentThread().setName("session=" + ses);
logger.info("Control utility [ver. " + ACK_VER_STR + "]");
logger.info(COPYRIGHT);
logger.info("User: " + System.getProperty("user.name"));
logger.info("Time: " + startTime.format(formatter));
String commandName = "";
Throwable err = null;
boolean verbose = false;
try {
if (isHelp(rawArgs)) {
printHelp(rawArgs);
return EXIT_CODE_OK;
}
verbose = F.exist(rawArgs, CMD_VERBOSE::equalsIgnoreCase);
ConnectionAndSslParameters args = new CommonArgParser(logger).parseAndValidate(rawArgs.iterator());
Command command = args.command();
commandName = command.name();
GridClientConfiguration clientCfg = getClientConfiguration(args);
int tryConnectMaxCount = 3;
boolean suppliedAuth = !F.isEmpty(args.userName()) && !F.isEmpty(args.password());
boolean credentialsRequested = false;
while (true) {
try {
if (!args.autoConfirmation()) {
command.prepareConfirmation(clientCfg);
if (!confirm(command.confirmationPrompt())) {
logger.info("Operation cancelled.");
return EXIT_CODE_OK;
}
}
logger.info("Command [" + commandName + "] started");
logger.info("Arguments: " + argumentsToString(rawArgs));
logger.info(DELIM);
lastOperationRes = command.execute(clientCfg, logger, args.verbose());
break;
} catch (Throwable e) {
if (!isAuthError(e))
throw e;
if (suppliedAuth)
throw new GridClientAuthenticationException("Wrong credentials.");
if (tryConnectMaxCount == 0) {
throw new GridClientAuthenticationException("Maximum number of " + "retries exceeded");
}
logger.info(credentialsRequested ? "Authentication error, please try again." : "This cluster requires authentication.");
if (credentialsRequested)
tryConnectMaxCount--;
String user = retrieveUserName(args, clientCfg);
String pwd = new String(requestPasswordFromConsole("password: "));
clientCfg = getClientConfiguration(user, pwd, args);
credentialsRequested = true;
}
}
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_OK);
return EXIT_CODE_OK;
} catch (IllegalArgumentException e) {
logger.severe("Check arguments. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
if (verbose)
err = e;
return EXIT_CODE_INVALID_ARGUMENTS;
} catch (Throwable e) {
if (isAuthError(e)) {
logger.severe("Authentication error. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + ERR_AUTHENTICATION_FAILED);
if (verbose)
err = e;
return ERR_AUTHENTICATION_FAILED;
}
if (isConnectionError(e)) {
IgniteCheckedException cause = X.cause(e, IgniteCheckedException.class);
if (isConnectionClosedSilentlyException(e))
logger.severe("Connection to cluster failed. Please check firewall settings and " + "client and server are using the same SSL configuration.");
else {
if (isSSLMisconfigurationError(cause))
e = cause;
logger.severe("Connection to cluster failed. " + errorMessage(e));
}
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_CONNECTION_FAILED);
if (verbose)
err = e;
return EXIT_CODE_CONNECTION_FAILED;
}
if (X.hasCause(e, IllegalArgumentException.class)) {
IllegalArgumentException iae = X.cause(e, IllegalArgumentException.class);
logger.severe("Check arguments. " + errorMessage(iae));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
if (verbose)
err = e;
return EXIT_CODE_INVALID_ARGUMENTS;
}
logger.severe(errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_UNEXPECTED_ERROR);
err = e;
return EXIT_CODE_UNEXPECTED_ERROR;
} finally {
LocalDateTime endTime = LocalDateTime.now();
Duration diff = Duration.between(startTime, endTime);
if (nonNull(err))
logger.info("Error stack trace:" + System.lineSeparator() + X.getFullStackTrace(err));
logger.info("Control utility has completed execution at: " + endTime.format(formatter));
logger.info("Execution time: " + diff.toMillis() + " ms");
Arrays.stream(logger.getHandlers()).filter(handler -> handler instanceof FileHandler).forEach(Handler::close);
}
}
Aggregations