Infinispan Cache store - "class not found" Exception in wildlfy addon module - wildfly

I am using the 11.0.7 Infinispan cache store which is configured with an XML file. I have imported that cache module in a Wildlfy server. I am using this dependency in my application. But when I try to fetch cache elements from cache, it gives me the exception ClassNotFound.
I have used this configuration:
<local-cache name="TaskStoreCache" statistics="false">
<locking acquire-timeout="60000" />
<persistence passivation="false">
<rocksdb-store path=" C:\CacheStore\Data\TaskStoreCache" preload="false" shared="false"
purge="false" read-only="false">
<expiration path="C: \CacheStore\Expired\TaskStoreCache"/>
</rocksdb-store>
</persistence>
<memory max-count="500"/>
<encoding media-type="application/x-java-object"/>
</local-cache>
And I used this serialization:
<serialization marshaller="org.infinispan.commons.marshall.JavaSerializationMarshaller">
<white-list>
<regex>com.xyz.cache.*</regex>
<regex>java.util.*</regex>
<regex>java.lang.*</regex>
</white-list>
</serialization>
I am sure it is a class loading related issue. Please help me with that.

You should double-check how the dependency is wrapped into your application (war/ear), and make sure the scope is correct.
If you did not pack it within your application, the module has to be present on your wildfly and known to your application (e.g. jboss-deployment-structure.xml)

Related

DB2 driver settings in Websphere Liberty

I have application running in Websphere Liberty and uses DB2 in Z/oS. I have set the db2 driver proerties in DB2JCCConfiguration.properties .How can make sure that the server has picked up properties I have set .I am not sure how to verify the trace to see if the properties are applied to server
To configure a datasource (for any backend DB) with Liberty, you can add configuration like this to your server.xml:
<featureManager>
<feature>jdbc-4.2</feature>
</featureManager>
<library id="driver-library">
<fileset dir="/path/to/driver/dir" includes="*.jar"/>
</library>
<dataSource id="DefaultDataSource" jndiName="jdbc/myDB">
<jdbcDriver libraryRef="driver-library"/>
<properties.db2.jcc serverName="example.db.hostname.com" portNumber="50000"
databaseName="myDB"
user="exampleUser"
password="examplePassword"
currentSchema="xyz"
fullyMaterializeInputStreams="true"/>
</dataSource>
To test if your configuration is correct and that your Liberty server can connect to your DB2 database, add the following configuration:
<featureManager>
<feature>appSecurity-3.0</feature>
<feature>restConnector-2.0</feature>
<feature>jdbc-4.2</feature>
</featureManager>
<!-- Any security mechanism can be used, <quickStartSecurity> is the simplest -->
<quickStartSecurity userName="admin" userPassword="admin"/>
And then go to: https://localhost:9443/ibm/api/validation/dataSource/DefaultDataSource
(this assumes your <dataSource> id is DefaultDataSource)
For more info, see this cheat sheet: https://aguibert.github.io/openliberty-cheat-sheet/#_ibm_db2

Infinispan cache table not auto-created with Wildfly 15+ using invalidation-cache and jdbc-store

I am attempting to use the jdbc-store type for my session cache in Wildfly 15+.
I ran the following commands to configure my standalone-full-ha.xml configuration file:
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/:add(mode=SYNC)
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/store=none:remove(){allow-resource-service-restart=true}
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/store=jdbc/:add(data-source="...",passivation=false,shared=true){allow-resource-service-restart=true}
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/component=transaction/:add()
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/component=transaction/:write-attribute(name=mode,value=BATCH)
/subsystem=infinispan/cache-container=web:write-attribute(name=default-cache,value=jdbc)
... which produces the following in the configuration file:
<cache-container name="web" default-cache="jdbc" module="org.wildfly.clustering.web.infinispan">
<transport lock-timeout="60000"/>
<invalidation-cache name="jdbc">
<transaction mode="BATCH"/>
<jdbc-store data-source="..." passivation="false" shared="true">
<table/>
</jdbc-store>
</invalidation-cache>
<distributed-cache name="dist">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
<file-store/>
</distributed-cache>
</cache-container>
It looks like I've configured the cache correctly using JBoss CLI, but when the cluster instances start-up, the session store table is not created in the database, even though everything starts up properly.
My question is, is there something that I should be setting in the <table/> element that I'm just overlooking? Looking at the documentation, I don't see any required attributes, or anything about auto-creation.
I've looked at previous examples of how to achieve this in Wildfly 11, but the string-keyed-jdbc-store element no longer seems to be valid. I know the Infinispan documentation mentions the create-on-start attribute on the string-keyed-table element, but this configuration is so wildly different in Wildfly that it's completely unhelpful.
Add
<property name="createTableOnStart">
true
</property>
in your jdbc-store element
and make sure your web.xml is <distributable />

Wildfly 12 infinispan cache lookup is not working

I'm migration from wildfly 10 to wildfly 12. I have created local cache same as configured in wildfly 10.
standalone-full.xml configuration:
<cache-container name="DataCache" default-cache="modelcache" statistics-enabled="false">
<local-cache name="modelcache" statistics-enabled="false"/>
</cache-container>
Lookup code in singleton ejb annotated with #startup:
#Resource(lookup = "java:jboss/infinispan/container/DataCache")
private CacheContainer Container;
#PostConstruct
public void init() {
Container.start();
modelCache = Container.getCache("modelcache");
}
I'm getting the below exception while deploying file
Caused by:
org.infinispan.commons.CacheConfigurationException: ISPN000436: Cache 'modelcache' has been requested, but no cache configuration exists
with that name and no default cache has been set for this container
How to fix this?
Put
<resource-ref>
<res-ref-name>infinispan/DataCache</res-ref-name>
<lookup-name>java:jboss/infinispan/cache/DataCache/modelcache</lookup-name>
</resource-ref>
in jboss-web.xml. When requesting the cache do it like this (note that the name annotation property is used to specify the resource):
#Resource(name = "infinispan/DataCache")
private Cache<K, V> cache;
See this thread for more details: https://developer.jboss.org/thread/277425
Put the following entry in your project descriptor file (web.xml, ejb-jar.xml, etc)
<resource-ref>
<res-ref-name>infinispan/DataCache</res-ref-name>
<lookup-name>java:jboss/infinispan/container/DataCache</lookup-name>
</resource-ref>
For wildfly 10 you can lookup your infinispan cache or cache container in the following way
You need to define your cache in standalone-ha.xml(High availability) under the following subsystem
<cache-container name="myCacheContainer" default-cache="myCache" module="org.wildfly.clustering.ejb.infinispan">
<transport lock-timeout="60000"/>
<replicated-cache name="myCache">
<expiration lifespan="86400000" max-idle="3600000"/>
</replicated-cache>
</cache-container>
Once you have defined the cache you can lookup either the cache or the container.
2.a To lookup the cache you should setup a resource ref element in your project
descriptor file i.e (web.xml,jboss-web.xml etc.)
infinispan/myCache
java:jboss/infinispan/cache/myCacheContainer/myCache
2.b If you want to lookup cache container instead you also need to define configuration lookup in your project descriptor. So resource ref looks like this
<resource-ref>
infinispan/myCacheContainer
org.infinispan.manager.CacheContainer
java:jboss/infinispan/container/myCacheContainer
infinispan/myCache-config
org.infinispan.configuration.cache.Configuration
java:jboss/infinispan/configuration/myCacheContainer/default
Now if using spring you can do a JNDI lookup for cache like this
<jee:jndi-lookup id="myCache"
jndi-name="infinispan/myCache" />
3.a Or you can lookup the container like this
<jee:jndi-lookup id="myCacheContainer"
jndi-name="infinispan/myCacheContainer" />
Now you can inject the cache like the following
#Resource(name="myCache")
private Cache cache;
4.a You can inject the container like the following
#Resource(name="myCacheContainer")
private CacheContainer cacheContainer;

Wildfly 10 Infinispan TreeCache is not working

I'm migrating from Wildfly 8.2 to 10.1 Unfortunately, I'm encountering problems with Infinispan TreeCache.
Here are several issues:
Invocation batching is no longer supported in Wildfly 10
configuration
Here's my config:
<subsystem xmlns="urn:jboss:domain:infinispan:4.0">
...
<cache-container name="my_container" default-cache="my_tree_cache" jndi-name="java:jboss/my_container">
<transport lock-timeout="60000"/>
<local-cache name="my_cache"/>
<local-cache name="my_tree_cache" batching="true"/>
</cache-container>
</subsystem>
Error on startup:
> Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[345,17]
> Message: WFLYCTL0197: Unexpected attribute 'batching' encountered
If I remove "batching" attribute. I get this error:
com.daiwacm.modjsf.dataaccess.DataException: getTreeCache has failed for jndi value (my_tree_cache)
Caused by: org.infinispan.commons.CacheConfigurationException: invocationBatching is not
enabled for cache 'my_tree_cache'. Make sure this is enabled by calling configurationBuilder.invocationBatching().enable()
If I set batching programmatically:
Context context = new InitialContext();
CacheContainer cacheContainer = (CacheContainer) context.lookup(jndiName);
TreeCacheFactory tcf = new TreeCacheFactory();
Cache cache = cacheContainer.getCache(cacheName);
cache.getCacheManager().defineConfiguration(cacheName,
new ConfigurationBuilder().read(cache.getCacheConfiguration()).invocationBatching().enable().build());
TreeCache treeCache = tcf.createTreeCache(cache);
I get this error:
> Caused by: org.infinispan.commons.CacheConfigurationException:
> ISPN000381: This configuration is not supported for simple cache
> at org.infinispan.configuration.cache.ConfigurationBuilder.validateSimpleCacheConfiguration(ConfigurationBuilder.java:219)
> ...
> at org.infinispan.configuration.cache.InvocationBatchingConfigurationBuilder.build(InvocationBatchingConfigurationBuilder.java:12)
> ...
Don't set the configuration programmatically; I am not sure this is a valid approach, despite it seems to ~work.
The configuration option you're looking for is
<local-cache name="my_cache">
<transaction transaction-mode="BATCH" />
</local-cache>
(please consult the schema in docs/schema/jboss-as-infinispan_4_0.xsd should you have any doubts)
The last problem is that for local caches, WF automatically enables certain optimizations when it's possible. When you redefine the cache programmatically, this optimization (simple cache) is set on. So you'd have to set
new ConfigurationBuilder().read(cache.getCacheConfiguration())
.simpleCache(false)
.invocationBatching().enable()

Hibernate search with infinispan, How to store the index in a persistent cache store

Hibernate search default infinispan configuration store indexes in memory,you have to reindex everything once you shutdown application.
I read infinispan document, there is a way to store index into a infinispan file store. After I do googling around and around, I still don't know how to configure it.
You can check Infinispan user guide chapters 5 (Persistence) and 16 (Infinispan as a storage for Lucene indexes). Chapter numbers are from Infinispan 8.2. Hibernate search also provides a "default-hibernatesearch-infinispan.xml" file to start with. You basically need to add persistence to metadata and actual index caches. Here is the one I use for index cache:
<distributed-cache name="LuceneIndexesData" mode="SYNC" remote-timeout="25000">
<transaction mode="NONE"/>
<state-transfer enabled="true" timeout="480000" await-initial-transfer="true"/>
<indexing index="NONE"/>
<locking striping="false" acquire-timeout="10000" concurrency-level="500" write-skew="false"/>
<eviction max-entries="-1" strategy="NONE"/>
<expiration max-idle="-1"/>
<persistence passivation="false">
<jdbc:string-keyed-jdbc-store preload="true" fetch-state="true" read-only="false" purge="false">
<jdbc:data-source jndi-url="java:comp/env/jdbc/..."/>
<jdbc:string-keyed-table drop-on-exit="false" create-on-start="true" prefix="ISPN_STRING_TABLE">
<jdbc:id-column name="ID" type="VARCHAR(255)"/>
<jdbc:data-column name="DATA" type="MEDIUMBLOB"/>
<jdbc:timestamp-column name="TIMESTAMP" type="BIGINT"/>
</jdbc:string-keyed-table>
<property name="key2StringMapper">org.infinispan.lucene.LuceneKey2StringMapper</property>
<write-behind/>
</jdbc:string-keyed-jdbc-store>
</persistence>
</distributed-cache>
This example uses JDBC because it works on a dynamic cluster. You need to replace "jdbc:string-keyed=jdbc-store" with a "file-store" if you want to store the index a file.