-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBackendUiDataService.php
More file actions
144 lines (121 loc) · 6.62 KB
/
BackendUiDataService.php
File metadata and controls
144 lines (121 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace Flowpack\DecoupledContentStore\BackendUi;
use Flowpack\DecoupledContentStore\BackendUi\Dto\ContentReleaseDetails;
use Flowpack\DecoupledContentStore\BackendUi\Dto\ContentReleaseOverviewRow;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\PrunnerJobId;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Repository\RedisEnumerationRepository;
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderingStatistics;
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager;
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingTimeStatisticsStore;
use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService;
use Flowpack\DecoupledContentStore\ReleaseSwitch\Infrastructure\RedisReleaseSwitchService;
use Neos\Flow\Annotations as Flow;
use Flowpack\Prunner\PrunnerApiService;
/**
* @Flow\Scope("singleton")
*/
class BackendUiDataService
{
/**
* @Flow\Inject
* @var PrunnerApiService
*/
protected $prunnerApiService;
/**
* @Flow\Inject
* @var RedisEnumerationRepository
*/
protected $redisEnumerationRepository;
/**
* @Flow\Inject
* @var RedisContentReleaseService
*/
protected $redisContentReleaseService;
/**
* @Flow\Inject
* @var RedisRenderingTimeStatisticsStore
*/
protected $redisRenderingStatisticsStore;
/**
* @Flow\Inject
* @var RedisRenderingErrorManager
*/
protected $redisRenderingErrorManager;
/**
* @Flow\Inject
* @var RedisReleaseSwitchService
*/
protected $redisReleaseSwitchService;
/**
* @Flow\Inject
* @var RedisClientManager
*/
protected $redisClientManager;
public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceIdentifier)
{
$contentReleaseIds = $this->redisContentReleaseService->fetchAllReleaseIds($redisInstanceIdentifier);
$metadata = $this->redisContentReleaseService->fetchMetadataForContentReleases($redisInstanceIdentifier, ...$contentReleaseIds);
$counts = $this->redisEnumerationRepository->countMultiple($redisInstanceIdentifier, ...$contentReleaseIds);
$iterationsCounts = $this->redisRenderingStatisticsStore->countMultipleRenderingStatistics($redisInstanceIdentifier, ...$contentReleaseIds);
$errorCounts = $this->redisRenderingErrorManager->countMultipleErrors($redisInstanceIdentifier, ...$contentReleaseIds);
$lastRenderingStatisticsEntries = $this->redisRenderingStatisticsStore->getLastRenderingStatisticsEntry($redisInstanceIdentifier, ...$contentReleaseIds);
$firstRenderingStatisticsEntries = $this->redisRenderingStatisticsStore->getFirstRenderingStatisticsEntry($redisInstanceIdentifier, ...$contentReleaseIds);
$result = [];
foreach ($contentReleaseIds as $contentReleaseId) {
$lastRendering = RenderingStatistics::fromJsonString($lastRenderingStatisticsEntries->getResultForContentRelease($contentReleaseId));
$firstRendering = RenderingStatistics::fromJsonString($firstRenderingStatisticsEntries->getResultForContentRelease($contentReleaseId));
$result[] = new ContentReleaseOverviewRow(
$contentReleaseId,
$metadata->getResultForContentRelease($contentReleaseId),
$counts->getResultForContentRelease($contentReleaseId),
$iterationsCounts->getResultForContentRelease($contentReleaseId),
$errorCounts->getResultForContentRelease($contentReleaseId),
$lastRendering->getTotalJobs() > 0 ? round($lastRendering->getRenderedJobs()
/ $lastRendering->getTotalJobs() * 100) : 100,
$firstRendering->getRenderedJobs(),
$contentReleaseId->equals($this->redisReleaseSwitchService->getCurrentRelease($redisInstanceIdentifier)),
$this->calculateReleaseSize($redisInstanceIdentifier, $contentReleaseId)
);
}
return $result;
}
private function calculateReleaseSize(RedisInstanceIdentifier $redisInstanceIdentifier, ContentReleaseIdentifier $contentReleaseIdentifier)
{
$redis = $this->redisClientManager->getRedis($redisInstanceIdentifier);
$allKeys = $redis->keys('contentStore:' . $contentReleaseIdentifier->getIdentifier() . ':*');
$size = 0;
foreach ($allKeys as $key) {
// We need to set the `samples` option to 0 here, as the default value is 5 and specifies the number of
// sampled nested values. With 0 all nested values are sampled.
$size += $redis->rawCommand('memory', 'usage', $key, 'samples', '0');
}
// bytes are returned, convert to megabytes
return round($size / 1000000, 2);
}
public function loadDetailsData(ContentReleaseIdentifier $contentReleaseIdentifier, RedisInstanceIdentifier $redisInstanceIdentifier): ContentReleaseDetails
{
$contentReleaseMetadata = $this->redisContentReleaseService->fetchMetadataForContentRelease($contentReleaseIdentifier, $redisInstanceIdentifier);
$contentReleaseJob = $this->prunnerApiService->loadJobDetail($contentReleaseMetadata->getPrunnerJobId()->toJobId());
$manualTransferJobs = count($contentReleaseMetadata->getManualTransferJobIds()) ? array_map(function (PrunnerJobId $item) {
return $this->prunnerApiService->loadJobDetail($item->toJobId());
}, $contentReleaseMetadata->getManualTransferJobIds()) : [];
$renderingStatistics = array_map(function(string $item) {
return RenderingStatistics::fromJsonString($item);
}, $this->redisRenderingStatisticsStore->getRenderingStatistics($contentReleaseIdentifier, $redisInstanceIdentifier));
$renderingErrorCount = count($this->redisRenderingErrorManager->getRenderingErrors($contentReleaseIdentifier, $redisInstanceIdentifier));
$currentReleaseIdentifier = $this->redisReleaseSwitchService->getCurrentRelease($redisInstanceIdentifier);
return new ContentReleaseDetails(
$contentReleaseIdentifier,
$contentReleaseJob,
$this->redisEnumerationRepository->count($contentReleaseIdentifier),
$renderingStatistics,
$renderingErrorCount,
$contentReleaseIdentifier->equals($currentReleaseIdentifier),
$manualTransferJobs
);
}
}