* caching added to nightly config
* routes for getting nightly config data
This commit is contained in:
parent
d7d810f815
commit
9cd08908dc
@ -12,6 +12,8 @@ return [
|
|||||||
App\Action\CiExecutorAction::class => App\Action\CiExecutorFactory::class,
|
App\Action\CiExecutorAction::class => App\Action\CiExecutorFactory::class,
|
||||||
App\Action\JcatPackageAction::class => App\Action\JcatPackageFactory::class,
|
App\Action\JcatPackageAction::class => App\Action\JcatPackageFactory::class,
|
||||||
App\Action\CiStreamAction::class => App\Action\CiStreamFactory::class,
|
App\Action\CiStreamAction::class => App\Action\CiStreamFactory::class,
|
||||||
|
App\Action\NightlyByNodesAction::class => App\Action\NightlyByNodesFactory::class,
|
||||||
|
App\Action\NightlyByStreamsAction::class => App\Action\NightlyByStreamsFactory::class,
|
||||||
App\Action\HomePageAction::class => App\Action\HomePageFactory::class,
|
App\Action\HomePageAction::class => App\Action\HomePageFactory::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@ -72,5 +74,17 @@ return [
|
|||||||
'middleware' => App\Action\CiStreamAction::class,
|
'middleware' => App\Action\CiStreamAction::class,
|
||||||
'allowed_methods' => ['GET'],
|
'allowed_methods' => ['GET'],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'api.nightly-by-nodes',
|
||||||
|
'path' => '/api/nightly-by-nodes',
|
||||||
|
'middleware' => App\Action\NightlyByNodesAction::class,
|
||||||
|
'allowed_methods' => ['GET'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'api.nightly-by-streams',
|
||||||
|
'path' => '/api/nightly-by-streams',
|
||||||
|
'middleware' => App\Action\NightlyByStreamsAction::class,
|
||||||
|
'allowed_methods' => ['GET'],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
27
src/App/Action/NightlyByNodesAction.php
Normal file
27
src/App/Action/NightlyByNodesAction.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Response\JsonCorsResponse;
|
||||||
|
use App\Service\CiExecutorService;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
class NightlyByNodesAction extends AbstractAction
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CiExecutorService
|
||||||
|
*/
|
||||||
|
private $ciExecutorService;
|
||||||
|
|
||||||
|
public function __construct(CiExecutorService $ciExecutorService)
|
||||||
|
{
|
||||||
|
$this->ciExecutorService = $ciExecutorService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||||
|
{
|
||||||
|
return new JsonCorsResponse($this->ciExecutorService->getActiveNightlyConfigurationByNode());
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/App/Action/NightlyByNodesFactory.php
Normal file
15
src/App/Action/NightlyByNodesFactory.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Service\CiExecutorService;
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class NightlyByNodesFactory
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$service = $container->get(CiExecutorService::class);
|
||||||
|
return new NightlyByNodesAction($service);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/App/Action/NightlyByStreamsAction.php
Normal file
27
src/App/Action/NightlyByStreamsAction.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Response\JsonCorsResponse;
|
||||||
|
use App\Service\CiExecutorService;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
class NightlyByStreamsAction extends AbstractAction
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CiExecutorService
|
||||||
|
*/
|
||||||
|
private $ciExecutorService;
|
||||||
|
|
||||||
|
public function __construct(CiExecutorService $ciExecutorService)
|
||||||
|
{
|
||||||
|
$this->ciExecutorService = $ciExecutorService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||||
|
{
|
||||||
|
return new JsonCorsResponse($this->ciExecutorService->getActiveNightlyConfiguration());
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/App/Action/NightlyByStreamsFactory.php
Normal file
15
src/App/Action/NightlyByStreamsFactory.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Service\CiExecutorService;
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class NightlyByStreamsFactory
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$service = $container->get(CiExecutorService::class);
|
||||||
|
return new NightlyByStreamsAction($service);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,6 +25,7 @@ class CiExecutorService
|
|||||||
const JCAT_CACHE_KEY = "jcat";
|
const JCAT_CACHE_KEY = "jcat";
|
||||||
const PACKAGE_CACHE_KEY = "packages";
|
const PACKAGE_CACHE_KEY = "packages";
|
||||||
const STREAM_CACHE_KEY = "stream";
|
const STREAM_CACHE_KEY = "stream";
|
||||||
|
const NIGHTLY_CACHE_KEY = "nightly";
|
||||||
|
|
||||||
private $testTypeMap = [
|
private $testTypeMap = [
|
||||||
'isDoRollbackBefore' => 'rollback_before',
|
'isDoRollbackBefore' => 'rollback_before',
|
||||||
@ -692,19 +693,45 @@ class CiExecutorService
|
|||||||
throw new \Exception("Jenkins redirect url is not working, return code was: " . $response->getStatusCode());
|
throw new \Exception("Jenkins redirect url is not working, return code was: " . $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActiveNightlyConfiguration()
|
public function getActiveNightlyConfigurationByNode(bool $forceReload = false)
|
||||||
{
|
{
|
||||||
$nightlyConfigHtml = $this->getNightlyConfigHtml();
|
$activeNightlyByStream = $this->getActiveNightlyConfiguration($forceReload);
|
||||||
$streams = $this->getHtmlDropdownValues($nightlyConfigHtml, "STREAM");
|
$configByNodes = [];
|
||||||
|
foreach ($activeNightlyByStream as $stream => $nodes) {
|
||||||
sort($streams, SORT_NATURAL);
|
foreach($nodes as $node) {
|
||||||
$stapler = $this->getStaplerTokens($nightlyConfigHtml, "STREAM");
|
if(!isset($configByNodes[$node])) { $configByNodes[$node] = []; }
|
||||||
|
array_push($configByNodes[$node], $stream);
|
||||||
$result = [];
|
}
|
||||||
foreach($streams as $stream) {
|
|
||||||
$result[$stream] = $this->getNightlyNodesForStream($stream, $stapler['url'], $stapler['token']);
|
|
||||||
}
|
}
|
||||||
return $result;
|
return $configByNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActiveNightlyConfiguration(bool $forceReload = false)
|
||||||
|
{
|
||||||
|
$cache = $this->getCache(self::NIGHTLY_CACHE_KEY);
|
||||||
|
$result = $cache->getItem(self::NIGHTLY_CACHE_KEY, $success);
|
||||||
|
if (!$success || $forceReload) {
|
||||||
|
$nightlyConfigHtml = $this->getNightlyConfigHtml();
|
||||||
|
$streams = $this->getHtmlDropdownValues($nightlyConfigHtml, "STREAM");
|
||||||
|
|
||||||
|
sort($streams, SORT_NATURAL);
|
||||||
|
$stapler = $this->getStaplerTokens($nightlyConfigHtml, "STREAM");
|
||||||
|
|
||||||
|
$ownNodes = $this->nodeService->getNodeNames();
|
||||||
|
|
||||||
|
$nightly = [];
|
||||||
|
foreach($streams as $stream) {
|
||||||
|
$streamNodes = $this->getNightlyNodesForStream($stream, $stapler['url'], $stapler['token']);
|
||||||
|
$nodeDiff = array_intersect($streamNodes, $ownNodes);
|
||||||
|
if($nodeDiff) {
|
||||||
|
$nightly[$stream] = array_values($nodeDiff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$cache->setItem(self::NIGHTLY_CACHE_KEY, serialize($nightly));
|
||||||
|
} else {
|
||||||
|
$nightly = unserialize($result);
|
||||||
|
}
|
||||||
|
return $nightly;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getHtmlDropdownValues(string $html, string $fieldName): array
|
private function getHtmlDropdownValues(string $html, string $fieldName): array
|
||||||
|
|||||||
@ -133,6 +133,13 @@ class CiNodeService
|
|||||||
return $this->nodes;
|
return $this->nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNodeNames(): array
|
||||||
|
{
|
||||||
|
return array_map(function($node) {
|
||||||
|
return $node["name"];
|
||||||
|
}, $this->nodes);
|
||||||
|
}
|
||||||
|
|
||||||
public function getNode($node): ?array
|
public function getNode($node): ?array
|
||||||
{
|
{
|
||||||
return array_pop(array_filter($this->nodes, function ($item) use ($node) {
|
return array_pop(array_filter($this->nodes, function ($item) use ($node) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user