15
15
use Symfony \Component \HttpFoundation \Response ;
16
16
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
17
17
use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
18
+ use Symfony \Component \Form \FormInterface ;
18
19
19
20
/**
20
21
* @Route("/admin")
@@ -34,6 +35,16 @@ public function __construct(ElasticsearchShardManager $elasticsearchShardManager
34
35
$ this ->elasticsearchNodeManager = $ elasticsearchNodeManager ;
35
36
}
36
37
38
+ private function filter (array $ shards , FormInterface $ form ): array
39
+ {
40
+ return $ this ->elasticsearchShardManager ->filter ($ shards , [
41
+ 'index ' => $ form ->get ('index ' )->getData (),
42
+ 'type ' => $ form ->get ('type ' )->getData (),
43
+ 'state ' => $ form ->get ('state ' )->getData (),
44
+ 'node ' => $ form ->get ('node ' )->getData (),
45
+ ]);
46
+ }
47
+
37
48
/**
38
49
* @Route("/shards", name="shards")
39
50
*/
@@ -62,12 +73,7 @@ public function index(Request $request): Response
62
73
63
74
$ nodesAvailable = $ this ->elasticsearchShardManager ->getNodesAvailable ($ shards , $ nodes );
64
75
65
- $ shards = $ this ->elasticsearchShardManager ->filter ($ shards , [
66
- 'index ' => $ form ->get ('index ' )->getData (),
67
- 'type ' => $ form ->get ('type ' )->getData (),
68
- 'state ' => $ form ->get ('state ' )->getData (),
69
- 'node ' => $ form ->get ('node ' )->getData (),
70
- ]);
76
+ $ shards = $ this ->filter ($ shards , $ form );
71
77
72
78
return $ this ->renderAbstract ($ request , 'Modules/shard/shard_index.html.twig ' , [
73
79
'shards ' => $ this ->paginatorManager ->paginate ([
@@ -91,24 +97,29 @@ public function stats(Request $request): Response
91
97
{
92
98
$ this ->denyAccessUnlessGranted ('SHARDS_STATS ' , 'global ' );
93
99
100
+ $ nodes = $ this ->elasticsearchNodeManager ->selectNodes (['data ' => 'yes ' ]);
101
+
102
+ $ form = $ this ->createForm (ElasticsearchShardFilterType::class, null , ['node ' => $ nodes ]);
103
+
104
+ $ form ->handleRequest ($ request );
105
+
94
106
$ query = [
95
107
'bytes ' => 'b ' ,
96
108
'h ' => 'index,shard,prirep,state,unassigned.reason,docs,store,node ' ,
97
109
];
98
110
99
- $ shards = $ this ->elasticsearchShardManager ->getAll ($ query );
111
+ $ shards = $ this ->elasticsearchShardManager ->getAll ($ query , [
112
+ 'index ' => $ form ->get ('index ' )->getData (),
113
+ ]);
100
114
101
- $ clusterStats = $ this ->elasticsearchClusterManager -> getClusterStats ( );
115
+ $ shards = $ this ->filter ( $ shards , $ form );
102
116
103
117
$ data = ['totals ' => [], 'tables ' => []];
104
118
$ data ['totals ' ]['shards_total ' ] = 0 ;
105
119
$ data ['totals ' ]['shards_total_primary ' ] = 0 ;
106
- $ data ['totals ' ]['shards_total_unassigned ' ] = 0 ;
107
- if (true === isset ($ clusterStats ['indices ' ]['shards ' ]['replication ' ])) {
108
- $ data ['totals ' ]['shards_replication ' ] = round ($ clusterStats ['indices ' ]['shards ' ]['replication ' ]*100 , 2 ).'% ' ;
109
- }
110
120
$ data ['totals ' ]['shards_total_documents ' ] = 0 ;
111
121
$ data ['totals ' ]['shards_total_size ' ] = 0 ;
122
+ $ data ['totals ' ]['shards_total_unassigned ' ] = 0 ;
112
123
$ data ['tables ' ]['shards_by_state ' ] = [];
113
124
$ data ['tables ' ]['shards_by_unassigned_reason ' ] = [];
114
125
$ data ['tables ' ]['shards_by_type ' ] = [];
@@ -172,6 +183,7 @@ public function stats(Request $request): Response
172
183
173
184
return $ this ->renderAbstract ($ request , 'Modules/shard/shard_stats.html.twig ' , [
174
185
'data ' => $ data ,
186
+ 'form ' => $ form ->createView (),
175
187
]);
176
188
}
177
189
0 commit comments