Search in sources :

Example 11 with StringConfiguration

use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.

the class RemoteCacheManager method createRemoteCache.

private <K, V> RemoteCache<K, V> createRemoteCache(String cacheName, boolean forceReturnValueOverride, TransactionMode transactionModeOverride, TransactionManager transactionManagerOverride) {
    RemoteCacheConfiguration cacheConfiguration = findConfiguration(cacheName);
    boolean forceReturnValue = forceReturnValueOverride || (cacheConfiguration != null ? cacheConfiguration.forceReturnValues() : configuration.forceReturnValues());
    RemoteCacheKey key = new RemoteCacheKey(cacheName, forceReturnValue);
    if (cacheName2RemoteCache.containsKey(key)) {
        return cacheName2RemoteCache.get(key).remoteCache();
    }
    OperationsFactory operationsFactory = createOperationFactory(cacheName, forceReturnValue, codec, null);
    PingResponse pingResponse;
    if (started) {
        // Verify if the cache exists on the server first
        pingResponse = await(operationsFactory.newFaultTolerantPingOperation().execute());
        // If ping not successful assume that the cache does not exist
        if (pingResponse.isCacheNotFound()) {
            // We may be able to create it. Don't use RemoteCacheAdmin for this, since it would end up calling this method again
            Map<String, byte[]> params = new HashMap<>(2);
            params.put(RemoteCacheManagerAdminImpl.CACHE_NAME, cacheName.getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
            if (cacheConfiguration != null && cacheConfiguration.templateName() != null) {
                params.put(RemoteCacheManagerAdminImpl.CACHE_TEMPLATE, cacheConfiguration.templateName().getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
            } else if (cacheConfiguration != null && cacheConfiguration.configuration() != null) {
                params.put(RemoteCacheManagerAdminImpl.CACHE_CONFIGURATION, new StringConfiguration(cacheConfiguration.configuration()).toStringConfiguration(cacheName).getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
            } else {
                // We cannot create the cache
                return null;
            }
            // Create and re-ping
            OperationsFactory adminOperationsFactory = new OperationsFactory(channelFactory, codec, listenerNotifier, configuration);
            pingResponse = await(adminOperationsFactory.newAdminOperation("@@cache@getorcreate", params).execute().thenCompose(s -> operationsFactory.newFaultTolerantPingOperation().execute()));
        }
    } else {
        pingResponse = PingResponse.EMPTY;
    }
    TransactionMode transactionMode = getTransactionMode(transactionModeOverride, cacheConfiguration);
    InternalRemoteCache<K, V> remoteCache;
    if (transactionMode == TransactionMode.NONE) {
        remoteCache = createRemoteCache(cacheName);
    } else {
        if (!await(checkTransactionSupport(cacheName, operationsFactory).toCompletableFuture())) {
            throw HOTROD.cacheDoesNotSupportTransactions(cacheName);
        } else {
            TransactionManager transactionManager = getTransactionManager(transactionManagerOverride, cacheConfiguration);
            remoteCache = createRemoteTransactionalCache(cacheName, forceReturnValueOverride, transactionMode == TransactionMode.FULL_XA, transactionMode, transactionManager);
        }
    }
    synchronized (cacheName2RemoteCache) {
        startRemoteCache(remoteCache, operationsFactory.getCodec(), forceReturnValue);
        RemoteCacheHolder holder = new RemoteCacheHolder(remoteCache, forceReturnValueOverride);
        remoteCache.resolveStorage(pingResponse.isObjectStorage());
        cacheName2RemoteCache.putIfAbsent(key, holder);
        return remoteCache;
    }
}
Also used : StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) HashMap(java.util.HashMap) PingResponse(org.infinispan.client.hotrod.impl.operations.PingResponse) OperationsFactory(org.infinispan.client.hotrod.impl.operations.OperationsFactory) RemoteCacheConfiguration(org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration) TransactionMode(org.infinispan.client.hotrod.configuration.TransactionMode) TransactionManager(javax.transaction.TransactionManager)

Example 12 with StringConfiguration

use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.

the class RemoteCacheAdminTest method cacheCreateMissingTemplate.

public void cacheCreateMissingTemplate(Method m) throws InterruptedException {
    RemoteCacheManagerAdmin admin = client(0).administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE);
    // Creation with a non-existent template fails
    expectException(HotRodClientException.class, () -> admin.createCache("some_name", "some_template_name"));
    // Cache can still be created later with a string configuration
    admin.createCache("some_name", new StringConfiguration("<infinispan><cache-container>" + "<local-cache name=\"some_name\"/>" + "</cache-container></infinispan>"));
    RemoteCache<Object, Object> someCache = client(0).getCache("some_name");
    someCache.put("key", "value");
}
Also used : StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin)

Example 13 with StringConfiguration

use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.

the class RemoteQueryRepeatedMappingTest method createCacheXMLConfig.

private StringConfiguration createCacheXMLConfig() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.encoding().mediaType(APPLICATION_PROTOSTREAM_TYPE);
    builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("Parent");
    String config = builder.build().toStringConfiguration(CACHE_NAME);
    return new StringConfiguration(config);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) StringConfiguration(org.infinispan.commons.configuration.StringConfiguration)

Example 14 with StringConfiguration

use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.

the class AnchoredKeysIT method testCreateAnchoredKeysCache.

@Test
public void testCreateAnchoredKeysCache() {
    BasicConfiguration config = new StringConfiguration("<infinispan><cache-container><replicated-cache name=\"anchored2\">\n" + "<locking concurrency-level=\"100\" acquire-timeout=\"1000\"/>\n" + "<anchored-keys xmlns=\"urn:infinispan:config:anchored-keys:" + Version.getMajorMinor() + "\" enabled=\"true\"/>\n" + "</replicated-cache></cache-container></infinispan>");
    RemoteCacheManager rcm = SERVER_TEST.hotrod().createRemoteCacheManager();
    rcm.administration().createCache("anchored2", config);
    test(rcm.getCache("anchored2"));
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) BasicConfiguration(org.infinispan.commons.configuration.BasicConfiguration) Test(org.junit.Test)

Example 15 with StringConfiguration

use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.

the class HotRodAdmin method testCreateDeleteCacheFragment.

@Test
public void testCreateDeleteCacheFragment() {
    RemoteCacheManager rcm = SERVER_TEST.hotrod().createRemoteCacheManager();
    String cacheName = "testCreateDeleteCacheFragment";
    String config = String.format("<distributed-cache name=\"%s\"/>", cacheName);
    RemoteCache<String, String> cache = rcm.administration().createCache(cacheName, new StringConfiguration(config));
    cache.put("k", "v");
    assertNotNull(cache.get("k"));
    rcm.administration().removeCache(cacheName);
    assertNull(rcm.getCache(cacheName));
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) Test(org.junit.Test)

Aggregations

StringConfiguration (org.infinispan.commons.configuration.StringConfiguration)18 Test (org.junit.Test)8 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)6 BasicConfiguration (org.infinispan.commons.configuration.BasicConfiguration)3 TransactionManager (javax.transaction.TransactionManager)2 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)2 RestClient (org.infinispan.client.rest.RestClient)2 Test (org.testng.annotations.Test)2 CacheMeterBinder (io.micrometer.core.instrument.binder.cache.CacheMeterBinder)1 HashMap (java.util.HashMap)1 RemoteCacheManagerAdmin (org.infinispan.client.hotrod.RemoteCacheManagerAdmin)1 RemoteCacheConfiguration (org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration)1 TransactionMode (org.infinispan.client.hotrod.configuration.TransactionMode)1 OperationsFactory (org.infinispan.client.hotrod.impl.operations.OperationsFactory)1 PingResponse (org.infinispan.client.hotrod.impl.operations.PingResponse)1 SingleHotRodServerTest (org.infinispan.client.hotrod.test.SingleHotRodServerTest)1 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)1 RestResponse (org.infinispan.client.rest.RestResponse)1 Json (org.infinispan.commons.dataconversion.internal.Json)1