DIRACGrid/DIRAC — Issue #342: BUG in MightyOptimizer (v6r0)
Author: graciani
Created: 2011-12-01 14:54:30+00:00
State: open
Labels: Bug, WMS

Optimizers should be imported also from the extensions, this is a possible fix:

```python
from DIRAC.ConfigurationSystem.Client.Helpers import getInstalledExtensions
```

```python

def __loadOptimizer( self, optimizerName ):
"""Need to load an optimizer
"""
gLogger.info( "Loading optimizer %s" % optimizerName )
try:
agentName = "%sAgent" % optimizerName
for ext in getInstalledExtensions():
try:
optimizerModule = __import__( '%s.WorkloadManagementSystem.Agent.%s' % ( ext, agentName ),
globals(),
locals(), agentName )
break
except:
continue
optimizerClass = getattr( optimizerModule, agentName )
optimizer = optimizerClass( "WorkloadManagement/%s" % agentName, self.am_getModuleParam( 'fullName' ) )
result = optimizer.am_initialize( self.jobDB, self.jobLoggingDB )
if not result[ 'OK' ]:
return S_ERROR( "Can't initialize optimizer %s: %s" % ( optimizerName, result[ 'Message' ] ) )
except Exception, e:
gLogger.exception( "LOADERROR" )
return S_ERROR( "Can't load optimizer %s: %s" % ( optimizerName, str( e ) ) )
return S_OK( optimizer )
```

But the main problem is that jobs pass the chain:

2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer INFO: Adding record for job 553790: 'status/minor/app=Checking/JobSanity/idem' from JobSanity
2011-12-01 13:24:29 UTC WorkloadManagement/JobSanityAgent VERB: self.jobDB.setNextOptimizer(553790,'JobSanity')
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer INFO: Next optimizer for job 553790 is AncestorFiles 2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer INFO: Loading optimizer AncestorFiles
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: LOADERROR
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: == EXCEPTION ==
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: :No module named AncestorFilesAgent2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: File "/opt/dirac/pro/DIRAC/WorkloadManagementSystem/Agent/MightyOptimizer.py", line 159, in __loadOptimizer
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: locals(), agentName )
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer EXCEPT: ===============
2011-12-01 13:24:29 UTC WorkloadManagement/MightyOptimizer ERROR: Optimizer 553790 Job AncestorFiles: Can't load optimizer AncestorFiles: No module named AncestorFilesAgent

and in the next iteration:

2011-12-01 13:24:59 UTC WorkloadManagement/MightyOptimizer INFO: == Processing job 553790 ==
2011-12-01 13:24:59 UTC WorkloadManagement/MightyOptimizer INFO: Finished optimizing job 553790

The job should have been declared Failed.