Uploaded image for project: 'OpenNMS'
  1. OpenNMS
  2. NMS-12268

ScriptPolicy scripts encounter LazyInitializationException on calling node.getSnmpInterface()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 24.1.3
    • Fix Version/s: 25.0.0
    • Component/s: None
    • Security Level: Default (Default Security Scheme)
    • Labels:
    • Sprint:
      Horizon 2019 - September 4th, Horizon 2019 - September 11th

      Description

      Steps to reproduce:

      1) Configure a ScriptPolicy in the default foreign-source definition, with its script attribute set to testing.groovy

      2) Create OPENNMS_HOME/etc/script-policies/testing.groovy with the following contents:

      import org.opennms.netmgt.model.OnmsSnmpInterface;
      
      for (OnmsSnmpInterface snmpi : node.getSnmpInterfaces()) {
        LOG.warn("Considering SNMP interface " + snmpi.getIfDescr());
      }
      return node;
      

      3) Provision or rescan an auto-provisioned node, or rescan a requisitioned node

      Expected result:
      Messages in provisiond.log corresponding to the LOG.warn in the script above

      Actual result:
      Exception stack traces in provisiond.log indicating the node's SNMP interfaces failed to load:

      2019-09-06 15:20:45,401 WARN  [scanExecutor-9] o.o.n.p.p.p.ScriptPolicy: Error applying ScriptPolicy.
      javax.script.ScriptException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.opennms.netmgt.model.OnmsNode.snmpInterfaces, no session or session was closed
      	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:355) ~[groovy-all-2.4.5.jar:2.4.5]
      	at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.5.jar:2.4.5]
      	at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
      	at org.opennms.netmgt.provision.persist.policies.ScriptPolicy.act(ScriptPolicy.java:127) [opennms-provision-persistence-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.persist.policies.ScriptPolicy.act(ScriptPolicy.java:56) [opennms-provision-persistence-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.BasePolicy.apply(BasePolicy.java:268) [opennms-provision-api-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.persist.policies.ScriptPolicy.apply(ScriptPolicy.java:56) [opennms-provision-persistence-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.service.NodeInfoScan.collectNodeInfo(NodeInfoScan.java:172) [opennms-provisiond-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.service.NodeInfoScan.access$000(NodeInfoScan.java:50) [opennms-provisiond-24.1.3.jar:?]
      	at org.opennms.netmgt.provision.service.NodeInfoScan$1.run(NodeInfoScan.java:82) [opennms-provisiond-24.1.3.jar:?]
      	at org.opennms.core.tasks.TaskBuilder$1.run(TaskBuilder.java:150) [org.opennms.core.tasks-24.1.3.jar:?]
      	at org.opennms.core.tasks.SyncTask.run(SyncTask.java:88) [org.opennms.core.tasks-24.1.3.jar:?]
      	at org.opennms.core.tasks.SyncTask.access$000(SyncTask.java:41) [org.opennms.core.tasks-24.1.3.jar:?]
      	at org.opennms.core.tasks.SyncTask$1.run(SyncTask.java:100) [org.opennms.core.tasks-24.1.3.jar:?]
      	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1736) [?:?]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
      	at java.lang.Thread.run(Thread.java:834) [?:?]
      Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.opennms.netmgt.model.OnmsNode.snmpInterfaces, no session or session was closed
      	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
      	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
      	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
      	at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
      	at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
      	at java_util_Set$iterator.call(Unknown Source) ~[?:?]
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-all-2.4.5.jar:2.4.5]
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-all-2.4.5.jar:2.4.5]
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) ~[groovy-all-2.4.5.jar:2.4.5]
      	at Script26.run(Script26.groovy:5) ~[?:?]
      	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:352) ~[groovy-all-2.4.5.jar:2.4.5]
      	... 20 more
      

       

      Notably, calling node.getIpInterfaces() as is done by the script in etc/examples/script-policies/example.groovy does not cause an equivalent problem. This leads me to think the NodeDao implementation might be missing some initialization for SNMP interfaces.

        Attachments

          Activity

            People

            • Assignee:
              cgorantla Chandra Gorantla
              Reporter:
              jeffg Jeff Gehlbach
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: