Skip to content

Commit

Permalink
Update Cloud roles file
Browse files Browse the repository at this point in the history
  • Loading branch information
plessbd committed Mar 27, 2019
1 parent 04bc8a8 commit e622509
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class ConfigFilesMigration extends AbstractConfigFilesMigration

private $cloudRolesFilePath;

private $templateCloudRolesFile;

public function __construct($currentVersion, $newVersion)
{
$this->cloudRolesFilePath = CONFIG_DIR."/roles.d/cloud.json";
parent::__construct($currentVersion, $newVersion);
$this->templateCloudRolesFile = DATA_DIR . '/templates/roles.d/cloud.json'
$this->cloudRolesFilePath = CONFIG_DIR . '/roles.d/cloud.json';
parent::__construct($currentVersion, $newVersion);
}

/**
Expand All @@ -29,7 +32,7 @@ public function __construct($currentVersion, $newVersion)
public function execute()
{
if (file_exists($this->cloudRolesFilePath)) {
$this->addCloudRolesGroupBy();
$this->addtoCloudRoles();
}
$this->assertPortalSettingsIsWritable();

Expand All @@ -42,13 +45,14 @@ public function execute()
/**
* Adds new group bys to roles.d/cloud.json
*/
public function addCloudRolesGroupBy()
public function addtoCloudRoles()
{
// Json::loadFile throws an exception if the file is completely empty or if there some other
// problem loading the file. If those exceptions are thrown catch them so the rest of the
// migration script can continue to run
try{
$cloudRolesFile = Json::loadFile($this->cloudRolesFilePath);
$templateCloudRoles = Json::loadFile($this->templateCloudRolesFile);
}
catch(Exception $e){
return false;
Expand All @@ -58,6 +62,9 @@ public function addCloudRolesGroupBy()
foreach($cloudRolesFile['+roles'] as $key => $unused) {
$cloudRolesFile['+roles'][$key]['+query_descripters'][] = array('realm' => 'Cloud', 'group_by' => 'person');
$cloudRolesFile['+roles'][$key]['+query_descripters'][] = array('realm' => 'Cloud', 'group_by' => 'username');
if ($key === '+default') {
$cloudRolesFile['+roles'][$key]['+summary_charts'] = $templateCloudRoles['+roles'][$key]['+summary_charts'];
}
}

// An exception can be thrown if there is a problem writing the file. Catch and log the issue
Expand Down
6 changes: 4 additions & 2 deletions classes/OpenXdmod/Setup/ResourcesSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenXdmod\Setup;

use \CCR\Json;

/**
* Resources setup.
*/
Expand Down Expand Up @@ -195,8 +197,8 @@ private function rolesFileMatches($realm)
return false;
}

return file_get_contents(TEMPLATE_DIR . '/roles.d/' . $realm . '.json')
=== file_get_contents($rolesFile);
return JSON::loadFile(TEMPLATE_DIR . '/roles.d/' . $realm . '.json', false)
=== JSON::loadFile($rolesFile, false);
}

/**
Expand Down
85 changes: 77 additions & 8 deletions configuration/roles.d/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"group_by": "vm_size_memory"
},
{
"realm": "Cloud",
"group_by": "submission_venue"
"realm": "Cloud",
"group_by": "submission_venue"
},
{
"realm": "Cloud",
Expand All @@ -37,6 +37,75 @@
"realm": "Cloud",
"group_by": "username"
}
],
"+summary_charts": [{
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "resource",
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
"metric": "cloud_core_time",
"realm": "Cloud",
"sort_type": "value_desc",
"std_err": false,
"value_labels": false,
"x_axis": true
}],
"total": 1
},
"global_filters": {
"data": [],
"total": 0
},
"legend_type": "off",
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": true,
"title": "Cloud - Total CPU Hours by Resource"
},
{
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "project",
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
"metric": "cloud_num_sessions_started",
"realm": "Cloud",
"sort_type": "value_desc",
"std_err": false,
"value_labels": false,
"x_axis": true
}],
"total": 1
},
"global_filters": {
"data": [],
"total": 0
},
"legend_type": "off",
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": true,
"title": "Cloud - Number of Sessions Started by Project"
}
]
},
"+pub": {
Expand Down Expand Up @@ -65,16 +134,16 @@
"group_by": "vm_size_memory"
},
{
"realm": "Cloud",
"group_by": "submission_venue"
"realm": "Cloud",
"group_by": "submission_venue"
},
{
"realm": "Cloud",
"group_by": "person"
"realm": "Cloud",
"group_by": "person"
},
{
"realm": "Cloud",
"group_by": "username"
"realm": "Cloud",
"group_by": "username"
}
]
}
Expand Down
28 changes: 14 additions & 14 deletions templates/roles.d/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "column",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "project",
"has_std_err": true,
"group_by": "resource",
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
Expand All @@ -69,20 +69,20 @@
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": false,
"title": "Cloud - Total CPU Hours by Project"
"timeseries": true,
"title": "Cloud - Total CPU Hours by Resource"
},
{
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "column",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "project",
"has_std_err": true,
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
Expand All @@ -103,7 +103,7 @@
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": false,
"timeseries": true,
"title": "Cloud - Number of Sessions Started by Project"
}
]
Expand Down Expand Up @@ -134,16 +134,16 @@
"group_by": "vm_size_memory"
},
{
"realm": "Cloud",
"group_by": "submission_venue"
"realm": "Cloud",
"group_by": "submission_venue"
},
{
"realm": "Cloud",
"group_by": "person"
"realm": "Cloud",
"group_by": "person"
},
{
"realm": "Cloud",
"group_by": "username"
"realm": "Cloud",
"group_by": "username"
}
]
}
Expand Down

0 comments on commit e622509

Please sign in to comment.