use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClusterStateChangeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
try (GridClient client = Command.startClient(clientCfg)) {
Set<GridClientNode> serverNodes = client.compute().nodes().stream().filter(n -> !n.isClient() && !n.isDaemon()).collect(toSet());
Set<GridClientNode> supportedServerNodes = serverNodes.stream().filter(n -> n.supports(CLUSTER_READ_ONLY_MODE)).collect(toSet());
Set<GridClientNode> notSupportedSafeDeactivation = supportedServerNodes.stream().filter(n -> !n.supports(SAFE_CLUSTER_DEACTIVATION)).collect(toSet());
if (!supportedServerNodes.equals(serverNodes) && state == ACTIVE_READ_ONLY)
throw new IgniteException("Not all nodes in cluster supports cluster state " + state);
if (!notSupportedSafeDeactivation.isEmpty() && state == INACTIVE && !forceDeactivation) {
throw new GridClientException("Deactivation stopped. Found a nodes that do not support the " + "correctness checking of this operation: " + notSupportedSafeDeactivation + ". Deactivation " + "clears in-memory caches (without persistence) including the system caches. " + "To deactivate cluster pass '--force' flag.");
}
if (F.isEmpty(supportedServerNodes))
client.state().active(ClusterState.active(state));
else if (notSupportedSafeDeactivation.isEmpty())
client.state().state(state, forceDeactivation);
else
client.state().state(state);
log.info("Cluster state changed to " + state);
return null;
} catch (Throwable e) {
log.info("Failed to change cluster state to " + state);
throw e;
}
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class MvccJdbcTransactionFinishOnDeactivatedClusterSelfTest method deactivateThroughClient.
/**
*/
private void deactivateThroughClient() throws Exception {
GridClientConfiguration clientCfg = new GridClientConfiguration();
clientCfg.setServers(Collections.singletonList("127.0.0.1:11211"));
try (GridClient client = GridClientFactory.start(clientCfg)) {
GridClientClusterState state = client.state();
log.info(">>> Try to deactivate ...");
state.active(false);
}
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClientCacheBenchmark method configuration.
/**
* @return Test client configuration.
*/
private GridClientConfiguration configuration() {
GridClientConfiguration cfg = new GridClientConfiguration();
cfg.setServers(Collections.singleton("localhost:11211"));
GridClientDataConfiguration cacheCfg = new GridClientDataConfiguration();
cacheCfg.setName("partitioned");
cacheCfg.setAffinity(new GridClientPartitionAffinity());
cfg.setDataConfigurations(Collections.singletonList(cacheCfg));
return cfg;
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClientPropertiesConfigurationSelfTest method testCreation.
/**
* Test client configuration loaded from the properties.
*
* @throws Exception In case of exception.
*/
@Test
public void testCreation() throws Exception {
// Validate default configuration.
GridClientConfiguration cfg = new GridClientConfiguration();
cfg.setServers(Arrays.asList("localhost:11211"));
validateConfig(0, cfg);
// Validate default properties-based configuration.
cfg = new GridClientConfiguration();
cfg.setServers(Arrays.asList("localhost:11211"));
validateConfig(0, cfg);
// Validate loaded configuration.
Properties props = loadProperties(1, GRID_CLIENT_CONFIG);
validateConfig(0, new GridClientConfiguration(props));
// Validate loaded configuration with changed key prefixes.
Properties props2 = new Properties();
for (Map.Entry<Object, Object> e : props.entrySet()) props2.put("new." + e.getKey(), e.getValue());
validateConfig(0, new GridClientConfiguration("new.ignite.client", props2));
validateConfig(0, new GridClientConfiguration("new.ignite.client.", props2));
// Validate loaded test configuration.
File tmp = uncommentProperties(GRID_CLIENT_CONFIG);
props = loadProperties(25, tmp.toURI().toURL());
validateConfig(2, new GridClientConfiguration(props));
// Validate loaded test configuration with changed key prefixes.
props2 = new Properties();
for (Map.Entry<Object, Object> e : props.entrySet()) props2.put("new." + e.getKey(), e.getValue());
validateConfig(2, new GridClientConfiguration("new.ignite.client", props2));
validateConfig(2, new GridClientConfiguration("new.ignite.client.", props2));
// Validate loaded test configuration with empty key prefixes.
props2 = new Properties();
for (Map.Entry<Object, Object> e : props.entrySet()) props2.put(e.getKey().toString().replace("ignite.client.", ""), e.getValue());
validateConfig(2, new GridClientConfiguration("", props2));
validateConfig(2, new GridClientConfiguration(".", props2));
}
use of org.apache.ignite.internal.client.GridClientConfiguration in project gridgain by gridgain.
the class ClientPropertiesConfigurationSelfTest method testSpringConfig.
/**
* Validate spring client configuration.
*
* @throws Exception In case of any exception.
*/
@Test
public void testSpringConfig() throws Exception {
GridClientConfiguration cfg = new FileSystemXmlApplicationContext(GRID_CLIENT_SPRING_CONFIG.toString()).getBean(GridClientConfiguration.class);
assertEquals(Arrays.asList("127.0.0.1:11211"), new ArrayList<>(cfg.getServers()));
assertNull(cfg.getSecurityCredentialsProvider());
Collection<GridClientDataConfiguration> dataCfgs = cfg.getDataConfigurations();
assertEquals(1, dataCfgs.size());
GridClientDataConfiguration dataCfg = dataCfgs.iterator().next();
assertEquals("partitioned", dataCfg.getName());
assertNotNull(dataCfg.getPinnedBalancer());
assertEquals(GridClientRandomBalancer.class, dataCfg.getPinnedBalancer().getClass());
assertNotNull(dataCfg.getAffinity());
assertEquals(GridClientPartitionAffinity.class, dataCfg.getAffinity().getClass());
}
Aggregations