Search in sources :

Example 1 with RemoteServerConfiguration

use of org.infinispan.persistence.remote.configuration.RemoteServerConfiguration in project infinispan by infinispan.

the class RemoteStore method buildRemoteConfiguration.

private ConfigurationBuilder buildRemoteConfiguration(RemoteStoreConfiguration configuration, Marshaller marshaller) {
    ConfigurationBuilder builder = (configuration.uri() != null && !configuration.uri().isEmpty()) ? HotRodURI.create(configuration.uri()).toConfigurationBuilder() : new ConfigurationBuilder();
    List<RemoteServerConfiguration> servers = configuration.servers();
    for (RemoteServerConfiguration s : servers) {
        builder.addServer().host(s.host()).port(s.port());
    }
    ConnectionPoolConfiguration poolConfiguration = configuration.connectionPool();
    Long connectionTimeout = configuration.connectionTimeout();
    Long socketTimeout = configuration.socketTimeout();
    builder.classLoader(configuration.getClass().getClassLoader()).balancingStrategy(configuration.balancingStrategy()).connectionPool().exhaustedAction(ExhaustedAction.valueOf(poolConfiguration.exhaustedAction().toString())).maxActive(poolConfiguration.maxActive()).minIdle(poolConfiguration.minIdle()).minEvictableIdleTime(poolConfiguration.minEvictableIdleTime()).connectionTimeout(connectionTimeout.intValue()).forceReturnValues(configuration.forceReturnValues()).keySizeEstimate(configuration.keySizeEstimate()).marshaller(marshaller).asyncExecutorFactory().factoryClass(configuration.asyncExecutorFactory().factory().getClass()).asyncExecutorFactory().withExecutorProperties(configuration.asyncExecutorFactory().properties()).socketTimeout(socketTimeout.intValue()).tcpNoDelay(configuration.tcpNoDelay()).valueSizeEstimate(configuration.valueSizeEstimate()).version(configuration.protocol() == null ? ProtocolVersion.DEFAULT_PROTOCOL_VERSION : configuration.protocol());
    SslConfiguration ssl = configuration.security().ssl();
    if (ssl.enabled()) {
        builder.security().ssl().enable().keyStoreType(ssl.keyStoreType()).keyAlias(ssl.keyAlias()).keyStoreFileName(ssl.keyStoreFileName()).keyStorePassword(ssl.keyStorePassword()).keyStoreCertificatePassword(ssl.keyStoreCertificatePassword()).trustStoreFileName(ssl.trustStoreFileName()).trustStorePassword(ssl.trustStorePassword()).trustStoreType(ssl.trustStoreType()).protocol(ssl.protocol()).sniHostName(ssl.sniHostName());
    }
    AuthenticationConfiguration auth = configuration.security().authentication();
    if (auth.enabled()) {
        builder.security().authentication().enable().callbackHandler(auth.callbackHandler()).clientSubject(auth.clientSubject()).saslMechanism(auth.saslMechanism()).serverName(auth.serverName()).saslProperties(auth.saslProperties()).username(auth.username()).password(auth.password()).realm(auth.realm());
    }
    Properties propertiesToUse;
    Properties actualProperties = configuration.properties();
    if (!actualProperties.contains("blocking")) {
        // Need to make a copy to not change the actual configuration properties
        propertiesToUse = new Properties(actualProperties);
        // Make sure threads are marked as non blocking if user didn't specify
        propertiesToUse.put("blocking", "false");
    } else {
        propertiesToUse = actualProperties;
    }
    builder.withProperties(propertiesToUse);
    return builder;
}
Also used : RemoteServerConfiguration(org.infinispan.persistence.remote.configuration.RemoteServerConfiguration) AuthenticationConfiguration(org.infinispan.persistence.remote.configuration.AuthenticationConfiguration) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) SslConfiguration(org.infinispan.persistence.remote.configuration.SslConfiguration) Properties(java.util.Properties) ConnectionPoolConfiguration(org.infinispan.persistence.remote.configuration.ConnectionPoolConfiguration)

Example 2 with RemoteServerConfiguration

use of org.infinispan.persistence.remote.configuration.RemoteServerConfiguration in project infinispan by infinispan.

the class RollingUpgradeDynamicStoreIT method connectTargetCluster.

protected void connectTargetCluster() throws IOException {
    RestCacheClient client = target.getClient().cache(CACHE_NAME);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    addRemoteStore(builder);
    RemoteStoreConfiguration remoteStore = (RemoteStoreConfiguration) builder.build().persistence().stores().iterator().next();
    RestEntity restEntity = RestEntity.create(MediaType.APPLICATION_JSON, SerializationUtils.toJson(remoteStore));
    RestResponse response = join(client.connectSource(restEntity));
    assertEquals(response.getBody(), 204, response.getStatus());
    response = join(client.sourceConnection());
    RemoteStoreConfiguration remoteStoreConfiguration = SerializationUtils.fromJson(response.getBody());
    List<RemoteServerConfiguration> servers = remoteStoreConfiguration.servers();
    assertEquals(1, servers.size());
    RemoteServerConfiguration initialConfig = remoteStore.servers().iterator().next();
    assertEquals(initialConfig.host(), servers.get(0).host());
    assertEquals(initialConfig.port(), servers.get(0).port());
}
Also used : RemoteServerConfiguration(org.infinispan.persistence.remote.configuration.RemoteServerConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Aggregations

RemoteServerConfiguration (org.infinispan.persistence.remote.configuration.RemoteServerConfiguration)2 Properties (java.util.Properties)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestEntity (org.infinispan.client.rest.RestEntity)1 RestResponse (org.infinispan.client.rest.RestResponse)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 AuthenticationConfiguration (org.infinispan.persistence.remote.configuration.AuthenticationConfiguration)1 ConnectionPoolConfiguration (org.infinispan.persistence.remote.configuration.ConnectionPoolConfiguration)1 RemoteStoreConfiguration (org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)1 SslConfiguration (org.infinispan.persistence.remote.configuration.SslConfiguration)1