Support Questions

Find answers, ask questions, and share your expertise

unable to resolve class groovy.yaml.YamlSlurper in Nifi

avatar
Explorer

Using Nifi 1.23.2 I'm not able to resolve the YamlSlurper class in a ExecuteScript processor (Groovy 3.0.17) nor in the ExecuteGroovyScript processor (Groovy 3.0.18). With a minimal script body like

import groovy.yaml.YamlSlurper
return

I get the following after clicking Verify Properties:

Perform Validation
Component is invalid: 'GroovyScript' is invalid because org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script53405bee.groovy: 1: unable to resolve class groovy.yaml.YamlSlurper @ line 1, column 392. che.nifi.logging.ComponentLog;import gro ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class groovy.yaml.YamlSlurper @ line 1, column 392. at
 org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:262) at
 org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1424) at
 org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:262) at
 org.codehaus.groovy.control.CompilationUnit.lambda$new$16(CompilationUnit.java:739) at
 org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:902) at
 org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:628) at
 groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389) at
 groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332) at
 org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163) at
 org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154) at
 groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330) at
 groovy.lang.GroovyShell.parseClass(GroovyShell.java:526) at
 groovy.lang.GroovyShell.parse(GroovyShell.java:538) at
 groovy.lang.GroovyShell.parse(GroovyShell.java:570) at
 org.apache.nifi.processors.groovyx.ExecuteGroovyScript.getGroovyScript(ExecuteGroovyScript.java:338) at
 org.apache.nifi.processors.groovyx.ExecuteGroovyScript.customValidate(ExecuteGroovyScript.java:222) at
 org.apache.nifi.components.AbstractConfigurableComponent.validate(AbstractConfigurableComponent.java:130) at
 org.apache.nifi.controller.AbstractComponentNode.computeValidationErrors(AbstractComponentNode.java:780) at
 org.apache.nifi.controller.StandardProcessorNode.computeValidationErrors(StandardProcessorNode.java:1141) at
 org.apache.nifi.controller.AbstractComponentNode.performValidation(AbstractComponentNode.java:735) at
 org.apache.nifi.controller.AbstractComponentNode.verifyConfig(AbstractComponentNode.java:392) at
 org.apache.nifi.controller.StandardProcessorNode.verifyConfiguration(StandardProcessorNode.java:1071) at
 org.apache.nifi.web.dao.impl.StandardProcessorDAO.verifyProcessorConfiguration(StandardProcessorDAO.java:488) at
 org.apache.nifi.web.dao.impl.StandardProcessorDAO$$FastClassBySpringCGLIB$$779e089b.invoke(<generated>) at
 org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at
 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at
 org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) at
 org.apache.nifi.web.dao.impl.StandardProcessorDAO$$EnhancerBySpringCGLIB$$4feca1d.verifyProcessorConfiguration(<generated>) at
 org.apache.nifi.web.StandardNiFiServiceFacade.performProcessorConfigVerification(StandardNiFiServiceFacade.java:843) at
 org.apache.nifi.web.StandardNiFiServiceFacade$$FastClassBySpringCGLIB$$358780e0.invoke(<generated>) at
 org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at
 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at
 org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at
 org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) at
 org.apache.nifi.web.StandardNiFiServiceFacade$$EnhancerBySpringCGLIB$$245ce634.performProcessorConfigVerification(<generated>) at
 org.apache.nifi.web.api.ProcessorResource.lambda$performAsyncConfigVerification$27(ProcessorResource.java:1097) at
 org.apache.nifi.web.api.concurrent.AsyncRequestManager$2.run(AsyncRequestManager.java:117) at
 java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at
 java.base/java.util.concurrent.FutureTask.run(Unknown Source) at
 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
 java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
 java.base/java.lang.Thread.run(Unknown Source) 1 error

I also tried

def YamlSlurper = groovy.yaml.YamlSlurper
def y = new YamlSlurper()

Same result.

Bug? Or am I missing something? Is there a workaround?

1 ACCEPTED SOLUTION

avatar
Super Collaborator

It could be NiFi only includes the core Groovy jar files and you may need to download the additional ones and add to the NiFi lib directory for the additional classes to be accessible. 

View solution in original post

2 REPLIES 2

avatar
Super Collaborator

It could be NiFi only includes the core Groovy jar files and you may need to download the additional ones and add to the NiFi lib directory for the additional classes to be accessible. 

avatar
Explorer

Yes, turns out the groovy-yaml module is an optional module in Groovy 3, however groovy-yaml-3.0.17.jar is actually included in nifi-scripting-nar-1.23.2 but the ExecuteScript processor when started throws the exception I mentioned. Possibly this indicates there are other dependencies that would need to be explicitly included in the classpath (e.g. jackson-databind, jackson-dataformat-yaml, groovy-json)

I was hoping to use YamlSlurper followed by JsonBuilder to do YAML to JSON conversions. In the end I used the Jackson YamlFactory and ObjectMapper to achieve the desired result.