Skip to content

Commit 2d0229a

Browse files
committed
[smarcet] - #13689
* added sangria UI to fix user missmatch errors * added sangria UI to report AUC metric ( with CSV export) * refactored AUC services to log on DB user missmatch errors * refactored AUC services to use translation user table as a last resort to match OpenStack Users with AUC users
1 parent 96dc743 commit 2d0229a

43 files changed

Lines changed: 2047 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

auc-metrics/_config/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Injector:
2020
Member:
2121
extensions:
2222
- AUCMetricMember
23+
SangriaPage_Controller:
24+
extensions:
25+
- SangriaAUCExtension
26+
SangriaApi:
27+
extensions:
28+
- SangriaAUCRouterApiExtension
2329
AUCActiveCommitterService:
2430
user: openstackdev
2531
keyfile: '/root/.ssh/id_rsa'

auc-metrics/_config/injector.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
Name: 'auc-metrics-injection'
3+
---
4+
Injector:
5+
MemberRepository:
6+
class: SapphireMemberRepository
7+
AUCMetricRepository:
8+
class: SapphireAUCMetricRepository
9+
AUCMetricMissMatchErrorRepository:
10+
class: SapphireAUCMetricMissMatchErrorRepository
11+
AUCMetricService:
12+
constructor:
13+
0: '%$AUCMetricMissMatchErrorRepository'
14+
1: '%$MemberRepository'
15+
2: '%$TransactionManager'
16+
SangriaAucMetricsRestfullApi:
17+
constructor:
18+
0: '%$AUCMetricRepository'
19+
SangriaAucMetricsUserMissMatchesRestfullApi:
20+
constructor:
21+
0: '%$AUCMetricMissMatchErrorRepository'
22+
1: '%$AUCMetricService'
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class SangriaAUCExtension
17+
*/
18+
final class SangriaAUCExtension extends Extension
19+
{
20+
static $allowed_actions = [
21+
'AUCFixMissMatchConflicts',
22+
'AUCMetricsList',
23+
];
24+
25+
public function onBeforeInit()
26+
{
27+
Config::inst()->update(get_class($this), 'allowed_actions', self::$allowed_actions);
28+
Config::inst()->update(get_class($this->owner), 'allowed_actions', self::$allowed_actions);
29+
}
30+
31+
public function AUCFixMissMatchConflicts(SS_HTTPRequest $request)
32+
{
33+
Requirements::css("sangria/ui/source/css/sangria.css");
34+
return $this->owner->Customise
35+
(
36+
['OpenStackResourceApiBaseUrl' => OPENSTACK_RESOURCE_API_BASE_URL]
37+
)->renderWith(array('SangriaPage_AUCFixMissMatchConflicts', 'SangriaPage', 'SangriaPage'));
38+
}
39+
40+
public function AUCMetricsList(SS_HTTPRequest $request){
41+
42+
Requirements::css("sangria/ui/source/css/sangria.css");
43+
Requirements::css('node_modules/jquery-datetimepicker/build/jquery.datetimepicker.min.css');
44+
45+
Requirements::javascript('node_modules/php-date-formatter/js/php-date-formatter.min.js');
46+
Requirements::javascript('node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js');
47+
48+
return $this->owner->Customise
49+
(
50+
[]
51+
)->renderWith(array('SangriaPage_AUCMetricsList', 'SangriaPage', 'SangriaPage'));
52+
}
53+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class SangriaAucMetricsRestfullApi
17+
*/
18+
final class SangriaAucMetricsRestfullApi extends AbstractRestfulJsonApi
19+
{
20+
21+
/**
22+
* @var IAUCMetricRepository
23+
*/
24+
private $repository;
25+
26+
/**
27+
* SangriaAucMetricsRestfullApi constructor.
28+
* @param IAUCMetricRepository $repository
29+
*/
30+
public function __construct(IAUCMetricRepository $repository)
31+
{
32+
parent::__construct();
33+
$this->repository = $repository;
34+
}
35+
36+
/**
37+
* @return bool
38+
*/
39+
public function authorize(){
40+
//check permissions
41+
if(!Permission::check("SANGRIA_ACCESS"))
42+
return false;
43+
return true;
44+
}
45+
46+
static $url_handlers = [
47+
' user-miss-matches' => 'handleUserMissMatches',
48+
'GET ' => 'getMetrics',
49+
'GET csv' => 'exportMetricToCSV',
50+
];
51+
52+
static $allowed_actions = [
53+
'handleUserMissMatches',
54+
'getMetrics',
55+
'exportMetricToCSV',
56+
];
57+
58+
/**
59+
* @param SS_HTTPRequest $request
60+
* @return mixed|SS_HTTPResponse
61+
*/
62+
function handleUserMissMatches(SS_HTTPRequest $request){
63+
$api = SangriaAucMetricsUserMissMatchesRestfullApi::create();
64+
return $api->handleRequest($request, DataModel::inst());
65+
}
66+
67+
/**
68+
* @param SS_HTTPRequest $request
69+
* @return SS_HTTPResponse
70+
*/
71+
function getMetrics(SS_HTTPRequest $request){
72+
try
73+
{
74+
$query_string = $request->getVars();
75+
$page = intval((isset($query_string['page'])) ? Convert::raw2sql($query_string['page']) : 0);
76+
$page_size = intval((isset($query_string['page_size'])) ? Convert::raw2sql($query_string['page_size']) : 25);
77+
78+
// zero mean showing all ...
79+
if($page_size == 0) $page_size = PHP_INT_MAX;
80+
81+
$order = (isset($query_string['order'])) ? Convert::raw2sql($query_string['order']) : '';
82+
$filter = (isset($query_string['filter'])) ? Convert::raw2sql($query_string['filter']) : '';
83+
$search_term = (isset($query_string['search_term'])) ? Convert::raw2sql($query_string['search_term']) : '';
84+
$type = (isset($query_string['type'])) ? Convert::raw2sql($query_string['type']) : '';
85+
86+
list($list, $count) = $this->repository->getAllByPage
87+
(
88+
$page,
89+
$page_size,
90+
$order,
91+
$search_term,
92+
$type,
93+
$filter
94+
);
95+
96+
$items = [];
97+
foreach ($list as $item){
98+
$expires_epoch = new DateTime($item->Expires);
99+
$created_epoch = new DateTime($item->Created);
100+
$items[] =
101+
[
102+
'id' => intval($item->ID),
103+
'identifier' => $item->Identifier,
104+
'value' => $item->Value,
105+
'value_description' => $item->ValueDescription,
106+
'created' => $created_epoch->format("Y-m-d h:i:s A"),
107+
'expires' => $expires_epoch->format("Y-m-d h:i:s A"),
108+
'member_id' => intval($item->FoundationMember()->ID),
109+
'member_full_name' => $item->FoundationMember()->FullName,
110+
'member_email' => $item->FoundationMember()->Email,
111+
];
112+
}
113+
114+
return $this->ok(array('items' => $items, 'count' => $count));
115+
}
116+
catch(NotFoundEntityException $ex2)
117+
{
118+
SS_Log::log($ex2->getMessage(), SS_Log::WARN);
119+
return $this->notFound($ex2->getMessage());
120+
}
121+
catch(Exception $ex)
122+
{
123+
SS_Log::log($ex->getMessage(), SS_Log::ERR);
124+
return $this->serverError();
125+
}
126+
}
127+
128+
/**
129+
* @param SS_HTTPRequest $request
130+
*/
131+
function exportMetricToCSV(SS_HTTPRequest $request){
132+
133+
$query_string = $request->getVars();
134+
$order = (isset($query_string['order'])) ? Convert::raw2sql($query_string['order']) : '';
135+
$search_term = (isset($query_string['search_term'])) ? Convert::raw2sql($query_string['search_term']) : '';
136+
$type = (isset($query_string['type'])) ? Convert::raw2sql($query_string['type']) : '';
137+
$filter = (isset($query_string['filter'])) ? Convert::raw2sql($query_string['filter']) : '';
138+
139+
list($list, $count) = $this->repository->getAllByPage
140+
(
141+
1,
142+
PHP_INT_MAX,
143+
$order,
144+
$search_term,
145+
$type,
146+
$filter
147+
);
148+
149+
$filename = "AUCMetrics" . date('Ymd') . ".csv";
150+
151+
$items = [];
152+
foreach ($list as $item){
153+
$expires_epoch = new DateTime($item->Expires);
154+
$created_epoch = new DateTime($item->Created);
155+
$items[] =
156+
[
157+
'id' => intval($item->ID),
158+
'identifier' => $item->Identifier,
159+
'value' => $item->Value,
160+
'value_description' => $item->ValueDescription,
161+
'created' => $created_epoch->format("Y-m-d h:i:s A"),
162+
'expires' => $expires_epoch->format("Y-m-d h:i:s A"),
163+
'member_id' => intval($item->FoundationMember()->ID),
164+
'member_full_name' => $item->FoundationMember()->FullName,
165+
'member_email' => $item->FoundationMember()->Email,
166+
];
167+
}
168+
169+
return CSVExporter::getInstance()->export($filename, $items, ',');
170+
}
171+
}

0 commit comments

Comments
 (0)