Fields set inside private method are not exported to zookeeper

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fields set inside private method are not exported to zookeeper

lukestephenon
In the following glu script, all variables are exported as expected.
class GoodScript {
    def x
    def y

    def install = {
        x = 'hello'
        y = 'Glu'
    }
...
}

However, if any fields are set inside a private method (rather than a groovy closure) the value is not exported.

class BadScript {
    def x
    def y

    def install = {
        configureParamsClosure()
        configureParamsMethod()
    }

    def configureParamsClosure = {
        x = 'hello'
    }
    
    private void configureParamsMethod() {
        y = 'Glu'
    }
...
}

In the example above, the field "y" is set, but is not present in the exported state (on disk or to zookeeper).  For us, this meant that everything ran very happily until an agent was restarted.  The fields that the script set inside a private method were not exported and as a result those mount points had to be force uninstalled.

This may be a limitation of groovy, I haven't yet tracked down the root cause of the issue.  If it is a limitation that can't be fixed, would be good to add a warning to the relevant section in the documentation.  I'd also recommend bouncing the agent as part of the testing strategy of any glu script changes.

Anyone know why the field set within a private method is not exported?
Reply | Threaded
Open this post in threaded view
|

Re: Fields set inside private method are not exported to zookeeper

frenchyan
Administrator
This comment in the example: https://github.com/pongasoft/glu/blob/master/scripts/org.linkedin.glu.script-jetty/src/main/groovy/JettyGluScript.groovy#L269 tells about it but I agree I should add a big warning in the documentation. It is not glu, but groovy specific.

This page explains the rules: http://groovy.codehaus.org/Groovy+Beans


Yan