H2OGridSearch H2OGBM pyspark: NullPointerException in extractH2OParameters - machine-learning

I'm trying to run a grid search for Gradient Boosting Machine in pyspark with H2O Sparkling Water.
Produced a reproducible example with the famous iris dataset.
from pysparkling import H2OContext, H2OConf
import pyspark
from pyspark.sql.types import StructType, StructField, FloatType, StringType
from pyspark.conf import SparkConf
from pyspark.sql import SQLContext
conf = SparkConf()
conf.setMaster("local").setAppName("test")
conf.set("spark.sql.shuffle.partitions", 3)
conf.set("spark.default.parallelism", 3)
conf.set("spark.debug.maxToStringFields", 100)
sc = pyspark.SparkContext(conf=conf)
sqlContext = SQLContext(sc)
hc = H2OContext.getOrCreate(sc, H2OConf(sc).set_internal_cluster_mode())
schema = StructType([
StructField("sepal_length", FloatType(), True),
StructField("sepal_width", FloatType(), True),
StructField("petal_length", FloatType(), True),
StructField("petal_width", FloatType(), True),
StructField("class", StringType(), True)])
iris_df = sqlContext.read \
.format('com.databricks.spark.csv') \
.option('header', 'false') \
.option('delimiter', ',') \
.schema(schema) \
.load('../../../../Downloads/iris.data')
If I try to follow this page of H2O docs and just translate to python
gbm_params = {'learnRate': [0.01, 0.1],
'ntrees': [100 , 200, 300, 500]}
gbm_grid = H2OGridSearch()\
.setLabelCol("class") \
.setHyperParameters(gbm_params)\
.setAlgo(H2OGBM().setMaxDepth(30))
model_pipeline = Pipeline().setStages([gbm_grid])
model = model_pipeline.fit(iris_df)
I get an internal NullPointerException, I guess there's something missing in the configuration.
Py4JJavaError: An error occurred while calling o111.fit.
: java.lang.NullPointerException
at ai.h2o.sparkling.ml.algos.H2OGridSearch.extractH2OParameters(H2OGridSearch.scala:352)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.fit(H2OGridSearch.scala:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Unknown Source)
If I try to rewrite it in a different way, I get a different error,
gbm_grid = H2OGridSearch(algo=H2OGBM().setMaxDepth(30),
hyperParameters={'learnRate': [0.01, 0.1]},
withDetailedPredictionCol=True,
labelCol='class',
stoppingMetric="AUC")
model_pipeline = Pipeline().setStages([gbm_grid])
model = model_pipeline.fit(iris_df)
This is the output, no matter how do I change the hyperparameters,
Py4JJavaError: An error occurred while calling o1817.fit.
: java.lang.NoSuchFieldException: learnRate
at java.lang.Class.getField(Unknown Source)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.findField(H2OGridSearch.scala:170)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.processHyperParams(H2OGridSearch.scala:154)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.fit(H2OGridSearch.scala:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Unknown Source)
The following works, however it is not useful since there is no grid,
gbm_grid = H2OGridSearch(algo=H2OGBM().setMaxDepth(30),
#hyperParameters=gbm_params,
withDetailedPredictionCol=True,
labelCol='class',
stoppingMetric="AUC")
model_pipeline = Pipeline().setStages([gbm_grid])
model = model_pipeline.fit(iris_df)
model.stages[0].transform(iris_df).head()
And finally, just to be sure that learnRate is a parameter of H2OGBM, this also works,
gbm_model = H2OGBM(labelCol='class',
withDetailedPredictionCol=True).setLearnRate(0.01).setMaxDepth(5).setNtrees(100)
model_pipeline = Pipeline().setStages([gbm_model])
model = model_pipeline.fit(iris_df)
model.stages[0].transform(iris_df).head()
EDIT: missing imports
from pyspark.ml.pipeline import Pipeline
from ai.h2o.sparkling.ml.algos import H2OGridSearch
from ai.h2o.sparkling.ml.algos import H2OGBM
and sparking water version
h2o-pysparkling-2-4 3.28.0.1-1 pypi_0 pypi
EDIT after comments for Spark/H2O/Java versions
Spark: 2.4.4
H2O: 3.28.0.3
Java: 1.8.0_232
EDIT java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~16.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Get the same error if I use learn_rate instead of learnRate.
gbm_grid = H2OGridSearch(algo=H2OGBM().setMaxDepth(30),
hyperParameters={'learn_rate': [0.01, 0.1]},
withDetailedPredictionCol=True,
labelCol='class',
stoppingMetric="AUC")
model_pipeline = Pipeline().setStages([gbm_grid])
model = model_pipeline.fit(iris_df)
...
Py4JJavaError: An error occurred while calling o1376.fit.
: java.lang.NoSuchFieldException: learn_rate
at java.lang.Class.getField(Class.java:1703)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.findField(H2OGridSearch.scala:170)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.processHyperParams(H2OGridSearch.scala:154)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.fit(H2OGridSearch.scala:71)
at ai.h2o.sparkling.ml.algos.H2OGridSearch.fit(H2OGridSearch.scala:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)

Why not use a workaround and utilize H2O UI to create the grid? There's a checkbox to make your chosen parameter griddable, and you can supply the parameter values as a comma-separated list via the web form where you would normally put a single value.

There's a workaround here I did not notice (probably I should have posted it as a bug in github in the first place).
gbm_grid = H2OGridSearch(algo=H2OGBM().setMaxDepth(30),
hyperParameters={'_learn_rate':[0.01, 0.1], '_ntrees': [100, 200]},
withDetailedPredictionCol=True,
labelCol='class',
stoppingMetric="AUC")
model_pipeline = Pipeline().setStages([gbm_grid])
model = model_pipeline.fit(iris_df)
model.stages[0].transform(iris_df).head()

Related

Jenkins Artifactory plugin - upload from shared library

I've using Jenkins Artifactory plugin from a scripted pipeline to upload artifacts to the Artifactory. The pipeline code was this:
def uploadSpec = ...
def artifactory = Artifactory.server 'myTag'
def buildInfo = server.upload(JsonOutput.toJson(uploadSpec))
server.publishBuildInfo buildInfo
This has been working well, however this, among a lot of other code, has been duplicated in multiple projects. I am now extracting all common code and putting it into a Jenkins Shared Library. I got everything else to work, however I'm struggling to get the artifactory bit working. I've tried all sorts of things with different errors. My last attempt was this:
def server = getArtifactoryServer serverTag
server.upload(JsonOutput.toJson(myUploadSpec))
This results in a NullPointerException, which I traced (in the plugin source code) to cpsScript variable, which is not set. I tried using the upload step as defined here:
def buildInfo = artifactoryUpload(
spec: myUploadSpec,
buildInfo: new BuildInfo(),
module: null,
failNoOp: false,
server: server
)
Yet, this results in a different error:
WARNING: Unknown parameter(s) found for class type 'org.jfrog.hudson.pipeline.scripted.steps.UploadStep': module
org.kohsuke.stapler.NoStaplerConstructorException: There's no #DataBoundConstructor on any constructor of class java.lang.String
at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:265)
at org.jenkinsci.plugins.structs.describable.DescribableModel.<init>(DescribableModel.java:153)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:269)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
Caused: java.lang.IllegalArgumentException: Could not instantiate {spec={files=[{pattern=Vertx365/Production/build/vertx365-production-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertx365/vertx365-production/3.37.0/}, {pattern=Vertx365/QA/build/vertx365-qa-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertx365/vertx365-qa/3.37.0/}, {pattern=VertxBCSS/Production/build/vertxbcss-production-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxbcss/vertxbcss-production/3.37.0/}, {pattern=VertxBCSS/QA/build/vertxbcss-qa-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxbcss/vertxbcss-qa/3.37.0/}, {pattern=VertxBIM/Production/build/vertxbim-production-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxbim/vertxbim-production/3.37.0/}, {pattern=VertxBIM/QA/build/vertxbim-qa-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxbim/vertxbim-qa/3.37.0/}, {pattern=VertxCatering/QA/build/vertxcatering-qa-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxcatering/vertxcatering-qa/3.37.0/}, {pattern=VertxLockhart/Production/build/vertxlockhart-production-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxlockhart/vertxlockhart-production/3.37.0/}, {pattern=VertxLockhart/QA/build/vertxlockhart-qa-3.37.0.zip, target=vertx-release/com/bunzl/vertx/release/vertxlockhart/vertxlockhart-qa/3.37.0/}]}, buildInfo=org.jfrog.hudson.pipeline.common.types.buildInfo.BuildInfo#caaf82, failNoOp=false, module=null, server=org.jfrog.hudson.pipeline.common.types.ArtifactoryServer#1e1cacd} for org.jfrog.hudson.pipeline.scripted.steps.UploadStep
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:269)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at com.bunzl.pipeline.artifactory.Artifactory.uploadFiles(Artifactory.groovy:10)
at com.bunzl.pipeline.artifactory.Artifactory.uploadFiles(Artifactory.groovy)
at WorkflowScript.run(WorkflowScript:117)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor134.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.util.concurrent.FutureTask.run(Unknown Source)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Of course, I can retrieve the ArtifactoryServer object in the main pipeline and then pass it into the shared library call, but that's a wrong design.
So, how can I achieve what I need (i.e.upload artifacts to a server with specified tag) inside a shared library?
Any idea on how I can get this working?
EDIT: Per request in a comment, I have this structure (for the class calling artifactory):
+
|
+- src
|
+- com
|
+- mycompany
|
+- mypackage
|
+- Artifactory.groovy
Here's the code in this class (with private/proprietary bits replace):
package com.mycompany.mypackage
import groovy.json.JsonOutput
def uploadFiles(String serverTag, List files, boolean buildInfoPublish = true) {
def server = getArtifactoryServer serverTag
def buildInfo = server.upload(JsonOutput.toJson([files: files]))
if (buildInfoPublish) {
publishBuildInfo buildInfo: buildInfo, server: server
}
}
The library is defined in Jenkins as a global library named config-library and is being used/called like this:
def configLibrary = library('config-library#my-version')
def artifactory = configLibrary.com.mycompany.mypackage.Artifactory.new()
def files = ...
artifactory.uploadFiles('myTag', files)
I finally figured it out after debugging a local installation of the plugin. Apparently, artifactoryUpload expects the spec parameter to be a JSON string, not an object. So, the solution is quite simple:
def server = getArtifactoryServer serverTag
def buildInfo = artifactoryUpload(
spec: JsonOutput.toJson(myUploadSpec),
buildInfo: new BuildInfo(),
module: null,
failNoOp: false,
server: server
)

Groovy scoping in Jenkins Shared Library

I'm currently refactoring our Jenkins pipeline from a pipeline project to a multibranch pipeline project and trying to make some functionality more modular and trying to migrate more code to a shared pipeline project. However, this results in compile errors that feels related to groovy scoping, where it tries to use the same scope as the function when calling to a third party library instead of using the global scope.
The original function resided in my scripted pipeline jenkinsfile and looks like this:
def bootstrapPythonEnvironment( String client, String credentials, String label = "#head" ) {
String bootstrapWorkspace = "${client}_BootstrapWorkspace"
def p4 = p4(credential: credentials,
workspace: manualSpec(
charset: 'winansi',
name: bootstrapWorkspace,
spec: clientSpec(
view: "//MyGameContent/BuildScripts/Python/... //${bootstrapWorkspace}/BootstrapScripts/..." )
))
p4.run('sync', "//MyGameContent/...", label)
}
However, when moving it from the Jenkinsfile to: vars/BuildTools.groovy
and I call it through:
BuildTools.bootstrapJenkinsEnvironment( env.MyClient, 'CSSBuildmachine', '#head' )
then I get the following error:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static BuildTools.bootstrapPythonEnvironment() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [jenkins-Stekdatorn-TestWorkspace-null-0, CSSBuildmachine, ...]
Possible solutions: bootstrapPythonEnvironment(java.lang.String, java.lang.String, java.lang.String), bootstrapPythonEnvironment(java.lang.String, java.lang.String)
So I changed the function declaration to incluide static:
static def bootstrapPythonEnvironment( String client, String credentials, String label = "#head" )
This helps a bit, but now the error I get is:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static BuildTools.clientSpec() is applicable for argument types: (java.util.LinkedHashMap) values: [[view://MyGameContent/BuildScripts/Python/... //jenkins-Stekdatorn-TestWorkspace-null-0_BootstrapWorkspace/BootstrapScripts/...]]
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1501)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1487)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at BuildTools.bootstrapPythonEnvironment(BuildTools.groovy:11)
at WorkflowScript.run(WorkflowScript:18)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:84)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor324.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor320.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:107)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor324.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:87)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at sun.reflect.GeneratedMethodAccessor324.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:186)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66)
at java.util.concurrent.FutureTask.run(Unknown Source)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I have tried moving this file to src/com/coffeestain/build/Python.groovy and putting it in there but in the function:
class Python {
static def bootstrap( String client, String credentials, String label = "#head" ) {
// Snipped out code
}
}
but it just gives me a similar message when I'm trying to import it with:
#Library('MyGameBuildtools') import com.coffeestain.build.*
and call it with:
Python.bootstrap( env.P4CLIENT, 'CSSBuildmachine', "#head" )
However, this gives me the same error in another form:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static com.coffeestain.build.Python.clientSpec() is applicable for argument types: (java.util.LinkedHashMap) values: [[view://MyGameContent/BuildScripts/Python/... //jenkins-Stekdatorn-TestWorkspace-null-0_BootstrapWorkspace/BootstrapScripts/...]]
My current workaround is to add it to the file vars/bootstrapPythonEnvironment.groovy with the definition:
def call( String client, String credentials, String label = "#head" ) {
// Snipped out code
}
But this feels unfeasible in the long run to have a file for each function I add.
Thanks Dominik Gebhart for helping me solve this!
clientSpec and P4 comes from the P4 Plugin.
I solved it by changing the function to this, note how context is used:
static def bootstrapPythonEnvironment( context, String client, String credentials, String label = "#head" ) {
String bootstrapWorkspace = "${client}_BootstrapWorkspace"
def p4 = context.p4(credential: credentials,
workspace: context.manualSpec(
charset: 'winansi',
name: bootstrapWorkspace,
spec: context.clientSpec(
view: "//MyGameContent/BuildScripts/Python/... //${bootstrapWorkspace}/BootstrapScripts/..." )
))
p4.run('sync', "//MyGameContent/...", label)
}
and I call it through:
MyGameUtils.bootstrapPythonEnvironment( this, env.P4CLIENT, 'CSSBuildmachine' )

Jenkins Groovy StackOverFlowError when accessing a property

I'm trying to write a small job DSL, but I'm struggling with getting java.lang.StackOverflowError errors when accessing a class property.
Therefore not even a complex script is necessary. See the following script
class Komponente {
String name
Komponente(name) {
this.name = name
}
String getName() {
return this.name
}
String toString() {
return 'Klasse: Komponente (name: [' + this.name +'])'
}
}
Komponente komponente = new Komponente('Testkomponente')
println 'Erstellte Komponente: ' + komponente.getName()
​
When running it on the Groovy web console it works fine, but when running it in my Jenkins I get:
FATAL: null
java.lang.StackOverflowError
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:1038)
at java.lang.ClassLoader.loadClass(ClassLoader.java:406)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
at groovy.lang.GroovyClassLoader$InnerLoader.loadClass(GroovyClassLoader.java:425)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
at sun.reflect.GeneratedMethodAccessor316.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
at Komponente.getProperty(script)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
at Komponente.getName(script:10)
at sun.reflect.GeneratedMethodAccessor316.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
at Komponente.getProperty(script)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
at Komponente.getName(script:10)
...
(As you can see this repeates)
How can I access a class property in a Groovy script running on Jenkins, without getting StackOverflowError exception?
My system:
Jenkins-version is 2.73.3
JobDSL Plugin 1.68
Stapler Groovy module org.kohsuke.stapler:stapler-groovy:1.250
Apache Groovy org.codehaus.groovy:groovy-all:2.4.11
I already did some searching for this error message, but all Jenkins-Issues I found were fixed and closed at least in 2.7.1 so should be included in my jenkins version.
Remove getName() method from your class. When you specify class field like String name you get methods String getName() and void setName(String name) out of the box.
Keep in mind that Jenkins Groovy script execution environment is a little bit different than the plain Groovy (e.g. in Groovy console) - Jenkins uses groovy-cps execution environment.
In your case following class org.kohsuke.groovy.sandbox.impl.Checker caused errors - according to your stack trace calling Komponente.getName() triggered Komponente.getProperty() method through the following execution chain:
at Komponente.getProperty(script)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
at Komponente.getName(script:10)
And Komponente.getProperty() triggered Komponente.getName() and you run into infinite loop that caused StackOverflowError.
Similar problem happened when I copied your class to my test pipeline script, here is the stack trace I got:
Started by user admin
[Pipeline] End of Pipeline
java.lang.StackOverflowError: Excessively nested closures/functions at Komponente.getName(WorkflowScript:10) - look for unbounded recursion - call depth: 1025
at com.cloudbees.groovy.cps.impl.CpsFunction.invoke(CpsFunction.java:28)
at com.cloudbees.groovy.cps.impl.CpsCallableInvocation.invoke(CpsCallableInvocation.java:40)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:62)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
It's not that straightforward as yours, but it is caused by the same thing. When I removed String getName() method it worked as expected. It should work for you as well. Hope it helps.

got error when run mahout cat ponut.csv

when i run
mahout cat ponut.csv
got this error
Running on hadoop, using /usr/local/bin/hadoop and HADOOP_CONF_DIR=
MAHOUT-JOB: /Users/shawn/Code/mahout/examples/target/mahout-examples-0.9-job.jar
Exception in thread "main" java.io.FileNotFoundException: donut.csv (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:120)
at org.apache.mahout.classifier.sgd.TrainLogistic.open(TrainLogistic.java:315)
at org.apache.mahout.classifier.sgd.PrintResourceOrFile.main(PrintResourceOrFile.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:72)
at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:145)
at org.apache.hadoop.util.ProgramDriver.driver(ProgramDriver.java:153)
at org.apache.mahout.driver.MahoutDriver.main(MahoutDriver.java:195)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Mahout version is 0.9.
I run mvn install form source.
The file name is donut.csv :)
And it is present at-
examples/src/main/resources/donut.csv
You can try :
bin/mahout cat examples/src/main/resources/donut.csv

jgrapht-jdk1.6 "HelloJGraphT.java" compilation problem

JGraphT package includes some examples to experiment oneself. HelloJGraphT.java is one of them. I can run it, without any error, in Netbeans6.0.1. But, when i use dos command prompt in the following way:
javac -cp jgrapht-jdk1.6.jar HelloJGraphT.java
it compiles. But, if i run it using:
java HelloJGraphT
it gives the following errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jgrapht/Graph
Caused by: java.lang.ClassNotFoundException: org.jgrapht.Graph
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Any clue?
I'm using jdk 1.6
You need to import the JGraphT library to your project.

Resources