Try building a fat jar that has your Ignite dependencies in it and
referencing it in the module configuration of ExecuteScript. You might
be seeing a collision between the Grapes classloader and the one NiFi
is using here.

On Fri, Jul 24, 2020 at 12:17 PM Carlos Manuel Fernandes (DSI)
<carlos.antonio.fernan...@cgd.pt> wrote:
>
> Hello,
>
>
>
> I am trying to connect Nifi with Apache Ignite  to put  some data  on Ignite 
> cache using ExecuteScript because  putIgniteCache  and GetIgniteCache 
> processors are bounded to an older Ignite version.
>
>
>
> I made Test1 (below) using standalone groovy without Nifi and work Well.   
> Test2(below) using Nifi groovy ExecuteScript  in Ignition.start  always  run 
> on error:  java.lang.ClassNotFoundException: 
> org.apache.ignite.configuration.IgniteConfiguration. I am certain the two 
> Grabs work well  because  I haven’t errors on Import statements and  the jars 
> are in the grapes Folder.
>
>
>
> Any idea?
>
>
>
> Thanks
>
> Carlos
>
>
>
> Test1 – StandAlone groovy program (work well)
>
>
>
>
>
> @Grab ('org.apache.ignite:ignite-core:2.8.1')
>
> @Grab ('org.apache.ignite:ignite-spring:2.8.1')
>
>
>
> import org.apache.ignite.Ignite;
>
> import org.apache.ignite.IgniteCache;
>
> import org.apache.ignite.Ignition
>
>
>
> Ignition.setClientMode(true);
>
>
>
> // Here, we provide the cache configuration file
>
> Ignite objIgnite = Ignition.start("c:\\tmp\\ignite\\first-config.xml");
>
>
>
> // create cache if not already existing
>
> IgniteCache<Integer, String> objIgniteCache = 
> objIgnite.getOrCreateCache("myFirstIgniteCache");
>
>
>
> // Populating the cache with few values
>
> objIgniteCache.put(1, "salman");
>
> objIgniteCache.put(2, "Abhishek");
>
> objIgniteCache.put(3, "Siddharth");
>
> objIgniteCache.put(4, "Dev");
>
>
>
> // Get these items from cache
>
> System.out.println(objIgniteCache.get(1));
>
> System.out.println(objIgniteCache.get(2));
>
> System.out.println(objIgniteCache.get(3));
>
> System.out.println(objIgniteCache.get(4));
>
> Ignition.stop(true);
>
>
>
>
>
>
>
> Test2 – ExecuteScript groovy code (don’t work)
>
>
>
> @Grab ('org.apache.ignite:ignite-core:2.8.1')
>
> @Grab ('org.apache.ignite:ignite-spring:2.8.1')
>
>
>
> import org.apache.ignite.Ignite;
>
> import org.apache.ignite.IgniteCache;
>
> import org.apache.ignite.Ignition
>
>
>
> def flowFile = session.get()
>
> if (!flowFile) return
>
>
>
> try {
>
>        Ignition.setClientMode(true);
>
>
>
>        // Here, we provide the cache configuration file
>
>        log.info("Before Ignite")
>
>        Ignite objIgnite = 
> Ignition.start("/apps/nifi-scripts/first-config.xml");
>
>        log.info("After Ignite")
>
>
>
>        // create cache if not already existing
>
>        IgniteCache<Integer, String> objIgniteCache = 
> objIgnite.getOrCreateCache("myFirstIgniteCache");
>
>
>
>        // Populating the cache with few values
>
>        log.info("Put on cache")
>
>        objIgniteCache.put(1, "salman");
>
>        objIgniteCache.put(2, "Abhishek");
>
>        objIgniteCache.put(3, "Siddharth");
>
>        objIgniteCache.put(4, "carlos");
>
>
>
>        // Get these items from cache
>
>        log.info("get from cache")
>
>        System.out.println(objIgniteCache.get(1));
>
>        System.out.println(objIgniteCache.get(2));
>
>        System.out.println(objIgniteCache.get(3));
>
>        System.out.println(objIgniteCache.get(4));
>
>
>
>        log.info("cachequery for 4 is :${objIgniteCache.get(4)}")
>
>        Ignition.stop(true);
>
>        session.transfer(flowFile, REL_SUCCESS)
>
> }
>
> catch(Exception e) {
>
>        log.error('Error:', e)
>
>        session.transfer(flowFile, REL_FAILURE)
>
> }
>
> finally {
>
>
>
>        log.info("end")
>
> }
>
>
>
>
>
> Caused by: java.lang.ClassNotFoundException: 
> org.apache.ignite.configuration.IgniteConfiguration
>
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>
>         at org.springframework.util.ClassUtils.forName(ClassUtils.java:251)
>
>         at 
> org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
>
>         at 
> org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1444)
>
>         at 
> org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1389)
>
>         ... 37 common frames omitted

Reply via email to