Skip to content

Commit ddf6357

Browse files
committed
Add scripts to ease migration to new WLCG heirachical scope structure
- scripts should create and then apply the new scope tags
1 parent 9c97f14 commit ddf6357

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* Script to query and update each Site with WLCG scope tags to migrate them
5+
* to a new heirachical structure.
6+
*
7+
* Desired Behaviour:
8+
* Sites get every possible combination of their existing WLCG VO and tierN
9+
* scope tags in the new heirachical structure.
10+
* - a site with alice and tier1 should get alice.tier1
11+
* - a site with alice, atlas and tier2 should get alice.tier2 and atlas.tier2
12+
* - a site with atlas and tier2 should get atlas.tier2
13+
* - a site with alice, tier1 and tier2 should get alice.tier1 and alice.tier2
14+
* - a site with alice, atlas, tier1 and tier2 should get
15+
* - alice.tier1
16+
* - alice.tier2
17+
* - atlas.tier1
18+
* - atlas.tier2
19+
*
20+
* This script is intended to be one time use, i.e. once it has run to
21+
* completion - I don't anticpate needing the script again.
22+
* However, effort has been taken to ensure the script can be safely
23+
* run muliptle times - i.e. should a update randomly fail, the whole
24+
* script can be re-run.
25+
*
26+
* Usage: php resources/wlcg-scope-tag-migration/WLCGScopeTagAddRunner.php
27+
*/
28+
29+
require_once dirname(__FILE__) . "/../../lib/Doctrine/bootstrap.php";
30+
require dirname(__FILE__) . '/../../lib/Doctrine/bootstrap_doctrine.php';
31+
require_once dirname(__FILE__) . '/../../lib/Gocdb_Services/Factory.php';
32+
33+
// This will supply the WLCG VO and tierN scope tags.
34+
require_once dirname(__FILE__) . "/WLCGScopeTagList.php";
35+
36+
37+
$sectionBreak = "=========================================================\n";
38+
$em = $entityManager;
39+
40+
echo "Querying for all sites\n";
41+
$siteDql = "SELECT s FROM Site s";
42+
$allSitesList = $entityManager->createQuery($siteDql)->getResult();
43+
44+
echo "Starting update of Sites: " . date('D, d M Y H:i:s') . "\n";
45+
echo $sectionBreak;
46+
47+
foreach ($allSitesList as $site) {
48+
echo $site->getShortName() . ":\n";
49+
50+
$siteScopes = $site->getScopes()->toArray();
51+
52+
// Sites can support multiple CERN VOs - at any and multiple tiers.
53+
// Check each combination in turn.
54+
foreach ($wlcgScopesList as $wlcgScope) {
55+
foreach ($tierScopesList as $tierScope) {
56+
if (
57+
(in_array($wlcgScope, $siteScopes)) &&
58+
(in_array($tierScope, $siteScopes))
59+
) {
60+
$newScopeName = $wlcgScope . "." . $tierScope;
61+
62+
// check if new scope has been already applied
63+
// (from a previous run).
64+
if (in_array($newScopeName, $siteScopes)) {
65+
echo "Skipping, site already has " . $newScopeName . "\n";
66+
continue;
67+
} else {
68+
// apply new scope tag in a transaction.
69+
$em->getConnection()->beginTransaction();
70+
try {
71+
// need the object not the name to add to a site.
72+
$site->addScope($allScopeDict[$newScopeName]);
73+
$em->merge($site);
74+
$em->flush();
75+
$em->getConnection()->commit();
76+
echo "Added " . $newScopeName . "\n";
77+
} catch (\Exception $ex) {
78+
$em->getConnection()->rollback();
79+
$em->close();
80+
throw $ex;
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}
87+
88+
$em->flush();
89+
echo "Completed ok: " . date('D, d M Y H:i:s') . "\n";
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* Script to create new scope tags for the WLCG new heirachical structure.
5+
*
6+
* Desired Behaviour:
7+
* Create every combination of VO.tierN for the supplied WLCG VO and tierN
8+
* scope tags.
9+
*
10+
* This script is intended to be one time use, i.e. once it has run to
11+
* completion - I don't anticpate needing the script again.
12+
* However, effort has been taken to ensure the script can be safely
13+
* run muliptle times - i.e. should a update randomly fail, the whole
14+
* script can be re-run.
15+
*
16+
* Usage: php resources/wlcg-scope-tag-migration/WLCGScopeTagCreateRunner.php
17+
*/
18+
19+
require_once dirname(__FILE__) . "/../../lib/Doctrine/bootstrap.php";
20+
require dirname(__FILE__) . '/../../lib/Doctrine/bootstrap_doctrine.php';
21+
require_once dirname(__FILE__) . '/../../lib/Gocdb_Services/Factory.php';
22+
23+
// This will supply the WLCG VO and tierN scope tags.
24+
require_once dirname(__FILE__) . "/WLCGScopeTagList.php";
25+
26+
$sectionBreak = "=========================================================\n";
27+
$em = $entityManager;
28+
$serv = \Factory::getScopeService();
29+
30+
echo "Starting creation of Scopes: " . date('D, d M Y H:i:s') . "\n";
31+
32+
foreach ($wlcgScopesList as $wlcgScope) {
33+
foreach ($tierScopesList as $tierScope) {
34+
$newScopeName = $wlcgScope . "." . $tierScope;
35+
36+
echo "Trying to create " . $newScopeName . "\n";
37+
38+
if (in_array($newScopeName, array_keys($allScopeDict))) {
39+
echo "Skipping " . $newScopeName . "\n";
40+
echo "It already exists\n";
41+
echo $sectionBreak;
42+
continue;
43+
}
44+
45+
$newScope = new Scope();
46+
$newScope->setName($newScopeName);
47+
$newScope->setDescription("Tag for WLCG " . $tierScope . " " .
48+
"resources that support the " . $wlcgScope . " VO ");
49+
$newScope->setReserved(true);
50+
51+
$em->getConnection()->beginTransaction();
52+
try {
53+
$em->persist($newScope);
54+
$em->flush();
55+
$em->getConnection()->commit();
56+
} catch (\Exception $e) {
57+
$em->getConnection()->rollback();
58+
$em->close();
59+
throw $e;
60+
}
61+
62+
echo "Done" . "\n";
63+
echo $sectionBreak;
64+
}
65+
}
66+
67+
$em->flush();
68+
echo "Completed ok: " . date('D, d M Y H:i:s') . "\n";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* A simple script to home some variables useful for the WLCG Scope tag
5+
* migration.
6+
*/
7+
8+
$wlcgScopesList = ["alice", "atlas", "belle", "cms", "dune", "lhcb"];
9+
$tierScopesList = ["tier0", "tier1", "tier2", "tier3"];
10+
11+
// Retrieve all scope objects from the DB and store as an dict, with the
12+
// name as the key, for later reference.
13+
$scopeDql = "SELECT s FROM Scope s";
14+
$allScopeList = $entityManager->createQuery($scopeDql)->getResult();
15+
$allScopeDict = [];
16+
foreach ($allScopeList as $scope) {
17+
$allScopeDict[$scope->getName()] = $scope;
18+
}

0 commit comments

Comments
 (0)