Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

No session after session closed in other step #2463

stephasaurus ·
Hi - I am writing a configuration that contains a step A that gathers a lot of build IDs for certain configurations and saves them to a variable. In a later step B in the same config, I take that set of build IDs, instantiate build objects, and then delete those builds from QuickBuild.

Both of these steps run groovy scripts that follow the following general format:


groovy:
try
{
com.pmease.quickbuild.persistence.SessionManager.openSession();
//stuff
}
finally
{
com.pmease.quickbuild.persistence.SessionManager.closeSession();
}


The problem I'm running into is that step A can run just fine, but step B will error out with:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pmease.quickbuild.model.Build.promotedTo, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)....


The only way I've gotten step B to run successfully after step A is to restart my QB server. After that the config will run successfully once but after that, it will fail on step B with the error above. Step B is using the "build.getPromotedTo" that was mentioned in a previous thread. I have to use system.getBuildManager() in both step A and B, so I have to use open/close session, and A and B can't be combined into one step. Any help resolving this will be much appreciated. Thank you!
  • replies 10
  • views 2591
  • stars 0
robinshen ADMIN ·
Can you please show me the logic of stepB and also please makes sure that step B runs on QB server to make it work.
stephasaurus ·
Yes, step B is running on the server.

Here is the code for it. I've tested it, and it seems to do what I want it to do, but it'll only run successfully after I restart the QB server.


groovy:

try
{
com.pmease.quickbuild.persistence.SessionManager.openSession();
String []buildIds = vars.getValue("buildIds").toString().split(",");

for (id in buildIds)
{
com.pmease.quickbuild.model.Build codeBuild = (com.pmease.quickbuild.model.Build)system.getBuildManager().load(id.toLong());

if(codeBuild.getPromotedFrom() != null)
{
com.pmease.quickbuild.model.Build parentBuild = (com.pmease.quickbuild.model.Build)system.getBuildManager().load(codeBuild.getPromotedFrom().getId().toLong());
system.getBuildManager().delete(parentBuild);
}
deleteBuildsRec(codeBuild);
}
}
finally
{
com.pmease.quickbuild.persistence.SessionManager.closeSession();
}

def deleteBuildsRec(delBuild)
{
if(delBuild.getPromotedTo().size() > 0)
{
for(promotedBuild in delBuild.getPromotedTo())
{
deleteBuildsRec(promotedBuild);
}
}
system.getBuildManager().delete(delBuild);
}
robinshen ADMIN ·
Which QB version are you using? I tested this on latest QB5 version and it works every time.
stephasaurus ·
We are also using QB5. It usually happens if I run the step over and over in quick succession (within 1 minute).
robinshen ADMIN ·
I am running this logic many times within one minute but can not reproduce the issue. Is this happening consistently at your side? If yes, can you please create a sample database demonstrating the issue?
Gouss ·
Hello,

I have the same kind of problem on a node executing a plugin that should list the version name given a configuration.

basically I found on the forum the SessionManager.OpenSession() that does the work when I run the step once logged in but on the node, no session is especially open.


SessionManager.openSession();
try {
for (int idx=0; idx < configList.length; idx++) {
...
Configuration config = Quickbuild.getInstance().getConfigurationManager().get(buildpath);
...
} catch (Exception e) {
throw new QuickbuildException(e.getMessage());
} finally {
SessionManager.closeSession();
}


hopping this will help.

PS: I am searching for a way to create a session for the user that run the job on the nodes but have not found it yet. version is 5.1.6, 2013-12-25
robinshen ADMIN ·
>> "PS: I am searching for a way to create a session for the user that run the job on the nodes but have not found it yet. version is 5.1.6, 2013-12-25"

The database session does not differentiate between users, or do you mean some other thing?
Gouss ·
I would like to use this code in my plugin as a step launched from a node that is not the server but it fails with a "no session or session was closed".

I wondered how to create a session on this type of node or any other solution to have this step working (and avoiding to have a queue of tasks waiting on the server).
robinshen ADMIN ·
Hibernate session only works on server. If you are running from non-server nodes, consider calling grid.serverNode.executeJob to execute the job on server node and then in the job class call hibernate session relevant features to do the job.
Gouss ·
thanks for the tip!