Search in sources :

Example 51 with GridClientConfiguration

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;
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) CommandLogger.optional(org.apache.ignite.internal.commandline.CommandLogger.optional) CMD_AUTO_CONFIRMATION(org.apache.ignite.internal.commandline.CommonArgParser.CMD_AUTO_CONFIRMATION) GridClient(org.apache.ignite.internal.client.GridClient) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) IgniteException(org.apache.ignite.IgniteException) ClusterState(org.apache.ignite.cluster.ClusterState) Set(java.util.Set) CommandLogger.or(org.apache.ignite.internal.commandline.CommandLogger.or) Logger(java.util.logging.Logger) LinkedHashMap(java.util.LinkedHashMap) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) GridClientException(org.apache.ignite.internal.client.GridClientException) SET_STATE(org.apache.ignite.internal.commandline.CommandList.SET_STATE) Map(java.util.Map) SAFE_CLUSTER_DEACTIVATION(org.apache.ignite.internal.IgniteFeatures.SAFE_CLUSTER_DEACTIVATION) GridClientNode(org.apache.ignite.internal.client.GridClientNode) Collectors.toSet(java.util.stream.Collectors.toSet) CLUSTER_READ_ONLY_MODE(org.apache.ignite.internal.IgniteFeatures.CLUSTER_READ_ONLY_MODE) GridClientException(org.apache.ignite.internal.client.GridClientException) IgniteException(org.apache.ignite.IgniteException) GridClient(org.apache.ignite.internal.client.GridClient)

Example 52 with GridClientConfiguration

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);
    }
}
Also used : GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 53 with GridClientConfiguration

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;
}
Also used : GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Example 54 with GridClientConfiguration

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));
}
Also used : Properties(java.util.Properties) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) Map(java.util.Map) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 55 with GridClientConfiguration

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());
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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