Search in sources :

Example 1 with HotRodEntityDescriptor

use of org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor in project keycloak by keycloak.

the class DefaultHotRodConnectionProviderFactory method lazyInit.

public void lazyInit() {
    if (config.getBoolean("embedded", false)) {
        HotRodUtils.createHotRodMapStoreServer(config.getInt("embeddedPort", 11444));
    }
    ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();
    remoteBuilder.addServer().host(config.get("host", "localhost")).port(config.getInt("port", 11444)).clientIntelligence(ClientIntelligence.HASH_DISTRIBUTION_AWARE).marshaller(new ProtoStreamMarshaller());
    if (config.getBoolean("enableSecurity", true)) {
        remoteBuilder.security().authentication().saslMechanism("SCRAM-SHA-512").username(config.get("username", "admin")).password(config.get("password", "admin")).realm(config.get("realm", "default"));
    }
    boolean configureRemoteCaches = config.getBoolean("configureRemoteCaches", false);
    if (configureRemoteCaches) {
        configureRemoteCaches(remoteBuilder);
    }
    remoteBuilder.addContextInitializer(ProtoSchemaInitializer.INSTANCE);
    remoteCacheManager = new RemoteCacheManager(remoteBuilder.build());
    Set<String> remoteCaches = HotRodMapStorageProviderFactory.ENTITY_DESCRIPTOR_MAP.values().stream().map(HotRodEntityDescriptor::getCacheName).collect(Collectors.toSet());
    if (configureRemoteCaches) {
        // access the caches to force their creation
        remoteCaches.forEach(remoteCacheManager::getCache);
    }
    registerSchemata(ProtoSchemaInitializer.INSTANCE);
    RemoteCacheManagerAdmin administration = remoteCacheManager.administration();
    if (config.getBoolean("reindexAllCaches", false)) {
        LOG.infof("Reindexing all caches. This can take a long time to complete. While the rebuild operation is in progress, queries might return fewer results.");
        remoteCaches.forEach(administration::reindexCache);
    } else {
        String reindexCaches = config.get("reindexCaches", "");
        if (reindexCaches != null) {
            Arrays.stream(reindexCaches.split(",")).map(String::trim).filter(e -> !e.isEmpty()).filter(remoteCaches::contains).peek(cacheName -> LOG.infof("Reindexing %s cache. This can take a long time to complete. While the rebuild operation is in progress, queries might return fewer results.", cacheName)).forEach(administration::reindexCache);
        }
    }
}
Also used : RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin) Arrays(java.util.Arrays) GeneratedSchema(org.infinispan.protostream.GeneratedSchema) Logger(org.jboss.logging.Logger) URISyntaxException(java.net.URISyntaxException) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) KeycloakSession(org.keycloak.models.KeycloakSession) Set(java.util.Set) RemoteCache(org.infinispan.client.hotrod.RemoteCache) Collectors(java.util.stream.Collectors) ProtoSchemaInitializer(org.keycloak.models.map.storage.hotRod.common.ProtoSchemaInitializer) HotRodMapStorageProviderFactory(org.keycloak.models.map.storage.hotRod.HotRodMapStorageProviderFactory) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ProtobufMetadataManagerConstants(org.infinispan.query.remote.client.ProtobufMetadataManagerConstants) ClientIntelligence(org.infinispan.client.hotrod.configuration.ClientIntelligence) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) URI(java.net.URI) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) HotRodEntityDescriptor(org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor) HotRodUtils(org.keycloak.models.map.storage.hotRod.common.HotRodUtils) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 RemoteCacheManagerAdmin (org.infinispan.client.hotrod.RemoteCacheManagerAdmin)1 ClientIntelligence (org.infinispan.client.hotrod.configuration.ClientIntelligence)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)1 GeneratedSchema (org.infinispan.protostream.GeneratedSchema)1 ProtobufMetadataManagerConstants (org.infinispan.query.remote.client.ProtobufMetadataManagerConstants)1 Logger (org.jboss.logging.Logger)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)1 HotRodMapStorageProviderFactory (org.keycloak.models.map.storage.hotRod.HotRodMapStorageProviderFactory)1 HotRodEntityDescriptor (org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor)1 HotRodUtils (org.keycloak.models.map.storage.hotRod.common.HotRodUtils)1 ProtoSchemaInitializer (org.keycloak.models.map.storage.hotRod.common.ProtoSchemaInitializer)1