1
2
3
4
5
6
7 """This module has to be used to migrate older versions of GangaObjects (plugins) manually or within a script.
8 It is not suitable for repository migration when its internals change.
9 IMPORTANT: Once migrated the plugins may not be backward compatible."""
10
11 import Ganga.GPIDev.Streamers.MigrationControl as MigrationControl
12
13 import Ganga.Utility.logging
14 logger = Ganga.Utility.logging.getLogger()
15
16 _migrate_at_once = 100
17
18
20 """This function transforms older versions of GangaObjects to the current versions.
21 The migration is made in place over repository, i.e. it does not affect the job registry.
22 Therefore the job registry has to be rescanned after the migration. One may use jobs._impl._scan_repository() to do so.
23 Only completely converted jobs will be migrated. No jobs in "incomplete" state will be saved in the repository.
24 IMPORTANT: Once migrated the plugins may not be backward compatible.
25 Arguments:
26 repository - current job repository (can be accessed as jobs._impl._repository)
27 migration_control - migration control object that allows/denies migration of particular plugins (an instance of MigrationControl class)
28 If this argument is ommitted the migration will require interactive input.
29
30 Example of usage within a script:
31 from Ganga.GPIDev.Streamers.MigrationControl import MigrationControl
32 migration_control = MigrationControl()
33 migration_control.allow() #allows migration of all possible plugins
34 migrateGangaObjects(jobs._impl.repository, migration_control)
35 jobs._impl._scan_repository()
36 """
37
38 migration = MigrationControl.migration
39 if migration_control:
40 MigrationControl.migration = migration_control
41 try:
42 ids = repository.getJobIds({})
43 nn = 0
44 while ids:
45 ids_m = ids[:_migrate_at_once]
46 ids = ids[_migrate_at_once:]
47 try:
48 jobs = repository.checkoutJobs(ids_m)
49 except Exception, e:
50 msg = "Error while getting jobs from repository: " + str(e)
51 logger.error(msg)
52 else:
53 try:
54 jobs = filter(lambda j: j.status != "incomplete", jobs)
55 repository.commitJobs(jobs)
56 except Exception, e:
57 msg = "Error while saving converted jobs in the repository: " + str(e)
58 logger.error(msg)
59 else:
60 nn+=len(jobs)
61 finally:
62 MigrationControl.migration = migration
63