Search code examples
groovyyamlapache-nifi

unable to resolve class groovy.yaml.YamlSlurper in Nifi


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?


Solution

  • The groovy-yaml module is an optional module in Groovy 3. If I look in the lib\nifi-groovyx-nar-1.23.2.nar file of the Nifi installation, indeed I can see the the relevant jar is missing (I presume they only bundle the groovy-all jars).

    You can annotate your import with @Grab('org.codehaus.groovy:groovy-yaml:3.0.18'), or if you have the relevant jars locally, you can point the 'Additional classpath' property of your processor to the jars (groovy-yaml and dependencies).

    The groovy-yaml module is included in Groovy 4+, so maybe this extra requirement won't be needed in some future version of Nifi.