Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GT-145] Fixing, Refreshing and Enriching the Service Group Sample Data #470

Merged
merged 10 commits into from
Sep 14, 2023
8 changes: 5 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,11 @@ $ php deploy/DeployRequiredDataRunner.php requiredData

You can choose to deploy some sample data to seed your database. It consists of
a project which contains 2 NGIs, and another NGI not in a project. Each NGI contains
multiple sites which have services belonging to service groups, and the database is
populated with unique sample users, which have roles over relevant site, NGI and
project entities. The sample data has no real-world associations.
multiple sites, and each site has 1-5 services. Each service belongs to at least one
service group, of which there are 7. Each service group has 5-8 services. The
database is populated with unique sample users, which have roles over relevant site,
NGI, project and service group entities. The sample data has no real-world
associations.

```bash
$ cd lib/Doctrine
Expand Down
92 changes: 92 additions & 0 deletions lib/Doctrine/deploy/AddServiceGroupRoles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

require_once __DIR__ . "/../bootstrap.php";
require_once __DIR__ . "/AddUtils.php";

$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] .
"/UsersAndRoles.xml";
$usersRoles = simplexml_load_file($usersRolesFileName);

foreach ($usersRoles as $user) {
foreach ($user->USER_ROLE as $role) {
// Check for blank role, skip if it's blank
if ((string) $role->USER_ROLE == "") {
continue;
}

// Skip all non-serviceGroup roles
if ((string) $role->ENTITY_TYPE !== "serviceGroup") {
continue;
}

// get roletype entity
$userRole = (string) $role->USER_ROLE;
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(':roleType', $userRole)
->getResult();

/*
* Error checking: ensure each role type refers to exactly
* one role type
*/
if (count($roleTypes) !== 1) {
throw new Exception(count($roleTypes) . " role types " .
"found with name: " . $userRole);
}

// Set $roleType as the first and only role type in the
// roleTypes array
$roleType = $roleTypes[0];

// Get user entity
$userDN = (string) $user->CERTDN;
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up " .
"WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue', trim($userDN))
->getResult();

/*
* Error checking: ensure each "user" refers to exactly
* one user
*/
if (count($users) !== 1) {
throw new Exception(count($users) . " users found with DN: " .
$userDN);
}

// Set $doctrineUser as the first and only user in the users array
$doctrineUser = $users[0];

// get serviceGroup entity
$sgName = (string) $role->ON_ENTITY;
$dql = "SELECT sg FROM ServiceGroup sg WHERE sg.name = :service_group";
$serviceGroups = $entityManager->createQuery($dql)
->setParameter('service_group', $sgName)
->getResult();

/*
* Error checking: ensure each "service group" refers to exactly
* one service group
*/
if (count($serviceGroups) !== 1) {
throw new Exception(count($serviceGroups) . " Service Groups " .
"found name: " . $sgName);
}

// Set $serviceGroup as the first and only service group in the
// serviceGroups array
$serviceGroup = $serviceGroups[0];

$doctrineRole = new Role(
$roleType,
$doctrineUser,
$serviceGroup,
'STATUS_GRANTED'
);
$entityManager->persist($doctrineRole);
}
}

$entityManager->flush();
69 changes: 48 additions & 21 deletions lib/Doctrine/deploy/AddServiceGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* the doctrine prototype.
* XML format is the PROM GOCDB PI output for get_service_type
*/

$stFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceGroups.xml";
$sts = simplexml_load_file($stFileName);

Expand All @@ -25,36 +26,62 @@
$name = "";
$desc = "";
$monitored = false;
$email = "default@an_email.net";
$scope = "Local";
$email = "";
$scope = "";

foreach ($st as $key => $value) {
switch ($key) {
case "NAME":
$name = (string) $value;
break;
case "DESCRIPTION":
$desc = (string) $value;
break;
case "MONITORED":
if ( (string) $value == "Y") {$monitored = true;}
break;
case "CONTACT_EMAIL":
$email = (string) $value;
break;
case "SCOPE":
$scope = (string) $value;
break;
default:
break;
if ((string) $key == "NAME") {
$name = (string) $value;
}

if ((string) $key == "DESCRIPTION") {
$desc = (string) $value;
}

if ((string) $key == "MONITORED") {
if ((string) $value == "Y") {
$monitored = true;
}
}

if ((string) $key == "CONTACT_EMAIL") {
$email = (string) $value;
}
}

$instance->setName($name);
$instance->setDescription($desc);
$instance->setMonitored($monitored);
$instance->setEmail($email);
$instance->addScope(getScope($entityManager, $scope));

// Add the owned scope(s) to the service group
$sc = $st->SCOPES;
// Iterate through each owned scope
foreach ($sc->SCOPE as $sco) {
// Retrieve the scope
$scope = (string) $sco;

// Add the scope to the service group
$instance->addScope(getScope($entityManager, $scope));
}

// Add the owned services to the service group
// Iterate through each owned service
foreach ($st->SERVICE_ENDPOINT as $se) {
// Retrieve the service's hostname
$seName = (string) $se->HOSTNAME;

/* Query to find the service specified by hostname
* getSingleResult() ensures only one service is returned
*/
$dql = "SELECT s FROM Service s WHERE s.hostName = ?1";
$serviceName = $entityManager->createQuery($dql)
->setParameter(1, $seName)
->getSingleResult();

// Add the service to the service group
$instance->addService($serviceName);
}

$entityManager->persist($instance);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/deploy/DeploySampleDataRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
require __DIR__."/AddServiceEndpoints.php";
echo "Added Services, EndpointLocations and JOINED associations OK\n";

require __DIR__."/AddServiceGroups.php";
echo "Added Service Groups OK\n";

require __DIR__."/AddUsers.php";
echo "Added Users OK\n";

Expand All @@ -51,5 +54,5 @@
require __DIR__."/AddProjectRoles.php";
echo "Added EGI level Roles OK\n";

require __DIR__."/AddServiceGroups.php";
echo "Added Service Groups OK\n";
require __DIR__ . "/AddServiceGroupRoles.php";
echo "Added Service Group level Roles OK\n";
42 changes: 40 additions & 2 deletions lib/Doctrine/deploy/sampleData/ServiceEndpoints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
</SERVICE_ENDPOINT>
<SERVICE_ENDPOINT PRIMARY_KEY="75083G0">
<PRIMARY_KEY>75083G0</PRIMARY_KEY>
<HOSTNAME>sgas.smscg.ch</HOSTNAME>
<HOSTNAME>sgas.torchit.ch</HOSTNAME>
<GOCDB_PORTAL_URL>https://testing.host.com/portal/index.php?Page_Type=View_Object&amp;object_id=119910&amp;grid_id=0</GOCDB_PORTAL_URL>
<HOSTDN>/DC=com/DC=quovadisglobal/DC=grid/DC=Torch/DC=hosts/C=CH/ST=Zuerich/L=Zuerich/O=SWITCH/CN=sgas.smscg.ch</HOSTDN>
<HOSTDN>/DC=com/DC=quovadisglobal/DC=grid/DC=Torch/DC=hosts/C=CH/ST=Zuerich/L=Zuerich/O=SWITCH/CN=sgas.torchit.ch</HOSTDN>
<DESCRIPTION>Torch IT SGAS</DESCRIPTION>
<HOST_OS>Debian 6.0.6</HOST_OS>
<BETA>N</BETA>
<SERVICE_TYPE>SGAS</SERVICE_TYPE>
Expand Down Expand Up @@ -376,6 +377,23 @@
<ROC_NAME>NGI_SI</ROC_NAME>
<URL></URL>
</SERVICE_ENDPOINT>
<SERVICE_ENDPOINT PRIMARY_KEY="4184G0">
<PRIMARY_KEY>4184G0</PRIMARY_KEY>
<HOSTNAME>lfc.izolamrf.si</HOSTNAME>
<GOCDB_PORTAL_URL>https://testing.host.com/portal/index.php?Page_Type=View_Object&amp;object_id=4184&amp;grid_id=0</GOCDB_PORTAL_URL>
<DESCRIPTION>Local LFC for Izola MRF</DESCRIPTION>
<SERVICE_TYPE>Local-LFC</SERVICE_TYPE>
<HOST_IP>185.666.22.14</HOST_IP>
<SCOPE>Local</SCOPE>
<CORE></CORE>
<IN_PRODUCTION>N</IN_PRODUCTION>
<NODE_MONITORED>Y</NODE_MONITORED>
<SITENAME>Izola MRF</SITENAME>
<COUNTRY_NAME>Slovenia</COUNTRY_NAME>
<COUNTRY_CODE>SI</COUNTRY_CODE>
<ROC_NAME>NGI_SI</ROC_NAME>
<URL></URL>
</SERVICE_ENDPOINT>
<SERVICE_ENDPOINT PRIMARY_KEY="10007G0">
<PRIMARY_KEY>10007G0</PRIMARY_KEY>
<HOSTNAME>uni-bdii.grid-ljubljana-uni.si</HOSTNAME>
Expand Down Expand Up @@ -495,6 +513,26 @@
<ROC_NAME>NGI_HU</ROC_NAME>
<URL></URL>
</SERVICE_ENDPOINT>
<SERVICE_ENDPOINT PRIMARY_KEY="9067G0">
<PRIMARY_KEY>9067G0</PRIMARY_KEY>
<HOSTNAME>sgas.BudapestNRF-gridoperations.hu</HOSTNAME>
<GOCDB_PORTAL_URL>https://testing.host.com/portal/index.php?Page_Type=View_Object&amp;object_id=9067&amp;grid_id=0</GOCDB_PORTAL_URL>
<HOSTDN>/DC=com/DC=quovadisglobal/DC=grid/DC=BudapestNRF/DC=hosts/C=HU/ST=Budapest/L=Budapest/O=SWITCH/CN=sgas.BudapestNRF-gridoperations.hu</HOSTDN>
<DESCRIPTION>Budapest NRF SGAS</DESCRIPTION>
<HOST_OS>Debian 6.0.6</HOST_OS>
<BETA>N</BETA>
<SERVICE_TYPE>SGAS</SERVICE_TYPE>
<HOST_IP>130.59.204.77</HOST_IP>
<SCOPE>Local</SCOPE>
<CORE></CORE>
<IN_PRODUCTION>N</IN_PRODUCTION>
<NODE_MONITORED>N</NODE_MONITORED>
<SITENAME>Budapest NRF - Grid Operations</SITENAME>
<COUNTRY_NAME>Hungary</COUNTRY_NAME>
<COUNTRY_CODE>HU</COUNTRY_CODE>
<ROC_NAME>NGI_HU</ROC_NAME>
<URL></URL>
</SERVICE_ENDPOINT>
<SERVICE_ENDPOINT PRIMARY_KEY="4981G0">
<PRIMARY_KEY>4981G0</PRIMARY_KEY>
<HOSTNAME>lake-bdii.lakesidepprf.hu</HOSTNAME>
Expand Down
Loading
Loading